/
komodo_deform.py
158 lines (93 loc) · 4.25 KB
/
komodo_deform.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
"""
komodo dragon rig setup
deformation setup
"""
import maya.cmds as mc
import maya.mel as mm
import os
from rigTools import bSkinSaver
from rigLib.utils import name
from . import project
skinWeightsDir = 'weights/skinCluster'
swExt = '.swt'
bodyGeo = 'body_geo'
bodyMidresGeo = 'body_midres_geo'
def build( baseRig, characterName ):
modelGrp = '%s_model_grp' % characterName
# make twist joints
refTwistJoints = ['l_elbow1_jnt', 'l_knee1_jnt', 'r_elbow1_jnt', 'r_knee1_jnt']
maketwistJoints( baseRig, refTwistJoints )
# load skin weights
geoList = _getModelGeoObjects( modelGrp )
loadSkinWeights( characterName, geoList )
# apply delta mush deformer
_applyDeltaMush( bodyMidresGeo )
# wrap hires body mesh
_makeWrap( [bodyGeo], bodyMidresGeo )
def _makeWrap( wrappedObjs, wrapperObj ):
mc.select( wrappedObjs )
mc.select( wrapperObj, add=1 )
mm.eval( 'doWrapArgList "7" { "1","0","1", "2", "1", "1", "0", "0" }' )
def _applyDeltaMush( geo ):
deltaMushDf = mc.deltaMush( geo, smoothingIterations = 50 )[0]
def _getModelGeoObjects( modelGrp ):
geoList = [ mc.listRelatives( o, p = 1 )[0] for o in mc.listRelatives( modelGrp, ad = 1, type = 'mesh' ) ]
return geoList
def maketwistJoints( baseRig, parentJoints ):
twistJointsMainGrp = mc.group( n= 'twistJoints_grp', p= baseRig.jointsGrp, em=1 )
for parentJnt in parentJoints:
prefix = name.removeSuffix( parentJnt )
prefix = prefix[:-1]
parentJntChild = mc.listRelatives( parentJnt, c= 1, type= 'joint' )[0]
# make twist joints
twistJntGrp = mc.group( n = prefix + 'TwistJoint_grp', p = twistJointsMainGrp, em = 1 )
twistParentJnt = mc.duplicate( parentJnt, n = prefix + 'Twist1_jnt', parentOnly = True )[0]
twistChildJnt = mc.duplicate( parentJntChild, n = prefix + 'Twist2_jnt', parentOnly = True )[0]
# adjust twist joints
origJntRadius = mc.getAttr( parentJnt + '.radius' )
for j in [ twistParentJnt, twistChildJnt ]:
mc.setAttr( j + '.radius', origJntRadius * 2 )
mc.color( j, ud = 1 )
mc.parent( twistChildJnt, twistParentJnt )
mc.parent( twistParentJnt, twistJntGrp )
# attach twist joints
mc.pointConstraint( parentJnt, twistParentJnt )
# make IK handle
twistIk = mc.ikHandle( n = prefix + 'TwistJoint_ikh', sol = 'ikSCsolver', sj = twistParentJnt, ee = twistChildJnt )[0]
mc.hide( twistIk )
mc.parent( twistIk, twistJntGrp )
mc.parentConstraint( parentJntChild, twistIk )
def saveSkinWeights( characterName, geoList = [] ):
"""
save weights for character geometry objects
"""
for obj in geoList:
# weights file
wtFile = os.path.join( project.mainProjectPath, characterName, skinWeightsDir, obj + swExt )
# save skin weight file
mc.select( obj )
bSkinSaver.bSaveSkinValues( wtFile )
def loadSkinWeights( characterName, geoList = [] ):
"""
load skin weights for character geometry objects
"""
# weights folders
wtDir = os.path.join( project.mainProjectPath, characterName, skinWeightsDir )
wtFiles = os.listdir( wtDir )
# load skin weights
for wtFile in wtFiles:
extRes = os.path.splitext( wtFile )
# check extension format
if not extRes > 1:
continue
# check skin weight file
if not extRes[1] == swExt:
continue
# check geometry list
if geoList and not extRes[0] in geoList:
continue
# check if objects exist
if not mc.objExists( extRes[0] ):
continue
fullpathWtFile = os.path.join( wtDir, wtFile )
bSkinSaver.bLoadSkinValues( loadOnSelection = False, inputFile = fullpathWtFile )