How do I make my meshes appear shaded?
Most of the time when visualizing meshes in RViz they appear edgy, the shading is not good:
How do I make my mesh appear smooth?
ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
Most of the time when visualizing meshes in RViz they appear edgy, the shading is not good:
How do I make my mesh appear smooth?
A common mistake users tends to do is to subdivide the model to minimize the shading issue, this is NOT good as it increases the poly count of the scene without eliminating the problem!
The right solution is to tweak the shading properties of the mesh; If you have no idea of what shading is please read this little introduction.
You need Blender installed and the Collada I/O add-on (this PPA provides a Blender version with Collada support enabled).
File
> Import
> Collada (Default) (.dae)
Tab
):Ctrl
+Tab
) and select all faces (A
) of the modelSmooth
:Tab
)EdgeSplit
modifier:Result after the smoothing:
You can use this Python script to do the job for you; The script only modifies the selected objects. After that you need to individually tweak the split angle value and apply the modifier on each mesh.
import bpy
import re
# Applies only on selected objects
if len(bpy.context.selected_objects) > 0:
for obj in bpy.context.selected_objects:
if obj.type == 'MESH':
bpy.context.scene.objects.active = obj
bpy.ops.object.editmode_toggle()
bpy.ops.mesh.select_all(action='SELECT')
bpy.ops.mesh.remove_doubles()
bpy.ops.mesh.faces_shade_smooth()
bpy.ops.object.editmode_toggle()
bpy.ops.object.modifier_add(type='EDGE_SPLIT')
# Don't forget to tweak the split angle!
Once you are done tweaking the split angle values, select all your meshes again and use this script to apply the EdgeSplit
modifier:
import bpy
import re
# Apply the EdgeSplit modifier on selected objects
if len(bpy.context.selected_objects) > 0:
for obj in bpy.context.selected_objects:
if obj.type == 'MESH':
bpy.context.scene.objects.active = obj
bpy.ops.object.modifier_apply(apply_as='DATA', modifier="EdgeSplit")
Note that in case something didn't go well, you can easily revert the changes with a Remove doubles
in edit mode and switching back to flat shading.
Edge split only tweaks the vertex normals of the mesh. There is no modification to the mesh (vertices positions) itself. It is just a lightning trick.
Related dicussion: Shaded meshes in RViz, better visualisation.
This won't work for STL
meshes as they only support face normals. This should work for OBJ
and PLY
files but software support might vary. It works with PLY
in Blender but not with OBJ
(it should).
Asked: 2016-02-16 15:16:36 -0600
Seen: 858 times
Last updated: May 04 '17
Display an OGRE mesh and material in RVIZ
how to display a mesh with texture in RViz?
segfault after failed call do `GetParentLink`: collada_joint_publisher with diamondback [closed]
household_database visualization
How to visualize surface normals as Marker::Arrow for each point in rviz?
Corrected Odometry from GMapping / Karto?