1
1
import bpy
2
- from mathutils import Vector
3
2
from ...utils import copy_bone , flip_bone
4
3
from ...utils import strip_org , make_deformer_name , connected_children_names , make_mechanism_name
5
- from ...utils import create_circle_widget , create_sphere_widget , create_widget
4
+ from ...utils import create_circle_widget , create_widget
6
5
from ...utils import MetarigError
7
6
from rna_prop_ui import rna_idprop_ui_prop_get
8
7
@@ -27,126 +26,128 @@ def __init__(self, obj, bone_name, params):
27
26
def generate (self ):
28
27
org_bones = self .org_bones
29
28
30
- bpy .ops .object .mode_set (mode = 'EDIT' )
29
+ bpy .ops .object .mode_set (mode = 'EDIT' )
31
30
eb = self .obj .data .edit_bones
32
31
33
32
# Bone name lists
34
- ctrl_chain = []
35
- def_chain = []
36
- mch_chain = []
33
+ ctrl_chain = []
34
+ def_chain = []
35
+ mch_chain = []
37
36
mch_drv_chain = []
38
37
39
38
# Create ctrl master bone
40
39
org_name = self .org_bones [0 ]
41
40
temp_name = strip_org (self .org_bones [0 ])
42
41
43
- suffix = temp_name [- 2 :]
44
- master_name = temp_name [:- 5 ] + "_master" + suffix
45
- master_name = copy_bone ( self .obj , org_name , master_name )
46
- ctrl_bone_master = eb [ master_name ]
42
+ if temp_name [- 2 :] == '.L' or temp_name [- 2 :] == '.R' :
43
+ suffix = temp_name [- 2 :]
44
+ master_name = temp_name [:- 2 ] + "_master" + suffix
45
+ else :
46
+ master_name = temp_name + "_master"
47
+ master_name = copy_bone (self .obj , org_name , master_name )
48
+ ctrl_bone_master = eb [master_name ]
47
49
48
- ## Parenting bug fix ??
50
+ # Parenting bug fix ??
49
51
ctrl_bone_master .use_connect = False
50
- ctrl_bone_master .parent = None
52
+ ctrl_bone_master .parent = None
51
53
52
- ctrl_bone_master .tail += ( eb [ org_bones [- 1 ] ].tail - eb [org_name ].head ) * 1.25
54
+ ctrl_bone_master .tail += (eb [org_bones [- 1 ]].tail - eb [org_name ].head ) * 1.25
53
55
54
56
for bone in org_bones :
55
57
eb [bone ].use_connect = False
56
- if org_bones .index ( bone ) != 0 :
57
- eb [bone ].parent = None
58
+ if org_bones .index (bone ) != 0 :
59
+ eb [bone ].parent = None
58
60
59
61
# Creating the bone chains
60
62
for i in range (len (self .org_bones )):
61
63
62
- name = self .org_bones [i ]
64
+ name = self .org_bones [i ]
63
65
ctrl_name = strip_org (name )
64
66
65
67
# Create control bones
66
- ctrl_bone = copy_bone ( self .obj , name , ctrl_name )
67
- ctrl_bone_e = eb [ ctrl_name ]
68
+ ctrl_bone = copy_bone (self .obj , name , ctrl_name )
69
+ ctrl_bone_e = eb [ctrl_name ]
68
70
69
71
# Create deformation bones
70
- def_name = make_deformer_name ( ctrl_name )
71
- def_bone = copy_bone ( self .obj , name , def_name )
72
+ def_name = make_deformer_name (ctrl_name )
73
+ def_bone = copy_bone (self .obj , name , def_name )
72
74
73
75
# Create mechanism bones
74
- mch_name = make_mechanism_name ( ctrl_name )
75
- mch_bone = copy_bone ( self .obj , name , mch_name )
76
+ mch_name = make_mechanism_name (ctrl_name )
77
+ mch_bone = copy_bone (self .obj , name , mch_name )
76
78
77
79
# Create mechanism driver bones
78
- drv_name = make_mechanism_name (ctrl_name ) + "_drv"
79
- mch_bone_drv = copy_bone (self .obj , name , drv_name )
80
- mch_bone_drv_e = eb [drv_name ]
80
+ drv_name = make_mechanism_name (ctrl_name ) + "_drv"
81
+ mch_bone_drv = copy_bone (self .obj , name , drv_name )
81
82
82
83
# Adding to lists
83
- ctrl_chain += [ctrl_name ]
84
- def_chain += [def_bone ]
85
- mch_chain += [mch_bone ]
86
- mch_drv_chain += [drv_name ]
84
+ ctrl_chain += [ctrl_bone ]
85
+ def_chain += [def_bone ]
86
+ mch_chain += [mch_bone ]
87
+ mch_drv_chain += [mch_bone_drv ]
87
88
88
89
# Restoring org chain parenting
89
90
for bone in org_bones [1 :]:
90
- eb [bone ].parent = eb [ org_bones [ org_bones .index (bone ) - 1 ] ]
91
+ eb [bone ].parent = eb [org_bones [org_bones .index (bone ) - 1 ] ]
91
92
92
93
# Parenting the master bone to the first org
93
- ctrl_bone_master = eb [ master_name ]
94
- ctrl_bone_master .parent = eb [ org_bones [0 ] ]
94
+ ctrl_bone_master = eb [master_name ]
95
+ ctrl_bone_master .parent = eb [org_bones [0 ]]
95
96
96
97
# Parenting chain bones
97
98
for i in range (len (self .org_bones )):
98
99
# Edit bone references
99
- def_bone_e = eb [def_chain [i ]]
100
- ctrl_bone_e = eb [ctrl_chain [i ]]
101
- mch_bone_e = eb [mch_chain [i ]]
100
+ def_bone_e = eb [def_chain [i ]]
101
+ ctrl_bone_e = eb [ctrl_chain [i ]]
102
+ mch_bone_e = eb [mch_chain [i ]]
102
103
mch_bone_drv_e = eb [mch_drv_chain [i ]]
103
104
104
105
if i == 0 :
105
106
# First ctl bone
106
- ctrl_bone_e .parent = mch_bone_drv_e
107
+ ctrl_bone_e .parent = mch_bone_drv_e
107
108
ctrl_bone_e .use_connect = False
108
109
# First def bone
109
- def_bone_e .parent = eb [self .org_bones [i ]].parent
110
- def_bone_e .use_connect = False
110
+ def_bone_e .parent = eb [self .org_bones [i ]].parent
111
+ def_bone_e .use_connect = False
111
112
# First mch bone
112
113
mch_bone_e .parent = eb [self .org_bones [i ]].parent
113
- mch_bone_e .use_connect = False
114
+ mch_bone_e .use_connect = False
114
115
# First mch driver bone
115
116
mch_bone_drv_e .parent = eb [self .org_bones [i ]].parent
116
- mch_bone_drv_e .use_connect = False
117
+ mch_bone_drv_e .use_connect = False
117
118
else :
118
119
# The rest
119
- ctrl_bone_e .parent = mch_bone_drv_e
120
- ctrl_bone_e .use_connect = False
120
+ ctrl_bone_e .parent = mch_bone_drv_e
121
+ ctrl_bone_e .use_connect = False
121
122
122
- def_bone_e .parent = eb [def_chain [i - 1 ]]
123
- def_bone_e .use_connect = True
123
+ def_bone_e .parent = eb [def_chain [i - 1 ]]
124
+ def_bone_e .use_connect = True
124
125
125
- mch_bone_drv_e .parent = eb [ctrl_chain [i - 1 ]]
126
+ mch_bone_drv_e .parent = eb [ctrl_chain [i - 1 ]]
126
127
mch_bone_drv_e .use_connect = False
127
128
128
129
# Parenting mch bone
129
- mch_bone_e .parent = ctrl_bone_e
130
+ mch_bone_e .parent = ctrl_bone_e
130
131
mch_bone_e .use_connect = False
131
132
132
- # Creating tip conrtol bone
133
- tip_name = copy_bone ( self .obj , org_bones [- 1 ], temp_name )
134
- ctrl_bone_tip = eb [ tip_name ]
135
- flip_bone ( self .obj , tip_name )
133
+ # Creating tip control bone
134
+ tip_name = copy_bone (self .obj , org_bones [- 1 ], temp_name )
135
+ ctrl_bone_tip = eb [tip_name ]
136
+ flip_bone (self .obj , tip_name )
136
137
ctrl_bone_tip .length /= 2
137
138
138
139
ctrl_bone_tip .parent = eb [ctrl_chain [- 1 ]]
139
140
140
- bpy .ops .object .mode_set (mode = 'OBJECT' )
141
+ bpy .ops .object .mode_set (mode = 'OBJECT' )
141
142
142
143
pb = self .obj .pose .bones
143
144
144
145
# Setting pose bones locks
145
146
pb_master = pb [master_name ]
146
- pb_master .lock_scale = True ,False ,True
147
+ pb_master .lock_scale = True , False , True
147
148
148
- pb [tip_name ].lock_scale = True ,True ,True
149
- pb [tip_name ].lock_rotation = True ,True ,True
149
+ pb [tip_name ].lock_scale = True , True , True
150
+ pb [tip_name ].lock_rotation = True , True , True
150
151
pb [tip_name ].lock_rotation_w = True
151
152
152
153
pb_master ['finger_curve' ] = 0.0
@@ -160,103 +161,98 @@ def generate(self):
160
161
# Pose settings
161
162
for org , ctrl , deform , mch , mch_drv in zip (self .org_bones , ctrl_chain , def_chain , mch_chain , mch_drv_chain ):
162
163
163
- # Constraining the org bones
164
- #con = pb[org].constraints.new('COPY_TRANSFORMS')
165
- #con.target = self.obj
166
- #con.subtarget = ctrl
167
-
168
164
# Constraining the deform bones
169
- con = pb [deform ].constraints .new ('COPY_TRANSFORMS' )
170
- con .target = self .obj
165
+ con = pb [deform ].constraints .new ('COPY_TRANSFORMS' )
166
+ con .target = self .obj
171
167
con .subtarget = mch
172
168
173
169
# Constraining the mch bones
174
170
if mch_chain .index (mch ) == 0 :
175
- con = pb [mch ].constraints .new ('COPY_LOCATION' )
176
- con .target = self .obj
171
+ con = pb [mch ].constraints .new ('COPY_LOCATION' )
172
+ con .target = self .obj
177
173
con .subtarget = ctrl
178
174
179
- con = pb [mch ].constraints .new ('COPY_SCALE' )
180
- con .target = self .obj
175
+ con = pb [mch ].constraints .new ('COPY_SCALE' )
176
+ con .target = self .obj
181
177
con .subtarget = ctrl
182
178
183
- con = pb [mch ].constraints .new ('DAMPED_TRACK' )
184
- con .target = self .obj
179
+ con = pb [mch ].constraints .new ('DAMPED_TRACK' )
180
+ con .target = self .obj
185
181
con .subtarget = ctrl_chain [ctrl_chain .index (ctrl )+ 1 ]
186
182
187
- con = pb [mch ].constraints .new ('STRETCH_TO' )
188
- con .target = self .obj
183
+ con = pb [mch ].constraints .new ('STRETCH_TO' )
184
+ con .target = self .obj
189
185
con .subtarget = ctrl_chain [ctrl_chain .index (ctrl )+ 1 ]
190
- con .volume = 'NO_VOLUME'
186
+ con .volume = 'NO_VOLUME'
191
187
192
188
elif mch_chain .index (mch ) == len (mch_chain ) - 1 :
193
- con = pb [mch ].constraints .new ('DAMPED_TRACK' )
194
- con .target = self .obj
189
+ con = pb [mch ].constraints .new ('DAMPED_TRACK' )
190
+ con .target = self .obj
195
191
con .subtarget = tip_name
196
192
197
- con = pb [mch ].constraints .new ('STRETCH_TO' )
198
- con .target = self .obj
193
+ con = pb [mch ].constraints .new ('STRETCH_TO' )
194
+ con .target = self .obj
199
195
con .subtarget = tip_name
200
- con .volume = 'NO_VOLUME'
196
+ con .volume = 'NO_VOLUME'
201
197
else :
202
- con = pb [mch ].constraints .new ('DAMPED_TRACK' )
203
- con .target = self .obj
198
+ con = pb [mch ].constraints .new ('DAMPED_TRACK' )
199
+ con .target = self .obj
204
200
con .subtarget = ctrl_chain [ctrl_chain .index (ctrl )+ 1 ]
205
201
206
- con = pb [mch ].constraints .new ('STRETCH_TO' )
207
- con .target = self .obj
202
+ con = pb [mch ].constraints .new ('STRETCH_TO' )
203
+ con .target = self .obj
208
204
con .subtarget = ctrl_chain [ctrl_chain .index (ctrl )+ 1 ]
209
- con .volume = 'NO_VOLUME'
205
+ con .volume = 'NO_VOLUME'
210
206
211
207
# Constraining and driving mch driver bones
212
208
pb [mch_drv ].rotation_mode = 'YZX'
213
209
214
210
if mch_drv_chain .index (mch_drv ) == 0 :
215
211
# Constraining to master bone
216
- con = pb [mch_drv ].constraints .new ('COPY_LOCATION' )
217
- con .target = self .obj
218
- con .subtarget = master_name
212
+ con = pb [mch_drv ].constraints .new ('COPY_LOCATION' )
213
+ con .target = self .obj
214
+ con .subtarget = master_name
219
215
220
- con = pb [mch_drv ].constraints .new ('COPY_ROTATION' )
221
- con .target = self .obj
222
- con .subtarget = master_name
216
+ con = pb [mch_drv ].constraints .new ('COPY_ROTATION' )
217
+ con .target = self .obj
218
+ con .subtarget = master_name
223
219
con .target_space = 'LOCAL'
224
- con .owner_space = 'LOCAL'
220
+ con .owner_space = 'LOCAL'
225
221
226
222
else :
227
223
# Match axis to expression
228
224
options = {
229
- "X" : { "axis" : 0 ,
230
- "expr" : '(1-sy)*pi' },
231
- "-X" : { "axis" : 0 ,
232
- "expr" : '-((1-sy)*pi)' },
233
- "Y" : { "axis" : 1 ,
234
- "expr" : '(1-sy)*pi' },
235
- "-Y" : { "axis" : 1 ,
236
- "expr" : '-((1-sy)*pi)' },
237
- "Z" : { "axis" : 2 ,
238
- "expr" : '(1-sy)*pi' },
239
- "-Z" : { "axis" : 2 ,
240
- "expr" : '-((1-sy)*pi)' }
225
+ "X" : {"axis" : 0 ,
226
+ "expr" : '(1-sy)*pi' },
227
+ "-X" : {"axis" : 0 ,
228
+ "expr" : '-((1-sy)*pi)' },
229
+ "Y" : {"axis" : 1 ,
230
+ "expr" : '(1-sy)*pi' },
231
+ "-Y" : {"axis" : 1 ,
232
+ "expr" : '-((1-sy)*pi)' },
233
+ "Z" : {"axis" : 2 ,
234
+ "expr" : '(1-sy)*pi' },
235
+ "-Z" : {"axis" : 2 ,
236
+ "expr" : '-((1-sy)*pi)' }
241
237
}
242
238
243
239
axis = self .params .primary_rotation_axis
244
240
245
241
# Drivers
246
- drv = pb [mch_drv ].driver_add ("rotation_euler" , options [axis ]["axis" ]).driver
247
- drv .type = 'SCRIPTED'
248
- drv .expression = options [axis ]["expr" ]
249
- drv_var = drv .variables .new ()
250
- drv_var .name = 'sy'
251
- drv_var .type = "SINGLE_PROP"
252
- drv_var .targets [0 ].id = self .obj
242
+ drv = pb [mch_drv ].driver_add ("rotation_euler" , options [axis ]["axis" ]).driver
243
+ drv .type = 'SCRIPTED'
244
+ drv .expression = options [axis ]["expr" ]
245
+ drv_var = drv .variables .new ()
246
+ drv_var .name = 'sy'
247
+ drv_var .type = "SINGLE_PROP"
248
+ drv_var .targets [0 ].id = self .obj
253
249
drv_var .targets [0 ].data_path = pb [master_name ].path_from_id () + '.scale.y'
254
250
255
- # Setting bone curvature setting, costum property, and drivers
251
+ # Setting bone curvature setting, custom property, and drivers
256
252
def_bone = self .obj .data .bones [deform ]
257
253
258
254
def_bone .bbone_segments = 8
259
- drv = def_bone .driver_add ("bbone_in" ).driver # Ease in
255
+ drv = def_bone .driver_add ("bbone_in" ).driver # Ease in
260
256
261
257
drv .type = 'SUM'
262
258
drv_var = drv .variables .new ()
@@ -265,7 +261,7 @@ def generate(self):
265
261
drv_var .targets [0 ].id = self .obj
266
262
drv_var .targets [0 ].data_path = pb_master .path_from_id () + '["finger_curve"]'
267
263
268
- drv = def_bone .driver_add ("bbone_out" ).driver # Ease out
264
+ drv = def_bone .driver_add ("bbone_out" ).driver # Ease out
269
265
270
266
drv .type = 'SUM'
271
267
drv_var = drv .variables .new ()
@@ -274,7 +270,6 @@ def generate(self):
274
270
drv_var .targets [0 ].id = self .obj
275
271
drv_var .targets [0 ].data_path = pb_master .path_from_id () + '["finger_curve"]'
276
272
277
-
278
273
# Assigning shapes to control bones
279
274
create_circle_widget (self .obj , ctrl , radius = 0.3 , head_tail = 0.5 )
280
275
0 commit comments