forked from vishal980-glitch/MyCode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWire_To_Skin.py
93 lines (70 loc) · 3.22 KB
/
Wire_To_Skin.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#select wire first then wiredMesh :) , Made By : Vishal Nagpal, Gmail : [email protected]
#change skincluster name of wire "skinCluster1" to skinCluster2
# one tip distance could be euual to weight
import maya.cmds as cmds
start_time = time.time()
selection0 = cmds.ls(sl=True)
cmds.duplicate(selection0[0], n = 'Get_Test_Crv')
AllAtO = cmds.listAttr('Get_Test_Crv',l =True)
for x in AllAtO:
cmds.setAttr('Get_Test_Crv.'+x, l = 0)
cmds.makeIdentity(a = True )
spamSS =cmds.getAttr('Get_Test_Crv.spans')
cmds.select(d = True)
#------------------------------------------------------Find_SkinCluster
Meeshjnts = cmds.skinCluster(selection0[1], inf = True, q = True)
cmds.setAttr(Meeshjnts[0]+'.liw', 1)
#------------------------------------------------------Find_crv_Jnt
Aljnts = cmds.skinCluster(selection0[0], inf = True, q = True)
#------------------------------------------------------addInflunce_other_Jnts
for gfs in Aljnts:
cmds.select(selection0[1])
cmds.skinCluster(edit=True,ai=gfs,lw = 1)
#------------------------------------------------------Find_crv_Jnt_for Vertex
def fndJnt(verNam):
myJnt = []
for fg in Aljnts:
getJntt = cmds.skinPercent('skinCluster1',selection0[0]+'.controlPoints['+str(verNam)+']' , tv = True, q = True,t = fg )
if getJntt == 1.0:
myJnt.append(fg)
return myJnt
#------------------------------------------------------
for xx in range(spamS):
whichVer = []
PostionP = cmds.getAttr('Get_Test_Crv.controlPoints['+str(xx)+']')[0]
verName = cmds.select(selection0[0]+'.cv['+str(xx)+']', r =True)
cmds.setAttr(selection0[0]+'.cv['+str(xx)+'].xValue', 1)
whichVer.append(xx)
cmds.select(selection0[1])
cmds.duplicate(n = 'Get_Test_Mesh')
cmds.setAttr(selection0[0]+'.cv['+str(xx)+'].xValue', 0)
cmds.select(selection0[1])
polyCount = cmds.polyEvaluate( v=True )
set_01Z = []
set_02Z = []
diff = []
AlWeight= []
#-----------------------------------------------------set1
for d in range(int(polyCount)):
cmds.select(selection0[1]+'.vtx['+str(d)+']', r = True)
Attr = '%.3f'%cmds.xform(selection0[1]+'.vtx['+str(d)+']', q =True, ws = True, t=True)[1]
set_01Z.append((Attr))
for b in range(int(polyCount)):
cmds.select('Get_Test_Mesh'+'.vtx['+str(b)+']', r = True)
Attrs = '%.3f'%cmds.xform('Get_Test_Mesh'+'.vtx['+str(b)+']', q =True, ws = True, t=True)[1]
set_02Z.append((Attrs))
#---------------------------------------------------getDiff
for o in range(int(polyCount)):
dif = float(set_02Z[o]) - float(set_01Z[o])
diff.append((dif))
AlWeight.append((diff[o]/1.0))
#---------------------------------------------------addSkin
for R in range(int(polyCount)):
cmds.setAttr(Meeshjnts[0]+'.liw', 0)
if AlWeight[R] != 0.0:
cmds.skinPercent( 'skinCluster2','Normal.vtx['+str(R)+']', tv=(fndJnt(whichVer[0])[0], AlWeight[R]))
cmds.setAttr(selection0[0]+'.cv['+str(xx)+'].xValue', 0)
cmds.delete('Get_Test_Mesh')
cmds.delete('Get_Test_Crv')
#---------------------------------------------------Total_Time
print("--- %s seconds ---" % (time.time() - start_time))