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__() / ().

"""
Copyright: MAXON Computer GmbH
Author: Yannick Puech

Description:
    - Creates a new LOD object and adds it to the active BaseDocument.

Class/method highlighted:
    - c4d.LodObject
    - BaseDocument.InsertObject()

Compatible:
    - Win / Mac
    - R19, R20, R21, S22
"""
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().

"""
Copyright: MAXON Computer GmbH
Author: Yannick Puech

Description:
    - 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.

Class/method highlighted:
    - LodObject.GetLevelCount()

Compatible:
    - Win / Mac
    - R19, R20, R21, S22
"""
import c4d


def main():
    # Checks if there is an active object
    if op is None:
        raise RuntimeError("Failed to retrieve the active object.")

    # Checks if active object is a LOD object
    if not op.CheckType(c4d.Olod):
        raise TypeError("op is not a Lod Object.")

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

    # Checks if User LOD Level
    if criteria == c4d.LOD_CRITERIA_MANUAL:

        # Gets maximum level
        maxLevel = op.GetLevelCount() - 1

        # Sets current level to max level
        op[c4d.LOD_CURRENT_LEVEL] = maxLevel

        # Pushes an update event to Cinema 4D
        c4d.EventAdd()


if __name__ == '__main__':
    main()

Levels

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

"""
Copyright: MAXON Computer GmbH
Author: Yannick Puech

Description:
    - Hides the objects of the active LOD object 'op' current level.

Class/method highlighted:
    - LodObject.GetCurrentLevel()
    - LodObject.GetShowControlDescID()

Compatible:
    - Win / Mac
    - R19, R20, R21, S22
"""
import c4d


def main():
    # Checks if there is an active object
    if not op:
        return

    # Checks if active object is a LOD object
    if not op.CheckType(c4d.Olod):
        return

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

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

        # Pushes an update event to Cinema 4D
        c4d.EventAdd()


if __name__ == '__main__':
    main()

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:

"""
Copyright: MAXON Computer GmbH
Author: Yannick Puech

Description:
    - Configures the display settings for each level of the active LOD object 'op'.

Class/method highlighted:
    - c4d.LodObject
    - LodObject.GetDisplayBFCDescID()
    - LodObject.GetDisplayStModeDescID()

Compatible:
    - Win / Mac
    - R19, R20, R21, S22
"""
import c4d


def main():
    # Checks if there is an active object
    if op is None:
        raise RuntimeError("Failed to retrieve the active object.")

    # Checks if active object is a LOD object
    if not op.CheckType(c4d.Olod):
        raise TypeError("op is not a Lod Object.")

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

    # Iterates over all levels of LOD
    for level in range(levelCount):
        descID = op.GetDisplayBFCDescID(level)

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

        # Uses "Lines" shading
        descID = op.GetDisplayStModeDescID(level)
        if descID is not None:
            op[descID] = c4d.DISPLAYTAG_WDISPLAY_WIREFRAME

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

    # Pushes an update event to Cinema 4D
    c4d.EventAdd()


if __name__ == '__main__':
    main()

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

"""
Copyright: MAXON Computer GmbH
Author: Yannick Puech

Description:
    - 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.

Class/method highlighted:
    - LodObject.GetManualModeObjectListDescID()

Compatible:
    - Win / Mac
    - R19, R20, R21, S22
"""
import c4d


def main():
    # Gets selected objects and check if there is more than 1 object selected
    activeObjects = doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_0)
    if not activeObjects:
        raise RuntimeError("Failed to retrieve selected objects.")

    # Gets the last object selected
    lodObject = doc.GetTargetObject()
    if not lodObject.CheckType(c4d.Olod):
        raise TypeError("last selected object is not a Lod Object.")

    # Defines parameters
    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

    level = 0
    # Iterates over all active object
    for obj in activeObjects:

        if obj == lodObject:
            continue

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

        # Inserts object into "Objects" list of the given level
        listID = lodObject.GetManualModeObjectListDescID(level)
        if listID is None:
            continue

        # Creates InExcludeData
        inExData = c4d.InExcludeData()
        if inExData is None:
            continue

        # Inserts object into list
        inExData.InsertObject(obj, 1)

        # Sets parameter
        lodObject[listID] = inExData

        # Increments the level
        level = level + 1

    # Pushes an update event to Cinema 4D
    c4d.EventAdd()


if __name__ == '__main__':
    main()

In “Simplify” mode these settings are available:

"""
Copyright: MAXON Computer GmbH
Author: Yannick Puech

Description:
    - Configures the active LodObject 'op' to use the "Simplify" mode.
    - The first level uses the "Convex Hull" mode, the second the "Null" mode.
    - The second level uses the "Simplify" mode and a manual number of levels.

Class/method highlighted:
    - LodObject.GetLevelCount()

Compatible:
    - Win / Mac
    - R19, R20, R21, S22
"""
import c4d


def main():
    # Checks if there is an active object
    if op is None:
        raise RuntimeError("Failed to retrieve the active object.")

    # Checks if active object is a LOD object
    if not op.CheckType(c4d.Olod):
        raise TypeError("op is not a Lod Object.")

    # Defines some parameters
    op[c4d.LOD_MODE] = c4d.LOD_MODE_SIMPLIFY
    op[c4d.LOD_CRITERIA] = c4d.LOD_CRITERIA_MANUAL
    op[c4d.LOD_LEVEL_COUNT_DYN] = 2
    op[c4d.LOD_CURRENT_LEVEL] = 0

    # Gets first level
    descID = op.GetSimplifyModeDescID(0)
    if descID is not None:
        # Sets mode to "Convex Hull"
        op[descID] = c4d.LOD_SIMPLIFY_CONVEXHULL

        descID = op.GetPerObjectControlDescID(0)
        if descID is not None:
            # Sets "Per Object" to True
            op[descID] = True

    # Gets second level
    descID = op.GetSimplifyModeDescID(1)
    if descID is not None:
        # Sets mode to "Null"
        op[descID] = c4d.LOD_SIMPLIFY_NULL

        descID = op.GetNullDisplayDescID(1)
        if descID is not None:
            # Sets "Display" to "Circle"
            op[descID] = c4d.NULLOBJECT_DISPLAY_CIRCLE

    # Pushes an update event to Cinema 4D
    c4d.EventAdd()


if __name__ == '__main__':
    main()