-
-
Save jhoolmans/9195634 to your computer and use it in GitHub Desktop.
import maya.cmds as mc | |
import maya.OpenMaya as om | |
def softSelection(): | |
selection = om.MSelectionList() | |
softSelection = om.MRichSelection() | |
om.MGlobal.getRichSelection(softSelection) | |
softSelection.getSelection(selection) | |
dagPath = om.MDagPath() | |
component = om.MObject() | |
iter = om.MItSelectionList( selection,om.MFn.kMeshVertComponent ) | |
elements = [] | |
while not iter.isDone(): | |
iter.getDagPath( dagPath, component ) | |
dagPath.pop() | |
node = dagPath.fullPathName() | |
fnComp = om.MFnSingleIndexedComponent(component) | |
for i in range(fnComp.elementCount()): | |
elements.append([node, fnComp.element(i), fnComp.weight(i).influence()] ) | |
iter.next() | |
return elements | |
def createSoftCluster(): | |
softElementData = softSelection() | |
selection = ["%s.vtx[%d]" % (el[0], el[1])for el in softElementData ] | |
mc.select(selection, r=True) | |
cluster = mc.cluster(relative=True) | |
for i in range(len(softElementData)): | |
mc.percent(cluster[0], selection[i], v=softElementData[i][2]) | |
mc.select(cluster[1], r=True) | |
createSoftCluster() |
import maya.cmds as mc
import maya.OpenMaya as om
#----------------------------------------------------------------------Get_Skinned_Joints
selection0 = mc.ls(sl=True)
shapename = mc.listHistory(selection0[0])[0]
def GetHold():
positon = mc.xform(selection0[0], q =True, ws = True, t=True)
mc.joint(n = "Hold")
mc.parent("Hold",w = True)
mc.skinCluster("Hold", shapename)
mc.select(d = True)
mc.joint(n = "New_Jnt", p = positon )
mc.select(selection0[0])
mc.skinCluster(edit=True,ai="New_Jnt",lw = 1, wt = 0)
GetHold()
#------------------------------------------------Find_SkinCluster_Name
def SkinClustor(NamObj):
nodes = []
node = mc.listHistory(NamObj)
for damn in node:
if mc.nodeType(damn) == 'skinCluster':
nodes.append(damn)
return nodes
#-----------------------------------------------GetSoftValues
def softSelection():
mc.select(selection0[0])
selection = om.MSelectionList()
softSelection = om.MRichSelection()
om.MGlobal.getRichSelection(softSelection)
softSelection.getSelection(selection)
dagPath = om.MDagPath()
component = om.MObject()
iter = om.MItSelectionList( selection,om.MFn.kMeshVertComponent )
elements = []
while not iter.isDone():
iter.getDagPath( dagPath, component )
dagPath.pop()
node = dagPath.fullPathName()
fnComp = om.MFnSingleIndexedComponent(component)
for i in range(fnComp.elementCount()):
elements.append([node, fnComp.element(i), fnComp.weight(i).influence()] )
iter.next()
return elements
#---------------------------------------------------------------------Apply_weights
def createSoftCluster():
softElementData = softSelection()
selection = ["%s.vtx[%d]" % (el[0], el[1])for el in softElementData ]
#mc.select(selection, r=True)
#cluster = mc.cluster(relative=True)
for i in range(len(softElementData)):
mc.skinPercent( SkinClustor(shapename)[0],selection[i], tv=("New_Jnt", softElementData[i][2]))
#mc.percent(cluster[0], selection[i], v=softElementData[i][2])
#mc.select(cluster[1], r=True)
createSoftCluster()
#----------------------------------------------------end... :)
i have done some changes now it will work for skin cluster instead of normal cluster
Stacking clusters seems to be way more useful, compared to softMod, since the components are bound from the beginning. SoftMods deform based on radius from falloffCenter, making it unreliable whether components are in range when stacked.