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 (Cinema API).

  • LodObject::Alloc(): Creates a new LodObject.
  • LodObject::Free(): Deletes the given LodObject.
// This example creates a new LOD object and adds it to the given BaseDocument.
LodObject* const lodObject = LodObject::Alloc();
if (lodObject == nullptr)
return maxon::OutOfMemoryError(MAXON_SOURCE_LOCATION);
lodObject->SetName("New LOD Object"_s);
doc->InsertObject(lodObject, nullptr, nullptr);
#define MAXON_SOURCE_LOCATION
Definition: memoryallocationbase.h:69
const char * doc
Definition: pyerrors.h:226

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.
// get current criteria
GeData data;
lodObject->GetParameter(ConstDescID(DescLevel(LOD_CRITERIA)), data, DESCFLAGS_GET::NONE);
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
lodObject->SetParameter(ConstDescID(DescLevel(LOD_CURRENT_LEVEL)), maxLevel, DESCFLAGS_SET::NONE);
}
NONE
Definition: asset_browser.h:1
#define ConstDescID(...)
Definition: lib_description.h:592
maxon::Int32 Int32
Definition: ge_sys_math.h:51
@ LOD_CRITERIA
Definition: olod.h:7
@ LOD_CURRENT_LEVEL
Definition: olod.h:9
@ LOD_CRITERIA_MANUAL
Definition: olod.h:28

Levels

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

  • LodObject::GetLevelCount(): Returns the number of levels.
  • LodObject::GetCurrentLevel(): Returns the index of the current level.
// 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))
return maxon::UnexpectedError(MAXON_SOURCE_LOCATION);
lodObject->SetParameter(showControlID, false, DESCFLAGS_SET::NONE);

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:

  • LodObject::GetShowControlDescID(): Returns the DescID for the display mode.
  • LodObject::GetDisplayBFCDescID(): Returns the DescID for the backface culling mode.
  • LodObject::GetDisplayTexDescID(): Returns the DescID for the texture mode.
  • LodObject::GetDisplayEOGLDescID(): Returns the DescID for the Enhanced OpenGL mode.
  • LodObject::GetDisplayStModeDescID(): Returns the DescID for the shading style.
  • LodObject::GetDisplayShModeDescID(): Returns the DescID for the shading settings.

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))
return maxon::UnexpectedError(MAXON_SOURCE_LOCATION);
lodObject->SetParameter(descID, true, DESCFLAGS_SET::NONE);
// use "Lines" shading
if (!lodObject->GetDisplayShModeDescID(level, descID))
return maxon::UnexpectedError(MAXON_SOURCE_LOCATION);
lodObject->SetParameter(descID, DISPLAYTAG_SDISPLAY_NOSHADING, DESCFLAGS_SET::NONE);
// use "Wireframe" style
if (!lodObject->GetDisplayStModeDescID(level, descID))
return maxon::UnexpectedError(MAXON_SOURCE_LOCATION);
lodObject->SetParameter(descID, DISPLAYTAG_WDISPLAY_WIREFRAME, DESCFLAGS_SET::NONE);
}
PyObject PyObject PyObject int level
Definition: import.h:58
@ DISPLAYTAG_WDISPLAY_WIREFRAME
Definition: tdisplay.h:31
@ DISPLAYTAG_SDISPLAY_NOSHADING
Definition: tdisplay.h:13

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

  • LodObject::GetManualModeObjectListDescID(): Returns the DescID of the InExclude list.
// 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
lodObject->SetParameter(ConstDescID(DescLevel(LOD_MODE)), LOD_MODE_MANUAL_GROUPS, DESCFLAGS_SET::NONE);
lodObject->SetParameter(ConstDescID(DescLevel(LOD_CRITERIA)), LOD_CRITERIA_MANUAL, DESCFLAGS_SET::NONE);
lodObject->SetParameter(ConstDescID(DescLevel(LOD_LEVEL_COUNT_DYN)), objectCount, DESCFLAGS_SET::NONE);
// add objects to groups
for (Int32 level = 0; level < objectCount; ++level)
{
// get object
C4DAtom* const atom = objects->GetIndex(level);
BaseObject* const baseObject = static_cast<BaseObject*>(atom);
if (baseObject == nullptr)
return maxon::UnexpectedError(MAXON_SOURCE_LOCATION);
// 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))
return maxon::UnexpectedError(MAXON_SOURCE_LOCATION);
// create InEx data
InExcludeData* const inExData = data.GetCustomDataTypeWritable<InExcludeData>();
if (inExData == nullptr)
return maxon::UnexpectedError(MAXON_SOURCE_LOCATION);
// insert object into list
inExData->InsertObject(baseObject, 1);
// set parameter
lodObject->SetParameter(listID, data, DESCFLAGS_SET::NONE);
}
#define CUSTOMDATATYPE_INEXCLUDE_LIST
InExclude custom data type ID.
Definition: customgui_inexclude.h:24
#define atom
Definition: graminit.h:72
@ DEFAULTVALUE
Dummy value for the default value GeData constructor.
Definition: c4d_gedata.h:64
@ LOD_MODE
Definition: olod.h:6
@ LOD_LEVEL_COUNT_DYN
Definition: olod.h:13
@ LOD_MODE_MANUAL_GROUPS
Definition: olod.h:25

In "Simplify" mode these settings are available:

  • LodObject::GetSimplifyModeDescID(): Returns the DescID of the "Simplify Mode" parameter.
  • LodObject::GetDecimateStrengthDescID(): Returns the DescID of the strength parameter.
  • LodObject::GetPerObjectControlDescID(): Returns the DescID of the "Per Object" option.
  • LodObject::GetNullDisplayDescID(): Returns the DescID of the null display mode.
  • LodObject::GetNullRadiusDescID(): Returns the DescID of the null radius parameter.
  • LodObject::GetNullAspectRatioDescID(): Returns the DescID of the null aspect radius parameter.
  • LodObject::GetNullOrientationDescID(): Returns the DescID of the null orientation parameter.

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
lodObject->SetParameter(ConstDescID(DescLevel(LOD_MODE)), LOD_MODE_SIMPLIFY, DESCFLAGS_SET::NONE);
lodObject->SetParameter(ConstDescID(DescLevel(LOD_CRITERIA)), LOD_CRITERIA_MANUAL, DESCFLAGS_SET::NONE);
lodObject->SetParameter(ConstDescID(DescLevel(LOD_LEVEL_COUNT_DYN)), 2, DESCFLAGS_SET::NONE);
DescID descID;
// first level
// set mode to "Convex Hull"
if (!lodObject->GetSimplifyModeDescID(0, descID))
return maxon::UnexpectedError(MAXON_SOURCE_LOCATION);
lodObject->SetParameter(descID, LOD_SIMPLIFY_CONVEXHULL, DESCFLAGS_SET::NONE);
// set "Per Object" to true
if (!lodObject->GetPerObjectControlDescID(0, descID))
return maxon::UnexpectedError(MAXON_SOURCE_LOCATION);
lodObject->SetParameter(descID, true, DESCFLAGS_SET::NONE);
// second level
// set mode to "Null"
if (!lodObject->GetSimplifyModeDescID(1, descID))
return maxon::UnexpectedError(MAXON_SOURCE_LOCATION);
lodObject->SetParameter(descID, LOD_SIMPLIFY_NULL, DESCFLAGS_SET::NONE);
// set "Display" to "Circle"
if (!lodObject->GetNullDisplayDescID(1, descID))
return maxon::UnexpectedError(MAXON_SOURCE_LOCATION);
lodObject->SetParameter(descID, NULLOBJECT_DISPLAY_CIRCLE, DESCFLAGS_SET::NONE);
@ LOD_SIMPLIFY_NULL
Definition: olod.h:40
@ LOD_SIMPLIFY_CONVEXHULL
Definition: olod.h:38
@ LOD_MODE_SIMPLIFY
Definition: olod.h:26
@ NULLOBJECT_DISPLAY_CIRCLE
Definition: onull.h:9

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