Moo.
For piper's rigging system, my goal is to use matrices only in order to practice matrix math. Therefore, here is a script for a simple matrix constraint thanks Vasil Shotarov.
import pymel.core as pm
def parentMatrixConstraint(driver=None, target=None, t=True, r=True, s=True, offset=False):
if not driver or not target:
selected = pm.selected()
if len(selected) < 2:
pm.error('Not enough items selected and no driver or target found!')
driver = selected[-2]
target = selected[-1]
matrix_multiplication = pm.createNode('multMatrix')
decompose_matrix = pm.createNode('decomposeMatrix')
if offset:
offset = target.worldMatrix.get() * driver.worldInverseMatrix.get()
matrix_multiplication.matrixIn[0].set(offset)
driver.worldMatrix[0] >> matrix_multiplication.matrixIn[1]
target.parentInverseMatrix[0] >> matrix_multiplication.matrixIn[2]
else:
driver.worldMatrix[0] >> matrix_multiplication.matrixIn[0]
target.parentInverseMatrix[0] >> matrix_multiplication.matrixIn[1]
matrix_multiplication.matrixSum >> decompose_matrix.inputMatrix
if t:
decompose_matrix.outputTranslate >> target.translate
if r:
decompose_matrix.outputRotate >> target.rotate
if s:
decompose_matrix.outputScale >> target.scale
More matrix math to come!
Comentarios