c4d.utils

Functions

c4d.utils.SendModelingCommand(command, list[, mode=MODELINGCOMMANDMODE_ALL][, bc=None][, doc=None][, flags=MODELINGCOMMANDFLAGS_0])

With this function one can apply nearly all modeling commands. The function is applied to the objects in list. With the parameter mode you can decide if the current selection should be used to control what points/polygons are affected.

Note

Current State to Object(CSTO) has to be executed on a duplicate of an object because CSTO modifies the existing caches. In some cases you have to use a temporary document as well ObjectData.GetVirtualObjects().

This is a small example how you can use this function:

import c4d
from c4d import utils

settings = c4d.BaseContainer()                 # Settings
settings[c4d.MDATA_EXTRUDE_OFFSET] = 50.0      # Length of the extrusion

res = utils.SendModelingCommand(command = c4d.ID_MODELING_EXTRUDE_TOOL,
                                list = [op],
                                mode = c4d.MODELINGCOMMANDMODE_POLYGONSELECTION,
                                bc = settings,
                                doc = doc)
c4d.EventAdd()

if res is False:
  print "Something went wrong."
elif res is True:
  print "Command successful."
elif isinstance(res, list):
  print "Here you get the newly created object(s)."
Parameters:
  • command (int) – The modeling command. See MCOMMAND.
  • list (list of BaseObjects) – A list with objects which you want to apply the modeling command.
  • bc (c4d.BaseContainer) – This is a settings container which contains all the values of the tool you want to apply.
  • mode (int) –

    Modeling mode:

    MODELINGCOMMANDMODE_ALL All points/polygons.
    MODELINGCOMMANDMODE_POINTSELECTION Only the current point selection.
    MODELINGCOMMANDMODE_POLYGONSELECTION Only the current polygon selection.
    MODELINGCOMMANDMODE_EDGESELECTION Only the current edge selection.
  • doc (c4d.documents.BaseDocument) –
    The document for the operation. Should be set if possible. Must be set for MCOMMAND_MAKEEDITABLE, MCOMMAND_CURRENTSTATETOOBJECT and MCOMMAND_SPLINE_PROJECT.
    If you set the document, the objects which you pass to this function have to be in the same document. So pay attention that you use one send_modeling_command per document for objects.
  • flags (int) –

    The flags:

    MODELINGCOMMANDFLAGS_0 None.
    MODELINGCOMMANDFLAGS_CREATEUNDO Creates undo and inserts newly created objects into the passed document, instead of returning result.
Return type:

False, True or list of BaseObject

Returns:

True if the command succeeded, otherwise False if something went wrong. Some commands do not apply their task to the passed objects, they return a cloned object so just check it.

c4d.utils.DisjointMesh(op)
Separates the mesh of the object to make each polygon/line segment independent.
Each polygon/line will be given its own points thereby separating them so they can be moved independently, such as the Explosion object.
Parameters:op (c4d.PointObject) – The point object to disjoint.
Return type:bool
Param:True if the mesh was disjointed successfully, otherwise False.
c4d.utils.FitCurve(padr, error[, bt=None])

Creates a spline object that has the best fit through the given points.

Parameters:
  • padr (list of c4d.Vector) – The points to fit a curve to.
  • error (float) – Sets how closely the curve must match the passed points. The lower the value then the closer the curve will match.
  • bt (c4d.threading.BaseThread) –

    New in version R18.057.

    An optional thread.

Return type:

c4d.SplineObject

Returns:

A Spline object that fits the given points, or AllocationFailed error if a spline object cannot be obtained.

c4d.utils.CheckDisplayFilter(op, filter)

Checks if object op would be displayed with the given filter.

Example:

import c4d

activeView = doc.GetActiveBaseDraw()
displayFilter = activeView.GetDisplayFilter()
if c4d.utils.CheckDisplayFilter(op, displayFilter):
    print "Object Displayed!"
else:
    print "Object Not Displayed!"
Parameters:
  • op (c4d.BaseObject) – The object to check.
  • filter (int) –

    The filter bitmask:

    DISPLAYFILTER_0 None.
    DISPLAYFILTER_NULL Null.
    DISPLAYFILTER_POLYGON Polygon.
    DISPLAYFILTER_SPLINE Spline.
    DISPLAYFILTER_GENERATOR Generator.
    DISPLAYFILTER_HYPERNURBS Subdivision Surface.
    DISPLAYFILTER_UNUSED1 Unused.
    DISPLAYFILTER_DEFORMER Deformer.
    DISPLAYFILTER_CAMERA Camera.
    DISPLAYFILTER_LIGHT Light.
    DISPLAYFILTER_SCENE Scene.
    DISPLAYFILTER_PARTICLE Particle.
    DISPLAYFILTER_OTHER Other.
    DISPLAYFILTER_GRID Grid.
    DISPLAYFILTER_HORIZON Horizon.
    DISPLAYFILTER_WORLDAXIS World axis.
    DISPLAYFILTER_BOUNDS Bounding-box.
    DISPLAYFILTER_HUD HUD.
    DISPLAYFILTER_SDS HN mesh.
    DISPLAYFILTER_HIGHLIGHTING Highlighting.
    DISPLAYFILTER_MULTIAXIS Multi-select axis.
    DISPLAYFILTER_OBJECTHANDLES Highlight handles.
    DISPLAYFILTER_HANDLEBANDS Axis bands.
    DISPLAYFILTER_SDSCAGE HN cage.
    DISPLAYFILTER_NGONLINES N-gon lines.
    DISPLAYFILTER_JOINT Joint objects.
    DISPLAYFILTER_OBJECTHIGHLIGHTING Private.
    DISPLAYFILTER_GUIDELINES Axis Guidelines.
    DISPLAYFILTER_POI Navigation cross.
    DISPLAYFILTER_GRADIENT Gradient.
    DISPLAYFILTER_BASEGRID Base grid.
    DISPLAYFILTER_HANDLES Handles.
Return type:

bool

Returns:

True if the object would be displayed, otherwise False.

c4d.utils.CalculateVisiblePoints(bd, op)

Checks if points in the polygon object op are visible in the view bd.

Parameters:
Return type:

list of int

Returns:

A list of integers with the visibility status for each point: 1 if the point is visible otherwise 0.
None if the function fails.

c4d.utils.GenerateUVW(op, opmg, tp, texopmg[, view=None])

Generates a UVW tag for an object.

Parameters:
  • op (c4d.BaseObject) – The object to generate the UVW coordinates for.
  • opmg (c4d.Matrix) – The object’s global matrix.
  • tp (c4d.TextureTag) – The texture tag to generate the UVW coordinates from.
  • texopmg (c4d.Matrix) – The global matrix of the object that carries the texture tag.
  • view (c4d.BaseView) – The optional current view.
Return type:

c4d.UVWTag

Returns:

The created UVW tag, or None if the texture type is already UV or if the function failed.
If None is returned the UVW tag must be retrieved from the object itself.

c4d.utils.GetBBox(pObj, mg)

Calculates the bounding box of a hierarchy.

Parameters:
  • pObj (c4d.BaseObject) – The root object of a hierarchy.
  • mg (c4d.Matrix) – The transformation matrix for the bounding box.
Return type:

tuple(c4d.Vector, c4d.Vector)

Returns:

The center and the radius of the bounding box.

c4d.utils.FormatNumber(val, format, fps[, bUnit=True])

Converts val to a string.

Parameters:
  • val (any) – The value to convert to a string. Must be of type float, int or c4d.BaseTime.
  • format (int) –

    The format:

    FORMAT_FLOAT Floating point without unit.
    FORMAT_INT Integer without unit.
    FORMAT_PERCENT Floating point with % sign, 1.0 = 100%.
    FORMAT_DEGREE Floating point with ° sign. Measured in radians, displayed in degrees.
    FORMAT_METER Floating point in the current working unit.
    FORMAT_FRAMES Time formatted as frames. (Overrided by user preference.)
    FORMAT_SECONDS Time formatted as seconds. (Overrided by user preference.)
    FORMAT_SMPTE Time formatted as SMPTE. (Overrided by user preference.)
  • fps (int) – The frames per second, for time values.
  • bUnit (bool) – If True the unit is included in the formatted string.
Return type:

str

Returns:

The formatted string.

c4d.utils.StringToNumber(text, format, fps[, lengthunit])

Converts a string to a data value of type float, int or c4d.BaseTime.

Parameters:
  • text (str) – The string to convert to a value.
  • format (int) –

    The format:

    FORMAT_FLOAT Floating point without unit.
    FORMAT_INT Integer without unit.
    FORMAT_PERCENT Floating point with % sign, 1.0 = 100%.
    FORMAT_DEGREE Floating point with ° sign. Measured in radians, displayed in degrees.
    FORMAT_METER Floating point in the current working unit.
    FORMAT_FRAMES Time formatted as frames. (Overrided by user preference.)
    FORMAT_SECONDS Time formatted as seconds. (Overrided by user preference.)
    FORMAT_SMPTE Time formatted as SMPTE. (Overrided by user preference.)
  • fps (int) – The frames per second, for time values.
  • lengthunit (int) –

    New in version R18.057.

    Can be used to override the units conversion. By default the function uses the document’s units.
    For example a string of “50” results in 0.5 if the document’s units are Meters and the unit display setting is centimeters.
    If lengthunit is specified its value will be used instead of the document’s units setting.
Return type:

any

Returns:

The converted value.

c4d.utils.GetAngle(v1, v2)

Calculates the angle of two vectors.

Parameters:
Return type:

float

Returns:

The angle.

c4d.utils.RangeMap(value, mininput, maxinput, minoutput, maxoutput, clampval[, curve])

Map the value of a range to another, optionnaly applying a spline curve. Similiar to the RangeMapper Node in XPresso.

Here are several examples:

RangeMap(value=0.5, mininput=0, maxinput=1, minoutput=5, maxoutput=10, clampval=False)
#Output: 7.5

c4d.utils.RangeMap(value=1.5, mininput=0, maxinput=1, minoutput=5, maxoutput=10, clampval=False)
#Output: 12.5

c4d.utils.RangeMap(value=1.5, mininput=0, maxinput=1, minoutput=5, maxoutput=10, clampval=True)
#Output: 10.0
Parameters:
  • value (float) – The value to map.
  • mininput (float) – The minimum input.
  • maxinput (float) – The maximum input.
  • minoutput (float) – The minimum output.
  • maxoutput (float) – The maximum output.
  • clampval (bool) – Pass True to clamp the value in the range [minoutput, maxoutput].
  • curve (c4d.SplineData) – The optional curve to use.
c4d.utils.DegToRad(d)

New in version R18.039.

Convert a degrees value into radians.

Parameters:r (number) – Input value in degrees.
Return type:number
Returns:Converted value in radians.
c4d.utils.Rad(d)

Deprecated since version R18.039.

Use DegToRad() instead for better understanding of code.

Convert a degrees value into radians.

Parameters:r (number) – Input value in degrees.
Return type:number
Returns:Converted value in radians.
c4d.utils.RadToDeg(r)

New in version R18.039.

Convert a radians value into degrees.

Parameters:r (number) – Input value in radians.
Return type:number
Returns:Converted value in degrees.
c4d.utils.Deg(r)

Deprecated since version R18.039.

Use RadToDeg() instead for better understanding of code.

Convert a radians value into degrees.

Parameters:r (number) – Input value in radians.
Return type:number
Returns:Converted value in degrees.
c4d.utils.MixVec(v1, v2, t)

Mixes the two vectors together, such as mixing two colours.

Parameters:
  • v1 (c4d.Vector) – Vector to mix.
  • v2 (c4d.Vector) – Vector to mix.
  • t (number) – Mix amount: 0 < t < 1.0.
Return type:

c4d.Vector

Returns:

The mixed vector.

c4d.utils.MixNum(v1, v2, t)

Returns a mixed value of v1 and v2 using the parameter t, as calculated by v1+(v2-v1)*t.

Parameters:
  • v1 (float) – Value to mix.
  • v2 (float) – Value to mix.
  • t (number) – Mix amount: 0 < t < 1.0.
Return type:

float

Returns:

Mix amount, with 0 <= t <= 1.0.

c4d.utils.Pulse(a, b, x)

Returns 1.0 if x is between or equal to either of a and b, else 0.0.

Parameters:
  • a (number) – The float value.
  • b (number) – The float value.
  • x (number) – The float value.
Return type:

float

Returns:

The pulse value.

c4d.utils.Clamp(a, b, x)

Returns a if x is less than a and b if x is greater than b, else returns x.

Note

The order of parameters are different to Peachey’s definition.

Parameters:
  • a (number) – The float value.
  • b (number) – The float value.
  • x (number) – The float value.
Return type:

float

Returns:

The clamped value.

c4d.utils.ClampValue(x, a, b)

New in version R15.037.

Returns a if x is less than a and b if x is greater than b, else returns x.

Note

The order of parameters are the same to Peachey’s definition.

Parameters:
  • x (number) – The float value.
  • a (number) – The float value.
  • b (number) – The float value.
Return type:

float

Returns:

The clamped value.

c4d.utils.Step(a, b)

Returns 1.0 if x is greater than or equal to a, else 0.0.

Parameters:
  • a (number) – The float value.
  • b (number) – The float value.
Return type:

float

Returns:

The step value (1.0 or 0.0).

c4d.utils.Smoothstep(a, b, x)

Returns 0.0 if x is less than a and 1.0 if x is greater than b, else returns x mapped on the range [a,b] (a number between 0.0 and 1.0). The mapping is smoothed using an ease-in/ease-out curve.

Parameters:
  • a (float) – The float value.
  • b (float) – The float value.
  • x (float) – The float value.
Return type:

float

Returns:

The smoothed value.

c4d.utils.Boxstep(a, b, x)

Returns 0.0 if x is less than a and 1.0 if x is greater than b, else returns x mapped on the range [a,b] (a number between 0.0 and 1.0).

Parameters:
  • a (number) – The float value.
  • b (number) – The float value.
  • x (number) – The float value.
Return type:

float

Returns:

The stepped value.

c4d.utils.MatrixRotX(w)

Creates a rotation matrix about the X axis.

Parameters:w (float) – The angle around X.
Return type:c4d.Matrix
Returns:The rotation matrix.
c4d.utils.MatrixRotY(w)

Creates a rotation matrix about the Y axis.

Parameters:w (float) – The angle around Y.
Return type:c4d.Matrix
Returns:The rotation matrix.
c4d.utils.MatrixRotZ(w)

Creates a rotation matrix about the Z axis.

Parameters:w (float) – The angle around Z.
Return type:c4d.Matrix
Returns:The rotation matrix.
c4d.utils.QSlerp(q1, q2, alfa)

New in version R17.048.

Linear interpolates the quaternions q1 and q2 with the parameter alfa.

Parameters:
  • q1 (c4d.Quaternion) – The first quaternion.
  • q2 (c4d.Quaternion) – The second quaternion.
  • alfa (float) – The interpolation parameter. Between 0.0 (q1) and 1.0 (q2).
Return type:

c4d.Quaternion

Returns:

The interpolated quaternion.

c4d.utils.QSquad(q0, q1, q2, q3, alfa)

New in version R17.048.

Cubic interpolates the quaternions q1 and q2 with parameter alfa using spherical quadrangle interpolation.
q0 and q3 are used to provide C1-continuity at the borders (tangents): q0 = i-1, q1 = i, q2 = i+1, q3 = i+2
Parameters:
  • q0 (c4d.Quaternion) – The first quaternion to provide continuity.
  • q1 (c4d.Quaternion) – The first quaternion to interpolate from.
  • q2 (c4d.Quaternion) – The second quaternion to interpolate from.
  • q3 (c4d.Quaternion) – The second quaternion to provide continuity.
  • alfa (float) – The interpolation parameter. Between 0.0 (q1) and 1.0 (q2).
Return type:

c4d.Quaternion

Returns:

The interpolated quaternion.

c4d.utils.QBlend(q1, q2, r)

New in version R17.048.

Smooth interpolates the quaternions q1 and q2 with parameter r.

Parameters:
  • q1 (c4d.Quaternion) – The first quaternion.
  • q2 (c4d.Quaternion) – The second quaternion.
  • alfa (float) – The blending parameter. Between 0.0 (q1) and 1.0 (q2).
Return type:

c4d.Quaternion

Returns:

The interpolated quaternion.

c4d.utils.QSpline(qn_m1, qn, qn_p1, qn_p2, t)

New in version R17.048.

Smooth blends the quaternions qn and qn_p1 using spherical spline interpolation with parameter t.
qn_m1 (-1) and qn_p2 (-1+2) are used to provide C1-continuity at the borders (tangents).
Parameters:
  • qn_m1 (c4d.Quaternion) – The first quaternion (-1) to provide continuity.
  • qn (c4d.Quaternion) – The first quaternion to interpolate from.
  • qn_p1 (c4d.Quaternion) – The second quaternion to interpolate from.
  • qn_p2 (c4d.Quaternion) – The second quaternion (+2) to provide continuity.
  • t (float) – The blending parameter. Between 0.0 (qn) and 1.0 (qn_p1).
Return type:

c4d.Quaternion

Returns:

The interpolated quaternion.

c4d.utils.QSmoothCubic(qn_m1, qn, qn_p1, t)

New in version R18.020.

Smooth blends the quaternions qn and qn_p1 using Cubic interpolation with parameter t.
qn_m1 (-1) and qn_p2 (-1+2) are used to provide C1-continuity at the borders (tangents).
Parameters:
  • qn_m1 (c4d.Quaternion) – The first quaternion (-1) to provide continuity.
  • qn (c4d.Quaternion) – The first quaternion to interpolate from.
  • qn_p1 (c4d.Quaternion) – The second quaternion to interpolate from.
  • t (float) – The blending parameter. Between 0.0 (qn) and 1.0 (qn_p1).
Return type:

c4d.Quaternion

Returns:

The interpolated quaternion.

c4d.utils.QNorm(q)

New in version R17.048.

Gets a normalized copy of quaternion q.

Parameters:q (c4d.Quaternion) – The quaternion to normalize.
Return type:c4d.Quaternion
Returns:A normalized copy of q.
c4d.utils.QMul(q1, q2)

New in version R17.048.

Calculates the quaternion product of quaternions q1 and q2.

Parameters:
Return type:

c4d.Quaternion

Returns:

The quaternion product of q1 and q2.

c4d.utils.QMulS(q, s)

New in version R17.048.

Calculates the product of quaternion q with scalar s.

Parameters:
Return type:

c4d.Quaternion

Returns:

The product of q with s.

c4d.utils.QAdd()

New in version R17.048.

Calculates the quaternion addition of quaternions q1 and q2.

Parameters:
Return type:

c4d.Quaternion

Returns:

The quaternion addition of q1 and q2.

c4d.utils.QSub()

New in version R17.048.

Calculates the quaternion subtraction of quaternions q1 and q2.

Parameters:
Return type:

c4d.Quaternion

Returns:

The quaternion subtraction of q1 and q2.

c4d.utils.QInvert(q)

New in version R17.048.

Calculates the inverse of quaternion q.

Parameters:q (c4d.Quaternion) – The quaternion to invert.
Return type:c4d.Quaternion
Returns:The quaternion inverse of q.
c4d.utils.QDot(q1, q2)

New in version R18.020.

Calculates the Dot Product between q1 and q2.

Parameters:
Return type:

float

Returns:

The Dot Product of q1 and q2.

c4d.utils.QDeriv(q, w)

New in version R17.048.

Calculates the derivative of quaternion q by vector w.

Parameters:
Return type:

c4d.Quaternion

Returns:

The quaternion derivative of q by w.

c4d.utils.QLogN(q)

New in version R17.048.

Calculates the natural logarithm of quaternion q.

Parameters:q (c4d.Quaternion) – The quaternion.
Return type:c4d.Quaternion
Returns:The natural logarithm of q.
c4d.utils.QExpQ(q)

New in version R17.048.

Calculates the exponential of quaternion q.

Parameters:q (c4d.Quaternion) – The quaternion.
Return type:c4d.Quaternion
Returns:The exponential of q.
c4d.utils.MatrixToRotAxis(m)

Calculates rotation axis and angle from matrix m:

v, w = MatrixToRotAxis(m)
#v is the rotation axis, c4d.Vector
#w is the rotation angle, float
Parameters:m (c4d.Matrix) – Rotation matrix.
Return type:list
Returns:The rotation axis, and the angle.
c4d.utils.RotAxisToMatrix(v, w)

Calculate matrix from rotation axis v and angle w.

Parameters:
  • v (c4d.Vector) – The axis.
  • w (float) – The angle of rotation.
Return type:

c4d.Matrix

Returns:

The rotation matrix.

c4d.utils.GetOptimalAngle(hpb_old, hpb_new, rotation_order)

Modify hpb_new so that the “distance” to the last angle hpb_old is at minimum. This helps to avoid HPB singularity effects.

Parameters:
  • hpb_old (c4d.Vector) – The old HPB.
  • hpb_new (c4d.Vector) – The new HPB.
  • rotation_order (int) –

    The order of rotation:

    ROTATIONORDER_YXZGLOBAL Global YXZ order.
    ROTATIONORDER_YZXGLOBAL Global YZX order.
    ROTATIONORDER_ZYXGLOBAL Global ZYX order.
    ROTATIONORDER_ZXYGLOBAL Global ZXY order.
    ROTATIONORDER_XZYGLOBAL Global XZY order.
    ROTATIONORDER_XYZGLOBAL Global XYZ order.
    ROTATIONORDER_YXZLOCAL Local YXZ order.
    ROTATIONORDER_YZXLOCAL Local YZX order.
    ROTATIONORDER_ZYXLOCAL Local ZYX order.
    ROTATIONORDER_ZXYLOCAL Local ZXY order.
    ROTATIONORDER_XZYLOCAL Local XZY order.
    ROTATIONORDER_XYZLOCAL Local XYZ order.
    ROTATIONORDER_HPB HPB order.
    ROTATIONORDER_DEFAULT Default order. ROTATIONORDER_HPB.
Return type:

c4d.Vector

Returns:

The optimal angle.

c4d.utils.PointLineDistance(p0, v, p)

Calculates the distance from a point to a line.

Parameters:
Return type:

c4d.Vector

Returns:

Point-line vector.

c4d.utils.ReflectRay(v, n)

Find the ray vector after a reflection about a surface normal.

Parameters:
Return type:

c4d.Vector

Returns:

The reflected ray.

c4d.utils.CalcSpline(x, knots)

Calculates the value of a spline at a point.

Parameters:
  • x (float) – The position on the spline.
  • knots (list of float) – The knots list.
Return type:

float

Returns:

The spline value.

c4d.utils.CalcSplineV(x, knots)

Calculates the value of a spline at a point.

Parameters:
  • x (float) – The position on the spline.
  • knots (list of Vector) – The knots list.
Return type:

c4d.Vector

Returns:

The spline value.

c4d.utils.CalcSplinePoint(offset, type, closed, pcnt, padr[, tadr=None])

New in version R17.048.

Calculates a point along a spline curve from a set of points in 3D space.

Parameters:
  • offset (float) – The offset along the spline from 0.0 to 1.0.
  • type (int) –

    The type of spline. Check out Spline Types.

    SPLINETYPE_LINEAR Linear.
    SPLINETYPE_CUBIC Cubic.
    SPLINETYPE_AKIMA Akima.
    SPLINETYPE_BSPLINE B-Spline.
    SPLINETYPE_BEZIER Bezier.
  • closed (bool) – Whether the spline is closed or not.
  • pcnt (int) – The number of points in the spline.
  • padr (list of Vector) – The points array.
  • tadr (list of tangent(dict)) –
    The tangents array, required for Bezier, Cubic and Akima spline types (otherwise will default to b-spline).
    A tangent dictionary has to be defined as: dict(‘vl’: Vector, ‘vr’: Vector)
Return type:

c4d.Vector

Returns:

The resulting point calculated from the offset.

c4d.utils.CalcSplineTangent(offset, type, closed, pcnt, padr[, tadr=None])

New in version R17.048.

Calculates the tangent of a point along a spline curve from a given set of points and optional tangents.

Parameters:
  • offset (float) – The offset along the spline from 0.0 to 1.0.
  • type (int) –

    The type of spline. Check out Spline Types.

    SPLINETYPE_LINEAR Linear.
    SPLINETYPE_CUBIC Cubic.
    SPLINETYPE_AKIMA Akima.
    SPLINETYPE_BSPLINE B-Spline.
    SPLINETYPE_BEZIER Bezier.
  • closed (bool) – Whether the spline is closed or not.
  • pcnt (int) – The number of points in the spline.
  • padr (list of Vector) – The points array.
  • tadr (list of tangent(dict)) –
    The tangents array, required for Bezier, Cubic and Akima spline types (otherwise will default to b-spline).
    A tangent dictionary has to be defined as: dict(‘vl’: Vector, ‘vr’: Vector)
Return type:

c4d.Vector

Returns:

The resulting tangent (normalized) for the given offset.

c4d.utils.CalcSplineInsert(offset, type, closed, pcnt, padr[, tadr=None])

New in version R17.048.

Calculates data about a point would if it were inserted into the spline at the passed offset.

Parameters:
  • offset (float) – The offset along the spline from 0.0 to 1.0.
  • type (int) –

    The type of spline. Check out Spline Types.

    SPLINETYPE_LINEAR Linear.
    SPLINETYPE_CUBIC Cubic.
    SPLINETYPE_AKIMA Akima.
    SPLINETYPE_BSPLINE B-Spline.
    SPLINETYPE_BEZIER Bezier.
  • closed (bool) – Whether the spline is closed or not.
  • pcnt (int) – The number of points in the spline.
  • padr (list of Vector) – The points array.
  • tadr (list of tangent(dict)) –
    The tangents array, required for Bezier, Cubic and Akima spline types (otherwise will default to b-spline).
    A tangent dictionary has to be defined as: dict(‘vl’: Vector, ‘vr’: Vector)
Return type:

dict(int, Vector, Tangent, Vector, Vector)

Returns:

A dictionary with the following information:

  • “pointIndex”: The index that the resulting point would be if it were inserted into the spline.
  • “resultPoint”: The position of the resulting point.
  • “resultTangent”: The spline tangent information of the resulting point. dict(‘vl’: Vector,’vr’: Vector)
  • “leftTangent”: The correct new left tangent (tadr[pointIndex - 1].vr).
  • “rightTangent”: The correct new right tangent (tadr[pointIndex].vl).
c4d.utils.TransformTangent(newPos, planeNormal, position, tangent, tangentSide[, flags=c4d.TANGENTTRANSFORMFLAG_BREAK_SCALE])

New in version R17.048.

Creates a transformed tangent around a point and plane, allowing to directly set the position of one of the tangent handles and automatically rotating the rest of the tangent to match.

Parameters:
  • newPos (c4d.Vector) – The new position for the tangent handle.
  • planeNormal (c4d.Vector) – The normal of the plane for rotation of the handles.
  • position (c4d.Vector) – The position of the center of the tangent being modified.
  • tangent (dict) –
    The tangent to modify/derive the resulting tangent from.
    A tangent dictionary has to be defined as: dict(‘vl’: Vector, ‘vr’: Vector)
  • tangentSide (int) –

    The handle to modify of the tangent, left, right, or none:

    TANGENTSIDE_0 No tangent handles being modified.
    TANGENTSIDE_LEFT Modify the left tangent handle.
    TANGENTSIDE_RIGHT Modify the right tangent handle.
  • flags (int) –

    The flags for controlling tangent breaking, rotation and scale locking etc.

    TANGENTTRANSFORMFLAG_0 None.
    TANGENTTRANSFORMFLAG_LOCK_LENGTH Fix the length of the tangents, only change the rotation.
    TANGENTTRANSFORMFLAG_LOCK_ANGLE Fix the angle of the tangents, only change the length.
    TANGENTTRANSFORMFLAG_BREAK_SCALE Only scale one handle (but rotate both).
    TANGENTTRANSFORMFLAG_BREAK Only modify one handle.
Return type:

dict(‘vl’: Vector,’vr’: Vector)

Returns:

The resulting transformed tangent.

c4d.utils.CalcSplineMovement(newPos, offset, type, splineMg, bd, planeNormal, closed, lockTangentAngle, lockTangentLength, breakTangents, pcnt, padr, tadr)

New in version R17.048.

Moves a point on a spline curve to a user specified new position.

Parameters:
  • newPos (c4d.Vector) – The new position for the point of the curve at offset.
  • offset (float) – The offset to move to the position newPos.
  • type (int) –

    The type of spline to move. Check out Spline Types.

    SPLINETYPE_LINEAR Linear.
    SPLINETYPE_CUBIC Cubic.
    SPLINETYPE_AKIMA Akima.
    SPLINETYPE_BSPLINE B-Spline.
    SPLINETYPE_BEZIER Bezier.
  • splineMg (c4d.Matrix) – The matrix of the spline.
  • bd (c4d.BaseDraw) – The optional basedraw. Can be None.
  • planeNormal (c4d.Vector) – The normal for tangent rotation, typically Vector(0,0,1).
  • closed (bool) – The closed state of the spline.
  • lockTangentAngle (bool) – True if tangents angle may not be changed by this routine.
  • lockTangentLength (bool) – True if the tangents length may not be changed by this routine.
  • breakTangents (int) –

    Set to break the tangents while manipulating the curve if tangents exist:

    BREAKTANGENTS_FALSE Do not break any tangents.
    BREAKTANGENTS_TRUE Break the tangents.
    BREAKTANGENTS_AUTO Only break the tangents if they are already broken.
  • pcnt (int) – The number of points in the spline.
  • padr (list of Vector) – The points that describe the spline.
  • tadr (list of tangent(dict)) –
    The tangents that are used by the spline.
    A tangent dictionary has to be defined as: dict(‘vl’: Vector, ‘vr’: Vector)
Return type:

tuple(list of Vector, list of tangents)

Returns:

The resulting lists of points and tangents.

c4d.utils.CalcSplineDefaultTangents(type, closed, pcnt, padr)

New in version R17.048.

Calculates the default tangents for the passed points (spline segment) based on the spline type.

Parameters:
  • type (int) –

    The type of spline to move. Check out Spline Types.

    SPLINETYPE_LINEAR Linear.
    SPLINETYPE_CUBIC Cubic.
    SPLINETYPE_AKIMA Akima.
    SPLINETYPE_BSPLINE B-Spline.
    SPLINETYPE_BEZIER Bezier.
  • closed (bool) – The closed state of the spline.
  • pcnt (int) – The number of points in the spline.
  • padr (list of Vector) – The points that describe the spline.
Return type:

list of dict

Returns:

The resulting tangents. A tangent dictionary is defined as: dict(‘vl’: Vector, ‘vr’: Vector)

c4d.utils.BooleanSplines(initialSpline, booleanObjects, doc, bd, projectionAxis, booleanMode)

New in version R17.048.

Booleans an initial spline object with an array of other spline objects along a passed projection axis (in 2D).

Parameters:
  • initialSpline (c4d.BaseObject) – The original spline object that will have the operations applied to it.
  • booleanObjects (list of SplineObject) – The array of spline objects to boolean with initialSpline.
  • doc (c4d.documents.BaseDocument) – The active document that the objects belong to.
  • bd (c4d.BaseDraw) – The active basebraw.
  • projectionAxis

    The projection axis to use:

    SPLINEBOOL_AXIS_0 No axis.
    SPLINEBOOL_AXIS_SCREEN Project into the current screen.
    SPLINEBOOL_AXIS_ZY Project on the ZY (X axis) plane.
    SPLINEBOOL_AXIS_XZ Project on the XZ (Y axis) plane.
    SPLINEBOOL_AXIS_XY Project on the XY (Z axis) plane.
  • booleanMode

    The type of boolean to apply:

    SPLINEBOOL_MODE_AMINUSB Subtract B from A.
    SPLINEBOOL_MODE_BMINUSA Subtract A from B.
    SPLINEBOOL_MODE_UNION Union of both A and B.
    SPLINEBOOL_MODE_AND And intersection (overlap) of region of A and B.
    SPLINEBOOL_MODE_OR Or intersection (outside of overlap) of region of A and B.
    SPLINEBOOL_MODE_INTERSECTION Intersection (all segments inside and out) of region of A and B.
Return type:

Returns:

The spline object result of the Boolean operation, None if there was an error.

c4d.utils.RGBToHSV(col)

Converts RGB into the HSV color space and returns the converted value.

Parameters:col (c4d.Vector) – RGB color.
Return type:c4d.Vector
Returns:HSV color.
c4d.utils.HSVToRGB(col)

Converts HSV into the RGB color space and returns the converted value.

Parameters:col (c4d.Vector) – HSV color.
Return type:c4d.Vector
Returns:RGB color.
c4d.utils.RGBToHSL(col)

New in version R14.014.

Converts RGB into the HSL color space and returns the converted value.

Parameters:col (c4d.Vector) – RGB color.
Return type:c4d.Vector
Returns:HSL color.

Note

If you want the Hue value to be in degree, you have to multiply it yourself.

c4d.utils.HSLtoRGB(col)

New in version R14.014.

Converts HSL into the RGB color space and returns the converted value.

Parameters:col (c4d.Vector) – HSL color.
Return type:c4d.Vector
Returns:RGB color.
c4d.utils.VectorEqual(v1, v2[, epsilon=0.01])

Check if vector v1 and v2 are within epsilon of each other.

Parameters:
  • v1 (c4d.Vector) – The first vector.
  • v2 (c4d.Vector) – The second vector.
  • epsilon (float) – The epsilon value.
Return type:

bool

Returns:

True if the vectors are equal.

c4d.utils.Bias(b, x)

Returns the bias as the defined in the book “Texturing and Modeling” by Ebert.

The internal code:

import math

def Bias(b, x):
  return math.pow(x, -math.log(b) / 0.693147180559945)
Parameters:
  • b (number) – Bias value.
  • x (number) – The real value.
Return type:

float

Returns:

The bias.

c4d.utils.FCut(a, b, c)

Limit the value of a to between b and c.

Parameters:
  • a (float) – Value
  • b (float) – Lower bound
  • c (float) – Upper bound
c4d.utils.CutColor(vec)

Limit a color vector between 0.0 and 1.0.

Parameters:vec (c4d.Vector) – Bias value.
Return type:c4d.Vector
Returns:The limited color vector.
c4d.utils.Truncate(x)

Limit a color vector between 0.0 and 1.0.

The internal code:

import math

def Truncate(x):
  if x >= 0.0:
    return math.floor(x)
  else:
    return math.fceil(x)
Parameters:x (number) – The value to truncate.
Return type:float
Returns:The truncated value.
c4d.utils.VectorSum(vec)

Sum the vector components.

Parameters:x (c4d.Vector) – A color
Return type:float
Returns:The sum of the components.
c4d.utils.VectorGray(vec)

Sum the vector components and multiply by 1/3.

Parameters:vec (c4d.Vector) – A color
Return type:float
Returns:The gray value.
c4d.utils.VectorAngle(vec1, vec2)

Calculates the angle between two vectors in radians.

Parameters:
Return type:

float

Returns:

The angle in radians.

c4d.utils.VectorMin(vec)

Find the minimum component of the vector.

Parameters:vec (c4d.Vector) – The vector to find the minimum component of.
Return type:float
Returns:The minimum component of the vector.
c4d.utils.VectorMax(vec)

Find the maximum component of the vector.

Parameters:vec (c4d.Vector) – The vector to find the maximum component of.
Return type:float
Returns:The maximum component of the vector.
c4d.utils.MatrixMove(vec)

Create a translation matrix.

Parameters:vec (c4d.Vector) – The translation vector.
Return type:c4d.Matrix
Returns:The translation matrix.
c4d.utils.MatrixScale(s)

Create a scaling matrix.

Parameters:s (c4d.Vector) – The scaling vector for the axes.
Return type:c4d.Matrix
Returns:The scaling matrix.
c4d.utils.VectorToHPB(p)

Calculate euler angles from the vector p. The bank is always set to 0.0.

Parameters:p (c4d.Vector) – The vector to find the HPB for.
Return type:c4d.Vector
Returns:The rotation HPB.
c4d.utils.MatrixToHPB(m[, order=ROTATIONORDER_DEFAULT])

Calculate euler angles from the matrix m.

Parameters:
  • m (c4d.Matrix) – The rotation matrix.
  • order (int) –

    The order of rotation:

    ROTATIONORDER_YXZGLOBAL Global YXZ order.
    ROTATIONORDER_YZXGLOBAL Global YZX order.
    ROTATIONORDER_ZYXGLOBAL Global ZYX order.
    ROTATIONORDER_ZXYGLOBAL Global ZXY order.
    ROTATIONORDER_XZYGLOBAL Global XZY order.
    ROTATIONORDER_XYZGLOBAL Global XYZ order.
    ROTATIONORDER_YXZLOCAL Local YXZ order.
    ROTATIONORDER_YZXLOCAL Local YZX order.
    ROTATIONORDER_ZYXLOCAL Local ZYX order.
    ROTATIONORDER_ZXYLOCAL Local ZXY order.
    ROTATIONORDER_XZYLOCAL Local XZY order.
    ROTATIONORDER_XYZLOCAL Local XYZ order.
    ROTATIONORDER_HPB HPB order.
    ROTATIONORDER_DEFAULT Default order. ROTATIONORDER_HPB.
Return type:

c4d.Vector

Returns:

The HPB.

c4d.utils.HPBToMatrix(hpb[, order=ROTATIONORDER_DEFAULT])

Construct matrix from the euler angles hpb.

Parameters:
  • hpb (c4d.Vector) – The input HPB.
  • order (int) –

    The order of rotation:

    ROTATIONORDER_YXZGLOBAL Global YXZ order.
    ROTATIONORDER_YZXGLOBAL Global YZX order.
    ROTATIONORDER_ZYXGLOBAL Global ZYX order.
    ROTATIONORDER_ZXYGLOBAL Global ZXY order.
    ROTATIONORDER_XZYGLOBAL Global XZY order.
    ROTATIONORDER_XYZGLOBAL Global XYZ order.
    ROTATIONORDER_YXZLOCAL Local YXZ order.
    ROTATIONORDER_YZXLOCAL Local YZX order.
    ROTATIONORDER_ZYXLOCAL Local ZYX order.
    ROTATIONORDER_ZXYLOCAL Local ZXY order.
    ROTATIONORDER_XZYLOCAL Local XZY order.
    ROTATIONORDER_XYZLOCAL Local XYZ order.
    ROTATIONORDER_HPB HPB order.
    ROTATIONORDER_DEFAULT Default order. ROTATIONORDER_HPB.
Return type:

c4d.Matrix

Returns:

The rotation matrix.

c4d.utils.CalcLOD(val, lod, min, max)

This is a helper function to modify a user chosen subdivision value. For example:

sub = utils.CalcLOD(op[TUBEOBJECT_SUB, 1], hh["lod"], 1, 1000)
Parameters:
  • val (int) – The user chosen lod value.
  • lod (float) – The LOD value.
  • min (int) – The minimum lod.
  • max (int) – The maximum lod.
c4d.utils.CompareFloatTolerant(a, b)

Compares if two floats are close to each other on a bit basis (rather than a fixed epsilon).

Parameters:
  • a (float) – The first parameter.
  • b (float) – The second parameter.
Return type:

bool

Returns:

True if a and b are sufficiently close to each other, otherwise False.

c4d.utils.SinCos(w)

Get sine and cosine of w:

sn, cs = SinCos(80)
Parameters:w (float) – Value.
Return type:list
Returns:Sine and Cosine.
c4d.utils.TransformColor(input, colortransformation)

Transforms a color from one color profile to another.

Parameters:
  • input (c4d.Vector) – The color to transform.
  • colortransformation (int) –

    Transformation mode:

    COLORSPACETRANSFORMATION_NONE None.
    COLORSPACETRANSFORMATION_LINEAR_TO_SRGB Linear to sRGB color space transformation.
    COLORSPACETRANSFORMATION_SRGB_TO_LINEAR sRGB to linear color space transformation.
    COLORSPACETRANSFORMATION_LINEAR_TO_VIEW Linear to display color space transformation.
    COLORSPACETRANSFORMATION_SRGB_TO_VIEW sRGB to display color space transformation.
Return type:

c4d.Vector

Returns:

The transformed color.

c4d.utils.CalculateTranslationScale(src, dst)

Calculates the scale between src and dst.

Note

Both src and dst have to be of the same type: either c4d.documents.BaseDocument or c4d.UnitScaleData.

Parameters:
Return type:

float

Returns:

The scale.

c4d.utils.SphereLineIntersection(linePoint1, linePoint2, sphereCenter, sphereRadius)

New in version R16.021.

Calculates the intersection points between a line and a sphere in 3D space.

Parameters:
  • linePoint1 (c4d.Vector) – The first point of the line.
  • linePoint2 (c4d.Vector) – The second point of the line.
  • sphereCenter (c4d.Vector) – The center of the sphere.
  • sphereRadius (float) – The radius of the sphere.
Return type:

tuple(bool, float, float, Vector, Vector)

Returns:

A tuple with the following information:

  1. bool: True if the line segment intersected the sphere, otherwise False.
  2. float: The first intersection point (lowest) as an offset between linePoint1 and linePoint2.
  3. float: The second intersection point (highest) as an offset between linePoint1 and linePoint2.
  4. Vector: The actual 3D point where the line first intersects (enters) the sphere.
  5. Vector: The actual 3D point where the line subsequently intersects (exits) the sphere.

c4d.utils.CircleLineIntersection(linePoint1, linePoint2, circleCenter, circleRadius)

New in version R16.021.

Calculates the intersection points between a line and a circle in 2D space (although Z will also be calculated on the resulting hit points).

Parameters:
  • linePoint1 (c4d.Vector) – The first point of the line.
  • linePoint2 (c4d.Vector) – The second point of the line.
  • circleCenter (c4d.Vector) – The center of the circle.
  • circleRadius (float) – The radius of the circle.
Return type:

tuple(bool, float, float, Vector, Vector)

Returns:

A tuple with the following information:

  1. bool: True if the line segment intersected the circle, otherwise False.
  2. float: The first intersection point (lowest) as an offset between linePoint1 and linePoint2.
  3. float: The second intersection point (highest) as an offset between linePoint1 and linePoint2.
  4. Vector: The actual 3D point where the line first intersects (enters) the circle, Z may also be calculated.
  5. Vector: The actual 3D point where the line subsequently intersects (exits) the circle, Z may also be calculated.

c4d.utils.PointLineSegmentDistance(segmentPoint1, segmentPoint2, pos)

New in version R17.048.

Calculates the distance from a point to a line segment between two points.

Parameters:
  • segmentPoint1 (c4d.Vector) – The line segment first point.
  • segmentPoint2 (c4d.Vector) – The line segment second point.
  • pos (c4d.Vector) – The point to test against the line segment.
Return type:

tuple(float, Vector, float)

Returns:

A tuple with the following information:

  1. The distance between the point and the line segment.
  2. The intersection point on the segment.
  3. The offset along the segment of the intersection point.

c4d.utils.PointLineSegmentDistance2D(segmentPoint1, segmentPoint2, pos)

New in version R17.048.

Calculates the distance from a point to a line segment between two points in 2D ignoring the Z value.

Parameters:
  • segmentPoint1 (c4d.Vector) – The line segment first point.
  • segmentPoint2 (c4d.Vector) – The line segment second point.
  • pos (c4d.Vector) – The point to test against the line segment.
Return type:

tuple(float, Vector, float)

Returns:

A tuple with the following information:

  1. The distance between the point and the line segment.
  2. The intersection point on the segment.
  3. The offset along the segment of the intersection point.

c4d.utils.InitBakeTexture(doc, textags, texuvws, destuvws, bc[, th=None])

New in version R18.011.

Initializes a bake operation of a single tag for BakeTexture().

Parameters:
  • doc (c4d.documents.BaseDocument) – The document.
  • textags (c4d.TextureTag) – The texture tag(s) to bake. Must be assigned to an object.
  • texuvws (c4d.UVWTag) – The UVW tag(s) to bake. Must be valid if UVW projection is selected in the texture tag(s), ignored otherwise.
  • destuvws (c4d.UVWTag) – The destination UVW tag for the bake. If not None, the current projection is transformed into the UVW tag.
  • bc (c4d.BaseContainer) –

    The bake settings:

    BAKE_TEX_USE_CAMERA_VECTOR bool Use camera vector.
    BAKE_TEX_USE_POLYSELECTION bool Use polygon selection.
    BAKE_TEX_AMBIENT_OCCLUSION bool Bake ambient occlusion.
    BAKE_TEX_NORMAL bool Bake normal channel.
    BAKE_TEX_SURFACECOLOR bool Bake surface color.
    BAKE_TEX_COLOR bool Bake color.
    BAKE_TEX_DIFFUSION bool Bake diffusion channel.
    BAKE_TEX_LUMINANCE bool Bake luminance.
    BAKE_TEX_ALPHA bool Bake alpha channel.
    BAKE_TEX_ILLUMINATION bool Bake illumination.
    BAKE_TEX_SHADOWS bool Bake shadows.
    BAKE_TEX_BUMP bool Bake bump.
    BAKE_TEX_TRANSPARENCY bool Bake transparency.
    BAKE_TEX_UVMAP bool Bake UV map.
    BAKE_TEX_REFLECTION bool Bake reflection.
    BAKE_TEX_DISPLACEMENT bool Bake displacement.
    BAKE_TEX_WIDTH int Width.
    BAKE_TEX_HEIGHT int Height.
    BAKE_TEX_PIXELBORDER int Pixel border.
    BAKE_TEX_FILL_COLOR Vector Fill color.
    BAKE_TEX_UV_LEFT float Left UV coordinate.
    BAKE_TEX_UV_RIGHT float Right UV coordinate.
    BAKE_TEX_UV_TOP float Top UV coordinate.
    BAKE_TEX_UV_BOTTOM float Bottom UV coordinate.
    BAKE_TEX_SUPERSAMPLING int Supersampling.
    BAKE_TEX_USE_BUMP bool Use bump.
    BAKE_TEX_NO_GI bool No GI.
    BAKE_TEX_CONTINUE_UV bool Continue UV.
    BAKE_TEX_USE_PHONG_TAG bool The pixel will be clamped to the current polygon if set to True and if the angle between polygons is bigger than their phong angle. Only needed if BAKE_TEX_CONTINUE_UV is set to True.
    BAKE_TEX_COLORPROFILE ColorProfile Color profile of the baked texture.
    BAKE_TEX_SHOW_STATUS bool Show status.
    BAKE_TEX_PROGRESS_BITMAP bool Show the bitmap in a preview during baking.
    BAKE_TEX_GENERATE_UNDO bool Generate undo for UVW tags and Vertex tags created by the baker.
    BAKE_TEX_PREVIEW bool Bake texture preview.
    BAKE_TEX_COLOR_ILLUM bool Illumination in color.
    BAKE_TEX_COLOR_SHADOWS bool Shadows in color.
    BAKE_TEX_COLOR_LUMINANCE bool Luminance in color.
    BAKE_TEX_COLOR_DIFFUSION bool Diffusion in color.
    BAKE_TEX_LUMINANCE_DIFFUSION bool Diffusion in luminance.
    BAKE_TEX_ILLUMINATION_SHADOWS bool Shadows in luminance.
    BAKE_TEX_NORMAL_METHOD int Normal method:
    BAKE_TEX_NORMAL_METHOD_OBJECT   Object.
    BAKE_TEX_NORMAL_METHOD_TANGENT   Tangent.
    BAKE_TEX_NORMAL_METHOD_WORLD   World.
    BAKE_TEX_NORMAL_FLIP_X bool Flip X.
    BAKE_TEX_NORMAL_FLIP_Y bool Flip Y.
    BAKE_TEX_NORMAL_FLIP_Z bool Flip Z.
    BAKE_TEX_NORMAL_SWAP_YZ bool Swap Y/Z.
    BAKE_TEX_NORMAL_SOURCE link Normal source.
    BAKE_TEX_SURFACE_ILLUMINATION bool Surface illumination.
    BAKE_TEX_AO_VERTEX_MAP bool Ambient occlusion in vertex map.
    BAKE_TEX_AO_SELFINTERSECTION bool Ambient occlusion self-intersection.
    BAKE_TEX_AO_VERTEXMAPS BaseContainer A container that stores all new generated vertex maps.
    BAKE_TEX_DISPLACEMENT_SOURCE link The high-res source object.
    BAKE_TEX_DISPLACEMENT_HEIGHT float A float that will receive the displacement height.
    BAKE_TEX_DISPLACEMENT_METHOD int Displacement method:
    BAKE_TEX_DISPLACEMENT_METHOD_OBJECT   Object.
    BAKE_TEX_DISPLACEMENT_METHOD_WORLD   World.
    BAKE_TEX_DISPLACEMENT_METHOD_TANGENT   Tangent.
    BAKE_TEX_DISPLACEMENT_METHOD_INTENSITY   Intensity.
    BAKE_TEX_DISPLACEMENT_METHOD_CENTEREDINTENSITY   Centered intensity.
    BAKE_TEX_DISPLACEMENT_METHOD_REDGREEN   Red <-> Green.
    BAKE_TEX_DISPLACEMENT_SUBPOLY bool Displacement subpoly.
    BAKE_TEX_DISPLACEMENT_SUBPOLY_SUBDIVISION int Displacement subpoly subdivision.
    BAKE_TEX_DISPLACEMENT_SUBPOLY_ROUND bool Displacement subpoly round.
    BAKE_TEX_DISPLACEMENT_SUBPOLY_ROUNDCONTOUR bool Displacement subpoly round contour.
    BAKE_TEX_DISPLACEMENT_SUBPOLY_HQREMAPPING bool Displacement subpoly HQ remapping.
    BAKE_TEX_DISPLACEMENT_SUBPOLY_MAPRESULT bool Displacement subpoly map result.
    BAKE_TEX_DISPLACEMENT_SUBPOLY_KEEPEDGES bool Displacement subpoly keep edges.
    BAKE_TEX_DISPLACEMENT_SUBPOLY_DISTRIBUTION bool Displacement subpoly distribution.
    BAKE_TEX_OPTIMAL_MAPPING int Optimal mapping:
    BAKE_TEX_OPTIMAL_MAPPING_OFF   Off.
    BAKE_TEX_OPTIMAL_MAPPING_CUBIC   Cubic.
    BAKE_TEX_OPTIMAL_MAPPING_ANGLE   Angle.
    BAKE_TEX_OPTIMAL_MAPPING_RELAXCOUNT int Optimal mapping relax count.
    BAKE_TEX_OPTIMAL_MAPPING_PREVIEW int Optimal mapping preview.
    BAKE_TEX_NO_INIT_BITMAP bool Set to True if the passed MultipassBitmap is already initialized.
    BAKE_TEX_AUTO_SIZE bool Auto size.
    BAKE_TEX_AUTO_SIZE_MIN int Minimum auto size.
    BAKE_TEX_AUTO_SIZE_MAX int Maximum auto size.
    BAKE_TEX_AUTO_PIXEL_SIZE float Automatic pixel size.
    BAKE_TEX_STATUSBAR str Status bar text.
  • th (c4d.threading.BaseThread) – The optional thread. Can be None. New in version R18.039.
Return type:

tuple(BaseDocument, int)

Returns:

A tuple with the following information:


c4d.documents.BaseDocument: The document for the bake to use for the call to BakeTexture().
int: The error result. BAKE_TEX_ERR_NONE if successful, otherwise one of these errors:
BAKE_TEX_ERR_NONE None.
BAKE_TEX_ERR_NO_DOC No document.
BAKE_TEX_ERR_NO_MEM No more memory available.
BAKE_TEX_ERR_NO_RENDER_DOC No render document.
BAKE_TEX_ERR_NO_TEXTURE_TAG textag is None or not in doc.
BAKE_TEX_ERR_NO_OBJECT One of the tags is not assigned to an object or to another object.
BAKE_TEX_ERR_NO_UVW_TAG UVW tag is missing.
BAKE_TEX_ERR_TEXTURE_MISSING No texture.
BAKE_TEX_ERR_WRONG_BITMAP MultipassBitmap was used, but it has the wrong type or wrong resolution.
BAKE_TEX_ERR_USERBREAK User break.
BAKE_TEX_ERR_NO_OPTIMAL_MAPPING Optimal mapping failed.
BAKE_TEX_ERR_NO_SOURCE_UVW_TAG UVW tag for the source object is missing.

c4d.utils.BakeTexture(doc, data, bmp, th, hook)

New in version R18.011.

Bakes the texture(s) specified by the last InitBakeTexture() call into bmp.

Parameters:
  • doc (c4d.documents.BaseDocument) – The document.
  • data (c4d.BaseContainer) –

    The bake settings:

    BAKE_TEX_USE_CAMERA_VECTOR bool Use camera vector.
    BAKE_TEX_USE_POLYSELECTION bool Use polygon selection.
    BAKE_TEX_AMBIENT_OCCLUSION bool Bake ambient occlusion.
    BAKE_TEX_NORMAL bool Bake normal channel.
    BAKE_TEX_SURFACECOLOR bool Bake surface color.
    BAKE_TEX_COLOR bool Bake color.
    BAKE_TEX_DIFFUSION bool Bake diffusion channel.
    BAKE_TEX_LUMINANCE bool Bake luminance.
    BAKE_TEX_ALPHA bool Bake alpha channel.
    BAKE_TEX_ILLUMINATION bool Bake illumination.
    BAKE_TEX_SHADOWS bool Bake shadows.
    BAKE_TEX_BUMP bool Bake bump.
    BAKE_TEX_TRANSPARENCY bool Bake transparency.
    BAKE_TEX_UVMAP bool Bake UV map.
    BAKE_TEX_REFLECTION bool Bake reflection.
    BAKE_TEX_DISPLACEMENT bool Bake displacement.
    BAKE_TEX_WIDTH int Width.
    BAKE_TEX_HEIGHT int Height.
    BAKE_TEX_PIXELBORDER int Pixel border.
    BAKE_TEX_FILL_COLOR Vector Fill color.
    BAKE_TEX_UV_LEFT float Left UV coordinate.
    BAKE_TEX_UV_RIGHT float Right UV coordinate.
    BAKE_TEX_UV_TOP float Top UV coordinate.
    BAKE_TEX_UV_BOTTOM float Bottom UV coordinate.
    BAKE_TEX_SUPERSAMPLING int Supersampling.
    BAKE_TEX_USE_BUMP bool Use bump.
    BAKE_TEX_NO_GI bool No GI.
    BAKE_TEX_CONTINUE_UV bool Continue UV.
    BAKE_TEX_USE_PHONG_TAG bool The pixel will be clamped to the current polygon if set to True and if the angle between polygons is bigger than their phong angle. Only needed if BAKE_TEX_CONTINUE_UV is set to True.
    BAKE_TEX_COLORPROFILE ColorProfile Color profile of the baked texture.
    BAKE_TEX_SHOW_STATUS bool Show status.
    BAKE_TEX_PROGRESS_BITMAP bool Show the bitmap in a preview during baking.
    BAKE_TEX_GENERATE_UNDO bool Generate undo for UVW tags and Vertex tags created by the baker.
    BAKE_TEX_PREVIEW bool Bake texture preview.
    BAKE_TEX_COLOR_ILLUM bool Illumination in color.
    BAKE_TEX_COLOR_SHADOWS bool Shadows in color.
    BAKE_TEX_COLOR_LUMINANCE bool Luminance in color.
    BAKE_TEX_COLOR_DIFFUSION bool Diffusion in color.
    BAKE_TEX_LUMINANCE_DIFFUSION bool Diffusion in luminance.
    BAKE_TEX_ILLUMINATION_SHADOWS bool Shadows in luminance.
    BAKE_TEX_NORMAL_METHOD int Normal method:
    BAKE_TEX_NORMAL_METHOD_OBJECT   Object.
    BAKE_TEX_NORMAL_METHOD_TANGENT   Tangent.
    BAKE_TEX_NORMAL_METHOD_WORLD   World.
    BAKE_TEX_NORMAL_FLIP_X bool Flip X.
    BAKE_TEX_NORMAL_FLIP_Y bool Flip Y.
    BAKE_TEX_NORMAL_FLIP_Z bool Flip Z.
    BAKE_TEX_NORMAL_SWAP_YZ bool Swap Y/Z.
    BAKE_TEX_NORMAL_SOURCE link Normal source.
    BAKE_TEX_SURFACE_ILLUMINATION bool Surface illumination.
    BAKE_TEX_AO_VERTEX_MAP bool Ambient occlusion in vertex map.
    BAKE_TEX_AO_SELFINTERSECTION bool Ambient occlusion self-intersection.
    BAKE_TEX_AO_VERTEXMAPS BaseContainer A container that stores all new generated vertex maps.
    BAKE_TEX_DISPLACEMENT_SOURCE link The high-res source object.
    BAKE_TEX_DISPLACEMENT_HEIGHT float A float that will receive the displacement height.
    BAKE_TEX_DISPLACEMENT_METHOD int Displacement method:
    BAKE_TEX_DISPLACEMENT_METHOD_OBJECT   Object.
    BAKE_TEX_DISPLACEMENT_METHOD_WORLD   World.
    BAKE_TEX_DISPLACEMENT_METHOD_TANGENT   Tangent.
    BAKE_TEX_DISPLACEMENT_METHOD_INTENSITY   Intensity.
    BAKE_TEX_DISPLACEMENT_METHOD_CENTEREDINTENSITY   Centered intensity.
    BAKE_TEX_DISPLACEMENT_METHOD_REDGREEN   Red <-> Green.
    BAKE_TEX_DISPLACEMENT_SUBPOLY bool Displacement subpoly.
    BAKE_TEX_DISPLACEMENT_SUBPOLY_SUBDIVISION int Displacement subpoly subdivision.
    BAKE_TEX_DISPLACEMENT_SUBPOLY_ROUND bool Displacement subpoly round.
    BAKE_TEX_DISPLACEMENT_SUBPOLY_ROUNDCONTOUR bool Displacement subpoly round contour.
    BAKE_TEX_DISPLACEMENT_SUBPOLY_HQREMAPPING bool Displacement subpoly HQ remapping.
    BAKE_TEX_DISPLACEMENT_SUBPOLY_MAPRESULT bool Displacement subpoly map result.
    BAKE_TEX_DISPLACEMENT_SUBPOLY_KEEPEDGES bool Displacement subpoly keep edges.
    BAKE_TEX_DISPLACEMENT_SUBPOLY_DISTRIBUTION bool Displacement subpoly distribution.
    BAKE_TEX_OPTIMAL_MAPPING int Optimal mapping:
    BAKE_TEX_OPTIMAL_MAPPING_OFF   Off.
    BAKE_TEX_OPTIMAL_MAPPING_CUBIC   Cubic.
    BAKE_TEX_OPTIMAL_MAPPING_ANGLE   Angle.
    BAKE_TEX_OPTIMAL_MAPPING_RELAXCOUNT int Optimal mapping relax count.
    BAKE_TEX_OPTIMAL_MAPPING_PREVIEW int Optimal mapping preview.
    BAKE_TEX_NO_INIT_BITMAP bool Set to True if the passed MultipassBitmap is already initialized.
    BAKE_TEX_AUTO_SIZE bool Auto size.
    BAKE_TEX_AUTO_SIZE_MIN int Minimum auto size.
    BAKE_TEX_AUTO_SIZE_MAX int Maximum auto size.
    BAKE_TEX_AUTO_PIXEL_SIZE float Automatic pixel size.
    BAKE_TEX_STATUSBAR str Status bar text.
  • bmp (c4d.bitmaps.BaseBitmap) – The bitmap to bake to.
  • th (c4d.threading.BaseThread) – The current thread. Can be None.
  • hook (function(dict)) –

    The bake progress hook callback function. This function gets passed a dictionary with the following information:

    ’version’ int Bake version.
    ’state’ int Bake state:
      BAKE_STATE_NONE None.
      BAKE_STATE_PREPARE Prepare.
      BAKE_STATE_GI_PREPASS GI prepass.
      BAKE_STATE_FILL_IMAGE Fill image.
      BAKE_STATE_COMPLETE Complete.
      BAKE_STATE_INITIALIZE Initialize.
      BAKE_STATE_RESIZENOTIFY Resize notify.
    ’data’ tuple(int, int, BaseBitmap) Only used in case of BAKE_STATE_RESIZENOTIFY state. Tuple data is resize width, resize height and cake bitmap.
    ’timedelta’ int Time.
    ’r’ float Progress, between 0 and 1.
    ’starttime’ int Start time in milliseconds.

    If the state is BAKE_STATE_RESIZENOTIFY, the return value has to be a bool to set the result of the resize operation. Otherwise the hook must return None.

Return type:

int

Returns:

BAKE_TEX_ERR_NONE if successful, otherwise one of these errors:

BAKE_TEX_ERR_NONE None.
BAKE_TEX_ERR_NO_DOC No document.
BAKE_TEX_ERR_NO_MEM No more memory available.
BAKE_TEX_ERR_NO_RENDER_DOC No render document.
BAKE_TEX_ERR_NO_TEXTURE_TAG textag is None or not in doc.
BAKE_TEX_ERR_NO_OBJECT One of the tags is not assigned to an object or to another object.
BAKE_TEX_ERR_NO_UVW_TAG UVW tag is missing.
BAKE_TEX_ERR_TEXTURE_MISSING No texture.
BAKE_TEX_ERR_WRONG_BITMAP MultipassBitmap was used, but it has the wrong type or wrong resolution.
BAKE_TEX_ERR_USERBREAK User break.
BAKE_TEX_ERR_NO_OPTIMAL_MAPPING Optimal mapping failed.
BAKE_TEX_ERR_NO_SOURCE_UVW_TAG UVW tag for the source object is missing.