Tutorials/beginner/heightmap

Heightmaps, or heightfeilds, are used to represent a terrain based on a greyscale image. The elevation at a given point on the heightmap is determined by the greyscale value of the corresponding pixel. Typically the more white a pixel is, the higher the resulting elevation.


 * 1) Steps ###

In order to create a height map you will need: 1) A square greyscale image, and each side must be (2^n)+1 pixels. 2) One or more textures to apply to the heightmap

Create a working directory:

cd; mkdir gazebo_heightmap; cd gazebo_heightmap

Create a 129x129 size greyscale image using your favorite image editing tools, such as Gimp or Photoshop. Use various brush to create gradients from black to white.

Save the image file as `~/gazebo_heightmap/myheightmap.png`.

Create a world file for the heightmap. Copy and paste the following code into a file called `heightmap.world`.

 



   dirt_diffusespecular.png dirt_normal.png 50                grass_diffusespecular.png grass_normal.png 20                fungus_diffusespecular.png fungus_normal.png 80                2 5 4 5

The ` ` describes the heightmap collision element as having a world size of 129x129x10 meters located at the origin. The ` ` element describes how the heightmap looks. The size and origin of the visual element should match the collision element. The ` ` and ` ` elements within the heightmap visual contain information about how textures are applied to the heightmap.

Each ` ` element has a ` `, ` `, and ` ` element. The ` ` element is a filename for the diffuse and specular, the ` ` element is a filename that has normal height information, and the ` ` element indicates how big each application of the texture is. The smaller the size, the more it's repeated over a heightfield.

The order of the ` ` element is used by the ` ` elements to mix together the textures at different elevations. In this case the first ` ` element tells Gazebo how to mix together the first two textures. The grass texture will first start to appear on the heightmap at an elevation of 2 meters with a 5 meter fade in while the dirt fades out. Similarly, the second ` ` element mixes together the second and third textures.

Now run Gazebo

gazebo heightmap.world