Height Map Using a Text File
An example text file (rsc/xmlScripts/heightMaps/heightMapExample.txt) is shown below:
5 5 10 10
1 1 1 1 1 1 0 0 0 1 1 0.5 0 0 1 1 0 0 0 1 1 1 1 1 1
The numbers in the first line are xSamples, ySamples, xSize, and ySize, respectively.
The remaining numbers are the xSamples * ySamples height values, row by row (x varies fastest).
Values are separated by whitespace, so line breaks are optional. A file with the wrong number of
height values is a fatal error.
XML approach
The matching asset is
rsc/xmlScripts/heightMaps/heightMapUsingTxt.xml. Load it through the world
configuration constructor in your application:
raisim::World world("/path/to/raisim2Lib/rsc/xmlScripts/heightMaps/heightMapUsingTxt.xml");
The XML file is equivalent to the following (the asset uses the snake_case
spellings center_x, lin_vel, …; the reader accepts both).
[THIS_DIR] expands to the directory of the XML file.
<?xml version="1.0" ?>
<raisim version="2.0.0">
<timeStep value="0.001"/>
<objects>
<sphere name="sphere" mass="1">
<dim radius="0.5" />
<inertia xx="0.1" xy="0" xz="0" yy="0.1" yz="0" zz="0.1" />
<state pos="0 0 5" quat="1 0 0 0" linVel="0 0 0" angVel="0 0 0" />
</sphere>
<capsule name="capsule" mass="1">
<dim radius="0.5" height="1" />
<inertia xx="0.1" xy="0" xz="0" yy="0.1" yz="0" zz="0.1" />
<state pos="1 0 5" quat="1 0 0 0" linVel="0 0 0" angVel="0 0 0" />
</capsule>
<box name="box" mass="1">
<dim x="0.5" y="1" z="2"/>
<inertia xx="0.1" xy="0" xz="0" yy="0.1" yz="0" zz="0.1" />
<state pos="1 1 5" quat="1 0 0 0" linVel="0 0 0" angVel="0 0 0" />
</box>
<heightmap name="terrain" text="[THIS_DIR]/heightMapExample.txt" centerX="0" centerY="0"/>
</objects>
</raisim>
C++ approach
The arguments are the file path, centerX, and centerY:
auto hm = world.addHeightMap("<PATH-TO-TEXT-FILE>/heightMapExample.txt", 0, 0);