/
gen2DRig (tanimator's conflicted copy 2014-11-28).py
165 lines (122 loc) · 5.95 KB
/
gen2DRig (tanimator's conflicted copy 2014-11-28).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
159
160
161
162
163
164
165
import maya.cmds as mc
import maya.mel as mm
def rigJntDepth() :
sels = mc.ls(sl = True)
depthGrp = 'depthJnt_grp'
if not mc.objExists(depthGrp) :
depthGrp = mc.group(em = True, n = depthGrp)
for each in sels :
if mc.getAttr('%s.visibility' % each) :
joint = mc.createNode('joint')
if '_ply' in each :
newName = each.replace('_ply', '_jnt')
else :
newName = '%s_jnt' % each
joint = mc.rename(joint, newName)
mc.delete(mc.pointConstraint(each, joint))
mc.skinCluster(each, joint, tsb = True)
mc.parent(joint, depthGrp)
def addDepthJntAttr(obj = 'placement_ctrlShape') :
sels = mc.ls(sl = True)
for each in sels :
attrName = each.replace('_jnt', '')
mc.addAttr(obj, ln = attrName, min = -10, max = 10, dv = 0)
mc.setAttr('%s.%s' % (obj, attrName), e = True, keyable = True)
attr = '%s.%s' % (obj, attrName)
mdvNode = mc.createNode('multiplyDivide', n = '%s_mdv' % attrName)
mc.setAttr('%s.input2X' % mdvNode, 0.1)
mc.connectAttr(attr, '%s.input1X' % mdvNode, f = True)
mc.connectAttr('%s.outputX' % mdvNode, '%s.translateZ' % each, f = True)
def rigFace() :
jntGrp = 'facialJnt_grp'
if not mc.objExists(jntGrp) :
mc.group(em = True, n = jntGrp)
facePolyMap = {'L_brow_ply': 'L_brow_ctrl',
'L_baseEye_ply': 'L_baseEye_ctrl',
'L_eye_ply': 'L_eye_ctrl',
'R_brow_ply': 'R_brow_ctrl',
'R_baseEye_ply': 'R_baseEye_ctrl',
'R_eye_ply': 'R_eye_ctrl',
'nose_ply': 'noseface_ctrl',
'mouth_ply': 'mount_ctrl'
}
for each in facePolyMap :
poly = each
ctrl = facePolyMap[poly]
if mc.objExists(poly) :
movePivot(ctrl, poly)
joint = mc.createNode('joint', n = poly.replace('_ply', '_jnt'))
mc.delete(mc.pointConstraint(poly, joint))
mc.skinCluster(poly, joint, tsb = True)
mc.parentConstraint(ctrl, joint)
mc.scaleConstraint(ctrl, joint)
mc.parent(joint, jntGrp)
def rigFace2() :
jntGrp = 'facialJnt_grp'
if not mc.objExists(jntGrp) :
mc.group(em = True, n = jntGrp)
facePolyMap = {'L_brow_ply': 'L_brow_ctrl',
'L_baseEye_ply': 'L_baseEye_ctrl',
'L_eye_ply': 'L_eye_ctrl',
'R_brow_ply': 'R_brow_ctrl',
'R_baseEye_ply': 'R_baseEye_ctrl',
'R_eye_ply': 'R_eye_ctrl',
'nose_ply': 'noseface_ctrl',
'mouth_ply': 'mouth_ctrl',
'L_eyeLine_ply': 'L_eyeLine_ctrl',
'R_eyeLine_ply': 'R_eyeLine_ctrl',
'L_wrinkle_ply': 'L_wrinkle_ctrl',
'R_wrinkle_ply': 'R_wrinkle_ctrl'
}
# facePolyMap = {'L_brow_ply': 'L_brow_ctrl',
# 'L_Eye_line_ply': 'L_baseEye_ctrl',
# 'L_eye_ply': 'L_eye_ctrl',
# 'R_brow_ply': 'R_brow_ctrl',
# 'R_Eye_line_ply': 'R_baseEye_ctrl',
# 'R_eye_ply': 'R_eye_ctrl',
# 'nose_ply': 'noseface_ctrl',
# 'mouth_ply': 'mount_ctrl',
# 'L_wrinkle_ply': 'L_wrinkle_ctrl',
# 'R_wrinkle_ply': 'R_wrinkle_ctrl'
# }
for each in facePolyMap :
poly = each
ctrl = facePolyMap[poly]
if mc.objExists(poly) :
joint = mc.createNode('joint', n = ctrl.replace('_ctrl', '_jnt'))
jntZgrp = mc.group(joint, n = '%sJnt_zGrp' % ctrl.replace('_ctrl', '_jnt'))
mc.delete(mc.pointConstraint(poly, jntZgrp))
mc.skinCluster(poly, joint, tsb = True)
mc.pointConstraint(ctrl, joint, mo = True)
# mc.connectAttr('%s.translateX' % ctrl, '%s.translateX' % joint, f = True)
# mc.connectAttr('%s.translateY' % ctrl, '%s.translateY' % joint, f = True)
# mc.connectAttr('%s.translateZ' % ctrl, '%s.translateZ' % joint, f = True)
mc.connectAttr('%s.rotateX' % ctrl, '%s.rotateX' % joint, f = True)
mc.connectAttr('%s.rotateY' % ctrl, '%s.rotateY' % joint, f = True)
mc.connectAttr('%s.rotateZ' % ctrl, '%s.rotateZ' % joint, f = True)
mc.connectAttr('%s.scaleX' % ctrl, '%s.scaleX' % joint, f = True)
mc.connectAttr('%s.scaleY' % ctrl, '%s.scaleY' % joint, f = True)
mc.connectAttr('%s.scaleZ' % ctrl, '%s.scaleZ' % joint, f = True)
mc.parent(jntZgrp, jntGrp)
else :
print '%s not exists' % poly
def movePivot(obj, target) :
loc = mc.spaceLocator()
mc.delete(mc.pointConstraint(target, loc[0]))
pos = mc.xform(loc[0], q=True, ws=True, t=True)
mc.xform(obj, piv = pos)
mc.delete(loc)
def hideUnused() :
hide = ['lf_allHandCtrl_grp', 'lf_handJnt_zGrp', 'rt_allHandCtrl_grp', 'rt_handJnt_zGrp', 'lf_eye_jnt', 'rt_eye_jnt', 'lwr_jaw1_jnt', 'upr_jaw1_jnt']
for each in hide :
if mc.objExists(each) :
mc.setAttr('%s.visibility' % each, 0)
def skinCurve() :
mc.skinCluster('lf_upArm_jnt', 'lf_loArm_jnt', 'lf_wrist_jnt', 'L_arm_pathCrv')
mc.skinCluster('rt_upArm_jnt', 'rt_loArm_jnt', 'rt_wrist_jnt', 'R_arm_pathCrv')
mc.skinCluster('lf_upLeg_jnt', 'lf_loLeg_jnt', 'lf_ankle_jnt', 'L_leg_pathCrv')
mc.skinCluster('rt_upLeg_jnt', 'rt_loLeg_jnt', 'rt_ankle_jnt', 'R_leg_pathCrv')
# def rigPlane() :
# 'lf_upLeg_nrJnt'
# mc.orientConstraint()
# [u'L_arm_pathCrv', u'L_arm_profileCrv', u'R_arm_pathCrv', u'R_arm_profileCrv', u'L_leg_pathCrv', u'L_leg_profileCrv', u'R_leg_pathCrv', u'R_leg_profileCrv']