nr.c4d.misc

This package contains miscallenous helper functions and classes.

nr.c4d.misc.aabb

This module provides the AABB class to compute the axis aligned bounding box of an object or a set of objects.

class nr.c4d.misc.aabb.AABB(translation=None)[source]

This class is used to compute the axis aligned bounding box of an object, a set of objects or a set of points.

from nr.c4d.misc import aabb
box = aabb.AABB()
box.add(point)
box.add_object(op, recursive=True)
print(box.midpoint)
print(box.size)
Parameters:translation – A c4d.Matrix that is applied to all points that are added to the AABB with add().
minv

The minimum Vector. Initialized with None.

maxv

The maximum Vector. Initialized with None.

init

True if the AABB object has been initialized with at least one point, False if not.

translation

The translation Matrix that is applied to all objects added to the box with add().

add(point)[source]

Add the specified point to the AABB. The point is multiplied by the internal translation matrix.

add_object(obj, recursive=False, slow=False)[source]

Add corner points of obj to the AABB.

Parameters:
  • obj – A c4d.BaseObject
  • recursive – If True, child objects will be added as well.
  • slow – If True, c4d.PointObject objects that are encountered are computed slowly by taking each point separately. This should usually not be necessary as the bounding box of the object is computed when c4d.MSG_UPDATE is sent.
midpoint

The mid point of the bounding box.

size

The size of the bounding box, from the middle to one of the corners.

nr.c4d.misc.normalalign

This module implements a function for checking the alignment of the normals of a polygon-object.

nr.c4d.misc.normalalign.align_object_normals(op, info=None, logger=None, normal_info=None)[source]

Align the normals of the c4d.PolygonObject op to point to the outside of the object. The same algorithmic restrictions as for test_object_normals() apply. The parameters are also the same. You can pass an already computed result of test_object_normals() for normal_info.

nr.c4d.misc.normalalign.test_object_normals(op, info=None, logger=None)[source]

Tests the normals of the c4d.PolygonObject op if they’re pointing to the in or outside of the object. Returns a list of boolean variables where each index defines wether the associated polygon’s normal is pointing into the right direction or not.

The algorithm works best on completely closed shapes with one segment only. The PolygonObject should also be valid, therefore not more than two polygons per edge, etc. The results might be incorrect with an invalid mesh structure.

Parameters:
  • op – The c4d.PolygonObject instance to test.
  • info – A PolygonObjectInfo instance for the passed object, or None to generate on demand. If an info object is passed, it must support the following data: polygons, normals and midpoints.
  • logger – An object implementing the logger interface. This is optional and only use for debug purposes.
Returns:

A list of bool values and the info object that was passed or has been generated.

nr.c4d.misc.octree

Experimental octree implementation in Python.

class nr.c4d.misc.octree.OcInterface[source]

Interface for reading size and position of data in the Octree.

get_metrics(item)[source]
class nr.c4d.misc.octree.OcItem(data, position, size)[source]
leaf_containers()

Iterator for all containers that are leaf nodes.

neighbours()

Iterates over all items that are contained in the same leaf containers of this node.

class nr.c4d.misc.octree.OcNode(tree, parent, position, size, depth)[source]

Represents a node in an Octree.

tree

A weak reference to the root node of the tree.

parent

A weak-reference to the parent node.

position

The position of the node in 3D space.

size

The size of the node in all-positive direction.

data

A list of OcItem instances.

children

A list of children. None if the OcNode is a leaf node.

append(obj)[source]

Appends obj to this OcNode and eventually to its child nodes. This might not work if the node can not contain the obj. This method must be called at the root node of the tree.

Parameters:obj – The obj to add.
Raises:RuntimeError – If this method is not called on the root node of the tree.
Returns:True if the obj was added, False if not.
append_item(item)[source]

Appends item to this OcNode and eventually to its child nodes. This might not work if the node can not contain the item or if the node is completely contained inside the

Parameters:item – The item to add.
Returns:True if the item was added, False if not.
is_leaf
subdivide()[source]

Subdivides the OcNode into 8 equally sized child nodes. This is done automatically when the maximum capacity of a node is reached by appending to it.

class nr.c4d.misc.octree.OcObjectImpl(translation=None)[source]
get_metrics(obj)
class nr.c4d.misc.octree.OcTree(max_capacity, max_depth, position, size, impl)[source]

Represents the full Octree. Note that elements that are large enough to fully contain the root node can not be added to it.

nr.c4d.misc.octree.box_box_contains(m1, s1, m2, s2)[source]

Returns True if the box spanned by m1 and s1 contains the box spanned by m2 and s2 completely.

nr.c4d.misc.octree.box_box_intersect(m1, s1, m2, s2)[source]

Checks if the AABB (axis-aligned bounding-box) defined by m1 and s1 intersects with the AABB of m2 and s2. The position must be the middle point of the box, the size defined the radius of the box from its middle point.

nr.c4d.misc.octree.box_point_contains(p, m, s)[source]

Checks if the point v is located inside the box defined by m and s. Returns True if it is, False if not.

nr.c4d.misc.octree.vector_variants(v)[source]

Yields all variants of the c4d.Vector v, that is, all possible combinations of positive and negative sign for all three components.

nr.c4d.misc.paramng

This module implements helper classes for easy management of GUI parameters by using a declared set of parameters and converting them to a Python management system.

Example:

import c4d
from nr.c4d.misc import paramng

class res:
  CHK_ON = 100001
  EDT_INDEX = 100002
  EDT_NAME = 100003

class MyDialog(c4d.gui.GeDialog):

  def __init__(self):
    super(MyDialog, self).__init__()

    # Create the DataManager instance associated with our dialog.
    # The dialog will be stored as a weak reference.
    self.params = paramng.DataManager(self)

    # Create the parameter declaration factory which will certainly
    # help us to declare the parameters to the DataManager.
    f = paramng.Factory(self.params)

    # Declare the parameters.
    f.b('on', res.CHK_ON, default=True)
    f.i('index', res.EDT_INDEX, min=0, max=100)
    f.s('name', res.EDT_NAME, default='Peter')

  def CreateLayout(self):
    return self.LoadDialogResource(res.DLG_MYDIALOG)

  def InitValues(self):
    # Initialize the declared parameters with either the globally
    # saved date, or, if no data was stored globally, the default
    # values.
    bc = c4d.plugins.GetWorldPluginData(PLUGIN_ID)
    if bc:
      paramng.from_base_container(self.params, bc)
    else:
      self.params.restore_defaults()

    # Trigger the Command() message for the CHK_ON widget.
    # Note: If you want to simulate a real Command() message, use
    # the Message() method and BFM_ACTION.
    msg = c4d.BaseContainer()
    self.Command(res.CHK_ON, msg)

    return True

  def DestroyWindow(self):
    # Store our dialog configuration.
    bc = paramng.to_base_container(self.params)
    c4d.plugins.SetWorldPluginData(self.params, bc, add=True)

    super(MyDialog, self).DestroyWindow()

  def Command(self, wid, msg):
    if wid == res.CHK_ON:
      on = self.params.get('on')
      self.Enable(res.EDT_INDEX, on)

    return True
class nr.c4d.misc.paramng.AbstractParameter[source]

Base class for parameter declarations for the DataManager class. It implements the retrieval and overriding of values.

get(reference)[source]
get_default()[source]
set(reference, value)[source]
set_default(reference)[source]
class nr.c4d.misc.paramng.BaseFactory(manager)[source]

The BaseFactory class for doing simple parameter declaration for a DataManager instance.

add_synonym(type_name, class_)[source]

Add a AbstractParameter class synonym to the BaseFactory which can be addressed by using the __call__() or declare() method. Raises ValueError if the synonym type_name is already taken.

declare(_BaseFactory__type_name, _BaseFactory__name, *args, **kwargs)[source]

Declare a new parameter to the wrapped DataManager instance by using one of the defined synonyms (see add_synonym()).

class nr.c4d.misc.paramng.C4DAbstractParameter(param)[source]

Base-class for Cinema 4D Dialog Widget declarations.

bc_get(container)[source]
bc_set(container, value)[source]
class nr.c4d.misc.paramng.C4DBoolParameter(param, default=False)[source]
typename = 'Bool'
class nr.c4d.misc.paramng.C4DFilenameParameter(param, default='')[source]
typename = 'Filename'
class nr.c4d.misc.paramng.C4DLongParameter(param, default=0, min=None, max=None, step=1, min2=None, max2=None, tristate=False)[source]
filter_set_kwargs(kwargs)
typename = 'Long'
class nr.c4d.misc.paramng.C4DParameter(param, default=None, **set_kwargs)[source]
bc_get(container)
bc_set(container, value)
filter_set_kwargs(kwargs)
get(reference)
get_default()
set(reference, value)
set_default(reference)
typename = None
class nr.c4d.misc.paramng.C4DRealParameter(param, default=0.0, min=None, max=None, step=1.0, format=1718773089, min2=None, max2=None, quadscale=False, tristate=False)[source]
typename = 'Real'
class nr.c4d.misc.paramng.C4DStringParameter(param, default='', tristate=False, flags=0)[source]
typename = 'String'
class nr.c4d.misc.paramng.C4DVectorParameter(px, py, pz)[source]
bc_get(container)
bc_set(container, value)
classmethod from_params(idx, idy, idz, default=0, min=None, max=None, step=1.0, format=1718773089, min2=None, max2=None, quadscale=False, tristate=False)

Creates a new C4DVectorParameter instance from idx, idy and idz being dialog symbols and *args and **kwargs being passed to each C4DRealParameter instance created for the C4DVectorParameter instance which is returned from this method.

get(reference)
get_default()
set(reference, value)
set_default(reference)
class nr.c4d.misc.paramng.DataManager(reference=None)[source]

This class allows for easy getting and setting of dialog parameters. The first step is to declare all available parameters to this class using declare() or __lshift__(). After that, you can easily retrieve parameters using the get() method.

declare(name, parameter)[source]

Declare a parameter to the DataManager. Raises an AssertionError if a parameter with the specified name is already defined or parameter is not a AbstractParameter instance.

default(name, reference=None)[source]

Get the default value of a parameter by name. Raises a RuntimeError if reference is not given and the reference attribute is not specified either.

dict(reference=None)[source]

Gather a Python dictionary filled with all the parameters from the specified reference. If reference is omitted and reference is not specified either, a RuntimeError is raised.

get(name, reference=None)[source]

Retrieve the value of a parameter by name. If reference is not specified, reference must be given. A RuntimeError is raised otherwise.

get_all(*names, **refkwargs)[source]

Get a generator of all values of the parameters specified by *names.

restore_defaults(reference=None)[source]

Restore the default values of all declared parameters.

set(name, value, reference=None)[source]

Set a value to a parameter by name. If reference is not specified, reference must be given. A RuntimeError is raised otherwise.

set_all(*names, **refkwargs)[source]

Set parameters specified in *names. An item of *names can be either a list or tuple of two items, or a string followed by any other value.

set_default(name, reference=None)[source]

Set the default value of the parameter specified via name.

class nr.c4d.misc.paramng.Factory(manager)[source]

Create a new BaseFactory instance with all standard parameter shortcuts assigned.

l/i LONG
r Real
s String
b Boool
f Filename
v Vector
nr.c4d.misc.paramng.from_base_container(manager, container, reference=None)[source]

The reverse to c4d_to_container().

nr.c4d.misc.paramng.to_base_container(manager, reference=None)[source]

Convert the values declared in the DataManager of manager to a c4d.BaseContainer via the specified reference or the reference specified in the manager.