Ask Your Question

Activating shading for a .stl based environment in gazebo

asked 2012-01-20 01:23:40 -0600

updated 2012-01-20 17:59:45 -0600

I built a simple rolling landscape terrain using the sculpt tool in Blender and exported this as STL. Using the terrain in a launch file works ok, but I can't figure out how to activate proper shading so visualization looks nice. I tried many of the available gazebo materials (PR2/Grey1, Gazebo/PioneerBody, Gazebo/White, Gazebo/GrassFloor) but all those resulted in a monochromatic landscape.

The relevant parts of the .world file are:

    <ambient>0.5 0.5 0.5 0.5</ambient>

   <model:physical name="landscape">
   <xyz>0 0 0</xyz> 
   <rpy>0 0 0</rpy>
   <body:trimesh name="landscape_body">
     <geom:trimesh name="landscape_geom">
       <scale>1.0 1.0 1.0</scale>
         <scale>1.0 1.0 1.0</scale>

Screenshot (using PR2/Grey1 material, Gazebo/GrassFloor looks the same, only green)

image description

The monochromatic visualization obviously makes judging distances of terrain features impossible. Shadows for the quadrotor UAV work (but shading apparently does not work).

The .stl, world and launch file are also available in the hector_gazebo_worlds package and can be started using

roslaunch hector_gazebo_worlds rolling_landscape_120m.launch

/edit: So I found out that terrain as well as quadrotor do not receive illumination at all, but if I spawn spheres or other objects via the gazebo toolbar, those receive proper illumination.

Update: I tried playing around with materials and found that there is a difference like night and day (literally ;) ) between built-in primitives and mesh files.

Consider this extract from a URDF file:

  <link name="base_link">
      <mass value="1.316" />
      <origin xyz="0 0 0" />
      <inertia ixx="0.0128" ixy="0.0" ixz="0.0"
      iyy="0.0128" iyz="0.0" 
        izz="0.0218" />

        <origin xyz="0 0 0" rpy="0 0 0" />
           <cylinder radius="0.4" length="0.2"/>
        <material name="DarkGrey" >
          <color rgba="0.3 0.3 0.3 1"/>

        <origin xyz="0 0 0" rpy="0 0 0" />
          <mesh filename="package://hector_quadrotor_urdf/meshes/quadrotor/quadrotor_base.stl"/>
      </c![image description](>


    <gazebo reference="base_link">

Looks like this in gazebo: image description

The cylinder apparently receives correct illumination.

If I now use the following line instead of the cylinder (everything else stays the same, most notably the material!)

 <mesh filename="package://hector_quadrotor_urdf/meshes/quadrotor/quadrotor_base.stl"/>

the same scene looks like this: image description

Can someone explain this? The mesh looks perfectly fine in Blender, Meshlab etc., so I doubt the normals are wrong. It seems very wrong that materials show such differences between being used for built-in primitives and external meshes.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2012-01-20 01:39:49 -0600

DimitriProsser gravatar image

I define my own materials and set them to image files that are non-monochromatic. It helps a bit with this problem. Take a look at the Gazebo.material file in simulator_gazebo/gazebo/gazebo/share/gazebo/Media/materials/scripts for an example. In your package, you can set it up to export materials to Gazebo (because you don't want to modify the simulator_gazebo folder if you didn't install from source). You can find that tutorial here.

edit flag offensive delete link more


The GrassFloor material actually is non-monochromatic and should work when setting genTexCoord to true, right? Doesn't work for me (in this scenario). While having a texture is better than nothing, I'd really like to have normal-based lighting, like when viewing the mesh in Blender, Meshlab etc.
Stefan Kohlbrecher gravatar image Stefan Kohlbrecher  ( 2012-01-20 01:46:33 -0600 )edit
Have you tried increasing the intensity of your point light source?
DimitriProsser gravatar image DimitriProsser  ( 2012-01-20 01:49:22 -0600 )edit
Yes :) I'll try setting ambient lower and playing around with the light sources once more
Stefan Kohlbrecher gravatar image Stefan Kohlbrecher  ( 2012-01-20 01:51:19 -0600 )edit
Ok, when setting ambient really really low, everything is very dark as expected. Added light sources produce shadows for the UAV, but otherwise do not illuminate the scene. There has to be something stupid I'm doing wrong :)
Stefan Kohlbrecher gravatar image Stefan Kohlbrecher  ( 2012-01-20 01:56:38 -0600 )edit
Oh, and when I spawn shapes like spheres, those get illuminated correctly. So I'll have a look at their material. /edit: Of which I don't know where to find it.
Stefan Kohlbrecher gravatar image Stefan Kohlbrecher  ( 2012-01-20 02:01:46 -0600 )edit
I gave you the link to the material files. That's where all materials are located.
DimitriProsser gravatar image DimitriProsser  ( 2012-01-20 03:52:34 -0600 )edit
Sure, but what's the material used by the spawnable objects? My guess from looking at them would be "Gazebo/White", but this doesn't work for my meshes.
Stefan Kohlbrecher gravatar image Stefan Kohlbrecher  ( 2012-01-20 08:38:22 -0600 )edit

answered 2012-11-17 08:26:01 -0600

equilibrium gravatar image

I had the exact same problem today. STL files exported by Blender somehow do not receive shading when spawned inside Gazebo. Tried reversing/recalculating normals to no avail. Just import the STL into Meshlab and export it without doing anything. This enabled the shading for the mesh.

edit flag offensive delete link more


Worked for me, thanks! I thought it was the "Unify Duplicated Vertices" option that appears when an STL is loaded in MeshLab that fixes it, but I tested without and it's not.

GuiRitter gravatar image GuiRitter  ( 2016-07-11 20:20:09 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2012-01-20 01:23:40 -0600

Seen: 1,317 times

Last updated: Nov 17 '12