Exemplo n.º 1
0
def main():
    # Creates a matrix and a sphere object
    matrix = c4d.BaseObject(1018545)
    sphere = c4d.BaseObject(c4d.Osphere)

    # If the matrix or the sphere object is not created
    if matrix is None or sphere is None:
        raise RuntimeError("Failed to create a matrix object or a sphere.")

    # Inserts theses 2 objects in the current document.
    doc.InsertObject(matrix)
    doc.InsertObject(sphere)

    # Creates an instance object
    instance = c4d.InstanceObject()
    if instance is None:
        raise RuntimeError("Failed to create an instance object.")

    # Inserts the instance object in the active document
    doc.InsertObject(instance, None, None)

    # Defines the reference object to be instanced.
    instance.SetReferenceObject(sphere)

    # Defines the matrix object as input position object.
    instance[c4d.INSTANCEOBJECT_MULTIPOSITIONINPUT] = matrix
    instance[c4d.INSTANCEOBJECT_RENDERINSTANCE_MODE] = c4d.INSTANCEOBJECT_RENDERINSTANCE_MODE_MULTIINSTANCE

    # Pushes an update event to Cinema 4D
    c4d.EventAdd()
Exemplo n.º 2
0
def main():
    # Creates cube
    cube = c4d.BaseObject(c4d.Ocube)
    if cube is None:
        raise RuntimeError("Failed to create a cube.")

    # Creates instance object
    instance = c4d.InstanceObject()
    if instance is None:
        raise RuntimeError("Failed to create an instance object.")

    # Inserts cube into the active document
    doc.InsertObject(cube, None, None)

    # Inserts instance object into the active document
    doc.InsertObject(instance, None, None)

    # Makes instance object active (selected)
    doc.SetActiveObject(instance)

    # Sets the instance reference object to the created cube
    instance.SetReferenceObject(cube)

    # Sets render instance mode to multi-instance
    instance[
        c4d.
        INSTANCEOBJECT_RENDERINSTANCE_MODE] = c4d.INSTANCEOBJECT_RENDERINSTANCE_MODE_MULTIINSTANCE

    # Displays instances as points
    instance[
        c4d.INSTANCEOBJECT_DRAW_MODE] = c4d.INSTANCEOBJECT_DRAW_MODE_POINTS

    # Initializes multi-instance matrices and colors
    matrices = list()
    colors = list()

    # The number of instances
    count = 100

    # Start position and translation step
    position = 0.0
    step = 300.0

    # Hue start and step
    hue = 0.0
    hueStep = 1.0 / count

    # Generates matrices and colors for 100 instances
    for i in range(count):
        # Calculates the current instance matrix
        matrix = c4d.utils.MatrixMove(c4d.Vector(position, 0.0, 0.0))
        matrices.append(matrix)
        position = position + step

        # Calculates the current instance color
        colorHSV = c4d.Vector(hue, 1.0, 1.0)
        colorRGB = c4d.utils.HSVToRGB(colorHSV)
        colors.append(colorRGB)
        hue = hue + hueStep

    # Stores instance matrices
    instance.SetInstanceMatrices(matrices)

    # Stores instance colors
    instance.SetInstanceColors(colors)

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