Wednesday, November 1, 2017

Reset SkinCluster

Hey, after figuring out if there was a way to somehow reset the skinCluster. I found macaroniKazoo's script that allowed to do it. However in some versions of maya it didn't work. Well I edited it and now it works correctly, plus it automatically detects that skinCluster is attached to the geometry.

The code:

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)
UPDATE: Now works for 2016-2015 version

No comments:

Post a Comment