LodObject Manual

About

A LodObject represents a LOD (level of detail) object generator. This generator creates geometry based on various parameters e.g. camera distance. The LodObject class provides access to the parameters of the dynamically defined levels. It is defined in the lib_lodobject.h header file.

LodObject objects are an instance of Olod.

Access

A LodObject object is a BaseObject and can be accessed like any other object. See BaseObject Manual.

Allocation/Deallocation

LodObject objects are created with the usual tools, see Entity Creation and Destruction Manual.

// This example creates a new LOD object and adds it to the given BaseDocument.
LodObject* lodObject = LodObject::Alloc();
if (!lodObject)
return false;
lodObject->SetName("New LOD Object");
doc->InsertObject(lodObject, nullptr, nullptr);

Properties

The standard parameters of a LodObject can be obtained and changed with C4DAtom::SetParameter()/ C4DAtom::GetParameter(). The parameter IDs are defined in olod.h.

// This example checks the current criteria of the given LOD object.
// If it is "User LOD Level" the current level is set to the maximum level.
GeData data;
// get current criteria
const Int32 criteria = data.GetInt32();
// check if User LOD Level
if (criteria == LOD_CRITERIA_MANUAL)
{
// get max level
const Int32 maxLevel = lodObject->GetLevelCount() - 1;
// set current level to max level
}

Levels

A LodObject object handles multiple levels. The current level is used to define the geometry it should create.

// This example hides the objects of the current level.
// get current level
const Int32 currentLevel = lodObject->GetCurrentLevel();
// hide current level
DescID showControlID;
if (lodObject->GetShowControlDescID(currentLevel, showControlID))
{
lodObject->SetParameter(showControlID, false, DESCFLAGS_SET_0);
}

Dynamic Parameter IDs

Each level contains multiple parameters that configure that level. The DescID for these parameters can be obtained with these functions.

In every mode a level defines various display parameters:

The IDs of the shading modes and styles are defined in tdisplay.h.

// This example configures the display settings for each level.
const Int32 maxLevel = lodObject->GetLevelCount();
for (Int32 level = 0; level < maxLevel; ++level)
{
DescID descID;
// enable backface culling
if (lodObject->GetDisplayBFCDescID(level, descID))
{
lodObject->SetParameter(descID, true, DESCFLAGS_SET_0);
}
// use "Lines" shading
if (lodObject->GetDisplayShModeDescID(level, descID))
{
}
// use "Wireframe" style
if (lodObject->GetDisplayStModeDescID(level, descID))
{
}
}

In "Manual Groups" mode a list of objects can be accessed:

// This example configures the given LodObject to use "Manual Groups".
// The objects referenced in the "objects" AtomArray are moved under
// the LodObject and are referenced in each group.
// use "Manual Groups" and a manually defined number of groups
// add objects to groups
for (Int32 level = 0; level < objectCount; ++level)
{
// get object
C4DAtom* atom = objects->GetIndex(level);
BaseObject* baseobject = static_cast<BaseObject*>(atom);
if (baseobject)
{
// make object a child object of the LOD object
baseobject->Remove();
doc->InsertObject(baseobject, lodObject, nullptr);
// insert into "Objects" list of the given level
DescID listID;
if (lodObject->GetManualModeObjectListDescID(level, listID))
{
// create InEx data
InExcludeData* inExData = static_cast<InExcludeData*>(customData);
if (inExData)
{
// insert object into list
inExData->InsertObject(baseobject, 1);
// set parameter
lodObject->SetParameter(listID, data, DESCFLAGS_SET_0);
}
}
}
}

In "Simplify" mode these settings are available:

The null display mode setting IDs are defined in onull.h.

// This example configures the given LodObject to use the "Simplify" mode.
// The first level uses the "Convex Hull" mode, the second the "Null" mode.
// use "Simplify" mode and a manual number of levels
DescID descID;
// first level
if (lodObject->GetSimplifyModeDescID(0, descID))
{
// set mode to "Convex Hull"
if (lodObject->GetPerObjectControlDescID(0, descID))
{
// set "Per Object" to true
lodObject->SetParameter(descID, true, DESCFLAGS_SET_0);
}
}
// second level
if (lodObject->GetSimplifyModeDescID(1, descID))
{
// set mode to "Null"
if (lodObject->GetNullDisplayDescID(1, descID))
{
// set "Display" to "Circle"
}
}

Dirty Checksums

The dirty checksum of levels and the cache can be obtained with:

  • LodObject::GetLevelDirty(): Returns the checksum for the level switch. Every time the level changes, the counter is increased.
  • LodObject::GetCacheDirty(): Returns the checksum for the cache creation. Every time the cache is rebuilt, the counter is increased.

Further Reading