Last active
September 14, 2017 18:26
-
-
Save EricTRocks/872491f63651dc15a7ce815ee559763f to your computer and use it in GitHub Desktop.
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
import maya.cmds as cmds | |
import maya.api.OpenMaya as om2 | |
import maya.api.OpenMayaAnim as omAnim2 | |
def setNewBindPose(): | |
sel = om2.MGlobal.getActiveSelectionList() | |
jntMObj = sel.getDependNode(0) | |
jntDepNode = om2.MFnDependencyNode(jntMObj) | |
jntWMtxPlug = jntDepNode.findPlug("worldMatrix", False).elementByLogicalIndex(0) | |
skinClusterDepNode = None | |
skinClusters = {} | |
conns = jntWMtxPlug.connectedTo(False, True) | |
for plug in conns: | |
if plug.node().hasFn(om2.MFn.kSkinClusterFilter): | |
skinClusterDepNode = om2.MFnDependencyNode(plug.node()) | |
skinCluster = omAnim2.MFnSkinCluster(plug.node()) | |
skinClusters[skinCluster] = plug | |
if skinClusters.keys() is None: | |
print "No skin clusters found!" | |
return False | |
for skinCluster, plug in skinClusters.iteritems(): | |
print skinCluster.name() | |
plugIndex = int(plug.name().split('[')[1].split(']')[0]) | |
jntBindPreMtxPlug = skinCluster.findPlug("bindPreMatrix", False).elementByLogicalIndex(plugIndex) | |
jntWInvMtxPlug = jntDepNode.findPlug("worldInverseMatrix", False).elementByLogicalIndex(0) | |
jntInvMatrixData = om2.MFnMatrixData( jntWInvMtxPlug.asMObject() ).object() | |
jntBindPreMtxPlug.setMObject(jntInvMatrixData) | |
setNewBindPose() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment