Read in an STL file into Blender, add color to it and export it as a DAE file (COLLADA), then feed that into Gazebo.
The color is not displayed correctly. It becomes darker (or brighter, depending on the emission) than the expected color. Expected color (part of the robot):
However, what I get when loading this onto Gazebo is:
The red in the figure above is lighter than the expected red (ignore the stripes; that’s normal for Gazebo). In this article it is assumed that you already have your model in Blender, colored and ready for export. I will not go through how to set up the environment or write the URDF for your robot.
You can’t automatically export the desired color with COLLADA. You need to manually edit the DAE file exported from Blender and set the
emission to proper values. Most of the times it’s enough to set it to the same value as the
- Ubuntu 18.04
- Gazebo 9.5.0
- Blender 2.79
Firstly, whatever you render using Cycles Render is not refleceted to the exported COLLADA file. Whatever you see when you export it using Blender Render is apparently what you get in the COLLADA file. Except, you don’t. When you use a color other than grayscale, you end up getting a color either lighter or darker than what you expect.
The problem arises from the fact that Blender’s COLLADA exported doesn’t handle colored emissions (actually, it seems like a limitation in Blender Render since there’s only one value to be specified for the emission). Emission is the color that the object itself emits. In other words, it’s the color of the object when seen in pitch black. It takes a value between 0 and 1, where 0 is no light emitted (black) and white at 1.
When you specify a value (say 0.4) for emission in Blender, it exports the COLLADA file as follows:
<effect id="Red-effect"> <profile_COMMON> <technique sid="common"> <phong> <emission> <color sid="emission">0.4 0.4 0.4 1</color> </emission> <ambient> <color sid="ambient">0 0 0 1</color> </ambient> <diffuse> <color sid="diffuse">0.6194061 0.024045 0.02145169 1</color> </diffuse> <specular> <color sid="specular">0.5 0.5 0.5 1</color> </specular> <shininess> <float sid="shininess">40</float> </shininess> <index_of_refraction> <float sid="index_of_refraction">1</float> </index_of_refraction> </phong> </technique> </profile_COMMON> </effect>
Notice that the
emission is all 0.4, which is gray. We want this to be red-ish, so we just replace that part manually with:
<emission> <color sid="emission">0.6194061 0.024045 0.02145169 1</color> </emission>
Sadly, there is no way to do this automatically at the moment. This means that if you want to update some of the meshes in Blender and export that to COLLADA, the manual change you just made will be overwritten.