Gazebo | Ignition | Community
Ask Your Question

How to add a color/material to a STL mesh in an URDF file?

asked 2016-06-23 04:52:50 -0500

pDotGetName gravatar image

I use STL meshes and urdf files and I can't seem to set the material colors in the urdf file. I tried adding material like this (similar to what I would do in an SDF file):

 <gazebo reference="link_name">


 <gazebo reference="link_name">

But it wouldn't work.

So: How can I set material/colours for STL files in an urdf file?

edit retag flag offensive close merge delete


Was this ever resolved?

plusk01 gravatar imageplusk01 ( 2017-01-05 00:14:26 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted

answered 2016-06-25 10:06:59 -0500

mrslvgg gravatar image

updated 2016-06-27 03:58:16 -0500

You need to define the color separately such as in the file materials.xacro:

  <material name="Orange">
    <color rgba="${255/255} ${108/255} ${10/255} 1.0"/>

Import materials.xacro in your file:

<xacro:include filename="$(find your_robot_description)/urdf/materials.xacro" />

Then you can use the color specifying a material tag for each link, such as:

<link name="$link_name">
    <material name="Orange"/>

For further information visit:

edit flag offensive delete link more


Well, that's basically how I do it. But the model doesn't change color even when I switch from Gazebo/White to Gazebo/Orange.

pDotGetName gravatar imagepDotGetName ( 2016-06-27 03:16:01 -0500 )edit

I edited my answer. Check the new method.

mrslvgg gravatar imagemrslvgg ( 2016-06-27 03:59:34 -0500 )edit

Isn't this edit's material for the ROS visualization? I currently have something like this: <visual> ... <material name="Orange"/> </visual> ... <gazebo reference="link"> <material>Gazebo/Orange</material> </gazebo> In RVIZ the color is shown correctly, but in Gazebo it remains white. Could the STL file be somehow broken?

pDotGetName gravatar imagepDotGetName ( 2016-06-27 06:36:21 -0500 )edit

This did not work for me, the model did not change colors.

JeremySMorgan gravatar imageJeremySMorgan ( 2018-11-30 02:27:19 -0500 )edit

answered 2021-03-23 13:39:17 -0500

Previous answers are actually correct, the trick here is not to provide a name for the "visual". e.g.:

Do not:

<visual name="foo"> <!-- gazebo will ignore your color request -->

Do instead:


Apart from that, you need to provide appropriate gazebo tags, I will leave a full working example below:

<?xml version="1.0"?>
<robot name="my_robot_name">

  <!-- this color take effect only on rviz -->
  <material name="WHITE_MTL">
    <color rgba="0.0 1.0 0.0 1.0"/> <!-- rviz green color -->

  <link name="my_link_name">
      <origin xyz="0 0 1" rpy="0 0 0"/>
      <mass value="0.5"/>
      <inertia ixx="0.002" ixy="0" ixz="0" iyy="0.002" iyz="0" izz="0.002"/>
    <visual> <!-- do not give a name! otherwise gazebo wont pick the color -->
      <origin xyz="0 0.0 0" rpy="0 0 0"/>
        <mesh filename="package://my_robot_description/meshes/stl/my_file.stl" scale="1.0 1.0 1.0"/>
      <material name="WHITE_MTL"/> <!-- rviz will use this color -->
    <collision name="my_collision1">
      <origin xyz="0 1.0 0" rpy="0 0 0"/>
        <cylinder radius="0.5" length="0.2"/>
    <collision name="my_collision2">
      <origin xyz="0 -1.0 0" rpy="0 0 0"/>
        <cylinder radius="0.1" length="0.3"/>

  <gazebo reference="my_link_name"> <!-- reference to a existing "link" -->
    <!-- NOTE: use Gazebo/DepthMap to take color from mesh (.dae only) -->

  <!-- fix arm base, so that it does not fall -->
  <link name="world"/>
  <joint name="world_to_robot" type="fixed">
    <parent link="world"/>
    <child link="my_link_name"/>
    <origin xyz="0 0 0.5" rpy="0 0 0"/>

edit flag offensive delete link more

Question Tools



Asked: 2016-06-23 04:52:50 -0500

Seen: 38,835 times

Last updated: Mar 23 '21