How to use custom textures on urdf models in gazebo?
Hello,
I am using ROS Kinetic with Gazebo 7.x and I know that I can use gazebo materials with
<gazebo reference="link">
<material>Gazebo/Orange</material>
</gazebo>
I did manage to use a custom .jpg file as a texture on my model by
editing the gazebo.materials script from usr/share/gazebo-7/media/materials/scripts
adding the .jpg file into the usr/share/gazebo-7/media/materials/textures folder.
However, since those folders are supposed to be read only and editing those does not seem right, I want to know a different way. I did read about adding the following to my package.xml, but I did not have any success with it.
<run_depend>gazebo_ros</run_depend>
<export>
<gazebo gazebo_media_path="${prefix}"/>
</export>
My package has the following structure:
- test_gazebo
- package.xml
- CMakeList.txt
- launch/
- media/
- materials/
- scripts/
- test.materials
- textures/
- test.jpg
- scripts/
- materials/
- models/
- test.urdf
- ...
Is the structure wrong for the media export to work? From what I understood ${prefix} is the path to the package and gazebo should use it to use the media folder, but it does not work for me.
Do I need to change the .urdf if I am using a different media path also? What I tried is using the in my script asigned name like
<gazebo reference="link">
<material>Custom/TextureName</material>
</gazebo>
Anyone might be able to help me out and knows what I am doing wrong?
Asked by Gieseltrud on 2017-05-23 16:50:18 UTC
Answers
Take a look on those two questions, I believe they have all the information you need: https://answers.ros.org/question/251455/how-do-i-add-texturepng-file-in-urdf/?answer=304695#post-id-304695 https://answers.ros.org/question/257694/questions-to-sdf-urdf-xacro-material-textures-using-gazebo/
Asked by hbaqueiro on 2018-10-03 11:20:34 UTC
Comments
If you set your resources path to any folder with a structure
media
-materials
--scripts
--textures
you can use any material you define in those folders just as if you were using the material form the /usr/share/gazebo-x
folder.
Just add
export $GAZEBO_RESOURCE_PATH=/path/to/your/resource/folder
to the ~/.bashrc file. I, for example, use the ~/.gazebo
folder for my materials and models.
EDIT Today I have found more convenient way how to set environment variables for gazebo-ros projects that I want to add to this answer.
You can also set the environment variables in your launch file like that
<env name="GAZEBO_MODEL_PATH" value="$(find robot_gazebo)/models"/>
<env name="GAZEBO_RESOURCE_PATH" value="$(find robot_gazebo)/media/materials"/>
Asked by kumpakri on 2018-10-04 08:35:32 UTC
Comments
Do you mean "editing the gazebo.materials script" or "editing the gazebo.material script"? Also is your file named "test.materials" or "test.material" ? Just checking because I have the same problem as you had and I still cannot resolve the issue. Thanks!
Asked by Roberto Z. on 2019-05-07 01:57:57 UTC