07 SendingDEM - project-SIMPLE/simple.toolchain GitHub Wiki

Sending a Digital Elevation Model (DEM) from GAMA

Link to the example model: LinkToUnity/Models/Code Examples/Send DEM.gaml

Vidoterrain-ezgif com-optimize

The principle is to use a Terrain game object in Unity and sending/updating from GAMA its height map.

Step 1: Creating a new terrain

In the Scene, click on the right button to add a new 3D Object/Terrain.

CreateNewTerrain

Step 2: Setting the new terrain

A first element to set is the name of the Terrain that will be used as a id from GAMA. To assign a particular material to the Terrain, click on the terrain setting icon.

Setup Terrain 1

Then, the material can be assigned in the corresponding field.

Setup Terrain 2

It is also important to set the resolution of the height map. For rendering and performance issues, it is highly recommended to use a low resolution like 65x65.

Setup Terrain 3

Step 3: Using the terrain for teleportation

To use the terrain for teleportation, first, remove the « Ground » game object inside the Teleport Area (in the Scene). Then, add the terrain as a collider for the Teleportation area.

Terrain Teleportation

Step 4: Updating the terrain from GAMA

There are two ways to update the terrain values (height map) from GAMA that correspond to two actions of the Unity Linker agent. The first one can be used to setup all the value of the height map, and the second one is dedicated to update specific cells of the terrain.

Updating all the values of the terrain’s height map We use for that the "update_terrain" action. The value of the height map can be either sent as a field or as a matrix. Note that for optimisation purposes, it is important to set the max_values as the maximal value can that be obtained during all the simulation.

do update_terrain (
	player:last(unity_player),  //player concerned
	id:"Dem",  //name of the Terrain in Unity
	field:f, //it is possible to send the grid either as a field or as a matrix
	resolution:65, //resolution of the target Terrain in Unity.
     max_value:max_value //optional : max possible value of the grid
);

Updating a subset of the values of the terrain’s height map

We use for that the "set_terrain_values" action. The principle is to give the new values for the cells as a matrix and the index of this "sub-matrix" according to the global height map matrix.

Terrain Update
do set_terrain_values(
	player:last(unity_player), //player concerned
	id:"Dem",  //name of the Terrain in Unity
	matrix: {1,1} matrix_with c.grid_value, //matrix containing the new values
	index_x : c.grid_x, //index x (column) of the matrix in the total grid
	index_y : c.grid_y //index y (row) of the matrix in the total grid
);
⚠️ **GitHub.com Fallback** ⚠️