Created
July 18, 2011 18:39
-
-
Save bohdon/1090276 to your computer and use it in GitHub Desktop.
maya space switch transformation matrix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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