LodObject Manual

About

A c4d.LodObject represents a LOD object generator. This generator creates geometry based on various parameters e.g. camera distance. The c4d.LodObject class provides access to the parameters of the dynamically defined levels.

Access

A c4d.LodObject object is a c4d.BaseObject an can be accessed like any other object.

Create

c4d.LodObject objects are created with LodObject.__init__() / ().

# This example creates a new LOD object and adds it to the active BaseDocument

import c4d

lodObject = c4d.LodObject()
lodObject.SetName("New LOD Object")
doc.InsertObject(lodObject)
c4d.EventAdd()

Properties

The standard parameters of a c4d.LodObject can be accessed with the [] operator GeListNode.__getitem__()/GeListNode.__setitem__() or C4DAtom.SetParameter()/C4DAtom.GetParameter().

# This example checks the current criteria of the active LOD object 'op'.
# If it is "User LOD Level" the current level is set to the maximum level.

import c4d

# get current criteria from active LOD object
criteria = op[c4d.LOD_CRITERIA]

# check if User LOD Level
if criteria == c4d.LOD_CRITERIA_MANUAL:
    # get maximum level
    maxLevel = op.GetLevelCount() - 1
    # set current level to max level
    op[c4d.LOD_CURRENT_LEVEL] = maxLevel
    c4d.EventAdd()

Levels

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

# This example hides the objects of the active LOD object 'op' current level.

import c4d

# get active LOD object current level
currentLevel = op.GetCurrentLevel()

# hide current level
showControlID = op.GetShowControlDescID(currentLevel)
if showControlID is not None:
    op[showControlID] = False
    c4d.EventAdd()

Dynamic Parameter IDs

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

In every mode a level defines various display parameters:

# This example configures the display settings for each level of the active LOD object 'op'.

import c4d

# get active LOD object number of levels
levelCount = op.GetLevelCount()

for level in xrange(levelCount):

    descID = op.GetDisplayBFCDescID(level)

    # enable backface culling
    if descID is not None:
        op[descID] = True

    # currently GetDisplayStModeDescID() and GetDisplayShModeDescID() are switched up
    # use "Lines" shading
    descID = op.GetDisplayStModeDescID(level)
    if descID is not None:
        op[descID] = c4d.DISPLAYTAG_SDISPLAY_NOSHADING

    # use "Wireframe" style
    descID = op.GetDisplayShModeDescID(level)
    if descID is not None:
        op[descID] = c4d.DISPLAYTAG_WDISPLAY_WIREFRAME

c4d.EventAdd()

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

# This example configures the active LOD object to use "Manual Groups".
# The selected objects referenced in the objects list are moved under the LOD object and are referenced in each group.
# Use "Manual Groups" and a manually defined number of groups.

import c4d

def main():

    activeObjects = doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_0)
    if len(activeObjects) <= 1:
        return

    lodObject = doc.GetTargetObject()
    if lodObject.GetType() != c4d.Olod:
        return

    lodObject[c4d.LOD_MODE] = c4d.LOD_MODE_MANUAL_GROUPS
    lodObject[c4d.LOD_CRITERIA] = c4d.LOD_CRITERIA_MANUAL
    lodObject[c4d.LOD_LEVEL_COUNT_DYN] = len(activeObjects) - 1
  
    for level, object in enumerate(activeObjects):
  
        if object == lodObject:
            continue

        # make object a child object of the LOD object
        object.Remove()
        doc.InsertObject(object, lodObject)

        # insert object into "Objects" list of the given level

        listID = lodObject.GetManualModeObjectListDescID(level)
        if listID is not None:
            # create InEx data
            inExData = c4d.InExcludeData()
            if inExData is not None:
                # insert object into list
                inExData.InsertObject(object, 1)
                # set parameter
                lodObject[listID] = inExData

    c4d.EventAdd()

if __name__=='__main__':
    main()

In “Simplify” mode these settings are available:

# This example configures the active LodObject 'op' 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.

import c4d

op[c4d.LOD_MODE] = c4d.LOD_MODE_SIMPLIFY
op[c4d.LOD_CRITERIA] = c4d.LOD_CRITERIA_MANUAL
op[c4d.LOD_LEVEL_COUNT_DYN] = 2

# first level
descID = op.GetSimplifyModeDescID(0)
if descID is not None:
    # set mode to "Convex Hull"
    op[descID] = c4d.LOD_SIMPLIFY_CONVEXHULL
    descID = op.GetPerObjectControlDescID(0)
    if descID is not None:
        # set "Per Object" to True
        op[descID] = True

# second level
descID = op.GetSimplifyModeDescID(1)
if descID is not None:
    # set mode to "Null"
    op[descID] = c4d.LOD_SIMPLIFY_NULL
    descID = op.GetNullDisplayDescID(1)
    if descID is not None:
        # set "Display" to "Circle"
        op[descID] = c4d.NULLOBJECT_DISPLAY_CIRCLE

c4d.EventAdd()