Ask Your Question
1

How do i add texture(.png file) in urdf

asked 2017-01-07 14:28:38 -0500

dinesh gravatar image

updated 2017-01-07 14:28:49 -0500

I tried to add png file in my urdf like below but its now working:

    <visual>
  <origin rpy="0 0 0" xyz="0 0 0.078335"/>
  <geometry>
    <mesh filename="package://myrobot1_description/meshes/velodyne_base.dae"/>
  </geometry>
  <material>
    <script>
      <uri>package://myrobot1_description/materials/scripts</uri>
      <uri>package://myrobot1_description/materials/textures</uri>
      <name>Table/Marble_Lightmap</name>
    </script>
  </material>
</visual>

So how do i fix this?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2018-10-02 12:09:11 -0500

hbaqueiro gravatar image

updated 2018-10-03 11:14:56 -0500

If your geometry is not a mesh, i.e. you have a basic geometry in your visual tag (box, sphere, cylinder), this should work:

Create a material file example.material (your_package/media/materials/scripts/example.material)

material YourMaterialName{
    technique
    {
        pass
        {
            texture_unit
            {
                texture your_material_image.jpg
                scale 1 1
            }
        }   
    }
}

This file can have multiple materials, not just this one. Then, outside the <link> tag of your URDF:

<gazebo reference="your_link">
    <material>YourMaterialName</material>
</gazebo>

However, if your geometry is a mesh, in addition you will need to prepare your mesh to receive the image. Open your mesh using Blender, then first imagine how would you cut your solid with a scissor in order to put all surfaces in a plane. Then, select those edges, press Ctrl+E and select Mark Seam. The edges will become red. Split the window into 2 and in the new window choose UV/Image Editor as the Editor Type (bottom left corner). Then, press A to select everything, press U and choose Unwrap. At the UV/Image Editor will appear a geometry showing all your object faces in a plane. Now you can export to COLLADA (.dae) and put in your visual geometry mesh.

If you could not follow up the Blender steps, take a look at this tutorial: https://youtu.be/f2-FfB9kRmE

edit flag offensive delete link more
1

answered 2018-10-04 09:06:58 -0500

kump gravatar image

I have never used the variablepackage:, because I don't know where is it pointing. I use file: and model: successfully. You can set the path for the file: variable in GAZEBO_RESOURCE_PATH variable.

export $GAZEBO_RESOURCE_PATH=/path/to/you/resource/folder

Make sure that your "resource folder" is of structure

media
-materials
--textures
--scripts

Then you can use <material> tags to refer to your material name defined in the script files. You only need to add <uri> to define which script to use, if you have multiple scripts that define the same named material.

<material>
          <script>
            <name>Gazebo/Texturename</name>
          </script>
</material>

or

<material>
          <script>
            <uri>materials://scripts/other_script.material</uri>
            <name>Gazebo/Texturename</name>
          </script>
</material>

or

<material>
          <script>
            <uri>media://materials/scripts/other_script.material</uri>
            <name>Gazebo/Texturename</name>
          </script>
</material>

or

<material>
          <script>
            <uri>file://media/materials/scripts/other_script.material</uri>
            <name>Gazebo/Texturename</name>
          </script>
</material>

since the resource folder is searched for folders media -> materials -> scripts or something like that. Try it yourself.

edit flag offensive delete link more

Your Answer

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

Add Answer

Question Tools

1 follower

Stats

Asked: 2017-01-07 14:28:38 -0500

Seen: 1,395 times

Last updated: Oct 04 '18