Harmonic And Jazzy Tutorial
Light and Color - Wavefront
System explanation
What software are we using and why
All of these instructions have been tested using the current version of Ubuntu: Noble Numbat.We are going to use two packages: Gazebo for the physics based Simulator and ROS2 (Robot Operating System) for the control system. There are many releases of each of these, and only some combinations are mutually compatible. Also, since we are focusing on a stable development platform, we will use the Long Term Support (LTS) versions that are current at the time we are posting this. As of 29Aug2024, this means we will use Gazebo Harmonic which is supported until 2028.
Complex Textures in OBJ and MTL Files (Wavefront)
In the last tutorial we built a cube and painted it using the Wavefront OBJ / MTL file structure.
In this tutorial, we are going to use am more complex method to paint texture on the cube. This is similar to the way textures are generated and applied if the objects are built using scene building software.
In this tutorial, we are going to use am more complex method to paint texture on the cube. This is similar to the way textures are generated and applied if the objects are built using scene building software.
Picking up from the last tutorial
Copy the manyColoredCube materials file and rename it to texturedCube. Add a new texture, that refers to the colorcalibration.png file
newmtl textureKa 1.0 1.0 1.0Kd 1.0 1.0 1.0Ks 1.0 1.0 1.0map_Ka colorCalibration.pngmap_Kd colorCalibration.pngmap_Ks colorCalibration.png
Copy the manyColoredCube object and rename it to be texturedCube. Reference the texuredCube materials file
mtllib texturedCube.mtlCopy the manyColoredCube sdf and rename it to be texturedCube sdf. Reference the texturedCube object in the cube model.
<uri>texturedCube.obj</uri>
newmtl textureKa 1.0 1.0 1.0Kd 1.0 1.0 1.0Ks 1.0 1.0 1.0map_Ka colorCalibration.pngmap_Kd colorCalibration.pngmap_Ks colorCalibration.png
Copy the manyColoredCube object and rename it to be texturedCube. Reference the texuredCube materials file
mtllib texturedCube.mtlCopy the manyColoredCube sdf and rename it to be texturedCube sdf. Reference the texturedCube object in the cube model.
<uri>texturedCube.obj</uri>
Compete Changes
The files that we will use are here
texturedCube.mtl
texturedCube.obj
texturedCube.sdf
One of the challenges is that the texture map uses its own coordinate system, which is shown below. This is a standard X/Y coordinate system with (0,0) in the lower left, the X-axis increases to the right and the Y-axis increase going up.
So, if you want to paint the front face of your cube with the complete color-calibration picture, you would first add the texture vertices:
vt 0.0 1.0 #upper leftvt 1.0 1.0 #upper rightvt 1.0 0.0 #lower rightvt 0.0 0.0 #lower leftvt 0.5 1.0vt 1.0 0.5vt 0.5 0.0vt 0.0 0.5vt 0.5 0.5 #center
and then add the vertices into the object description, changing it to
#x negative side (front)usemtl texturef 2/1/6 6/4/6 7/3/6 3/2/6
vt 0.0 1.0 #upper leftvt 1.0 1.0 #upper rightvt 1.0 0.0 #lower rightvt 0.0 0.0 #lower leftvt 0.5 1.0vt 1.0 0.5vt 0.5 0.0vt 0.0 0.5vt 0.5 0.5 #center
and then add the vertices into the object description, changing it to
#x negative side (front)usemtl texturef 2/1/6 6/4/6 7/3/6 3/2/6
As you can see, the entire png image has been painted onto the front face of the cube.
But you don't have to use the entire image.
If you wanted to texture the front of the cube with the only the lower right corner of the image, you would change the material specification to use some of the mid points of the image. Like:
#x negative side (front)usemtl texturef 2/9/6 6/7/6 7/3/6 3/6/6
#x negative side (front)usemtl texturef 2/9/6 6/7/6 7/3/6 3/6/6
So we can carve up the colorcalibration.png file into chunks and paint each of the vertical sides of the cube with a different segment of the image. and paint the top with the complete image. This is what we have in the final version of the file. Fire up the sim and take a tour of your new model with complex textures.
References
Here are some of the sources for the details of the data file formats: 1. Library Of Congress, https://www.loc.gov/preservation/digital/formats/fdd/fdd000507.shtml 2. Bourke1, https://paulbourke.net/dataformats/obj/ 3. Bourke2, https://paulbourke.net/dataformats/mtl/ 4. Gazebo1, https://gazebosim.org/api/gazebo/6/migrationsdf.html
Next Steps
The next steps are up to you. Maybe take a camera image and paint it on a cube, or change the cube into a tetrahedron and see what that does.
Also, you will notice that we only defined the visusal components of the cube in this tutorial - add in the collision tags and put your model into the arena from part 4. Add additional lights to the arena - or add some lights to your robot and drive it around in the dark.
What we did
In this tutorial we have:
1) Redefined our cube to use a complex texture image
2) learned how the parts of an image can be selected
3) painted faces of an object using a single image broken up into sub-sections.
Next step - Play with your new skills!
Previous Step | Current Step | Next Step |
Complex Textures | Have fun! |