mgear.core.transform

Functions to work with matrix and transformations

mgear.core.transform.convert2TransformMatrix(tm)

Convert a transformation Matrix

Convert a transformation Matrix or a matrix to a transformation matrix in world space.

Parameters:tm (matrix) – The input matrix.
Returns:The transformation matrix in worldSpace
Return type:matrix
mgear.core.transform.getChainTransform(positions, normal, negate=False)

Get a tranformation list from a positions list and normal.

Parameters:
  • positions (list of vector) – List with the chain positions.
  • normal (vector) – Normal direction.
  • negate (bool) – If true invert the chain orientation.
Returns:

The list containing the transformation matrix for the chain.

Return type:

list of matrix

>>> tra.getChainTransform(self.guide.apos, self.normal, self.negate)
mgear.core.transform.getChainTransform2(positions, normal, negate=False)

Get a tranformation list from a positions list and normal.

Note

getChainTransform2 is using the latest position on the chain

Parameters:
  • positions (list of vector) – List with the chain positions.
  • normal (vector) – Normal direction.
  • negate (bool) – If true invert the chain orientation.
Returns:

The list containing the transformation matrix for the chain.

Return type:

list of matrix

>>> tra.getChainTransform2(self.guide.apos,
                           self.normal,
                           self.negate)
mgear.core.transform.getFilteredTransform(m, translation=True, rotation=True, scaling=True)

Retrieve a transformation filtered.

Parameters:
  • m (matrix) – the reference matrix
  • translation (bool) – If true the return matrix will match the translation.
  • rotation (bool) – If true the return matrix will match the rotation.
  • scaling (bool) – If true the return matrix will match the scaling.
Returns:

The filtered matrix

Return type:

matrix

mgear.core.transform.getInterpolateTransformMatrix(t1, t2, blend=0.5)

Interpolate 2 matrix.

Parameters:
  • t1 (matrix) – Input matrix 1.
  • t2 (matrix) – Input matrix 2.
  • blend (float) – The blending value. Default 0.5
Returns:

The newly interpolated transformation matrix.

Return type:

matrix

>>> t = tra.getInterpolateTransformMatrix(self.fk_ctl[0],
                                          self.tws1A_npo,
                                          .3333)
mgear.core.transform.getOffsetPosition(node, offset=[0, 0, 0])

Get an offset position from dagNode

Parameters:
  • node (dagNode) – The dagNode with the original position.
  • offset (list of float) – Ofsset values for xyz. exp : [1.2, 4.6, 32.78]
Returns:

the new offset position.

Return type:

list of float

Example

self.root = self.addRoot()
vTemp = tra.getOffsetPosition( self.root, [0,-3,0.1])
self.knee = self.addLoc("knee", self.root, vTemp)
mgear.core.transform.getPositionFromMatrix(in_m)

Get the position values from matrix

Parameters:in_m (matrix) – The input Matrix.
Returns:The position values for xyz.
Return type:list of float
mgear.core.transform.getRotationFromAxis(in_a, in_b, axis='xy', negate=False)

Get the matrix rotation from a given axis.

Parameters:
  • in_a (vector) – Axis A
  • in_b (vector) – Axis B
  • axis (str) – The axis to use for the orientation. Default: “xy”
  • negate (bool) – negates the axis orientation.
Returns:

The newly created matrix.

Return type:

matrix

Example

x = datatypes.Vector(0,-1,0)
x = x * tra.getTransform(self.eff_loc)
z = datatypes.Vector(self.normal.x,
                     self.normal.y,
                     self.normal.z)
z = z * tra.getTransform(self.eff_loc)
m = tra.getRotationFromAxis(x, z, "xz", self.negate)
mgear.core.transform.getSymmetricalTransform(t, axis='yz', fNegScale=False)

Get the symmetrical tranformation

Get the symmetrical tranformation matrix from a define 2 axis mirror plane. exp:”yz”.

Parameters:
  • t (matrix) – The transformation matrix to mirror.
  • axis (str) – The mirror plane.
  • fNegScale (bool) – This function is not yet implemented.
Returns:

The symmetrical tranformation matrix.

Return type:

matrix

mgear.core.transform.getTransform(node)

Return the transformation matrix of the dagNode in worldSpace.

Parameters:node (dagNode) – The dagNode to get the translation
Returns:The transformation matrix
Return type:matrix
mgear.core.transform.getTransformFromPos(pos)

Create a transformation Matrix from a given position.

Parameters:pos (vector) – Position for the transformation matrix
Returns:The newly created transformation matrix
Return type:matrix
>>>  t = tra.getTransformFromPos(self.guide.pos["root"])
mgear.core.transform.getTransformLookingAt(pos, lookat, normal, axis='xy', negate=False)

Return a transformation mstrix using vector positions.

Return the transformation matrix of the dagNode oriented looking to an specific point.

Parameters:
  • pos (vector) – The position for the transformation
  • lookat (vector) – The aiming position to stablish the orientation
  • normal (vector) – The normal control the transformation roll.
  • axis (str) – The 2 axis used for lookat and normal. Default “xy”
  • negate (bool) – If true, invert the aiming direction.
Returns:

The transformation matrix

Return type:

matrix

>>>  t = tra.getTransformLookingAt(self.guide.pos["heel"],
                                   self.guide.apos[-4],
                                   self.normal,
                                   "xz",
                                   self.negate)
mgear.core.transform.getTranslation(node)

Return the position of the dagNode in worldSpace.

Parameters:node (dagNode) – The dagNode to get the translation
Returns:The transformation matrix
Return type:matrix
mgear.core.transform.matchWorldTransform(source, target)

Match 2 dagNode transformations in world space.

Parameters:
  • source (dagNode) – The source dagNode
  • target (dagNode) – The target dagNode
Returns:

None

mgear.core.transform.quaternionDotProd(q1, q2)

Get the dot product of 2 quaternion.

Parameters:
  • q1 (quaternion) – Input quaternion 1.
  • q2 (quaternion) – Input quaternion 2.
Returns:

The dot proct quaternion.

Return type:

quaternion

mgear.core.transform.quaternionSlerp(q1, q2, blend)

Get an interpolate quaternion based in slerp function.

Parameters:
  • q1 (quaternion) – Input quaternion 1.
  • q2 (quaternion) – Input quaternion 2.
  • blend (float) – Blending value.
Returns:

The interpolated quaternion.

Return type:

quaternion

Example

q = quaternionSlerp(datatypes.Quaternion(
                    t1.getRotationQuaternion()),
                    datatypes.Quaternion(
                        t2.getRotationQuaternion()), blend)
mgear.core.transform.resetTransform(node, t=True, r=True, s=True)

Reset the scale, rotation and translation for a given dagNode.

Parameters:
  • node (dagNode) – The object to reset the transforms.
  • t (bool) – If true translation will be reseted.
  • r (bool) – If true rotation will be reseted.
  • s (bool) – If true scale will be reseted.
Returns:

None

mgear.core.transform.setMatrixPosition(in_m, pos)

Set the position for a given matrix

Parameters:
  • in_m (matrix) – The input Matrix.
  • pos (list of float) – The position values for xyz
Returns:

The matrix with the new position

Return type:

matrix

>>> tnpo = tra.setMatrixPosition(tOld, tra.getPositionFromMatrix(t))
>>> t = tra.setMatrixPosition(t, self.guide.apos[-1])
mgear.core.transform.setMatrixRotation(m, rot)

Set the rotation for a given matrix

Parameters:
  • in_m (matrix) – The input Matrix.
  • rot (list of float) – The rotation values for xyz
Returns:

The matrix with the new rotation

Return type:

matrix

mgear.core.transform.setMatrixScale(m, scl=[1, 1, 1])

Set the scale for a given matrix

Parameters:
  • in_m (matrix) – The input Matrix.
  • scl (list of float) – The scale values for xyz
Returns:

The matrix with the new scale

Return type:

matrix