Building a geometry - part 1 - Loading a source scenenew

This tutorial will explain how to load an existing RED scene graph and convert it to a correct REDart geometry. The Importing geometries tutorial shows how to load an already setup geometry. This one uses raw RED data and build the geometry.

The process is done in a single method:

// Loading our geometry. Our scene is an old model, whose unit is ~2cm and our world is in meters:
g_convertMatrix.Scale( 0.02 );
RC_TEST( iassetmgr->LoadGeometrySourceFile( g_geometry_root, g_context, g_id2names, "../Resources/House_Source.red", g_convertMatrix, RED::LayerSet::ALL_LAYERS, 1.0 ) );

RED::Vector< RED::String > excludedNames;
RC_TEST( excludedNames.push_back( "Portal" ) );
RC_TEST( iassetmgr->CreateGeometry( g_geometry, g_geometry_root, RED::LayerSet::ALL_LAYERS, excludedNames, g_id2names, REDartProgressCB, NULL ) );

It loads a RED scene, translates and optimizes it to be used in REDart. The resulting object implements the RPL::IGeometry interface.

The conversion does all of this:

Once calling this method, we can add the newly created geometry to the scene:

// Setup the geometry positioning matrix.
const RED::Matrix& cmatx = cameras[ 1 ]->As< RPL::ICamera >()->GetMatrix();
RED::Vector3 cpos = cmatx.GetTranslation();
RC_TEST( iearth->GetTangentAxisSystem( g_matx, &( cpos._x ) ) );

// Apply some rotation:
RED::Matrix mrot;
mrot.RotationAxisMatrix( RED::Vector3::ZERO, RED::Vector3::ZAXIS, 1.57 );
g_matx *= mrot;

RC_TEST( iearth->AddGeometry( g_geometry, g_matx ) );

Note:

Once added to the planet, the geometry is owned by the planet and should not be modified. The planet is in charge of destroying it at the end. The geometry can however be updated by calling RPL::IPlanet::RefreshGeometry.

Currently, the geometry lighting is not very good. It is because the geometry does not have global illumination information yet. It will be built in the Building a geometry - part 2 - Setting up a GI cache tutorial.

All the lights are turned off. The Building a geometry - part 3 - Adding lights tuturial will explain how to configure them.

There are no reflections neither. While the reflection probes data are extracted from the original graph, the environment maps need to be rendered. This will be done in the Building a geometry - part 4 - Adding reflection probes tutorial.

The house is not well integrated in the landscape for now. We will see how to build elevation maps to modify the landscape under the geometry in the following tutorial: Building a geometry - part 5 - Defining ground elevation.

The house lighting is poor and the ground is incorrect