Skip to content

Generate large terrains for worlds

Pavel Vechersky edited this page Nov 30, 2016 · 2 revisions

The most efficient way to generate a large terrain for a world is to utilize Gazebo's heightmap object. For more detailed description of the heightmap tag specifications consult the SDF geometry element reference: http://sdformat.org/spec?elem=geometry&ver=1.4

Create the heightmap

To create a heightmap you need to provide a gray-scale image as in input. The darker parts of the image will correspond to the regions of lower elevation while the lighter parts will result in greater heights. The image must meet two requirements:

  1. It must be a square image

  2. The sides must be of size 2^n + 1 (the size of 129 seems to be most commonly used)

Once such image is available, the following geometry tag can be used for collision and visual elements of your terrain, specifying the path to the image, size of the heightmap, and the position of heightmap's center relative to Gazebo's coordinate frame:

<geometry>
  <heightmap>
    <uri>model://yosemite/materials/textures/yosemite.png</uri>
    <size>1000 1000 125</size>
    <pos>100 0 -30</pos>
  </heightmap>
</geometry>

Importing real-world elevation data

While you can create your own input images by hand, for smoother and more realistic terrains it might be easier to use the elevation data of real-world scenes. One possible source of real-world elevation data is the US Geological Survey: http://gdex.cr.usgs.gov/gdex/ (though you need to create an account to download the data)

Texture the heightmap

Heightmaps in Gazebo are textured in slices that are bound by specified height limits. Textures are specified in the visual element of your terrain using the SDF format. For n 'texture' objects, n-1 'blend' objects are required to specify the transitions between different textures. Below is an example of applying four textures to a terrain at various heights:

<geometry>
  <heightmap>
    <texture>
      <diffuse>file://media/materials/textures/dirt_diffusespecular.png</diffuse>
      <normal>file://media/materials/textures/flat_normal.png</normal>
      <size>50</size>
    </texture>
    <texture>
      <diffuse>file://media/materials/textures/terrain_detail.jpg</diffuse>
      <normal>file://media/materials/textures/flat_normal.png</normal>
      <size>75</size>
    </texture>
    <texture>
      <diffuse>file://yosemite/materials/textures/texture_forest.png</diffuse>
      <normal>file://media/materials/textures/flat_normal.png</normal>
      <size>100</size>
    </texture>
    <texture>
      <diffuse>file://yosemite/materials/textures/texture_mountains.png</diffuse>
      <normal>file://media/materials/textures/flat_normal.png</normal>
      <size>50</size>
    </texture>
    <blend>
      <min_height>35</min_height>
      <fade_dist>10</fade_dist>
    </blend>
    <blend>
      <min_height>60</min_height>
      <fade_dist>10</fade_dist>
    </blend>
    <blend>
      <min_height>90</min_height>
      <fade_dist>10</fade_dist>
    </blend>
    <uri>model://yosemite/materials/textures/yosemite.png</uri>
    <size>1000 1000 125</size>
    <pos>100 0 -30</pos>
  </heightmap>
</geometry>