The code:
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 mc | |
def resetSkinCluster(skinClusterNode): | |
''' | |
Originaly created by Macaronikazoo - edited by Steffano | |
Splats the current pose of the skeleton into the skinCluster | |
The current pose is becomes the bindpose | |
''' | |
numInputs= len(mc.listConnections(skinClusterNode + '.matrix',destination=False)) | |
for n in range(numInputs): | |
try: | |
slot = mc.listConnections(skinClusterNode + '.matrix[' + str(n) + ']',destination=False)[0] | |
except IndexError: | |
continue | |
#Getting World Inverse Matrix of each joint | |
if int(mc.about(version=1)) < 2016: | |
worldInverseMatrix= mc.getAttr(slot + '.worldInverseMatrix') | |
mc.setAttr(skinClusterNode + '.bindPreMatrix[' + str(n) + ']', worldInverseMatrix, type="matrix") | |
else: | |
worldInverseMatrix= mc.getAttr(slot + '.worldInverseMatrix') | |
tempNode = mc.shadingNode('decomposeMatrix',asUtility=1,n='temp__decomMatrix__WERL_') | |
mc.setAttr(tempNode + '.inputMatrix', worldInverseMatrix, type="matrix") | |
mc.connectAttr(tempNode + '.inputMatrix', skinClusterNode + '.bindPreMatrix[' + str(n) + ']') | |
mc.refresh(cv=1,f=1) | |
mc.delete(tempNode) | |
#reset the stored pose in any dagposes that are conn | |
for dPose in mc.listConnections(skinClusterNode,d=False,type='dagPose') or []: | |
mc.dagPose(slot, reset=True, n=dPose) | |
#For each element | |
selection = mc.ls(sl=1) | |
for item in selection: | |
listNonDefHist = mc.listHistory(item,pdo=1) | |
skinNode = mc.ls(listNonDefHist,typ='skinCluster') | |
if len(skinNode) > 0: | |
resetSkinCluster(skinNode[0]) | |
#Return to Current Selection | |
mc.select(selection,r=1) |
No comments:
Post a Comment