Ejemplo n.º 1
0
def CreateVectorVolume(vectorValue):
    """
    Creates a VolumeRef defined as a vector volume, with a cube of 20 cm filled with the vector value passed.

    :param vectorValue: The vector value to set.
    :type vectorValue: maxon.Vector32
    :return: The created Vector volume with the value defined inside.
    :rtype: maxon.frameworks.volume.VolumeRef
    """
    # Creates volume
    volumeRef = maxon.frameworks.volume.VolumeToolsInterface.CreateNewVector32Volume(
        maxon.Vector32(0.0))
    if volumeRef is None:
        raise MemoryError("Failed to create a float32 volume.")

    # Creates accessor
    access = maxon.frameworks.volume.GridAccessorInterface.Create(
        maxon.Vector32)
    if access is None:
        raise RuntimeError("Failed to retrieve the grid accessor.")

    # Initializes the grid for write access
    access.InitWithWriteAccess(volumeRef)

    # Sets values
    size = 20
    for x in range(size):
        for y in range(size):
            for z in range(size):
                pos = maxon.IntVector32(x, y, z)
                access.SetValue(pos, vectorValue)

    return volumeRef
def CreateVectorVolume(vectorValue):
    """Creates a VolumeRef defined as a vector volume, with a cube of 100 cm (10* 10) filled with the vector passed.

    Args:
        vectorValue (maxon.Vector32): The vector value to set.

    Returns:
        maxon.frameworks.volume.VolumeRef: The created Vector volume with the value defined inside.
    """
    # Creates volume
    volumeRef = maxon.frameworks.volume.VolumeToolsInterface.CreateNewVector32Volume(
        maxon.Vector32(0.0))
    if volumeRef is None:
        raise MemoryError("Failed to create a float32 volume.")

    # Creates accessor
    access = maxon.frameworks.volume.GridAccessorInterface.Create(
        maxon.Vector32)
    if access is None:
        raise RuntimeError("Failed to retrieve the grid accessor.")

    # Initializes the grid for write access
    access.InitWithWriteAccess(volumeRef)

    # Sets values
    size = 10
    step = 10.0
    for x in range(size):
        for y in range(size):
            for z in range(size):
                pos = maxon.IntVector32(x * step, y * step, z * step)
                access.SetValue(pos, vectorValue)

    return volumeRef
Ejemplo n.º 3
0
def main():
    # Creates VolumeObject
    volumeObj = c4d.BaseObject(c4d.Ovolume)
    if volumeObj is None:
        raise MemoryError("Failed to create a volume object.")

    # Inserts the volume Object within the scene
    doc.InsertObject(volumeObj, None, None)

    # Creates volume
    volume = maxon.frameworks.volume.VolumeToolsInterface.CreateNewFloat32Volume(
        0.0)
    if volume is None:
        raise MemoryError("Failed to create a float32 volume.")

    volume.SetGridClass(c4d.GRIDCLASS_FOG)
    volume.SetGridName("Example Grid")

    # Defines the initial matrix of the grid
    scaleMatrix = maxon.Matrix()
    volume.SetGridTransform(scaleMatrix)

    # Creates accessor
    access = maxon.frameworks.volume.GridAccessorInterface.Create(
        maxon.Float32)
    if access is None:
        raise RuntimeError("Failed to retrieve the grid accessor.")

    # Initializes the grid for write access, changed with R21
    initMethod = access.Init if c4d.GetC4DVersion(
    ) < 21000 else access.InitWithWriteAccess
    initMethod(volume)

    # Sets values in the shape of a helix
    offset = 0.0
    radius = 100.0
    height = 500.0
    step = 50.0
    stepSize = height / step

    while offset < step:
        sin, cos = c4d.utils.SinCos(offset)
        pos = maxon.IntVector32()
        pos.x = maxon.Int32(sin * radius)
        pos.y = maxon.Int32(cos * radius)
        pos.z = maxon.Int32(offset * stepSize)

        # Sets value
        access.SetValue(pos, 10.0)

        offset = offset + 0.1

    # Inserts volume in the VolumeObject
    volumeObj.SetVolume(volume)

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