Skip to content

Instantly share code, notes, and snippets.

@bohdon
Created July 18, 2011 18:39
Show Gist options
  • Save bohdon/1090276 to your computer and use it in GitHub Desktop.
Save bohdon/1090276 to your computer and use it in GitHub Desktop.
maya space switch transformation matrix
def switchDriver(node, index):
spaceA = node.getParent()
spaceB = getDriver(index)
deltaMatrix = getSpaceSwitch(spaceA, spaceB)
# change driver
node.driver.set(index)
node.translateSpace.set(deltaMatrix.getTranslation('world'))
newRot = deltaMatrix.getRotation()
newRot.setDisplayUnit('degrees')
node.rotateSpace.set(dt.Vector(newRot[0], newRot[1], newRot[2]))
node.scaleSpace.set(deltaMatrix.getScale('world'))
def getSpaceSwitch(spaceA, spaceB):
oldMatrix = getWorldMatrix(spaceA)
newMatrix = getWorldMatrix(spaceB)
return dt.TransformationMatrix(oldMatrix * newMatrix.inverse())
def getWorldMatrix(node):
if node is not None:
return node.worldMatrix.get()
else:
return dt.Matrix()
def getDriver(index):
if index == 1:
return ls('pCube2')[0]
elif index == 2:
return ls('pCube3')[0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment