ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

How to use custom OGRE materials in URDF in ROS Indigo that displays in Gazebo?

asked 2017-11-10 04:55:43 -0600

GuiRitter gravatar image

updated 2019-08-29 21:23:18 -0600

Hi everyone

I want to create a custom OGRE material file, store it in my ROS Indigo package, and have my robot's visual in Gazebo use these materials.

I don't want to use SDF (I know how to; in fact, I learned SDF before URDF).

Here's what I tried and the results I got:

  1. Using Gazebo's built in materials work.

    <gazebo reference="…">
  2. Adding materials to Gazebo's built in materials file at /usr/share/gazebo-2.2/media/materials/scripts/gazebo.material also works.

  3. This didn't work. It's for ROS Fuerte and Gazebo 1, so I had to make some changes:
    1. roscreate-pkg gazebo_tutorials std_msgs rospy roscpp gazebo failed because ERROR: dependency [gazebo] cannot be found. I installed through apt-get every package that had gazebo in the name, but that didn't fix it. So, instead, I replaced gazebo by all packages returned by rospack list that started with gazebo. Only after the package was created that I realized it was the command to generate the old package format. This and this pages confirm that rospack find gazebo used to work in the past and doesn't anymore. So I created a new package and replaced the <depend> tags by <build_depend>, <buildtool_depend> and <run_depend>.
    2. I tried with <gazebo gazebo_media_path="${prefix}" /> but, when launching the package, Warning [] Unable to get Material[…] for Geometry[…. Object will appear white. Then I replaced ${prefix} by the full path to where my ….material file was located; same result.
  4. The first snippet from the answer to this question results in Warning [] Unable to get Material[script] for Geometry[…. Object will appear white. Note it says script instead of the material name. I tried several variations for <uri>'s argument.
  5. This confirmed a suspicion that the ….material file must be inside a Media folder, so I'm testing with and without it.
  6. This led me
    1. here, but adding the <env> tag to the launch file also didn't work. Because find gazebo doesn't work anymore, I'm using "$GAZEBO_RESOURCE_PATH:$(find …)". I'm not certain if it makes sense.
    2. and here. There's two ….material files and one ….urdf file that uses one of those materials, but this file isn't used anywhere. Also, the syntax is strange. It says <material>b21.material</material>, which is the name of the file, but the materials defined there are named b21_base_dark and b21_base_blue. These names aren't used anywhere. I also tried to place my ….material file in the full Media/materials/scripts path as is used by this package. manifest.xml only confirms to me that "${prefix}" is correct, but I don't know what's the impact of not having the gazebo package anymore.
  7. I don't mind using a colored Collada file if it worked. I applied random face colors with MeshLab. Mesh is still white. In RViz, it's a darker gray. Adding an <ambient> tag as per here ...
edit retag flag offensive close merge delete


It works on Lunar. I've updated the first post. I still want to make it work in Indigo.

GuiRitter gravatar image GuiRitter  ( 2017-11-11 13:26:02 -0600 )edit

I've created a test package and updated the first post.

GuiRitter gravatar image GuiRitter  ( 2017-11-11 14:08:33 -0600 )edit

I've added tests, a fix and an image of what I'm getting now, and updated the first post.

GuiRitter gravatar image GuiRitter  ( 2017-11-17 07:38:18 -0600 )edit

1 Answer

Sort by » oldest newest most voted

answered 2018-12-14 10:20:42 -0600

ryan.delgizzi gravatar image

Thanks for a well documented question. I was trying to accomplish the same thing. After seeing your post, I decided to try a different approach. I came up with something that was good enough for me. Instead of going through and generating a material through OGRE and Gazebo, I built the colors in sdf using xacro. Based on your example repository and because you are posting in the ROS forums, I presume you are trying to apply these colors to a urdf file which gets loaded into gazebo.

My solution is to use an xacro marco to define a color using sdf xml.

<?xml version="1.0"?>
<robot xmlns:xacro="">
  <xacro:macro name="material_olive_green">
      <ambient>0.3137254 0.3254902 0.2352941 1</ambient>
      <diffuse>0.3137254 0.3254902 0.2352941 1</diffuse>
      <specular>0.1 0.1 0.1 1</specular>
      <emissive>0 0 0 0</emissive>

Then I call the macro as part of my gazebo element in my robot file.

<gazebo reference="${prefix}base_link">
  <xacro:material_olive_green />

Hopefully this is useful to somebody.

edit flag offensive delete link more


Thanks for the answer! However, your solution didn't work for me. The link is colored Orange like others. Please check the test package where I applied your solution on link #21.

GuiRitter gravatar image GuiRitter  ( 2019-08-29 21:26:10 -0600 )edit

Question Tools



Asked: 2017-11-10 04:55:43 -0600

Seen: 1,572 times

Last updated: Aug 29 '19