Gazebo heightmap terrain
A heightmap creates terrain from a grayscale image. Dark pixels are low points, bright pixels are high points, and Gazebo scales the result using the <size> element.
In Gazebo Harmonic, use the SDFormat <heightmap> geometry inside a normal static model. Put the same heightmap geometry in both <collision> and <visual> so physics and rendering use the same terrain.
The official Gazebo Harmonic GUI docs recommend --force-version 8 when more than one Gazebo version is installed.
Embedded heightmap world
The important part is the heightmap_terrain model. It is not included from Fuel or a separate model folder; it is embedded directly in the world file.
Complete world
Reusable model file
Heightmap elements
| Element | Meaning |
|---|---|
<uri> |
Path to the grayscale image. In this example it is relative to the SDF file. |
<size>x y z</size> |
Terrain width, length, and height range in meters. Here the image becomes a 60 m by 60 m terrain with up to 8 m of relief. |
<pos> |
Offset for the generated terrain. |
<sampling> |
Samples per heightmap datum. Higher values look smoother but cost more. |
<texture> |
Diffuse and normal textures used by the visual terrain. |
<blend> |
Optional. Use it when you add multiple textures and want different materials by elevation. |
<use_terrain_paging> |
Optional. Useful for very large terrains if the renderer supports terrain paging. |
Note
The SDFormat spec describes <heightmap> as a geometry based on a 2D grayscale image. It also supports DEM files. Gazebo Rendering's heightmap example shows both image heightmaps and DEM heightmaps.
Creating the heightmap image
Use a square grayscale image. Power-of-two-plus-one sizes such as 129x129, 257x257, or 513x513 are common for terrain grids.
- Black means the lowest terrain height.
- White means the highest terrain height.
- Smooth gradients create slopes.
- Sharp brightness changes create cliffs or collision edges.
- Increase the third value in
<size>to exaggerate height.
For example, if <size>60 60 8</size>:
- black pixels are near
z = 0 - white pixels are near
z = 8 - a 50% gray pixel is near
z = 4
Alternatives for terrain
Heightmap image: Best for local test worlds, rough outdoor terrain, and hand-authored hills. This is the simplest option.
DEM heightmap:
Best for real terrain data from GIS sources. Gazebo Harmonic lists DEM support, and the rendering example loads a .tif DEM. With DEM data, watch the vertical offset because real elevation files may include negative minimum elevation.
Mesh terrain:
Use <mesh> with .dae, .obj, or .stl when you need overhangs, caves, walls, buildings, or artist-authored geometry. Heightmaps cannot represent vertical overhangs because each x-y point has only one height.
SDF image extrusion:
SDFormat also has <image> geometry, which extrudes boxes from a grayscale image. It is useful for blocky obstacles, occupancy-map-like layouts, and quick maze or wall tests, not natural terrain.
Primitive terrain: Use planes, boxes, ramps, and cylinders for deterministic unit tests. This is better than a heightmap when you need exact contact geometry.
Fuel or GUI world editing: Gazebo can insert models from Fuel and save worlds from the GUI. This is useful for assembling a scene quickly, then you can edit the saved SDF by hand.
Common issues
- If the robot falls through the terrain, make sure the
<collision>also uses the heightmap geometry. - If the terrain appears flat, increase the z value in
<size>. - If textures do not load, run Gazebo from the
codefolder or use paths resolvable fromGZ_SIM_RESOURCE_PATH. - If startup uses the wrong Gazebo version, run
gz sim --versionsand usegz sim --force-version 8 ...for Harmonic.