Gazebo | Ignition | Community
Ask Your Question
0

problem adding an image as texture to an object

asked 2022-02-16 03:34:50 -0500

user1928 gravatar image

I want to display an image in the gazebo environment. Looking at a few answers suggested that I've to add an object & lay the image as texture over the object.

I followed what's suggested in the answers of this post, but no avail. Then I created a collada mesh as suggested by this tutorial. Still no luck. The object gets inserted like a grey plane as shown below. image description

What I did until now:

1) I created a directory for the model with the name ~/.gazebo/models/aruco_marker. This is how the folder looks like:

image description

2) contents of model.sdf:

<?xml version="1.0"?> <sdf version="1.4"> <model name="aruco_marker">   <static>true</static>
    <link name="link">
      <collision name="collision">
        <geometry>
          <plane>
            <normal>0 0 1</normal>
            <size>10 10</size>
          </plane>
        </geometry>
        <surface>
          <friction>
            <ode>
              <mu>100</mu>
              <mu2>50</mu2>
            </ode>
          </friction>
        </surface>
      </collision>
      <visual name="visual">
        <cast_shadows>false</cast_shadows>
        <geometry>
          <plane>
            <normal>0 0 1</normal>
            <size>10 10</size>    </plane>    <mesh>
        <uri>model://aruco_marker/materials/textures/4x4_1000-25_side50.dae</uri>
          </mesh>
        </geometry>
        <material>
          <script>
            <uri>model://aruco_marker/materials/scripts/aruco_marker.material</uri>
            <name>MyGroundPlane/Image</name>
          </script>
        </material>
      </visual>
    </link>   </model> </sdf>

3) contents of model.config

<model>
    <name>Aruco Marker</name>
    <version>1.0</version>
    <sdf version="1.4">model.sdf</sdf>
    <description>
        My textured ground plane.
    </description>
</model>

4) contents of materials/scripts/aruco_marker.material

material ArucoMarker/Image
{
  technique
  {
    pass
    {
      ambient 0.5 0.5 0.5 1.0
      diffuse 1.0 1.0 1.0 1.0
      specular 0.0 0.0 0.0 1.0 0.5
      texture_unit
      {
        texture 4x4_1000-25_side50.jpg
        filtering trilinear
      }
    }
  }
}

5) This is the .jpg file: image description

I generated a .dae file for it using an online converter

Any help is greatly appreciated, thanks!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2022-02-21 00:01:11 -0500

Veerachart gravatar image

You need to give the <uri> to the materials/scripts and materials/textures directory of your model, so that the material with the given <name> is read and the texture file is found. i.e.

    <material>
      <script>
        <uri>model://aruco_marker/materials/scripts/</uri>
        <uri>model://aruco_marker/materials/textures/</uri>
        <name>ArucoMarker/Image</name>
      </script>
    </material>

See this model from gazebo as an example http://models.gazebosim.org/pine_tree/

edit flag offensive delete link more

Comments

Thanks, it was helpful. I had another bug in my code. As can be seen in my post above, the name tag within the material tag in the visual section of my model.sdf file wasn't matching with the name mentioned in my .material script.

user1928 gravatar imageuser1928 ( 2022-02-21 04:42:49 -0500 )edit

I tried generating the collada (.dae) file with blender but that wasn't required. The one generated with the online convertor (mentioned in my post) was good enough.

user1928 gravatar imageuser1928 ( 2022-02-21 04:45:02 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2022-02-16 03:34:50 -0500

Seen: 81 times

Last updated: Feb 21