Gazebo | Ignition | Community
Ask Your Question
1

change color of models

asked 2013-06-26 06:46:33 -0600

Vahid gravatar image

updated 2013-06-28 06:50:25 -0600

Hi Dear All,

I want to change color of models in gazebo ( standalone version 1.8.6 ), i read some comments here, but those don't work, by the way any one can help me? for example i want to change color of Cube 20k, and i don't know what is tag of color?!! and also i can't fine any property for color in gazebo! because i use standalone version of gazebo, i use SDF, for Example SDF file of Cube20k is:

<?xml version="1.0" ?>
<sdf version="1.4">
  <model name="cube_20k">
    <link name="link">
      <pose>0 0 0.5 0 0 0</pose>
      <collision name="collision">
        <geometry>
          <mesh>
            <uri>model://cube_20k/meshes/cube_20k.stl</uri>
            <scale>0.5 0.5 0.5</scale>
          </mesh>
        </geometry>
      </collision>
      <visual name="visual">
        <geometry>
          <mesh>
            <uri>model://cube_20k/meshes/cube_20k.stl</uri>
            <scale>0.5 0.5 0.5</scale>
          </mesh>
        </geometry>
      </visual>
    </link>
  </model>
</sdf>

i got this error when i added the material tag to SDF file:

XML Element[material], child of element[mesh] not defined in SDF. Ignoring.[mesh]
Error [parser.cc:710] Error reading element <mesh>
Error [parser.cc:710] Error reading element <geometry>
Error [parser.cc:710] Error reading element <collision>
Error [parser.cc:710] Error reading element <link>
Error [parser.cc:710] Error reading element <model>
Error [parser.cc:369] Unable to read element <sdf>
Error:   Could not find the 'robot' element in the xml file
         at line 61 in /tmp/buildd/ros-fuerte-urdfdom-0.2.3-3precise-20130312-1505/urdf_parser/src/model.cpp

I've added material tag to SDF file of Cube20K in this way, and now color of my Cube20k is changed

<?xml version="1.0" ?>
<sdf version="1.4">
  <model name="cube_20k">
    <link name="link">
      <pose>0 0 0.5 0 0 0</pose>
      <collision name="collision">
        <geometry>
          <mesh>
            <uri>model://cube_20k/meshes/cube_20k.stl</uri>
            <scale>0.5 0.5 0.5</scale>
          </mesh>
        </geometry>
      </collision>
      <visual name="visual">
        <geometry>
          <mesh>
            <uri>model://cube_20k/meshes/cube_20k.stl</uri>
            <scale>0.5 0.5 0.5</scale>
          </mesh>
        </geometry>
        <material>
          <ambient>1 0 0 1</ambient>
          <diffuse>1 0 0 1</diffuse>
          <specular>0.1 0.1 0.1 1</specular>
          <emissive>0 0 0 0</emissive>
        </material>
      </visual>
    </link>
  </model>
</sdf>
edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2013-06-27 16:56:55 -0600

nkoenig gravatar image

In SDF you can use:

<visual name="castor_visual">
  <pose>-0.200 0 -0.12 0 0 0</pose>
  <geometry>
    <sphere>
      <radius>0.04</radius>
    </sphere>
  </geometry>
  <material>
    <ambient>1 0 0 1</ambient>
    <diffuse>1 0 0 1</diffuse>
    <specular>0.1 0.1 0.1 1</specular>
    <emissive>0 0 0 0</emissive>
  </material>
</visual>
edit flag offensive delete link more

Comments

thank you so much, it's work :)

Vahid gravatar imageVahid ( 2013-06-28 06:44:37 -0600 )edit

@nkoenig Why Gazebo is not able to detect <uri>file://media/materails/scripts/gazebo.material</uri?

CroCo gravatar imageCroCo ( 2022-09-12 05:48:02 -0600 )edit
0

answered 2013-06-26 09:58:00 -0600

davetcoleman gravatar image

Are you using SDF or URDF? I've documented info about colors in URDF here, and some of it is also useful for SDFs.

edit flag offensive delete link more

Comments

Thank you so much, I've changed the question and have added details, i've added the material tag but i got error!

Vahid gravatar imageVahid ( 2013-06-26 10:16:45 -0600 )edit

i don't see your material tag. also, add the errors to your above question because we can't see them

davetcoleman gravatar imagedavetcoleman ( 2013-06-26 13:46:34 -0600 )edit

Dear my friend, I've added the error in main question, also i copied the main SDF file in main question, I've followed this structure for adding material tag. i don't know where should i add material tag exactly, but I've added as a child for most tags but i got error for all of those.

Vahid gravatar imageVahid ( 2013-06-26 14:44:57 -0600 )edit
hsu gravatar imagehsu ( 2013-06-27 02:22:36 -0600 )edit

Thank you so much, but Cube_20K has stl file, and in your link is a material file under material tag, by the way I've Added like your link but i got error again!

Vahid gravatar imageVahid ( 2013-06-27 07:41:53 -0600 )edit

STL files don't support proper coloring in Gazebo, use DAE (Collada) files. This is documented here

davetcoleman gravatar imagedavetcoleman ( 2013-06-27 12:55:22 -0600 )edit

Thank you so much for your consideration, but for Cube2K there is not DAE file, how can i generate DAE file from STL or How Can i create DAE file?!

Vahid gravatar imageVahid ( 2013-06-27 14:46:42 -0600 )edit

what if i want the color to brown ? can any one help .. thanks in advance

hattan gravatar imagehattan ( 2014-08-22 07:51:51 -0600 )edit

Question Tools

Stats

Asked: 2013-06-26 06:46:33 -0600

Seen: 20,908 times

Last updated: Jun 28 '13