paya.lib.mathops#
- flipAxis(axis)#
Flips an axis letter, for example from
-x
tox
.
- absAxis(axis)#
Equivalent to:
axis.strip('-')
- missingAxis(*axes)#
Given two axes (lowercase), returns the missing one. Negative signs are stripped / ignored.
- inventRotateOrder(downAxis, upAxis)#
Returns an ‘optimal’ rotate order based on the given down and up axes.
- degToUI(val)#
- getUIAngleUnit()#
- Returns
The current angle unit. Note that this will be returned in a format that can be passed along to the data type constructors (e.g. ‘degrees’) rather than how it’s returned by
currentUnit()
(e.g. ‘deg’).- Return type
- getUIDistanceUnit()#
- Returns
The current distance unit. Note that this will be returned in a format that can be passed along to the data type constructors (e.g. ‘centimeters’) rather than how it’s returned by
currentUnit()
(e.g. ‘cm’).- Return type
- getUITimeUnit()#
- Returns
The current time unit. Note that this will be returned in a format that can be passed along to the data type constructors (e.g. ‘24FPS’) rather than how it’s returned by
currentUnit()
(e.g. ‘film’).- Return type
- onRadians()#
- Returns
True
if the UI is set to radians, otherwiseFalse
.- Return type
bool
- mathInfo(item)#
Deprecated; here for backward compatibility.
Equivalent to:
values = list(info(item).values()) return [values[0], values[1], values[3]]
- info(item, defaultUnitType=None, quiet=False)#
Returns a dict with the following keys (ordered):
'item'
: The item, conformed to the most specific Paya type possible.'dimension'
: One of1
,2
,3
,4
or16
.'unitType'
: One of'angle'
,'distance'
,'time'
orNone
.'isPlug'
:True
orFalse
.
Value conforming is performed in the following way:
If item is a
bool
, it’s returned as-is.If item is a
float
orint
, it’s returned as-is unless a defaultUnitType is specified, in which case aAngle
,Distance
orTime
instance is returned. UI units are used in every case.If item is a list of floats or ints, then:
If its dimension is 3 then, if defaultUnitType is set to
'angle'
, it’s instantiated asEulerRotation
; otherwise, asVector
.If its dimension is 4, then it’s always returned as a
Quaternion
.If its dimension is 16, then it’s always returned as a
Matrix
.In all other cases, it’s returned as a list with members intact.
Plugs are returned as
Attribute
instances, with the subtype / unit strictly based onMPlug
analysis performed bypaya.pluginfo
.- Parameters
- Returns
The dictionary.
- Return type
- class LinearInterpolator(*args, **kwargs)#
Inheritance
UserDict
MutableMapping
Mapping
Collection
Sized
Iterable
Container
Simple, dict-like interpolator implementation, similar to a linear animation curve in Maya. Works with any value type that can be handled by
pymel.util.arrays.blend()
, but types should not be mixed.- Example
interp = LinearInterpolator() interp[10] = 30 interp[20] = 40 print(interp[11]) # Result: 31.0
- chaseNones(source)#
Resolves
None
members in an iterable by filling in with neighbouring values. If the first member isNone
, the next defined value is used. If any internal member isNone
, the last resolved value is used.- Parameters
source – the iterable to fill-in
- Returns
A list with no
None
members.- Return type
- blendNones(source, ratios=None)#
A blending version of
chaseNones()
.- Parameters
source – the iterable to fill-in
ratios – if provided, it should be a list of ratios from 0.0 to 1.0 (one per member) to bias the blending; if omitted, it will be autogenerated using
floatRange()
; defaults to None
- Returns
A list with no
None
members.- Return type
- blendScalars(scalarA, scalarB, weight=0.5)#
Blends between two scalar values or plugs.
- multMatrices(*matrices)#
Performs efficient multiplication of any combination of matrix values or plugs. Consecutive values are reduced and consecutive plugs are grouped into
multMatrix
nodes.If any of the matrices are plugs, the return will also be a plug. Otherwise, it will be a value.
- createMatrix(*rowHints, manageScale=True, preserveSecondLength=False, thirdLength=None, translate=None, plug=None)#
Constructs static or dynamic transformation matrices.
- Shorthand
cm
- Parameters
*rowHints –
If provided, this must comprise exactly four or five arguments, in both cases passed as unpacked pairs of row identifier: vector input or value.
If four arguments are passed, they will be used to construct an orthogonal matrix, with the first vector as the ‘aim’ and the second as the ‘up’, for example:
matrix = r.createMatrix('y', loc1.t, 'x', loc2.t)
If six arguments are passed, they will be used to directly populate the matrix rows. This may result in a non-orthornormal (shear) matrix.
matrix = r.createMatrix('y', loc1.t, 'x', loc2.t, 'z', loc3.t)
If this argument is omitted, an identity matrix will be returned.
translate/t (
str
,list
,tuple
,Vector
,Point
,Math3D
) – A translate component for the matrix; this can be a point value or plug; defaults to NonemanageScale/ms (bool) – set this to
False
to allow scale to be defined by incidental operations; useful when you intend to discard scale later anyway; defaults toTrue
preserveSecondLength/psl (bool) – ignored if six arguments were passed; preserve the second vector’s length when performing orthogonal construction; defaults to True
thirdLength/tl (None,
float
,int
,Math1D
,str
) – ignored is six arguments were passed; if provided, defines the third (derived) vector’s length; defaults to Noneplug/p (bool) – if you already know whether the passed arguments contain plugs, specify it here to avoid extraneous checks; if no arguments have been passed, this will specify whether the returned identity matrix is a plug or value; defaults to None
- Returns
The constructed matrix.
- Return type
paya.runtime.plugs.Matrix
orpaya.runtime.data.Matrix
, depending on inputs.
- createScaleMatrix(*args)#
Quick(er) method to create static or dynamic scale matrices. Takes one, three or six arguments.
- Shorthand
csm
- Parameters
*args –
If one argument is passed, the same scaling factor will be applied to the XYZ base vectors.
If three arguments are passed, they will each be applied to the XYZ base vectors.
If six arguments are passed then they will be interpreted as axis: scalar pairs.
- Returns
The scale matrix.
- Return type
- deflipVectors(vectors)#
Returns a list where each vector is flipped if that would bring it closer to the preceding one. This is a value-only method.
- getAimVectors(points)#
- Parameters
- Raises
ValueError – Fewer than two points were provided.
- Returns
Aiming vectors derived from the input points. The output list will always be one member shorter than the input list.
- pointsIntoUnitCube(points)#
- getFramedAimAndUpVectors(points, upVector, tolerance=1e-07)#
Value-only method.
Returns paired lists of aim and up vectors based on points and upVector, which can be a single vector or one vector per point.
The final up vectors are derived using cross products, and biased towards the provided hints. Where the points are in-line, cross products are either blended from neighbours or swapped out for the user up vectors.
- Parameters
- Returns
A list of aim vectors and a list of up vectors.
- Return type
- getChainedAimMatrices(points, aimAxis, upAxis, upVector, squashStretch=False, globalScale=None, framed=False, tolerance=1e-07)#
- Parameters
points – the starting points
aimAxis – the matrix axes to align to the aiming vectors, for example ‘-y’.
upAxis – the matrix axes to align to the resolved up vectors, for example ‘x’
upVector – either one up vector hint, or a list of up vectors (one per point)
squashStretch (bool) – allow squash-and-stretch on the aiming vectors; defaults to False
globalScale/gs – an optional plug for the scale component; defaults to None
framed/fra (bool) – if there are no plugs in the passed parameters, perform cross product framing via
getFramedAimAndUpVectors()
(recommended when drawing chains with triads, for example legs); defaults to Falsetolerance/tol (float) – if framed is on, any cross products below this length will be interpolated from neighbours; defaults to 1e-7
- Type
- Raises
NotImplementedError – framed was requested but some of the arguments were plugs
- Returns
Chained-aiming matrices, suitable for drawing or driving chains or control hierarchies.
- Return type
[
Matrix
]
- parallelTransport(normal, tangents, fromEnd=False)#
Implements parallel transport as described in the Houdini demonstration by Manuel Casasola Merkle based on the paper by Hanson and Ma.
If any of the arguments are plugs, the outputs will be plugs as well. The first output normal is a pass-through of the normal argument.
- Parameters
- Returns
The resolved normals / up vectors.
- Return type
- blendCurveNormalSets(normalsA, normalsB, tangents, ratios=None, unwindSwitch=0)#
Blends between two sets of normals along a curve. The number of tangents, normalsA, normalsB and ratios must be the same. If any inputs are plugs then the outputs will also be plugs.
- Parameters
normalsA ([list, tuple,
Vector
,Vector
]) – the first set of normalsnormalsB ([list, tuple,
Vector
,Vector
]) – the first set of normalstangents ([list, tuple,
Vector
,Vector
]) – the curve tangents around which to rotate the normalsratios/rat (None, [float,
Math1D
]) – per-normal blend ratios; if omitted, a uniform range of floats will be generated automatically; defaults to NoneunwindSwitch/uws (int,
Math1D
) –an integer value or attribute to pick between:
0 for shortest angle unwinding (the default)
1 for positive angle unwinding
2 for negative angle unwinding
- Raises
ValueError – Unequal argument lengths.
- Returns
The blended set of curve normals.
- Return type
- bidirectionalParallelTransport(startNormal, endNormal, tangents, ratios=None, unwindSwitch=0)#
Blends between a forward and backward parallel-transport solution. If either startNormal or endNormal are
None
, the solution will only be performed in one direction and returned on its own.- Parameters
startNormal (list, tuple,
Vector
,Vector
) – the normal at the start of the blend rangetangents – tangents along the blend range; one normal will be generated per tangent; the more tangents, the higher the accurace of the parallel transport solve
ratios (None, [float,
Math1D
]) – if provided, should be a list of float values or plugs (one per tangent); if omitted, a uniform float range will be generated automatically; defaults to NoneunwindSwitch/uws (int,
Math1D
) –an integer value or attribute to pick between:
0 for shortest angle unwinding (the default)
1 for positive angle unwinding
2 for negative angle unwinding
- Raises
One of:
Unequal numbers of tangents and ratios (if provided)
Both startNormal and endNormal are
None
- Returns
The normals.
- Return type
[
Vector
]
- bevelTriadPoints(points, bevelLength)#
Given three point values or plugs, returns four points, to include a ‘bevel’ cutoff of the specified length.
Warning
Beta; does not guard against reversals.
- unbevelTriadPoints(points)#
Reverses the result of
bevelTriadPoints()
.Warning
Beta; does not guard against reversals.
- getBevelVector(v1, v2, upVector, forceUpVector=False)#
- Parameters
v1 – the first vector
v2 – the second vector
upVector – a fallback up vector to use when the two vectors are aligned.
- Returns
Returns the ‘connecting’ (bevel) vector from v1 to v2. The vector will be normalized.