Terrain And Road Importer

Terrain And Road Importer Terrain And Road Importer

The Terrain And Road Importer is a tool found in the World Editor, which will first import terrains, import roads, then terraform the terrain with respect to the imported roads. The terraforming operation ensures that all roads lie laterally flat on the terrain, whilst conforming to terrain elevations and inclines. Roads are rendered as Decal Roads.

Terrains should be stored as greyscale 16-bit .png files (without any added compression). Roads should be stored in one single .json file containing ordered lists of {node, width} pairings. This format is described later in this documentation.

Note: It is strongly recommended that this tool is used with the ‘Tech Ground’ map. This map has the resolution: 2048 x 2048, and uses 1-meter-per-pixel scaling. This means the user can provide a .png up to the same resolution. ie a .png with resolution 2000 x 2000 will overwrite the elevation on 2000 x 2000 of the Tech Ground level (leaving an unaltered edge at the far x and y edges).

The Tool:

The tool can be found in the mode bar of the World Editor, as shown in the image below.

The World Editor Mode Bar The World Editor Mode Bar

Clicking on the mode icon will open the tool window. This is described below.

The Tool Window The Tool Window

The window contains three buttons on the top row, and three sliders below this which control various parameters.

Import Terrain will open a file dialog window, where the user can select an appropriate terrain file (16-bit greyscale .png). Upon loading, the elevation (heightmap) of the terrain will change to what is stored on the file, using the chosen prominence (see slider).

Import Road(s) will open a file dialog window, where the user can select an appropriate roads file (.json format). Upon loading, Decal Roads will be created for each road. The terrain will then be modified (terraformed) underneath and near-to where the roads are located, in order to allow the roads to lay flat. Lastly, the Decal Roads will be laid on to the terrain. They will then become available in the Scene Tree window, etc.

Reset will remove any modified terrain and any Decal Roads. The terrain will be set flat (it will take the value z=0 everywhere).

Terrain Prominence Slider allows the user to contain the amount of prominence (zMax - zMin) to be used when importing a terrain file. This is discussed in more detail later in the documentation.

Terraform Margin Slider allows the user to define a margin around all the roads to be imported, before any terrain modification is performed. This is discussed in more detail later in the documentation.

Domain Of Influence Slider allows the user to set the domain of influence (DOI) of the terraforming operation. This is used in conjuction with the road margin parameter to define the slope of the terrain as it approaches the roads (to be imported). This is discussed in more detail later in the documentation.

Importing Terrains:

An Imported Terrain An Imported Terrain

Terrains can be imported using the ‘Import Terrain’ button in the tool window. The file should be of 16-bit greyscale .png format. The user may find third party tools such as GIMP useful for converting .png files to the correct format, but should ensure to switch the compression off.

In this described format, each pixel in the .png represents a 1 meter x 1 meter square and allows values in the range [0, 65535] where 0 represents the lowest elevation and 65535 represents the largest elevation.

In the tool, the user can set the prominence of the terrain (zMax) which tells BeamNG where to map the largest elevation value. For example, if zMax is set to 400m, then the values of the .png, which are in the range [0, 65535] will map to real elevations in the range [0m, 400m]. The scale is linear.

The result of importing the same .png file with different prominences is highlighted below.

Various Prominence Values Various Prominence Values

Importing Roads:

Roads can be imported using the ‘Import Road(s)’ button in the tool window. The roads should be encoded in .json format, and should all appear in the same file. In terms of heirarchy, the top level of the .json file indexes each road, then within each road there should be an ordered list of road nodes which contain the x, y, and z position of the road (the first three values), followed by the desired road width at the node (the fourth value).

An example roads file (.json format) is shown below.

Example Roads File Example Roads File

Note that the z-values are not used, since elevation is determined by the terrain. The user can use any numerical value in this field, but it should be present.

Resetting:

The tool can be reset using the ‘Reset’ button in the tool window. Upon doing so, the terrain will be set flat everywhere (z=0) and any Decal Roads will be deleted. The image below shows the result of clicking this button.

Reset Reset

Terraforming:

The following image highlights how the terrain is modified with respect to the imported roads, using various sets of terraforming parameters (DOI and margin).

Terraforming Examples Terraforming Examples

The behaviour of the slope of the terrain as it approaches the road(s) can be controlled used the DOI (domain of influence) and Margin sliders. The image below describes roughly what these parameters relate to.

Terraforming Model Terraforming Model

The DOI (domain of influence) describes how far away from the road the terraforming operation can modify the terrain. This is in meters. Larger values mean smoother slopes, but more terrain modification. Smaller values mean steeper slopes (which can often appear less natural).

The Margin value (in meters) adds a flat margin around the road (on the road plane). However, this margin region will also be smoothed into the domain of influence region, so it is best to think of this value as controlling the amount of ‘flat top’ the slope will have.

We recommend the user experiments with various terraforming values to find a satisfactory choice. The defaults should be fine for most uses.

Real Terrains:

If the user is willing to use third party software (such as QGIS) on data from digital elevation model resources (Eg OpenDEM ), it is possible to import real-world terrains. The following image shows some examples.

Real Terrains Real Terrains

Taking it further, and as suggestion, the user may wish to retrieve roads data from a source such as OpenStreetMap, and take the roads from the same region. This tool could then be used to combine the two together.

Last modified: July 5, 2024

Any further questions?

Join our discord
Our documentation is currently incomplete and undergoing active development. If you have any questions or feedback, please visit this forum thread.