-
Notifications
You must be signed in to change notification settings - Fork 2
/
MaxInfluence_Saurabh.py
53 lines (42 loc) · 1.54 KB
/
MaxInfluence_Saurabh.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
def limitPerJointInfluence(jnt_limit = 4, deselect = True):
'''
This script limits the influence for the number of joints affecting the deformation of a vertex.
Select any skinned mesh vertices or geometry and runCommand >>
limitPerJointInfluence(jnt_limit = 4)
'''
import pymel.core as pm
import time, sys, math
start_time = time.time()
initialSel = pm.ls(sl = True)
if isinstance(initialSel[0], pm.nt.Transform):
cmds.ConvertSelectionToVertices(initialSel)
vertSel = pm.selected()
geo = vertSel[0].node()
else:
vertSel = pm.selected()
geo = vertSel[0].node()
his = pm.listHistory(geo, pdo = True)
sknCls = pm.ls(his, typ = 'skinCluster')[0]
vertsList = cmds.ls(sl = True, fl = True)
for verts in vertsList:
vertWt = pm.skinPercent(sknCls, verts, q = True, value = True)
vertTrans = pm.skinPercent(sknCls, verts, q = True, transform = None)
dict = {}
for x in range(len(vertWt)):
if vertWt[x] == 0:
pass
else:
dict[vertTrans[x]] = vertWt[x]
sorted_dict = sorted(dict.items(), key=lambda item: item[1], reverse = True)
if len(sorted_dict) > jnt_limit:
rangeLen = -1 * (len(sorted_dict) - (jnt_limit-1))
for x in range(-1, rangeLen, -1):
pm.skinPercent(sknCls, verts, tv = [sorted_dict[x][0], 0])
lenVert = len(vertsList)
if deselect == True:
abc = geo.getTransform()
pm.select(abc)
pm.select(cl = True)
sys.stdout.write('\n %s Verts weight refined in. ' " %s seconds " % (lenVert, (time.time() - start_time)))
#### End of Script ####
limitPerJointInfluence(jnt_limit = 4, deselect = True)