# Building a geometry - part 5 - Defining ground elevation

This tutorial describes the methods used to modify the landscape under the geometry. This will anchor the geometry on the ground and clear the intersection between the geometry and the landscape.

As we saw in the "Importing geometries" tutorial, geometry is placed at the landscape altitude at the geometry position. Possibly automatically using the RPL::IGeometry::SetAutomaticSetOnGround method.

But the ground is not perfectly flat to receive the geometry and some intersections can occur.

There is sand in the house! Not cool!

In the same way, some prisms can appear inside the house. Like trees. Not cool neither!

## Generating elevation maps

In REDart, it is possible to define ground data to modify the landscape elevation and the prisms spawning area. Those data are elevation maps and density maps. And there is a single function to automatically generate them for a geometry (how convenient!):

``````// Generating the elevation and density data.
// Returned data:
RED::Vector< float > elevation;
RED::Vector< float > elevationWeight;
RED::Vector< float > density[4];
double min, max, bc[3];
RED::Vector3 upAxis = RED::Vector3::ZAXIS;
double scale = 0.02;

double defades[4] = { 3.0, 3.0, 3.0, 3.0 };
int res = 1024;

RC_TEST( iassetmgr->GenerateGeometryGroundFields( elevation, elevationWeight, density, min, max, bc, g_geometry_root, elfade, defades, res, REDartProgressCB, NULL ) );
``````

This method returns:

• an elevation map - defines the ground elevation offset in meters from the house position.
• an elevation weight map - defines the amount of elevation which is taken from the elevation map against the default landscape - allows to define fading areas.
• four density maps - one for each type of prisms - define the amount of prisms in the area.
• the bounding circle (center and radius) allowing to place the maps around the geometry position.

But before calling this method, the source scene must contain a RED::IMeshShape placeholder called "ground" (case sensitive). This object defines the ground elevation that we want under the house geometry. It must extend the geometry footprint on the ground by the fade distance. You must ensure that the original source file contains this ground mesh for the generation to work correctly.

The ground object must extend the house print

Note:

The ground mesh doesn't need to be a plane. It can define varying elevations.

Saving these data is very simple as usual:

``````// Saving the elevation and density data.
RC_TEST( iassetmgr->SaveGeometryGroundFields( elevation, elevationWeight, density, res, bc, "../Resources/House_Elevation.bin" ) );

// Setting the elevation data to the geometry.
RPL::IGeometry* igeometry = g_geometry->As< RPL::IGeometry >();
RC_TEST( igeometry->SetGroundElevation( elevation, elevationWeight, density, bc, res) );

// Refresh the geometry:
RC_TEST( iearth->RefreshGeometry( g_geometry ) );
``````

Note:

This method writes a non standard binary file. However it is totally feasible to write a standard image file (.png, .tiff) with the data. This would allow to modify them with an image software afterward.

Loading and setting the data to the geometry is also very simple:

``````// Loading the elevation data.
RED::Vector< float > elevation;
RED::Vector< float > elevationWeight;
RED::Vector< float > density[4];
int elres;
double elbc[3];
RC_TEST( iassetmgr->LoadGeometryGroundFields( elevation, elevationWeight, density, elres, elbc, "../Resources/House_Elevation.bin" ) );

// Setting the elevation data to the geometry.
RPL::IGeometry* igeometry = g_geometry->As< RPL::IGeometry >();
RC_TEST( igeometry->SetGroundElevation( elevation, elevationWeight, density, elbc, elres) );

// Refresh the geometry:
RC_TEST( iearth->RefreshGeometry( g_geometry ) );
``````
Your browser does not support the HTML5 canvas tag.

The house without and with ground elevation