-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathops_baking.py
697 lines (595 loc) · 26.7 KB
/
ops_baking.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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
import bpy
from .search_functions import *
################################# BAKING OPERATORS ##########################################################
# Mesh Proportions Baker operator
class ARMATURE_OT_mesh_pose_baker(bpy.types.Operator):
bl_label = "BlenRig 6 Mesh Baker"
bl_idname = "blenrig.mesh_pose_baker"
bl_description = "Bake current pose to mesh"
bl_options = {'REGISTER', 'UNDO'}
@classmethod
def poll(cls, context):
if not bpy.context.object:
return False
return (bpy.context.object.type == "MESH" and context.mode=='OBJECT')
#Baking
def bake(self, context):
props = context.window_manager.blenrig_6_props
if not bpy.context.object:
return False
old_ob = bpy.context.active_object
bake_meshes = [ob.name for ob in bpy.context.selected_objects if ob.type=="MESH"]
for name in bake_meshes:
if name in bpy.data.objects:
ob = bpy.data.objects[name]
bpy.context.view_layer.objects.active = ob
# Turn off SUBSURF for baking
for mod in ob.modifiers:
if mod.type == 'SUBSURF':
old_state = mod.show_viewport
mod.show_viewport = False
# --- get a mesh from the object ---
depsgraph = bpy.context.evaluated_depsgraph_get()
mesh_owner = ob.evaluated_get(depsgraph)
mesh = mesh_owner.to_mesh()
for mod in ob.modifiers:
if mod.type == 'SUBSURF':
mod.show_viewport = old_state
# If Bake to shape option is off
if props.bake_to_shape == False:
# Check if there are shapekeys in object
try:
if ob.data.shape_keys.key_blocks:
key = ob.data.shape_keys
shapekeys = key.key_blocks
# Transfer vertex locations to Basis key
for vert in ob.data.vertices:
shapekeys['Basis'].data[vert.index].co = mesh.vertices[vert.index].co
#Disable Shapekeys that influenced the Baked Shape to avoid double transforms
for i in range(len(ob.data.shape_keys.key_blocks)):
shape = ob.data.shape_keys.key_blocks[i]
if shape.value > 0.1:
shape.mute = True
# Make baked shape active
for i in range(len(shapekeys)):
shape = shapekeys[i]
if shape.name == 'Basis':
ob.active_shape_key_index = i
except (AttributeError):
# Transfer vertex locations to Mesh
for vert in ob.data.vertices:
vert.co = mesh.vertices[vert.index].co
# If Bake to shape option is on
else:
# Check if there are shapekeys in object
try:
ob.data.shape_keys.key_blocks
except (AttributeError):
Basis = ob.shape_key_add(from_mix=False)
Basis.name = 'Basis'
# Create new shape for storing the bake
baked_shape = ob.shape_key_add(from_mix=False)
baked_shape.name = 'Baked_shape'
baked_shape.value = 1
# Transfer vertex locations
for vert in ob.data.vertices:
baked_shape.data[vert.index].co = mesh.vertices[vert.index].co
#Disable Shapekeys that influenced the Baked Shape to avoid double transforms
for i in range(len(ob.data.shape_keys.key_blocks)):
shape = ob.data.shape_keys.key_blocks[i]
if shape.value > 0.1:
shape.mute = True
# Make baked shape active
for i in range(len(ob.data.shape_keys.key_blocks)):
shape = ob.data.shape_keys.key_blocks[i]
if shape.name == baked_shape.name:
shape.mute = False
ob.active_shape_key_index = i
# Remove unused baked mesh
ob.to_mesh_clear()
bpy.context.view_layer.objects.active = old_ob
#Unbind Mdef modifier if object is bound
def mdef_unbind(self, context):
if not bpy.context.object:
return False
old_ob = bpy.context.active_object
bake_meshes = [ob.name for ob in bpy.context.selected_objects if ob.type=="MESH"]
for name in bake_meshes:
if name in bpy.data.objects:
ob = bpy.data.objects[name]
bpy.context.view_layer.objects.active = ob
# unbind mdef modifiers
for i in range(len(ob.modifiers)):
mod = ob.modifiers[i]
if mod.type in ['MESH_DEFORM']:
if mod.is_bound == True:
bpy.ops.object.meshdeform_bind(modifier=mod.name)
# unbind sdef modifiers
for i in range(len(ob.modifiers)):
mod = ob.modifiers[i]
if mod.type in ['SURFACE_DEFORM']:
if mod.is_bound == True:
bpy.ops.object.surfacedeform_bind(modifier=mod.name)
bpy.context.view_layer.objects.active = old_ob
def execute(self, context):
self.bake(context)
self.mdef_unbind(context)
self.report({'INFO'}, "Baking done")
return{'FINISHED'}
# Hook Reset operator
class ARMATURE_OT_reset_hooks(bpy.types.Operator):
bl_label = "BlenRig 6 Reset Hooks"
bl_idname = "blenrig.reset_hooks"
bl_description = "Reset Hooks on Lattices and Curves"
bl_options = {'REGISTER', 'UNDO'}
@classmethod
def poll(cls, context):
if not bpy.context.object:
return False
return (bpy.context.object.type == "LATTICE", "CURVE" and context.mode=='OBJECT')
def activar_modif(self,context):
for a in bpy.context.object.modifiers:
bpy.context.object.modifiers[a.name].show_viewport = True
def reset_hooks(self,context):
selected_lattices = [ob.name for ob in bpy.context.selected_objects if ob.type=="LATTICE"]
for name in selected_lattices:
if name in bpy.data.objects:
ob = bpy.data.objects[name]
bpy.context.view_layer.objects.active = ob
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.lattice.select_all(action='SELECT')
for mod in ob.modifiers:
if mod.type == 'HOOK':
bpy.ops.object.hook_reset(modifier=mod.name)
bpy.ops.object.mode_set(mode='OBJECT')
selected_curves = [ob.name for ob in bpy.context.selected_objects if ob.type=="CURVE"]
for name in selected_curves:
if name in bpy.data.objects:
ob = bpy.data.objects[name]
bpy.context.view_layer.objects.active = ob
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.curve.select_all(action='SELECT')
for mod in ob.modifiers:
if mod.type == 'HOOK':
bpy.ops.object.hook_reset(modifier=mod.name)
bpy.ops.object.mode_set(mode='OBJECT')
def execute(self, context):
self.reset_hooks(context)
self.activar_modif(context)
self.report({'INFO'}, "Hooks Reseted")
return{'FINISHED'}
# Hook Disable Hooks modifier
class ARMATURE_OT_disable_hooks_modif(bpy.types.Operator):
bl_label = "BlenRig 6 Disable Hooks modifier"
bl_idname = "blenrig.disable_hooks_modif"
bl_description = "Disable Hooks modifier"
bl_options = {'REGISTER', 'UNDO'}
@classmethod
def poll(cls, context):
if not bpy.context.object:
return False
return (bpy.context.object.type == "LATTICE", "CURVE" and context.mode=='OBJECT')
def desactivar_modif(self,context):
for a in bpy.context.object.modifiers:
bpy.context.object.modifiers[a.name].show_viewport = False
def execute(self, context):
self.desactivar_modif(context)
self.report({'INFO'}, "Disable Lattice Hooks")
return{'FINISHED'}
# Reset Armature related Lattices and Curves operator
class ARMATURE_OT_reset_deformers(bpy.types.Operator):
bl_label = "BlenRig 6 Reset Deformers"
bl_idname = "blenrig.reset_deformers"
bl_description = "Reset Armature related Lattices and Curves"
bl_options = {'REGISTER', 'UNDO'}
@classmethod
def poll(cls, context):
if not bpy.context.object:
return False
else:
return (bpy.context.object.type=='ARMATURE' and \
context.mode=='POSE')
def reset_deformers(self, context):
# preparing scene
# activating lattices collection:
blenrig_temp_parent(1)
bpy.ops.object.mode_set(mode='OBJECT')
old_active = bpy.context.active_object
old_selected = bpy.context.selected_objects
old_visible_collections = [coll.name for coll in bpy.data.collections if coll.hide_viewport == False ]
for ob in old_selected:
ob.select_set(False)
# Armature related lattices and curves
deformers_collection = []
selected_deformers = []
for ob in bpy.data.objects:
if ob.type in 'LATTICE' or 'CURVE':
for mod in ob.modifiers:
if mod.type in 'HOOK':
if mod.object.name == bpy.context.object.name:
# Toggle on active collections
for coll in bpy.data.collections:
for coll_ob in coll.objects:
if ob.name == coll_ob.name:
deformers_collection.append(coll.name)
for coll in bpy.data.collections:
if coll.name in deformers_collection:
coll.hide_viewport = False
ob.select_set(True)
selected_deformers.append(ob.name)
for name in selected_deformers:
if name in bpy.data.objects:
ob = bpy.data.objects[name]
bpy.context.view_layer.objects.active = ob
# Reset Hooks
bpy.ops.blenrig.reset_hooks()
#Back to Armature
for ob in bpy.context.selected_objects:
ob.select_set(False)
for coll in bpy.data.collections:
coll.hide_viewport = True
for coll in bpy.data.collections:
if coll.name in old_visible_collections:
coll.hide_viewport = False
bpy.context.view_layer.objects.active = old_active
for ob in old_selected:
ob.select_set(True)
bpy.ops.object.mode_set(mode='POSE')
#Hack for updating objects
bpy.context.scene.frame_set(bpy.context.scene.frame_current)
# deactivating lattices collection:
blenrig_temp_parent(0)
def execute(self, context):
self.reset_deformers(context)
self.report({'INFO'}, "Lattices and Curves Reset")
return{'FINISHED'}
def enable_disable_colleciton(mode, target_coll):
# de/activating lattices collection:
mc = None
vlayer = bpy.context.view_layer
# obtain Master Colecction from active object:
obj = bpy.context.active_object
obj_name = obj.name
subcoll = [coll for coll in bpy.data.collections if obj_name in coll.objects]
for coll in bpy.data.collections:
if subcoll[0].name in coll.children:
# get the real Master Collection, even if the user has renamed the collection:
mc = vlayer.layer_collection.children[coll.name]
# print(mc)
if mc:
for child in reversed(mc.children):
coll = child.collection
# print(child)
if 'BlenRig' in coll:
if coll.name.startswith(target_coll):
print('Processing: ' + mc.name + ' > ' + coll.name)
vlayer.layer_collection.children[mc.name].children[coll.name].exclude = mode
break
else:
pass
else:
print("Error")
# Armature Baker All operator
class ARMATURE_OT_armature_baker_all_part_1(bpy.types.Operator):
bl_label = "BlenRig 6 Armature Baker"
bl_idname = "blenrig.armature_baker_all_part_1"
bl_description = "Bake current pose to armature"
bl_options = {'REGISTER', 'UNDO'}
@classmethod
def poll(cls, context):
if not bpy.context.object:
return False
else:
return (bpy.context.object.type=='ARMATURE' and \
context.mode=='POSE' or 'EDIT_ARMATURE')
def bake_all_1(self, context):
props = context.window_manager.blenrig_6_props
arm = context.active_object
#Get Objects List
mdef_cage = mdef_search('MESH_DEFORM')[1]
sdef_cage = mdef_search('SURFACE_DEFORM')[1]
mdef_objects = search_mod('MESH_DEFORM')[1]
armature_objects = search_mod('ARMATURE')[1]
sdef_objects = search_mod('SURFACE_DEFORM')[1]
#Link Objects to Temp Collection
from .guides.utils import blenrig_temp_unlink
blenrig_temp_unlink()
blenrig_temp_mdef_cage(True)
blenrig_temp_sdef_cage(True)
blenrig_temp('MESH_DEFORM')
blenrig_temp('ARMATURE')
blenrig_temp('SURFACE_DEFORM')
#Bake Surface Deform Objects First
bpy.ops.object.mode_set(mode='OBJECT')
bpy.ops.object.select_all(action='DESELECT')
for ob in sdef_objects:
if ob not in mdef_cage and ob not in sdef_cage:
context.view_layer.objects.active = bpy.data.objects[ob]
bpy.data.objects[ob].select_set(1)
if hasattr(context.active_object, 'data'):
if context.active_object.data.shape_keys:
if not props.bake_to_shape:
props.bake_to_shape = True
else:
props.bake_to_shape = False
bpy.ops.blenrig.mesh_pose_baker()
bpy.ops.object.select_all(action='DESELECT')
context.view_layer.objects.active = arm
bpy.ops.object.mode_set(mode='POSE')
#Bake Mesh Deform Objects Second
bpy.ops.object.mode_set(mode='OBJECT')
bpy.ops.object.select_all(action='DESELECT')
for ob in mdef_objects:
if ob not in mdef_cage and ob not in sdef_cage:
context.view_layer.objects.active = bpy.data.objects[ob]
bpy.data.objects[ob].select_set(1)
if hasattr(context.active_object, 'data'):
if context.active_object.data.shape_keys:
if not props.bake_to_shape:
props.bake_to_shape = True
else:
props.bake_to_shape = False
bpy.ops.blenrig.mesh_pose_baker()
bpy.ops.object.select_all(action='DESELECT')
context.view_layer.objects.active = arm
bpy.ops.object.mode_set(mode='POSE')
#Bake Armature Objects Third
bpy.ops.object.mode_set(mode='OBJECT')
bpy.ops.object.select_all(action='DESELECT')
for ob in armature_objects:
if ob not in mdef_cage and ob not in mdef_objects and ob not in sdef_objects:
context.view_layer.objects.active = bpy.data.objects[ob]
bpy.data.objects[ob].select_set(1)
if hasattr(context.active_object, 'data'):
if context.active_object.data.shape_keys:
if not props.bake_to_shape:
props.bake_to_shape = True
else:
props.bake_to_shape = False
bpy.ops.blenrig.mesh_pose_baker()
bpy.ops.object.select_all(action='DESELECT')
context.view_layer.objects.active = arm
bpy.ops.object.mode_set(mode='POSE')
#Bake Sdef Cages Last
bpy.ops.object.mode_set(mode='OBJECT')
bpy.ops.object.select_all(action='DESELECT')
for ob in sdef_cage:
context.view_layer.objects.active = bpy.data.objects[ob]
bpy.data.objects[ob].select_set(1)
if hasattr(context.active_object, 'data'):
if context.active_object.data.shape_keys:
if not props.bake_to_shape:
props.bake_to_shape = True
else:
props.bake_to_shape = False
bpy.ops.blenrig.mesh_pose_baker()
bpy.ops.object.select_all(action='DESELECT')
context.view_layer.objects.active = arm
bpy.ops.object.mode_set(mode='POSE')
#Bake Mdef Cages Last
bpy.ops.object.mode_set(mode='OBJECT')
bpy.ops.object.select_all(action='DESELECT')
for ob in mdef_cage:
context.view_layer.objects.active = bpy.data.objects[ob]
bpy.data.objects[ob].select_set(1)
if hasattr(context.active_object, 'data'):
if context.active_object.data.shape_keys:
if not props.bake_to_shape:
props.bake_to_shape = True
else:
props.bake_to_shape = False
bpy.ops.blenrig.mesh_pose_baker()
bpy.ops.object.select_all(action='DESELECT')
context.view_layer.objects.active = arm
bpy.ops.object.mode_set(mode='POSE')
#Bake Armature
bpy.ops.blenrig.advanced_armature_baker()
#Rebind Weight Transfer Meshes
bpy.ops.object.mode_set(mode='OBJECT')
bpy.ops.object.select_all(action='DESELECT')
blenrig_temp_unlink()
blenrig_temp('MESH_DEFORM')
for ob in mdef_objects:
context.view_layer.objects.active = bpy.data.objects[ob]
bpy.data.objects[ob].select_set(1)
if 'WeightsModel' in bpy.data.objects[ob].name:
print(bpy.context.active_object.name)
bpy.ops.blenrig.bind_mdef_modifiers(Bind_Type=True)
bpy.ops.object.select_all(action='DESELECT')
bpy.ops.object.select_all(action='DESELECT')
#Back to Armature
context.view_layer.objects.active = arm
bpy.ops.object.mode_set(mode='POSE')
#UnLink Objects to Temp Collection
blenrig_temp_mdef_cage(False)
blenrig_temp_sdef_cage(False)
blenrig_temp('MESH_DEFORM', False)
blenrig_temp('ARMATURE', False)
blenrig_temp('SURFACE_DEFORM', False)
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.blenrig.fix_misaligned_bones()
bpy.ops.blenrig.auto_bone_roll()
bpy.ops.armature.collection_solo_visibility(name="BONE-ROLLS")
context.object.data.show_axes = True
context.scene.cursor.location = [0,0,0]
def execute(self, context):
self.bake_all_1(context)
self.report({'INFO'}, "1º Baking part done")
return{'FINISHED'}
class ARMATURE_OT_armature_baker_all_part_2(bpy.types.Operator):
bl_label = "BlenRig 6 Armature Baker"
bl_idname = "blenrig.armature_baker_all_part_2"
bl_description = "Bake current pose to armature"
bl_options = {'REGISTER', 'UNDO'}
@classmethod
def poll(cls, context):
if not bpy.context.object:
return False
else:
return (bpy.context.object.type=='ARMATURE' and \
context.mode=='EDIT_ARMATURE')
def after_custom_align(self, context):
bpy.ops.blenrig.custom_bone_roll()
bpy.ops.blenrig.store_roll_angles()
context.object.data.show_axes = False
bpy.ops.armature.collection_solo_visibility(name="REPROPORTION")
bpy.ops.object.mode_set(mode='POSE')
bpy.ops.blenrig.reset_constraints()
context.object.data.pose_position = 'REST'
bpy.ops.blenrig.reset_deformers()
bpy.ops.blenrig.calculate_pole_angles()
context.object.data.pose_position = 'POSE'
context.object.data.reproportion = False
context.scene.cursor.location = [0,0,0]
def execute(self, context):
self.after_custom_align(context)
self.report({'INFO'}, "Baking Finish")
return{'FINISHED'}
# Armature Advanced Baker operator
class ARMATURE_OT_advanced_armature_baker(bpy.types.Operator):
bl_label = "BlenRig 6 Armature Baker"
bl_idname = "blenrig.advanced_armature_baker"
bl_description = "Bake current pose to armature"
bl_options = {'REGISTER', 'UNDO'}
@classmethod
def poll(cls, context):
if not bpy.context.object:
return False
else:
return (bpy.context.object.type=='ARMATURE' and \
context.mode=='POSE')
def bake_armature(self, context):
# preparing scene
bpy.ops.object.mode_set(mode='OBJECT')
old_active = bpy.context.active_object
old_selected = bpy.context.selected_objects
# activating lattices collection:
blenrig_temp_parent(1)
for ob in old_selected:
ob.select_set(False)
# unparenting external objects related to the armature
deformers_collection = []
parent_pairs = []
for ob in bpy.data.objects:
if ob.parent is not None:
if ob.parent.name == bpy.context.object.name:
ob.select_set(True)
parent_pairs.append([ob, ob.parent, ob.parent_bone])
bpy.ops.object.parent_clear(type='CLEAR_KEEP_TRANSFORM')
#Back to Armature
for ob in bpy.context.selected_objects:
ob.select_set(False)
bpy.context.view_layer.objects.active = old_active
for ob in old_selected:
ob.select_set(True)
bpy.ops.object.mode_set(mode='POSE')
posebones = bpy.context.object.pose.bones
# Bake Armature
bpy.ops.pose.armature_apply()
arm = bpy.context.object.data
# Reset Constraints
bpy.ops.blenrig.reset_constraints()
bpy.ops.object.mode_set(mode='OBJECT')
for ob in bpy.context.selected_objects:
ob.select_set(False)
# re-parenting external objects related to the armature
for pp in parent_pairs:
ob, parent, bone = pp
ob.parent = parent
ob.parent_type = 'BONE'
ob.parent_bone = bone
#Reseting Hooks
ob.select_set(True)
bpy.ops.blenrig.reset_hooks()
#Back to Armature
for ob in bpy.context.selected_objects:
ob.select_set(False)
bpy.context.view_layer.objects.active = old_active
for ob in old_selected:
ob.select_set(True)
bpy.ops.object.mode_set(mode='POSE')
#deactivating lattices collection:
blenrig_temp_parent(0)
def armature_update_values(self, context):
armobj = bpy.context.active_object
#Bone Length Properties Update
for b in armobj.pose.bones:
if b.keys() != '[]':
if 'b_length_L' in b.keys():
b['b_length_L'] = b.bone.length
if 'b_length_R' in b.keys():
b['b_length_R'] = b.bone.length
if 'b_length' in b.keys():
b['b_length'] = b.bone.length
#Floor constraints distance calculation
for b in armobj.pose.bones:
for C in b.constraints:
if C.type == 'FLOOR':
if 'Floor_Lips' in C.name:
C.offset = abs((b.head[2] - armobj.pose.bones[C.subtarget].head[2]) * 0.9)
if 'Floor_Foot' in C.name:
C.offset = abs(b.head[2] - armobj.pose.bones[b.custom_shape_transform.name].head[2])
#Blink rate calculation
for b in armobj.pose.bones:
if b.name == 'blink_ctrl_L':
try:
b['Blink_Rate_L'] = abs(armobj.pose.bones['eyelid_up_ctrl_L'].head[2] - armobj.pose.bones['eyelid_low_ctrl_L'].head[2])
except:
pass
if b.name == 'blink_ctrl_R':
try:
b['Blink_Rate_R'] = abs(armobj.pose.bones['eyelid_up_ctrl_R'].head[2] - armobj.pose.bones['eyelid_low_ctrl_R'].head[2])
except:
pass
def calc_poles(self, context):
bpy.ops.blenrig.calculate_pole_angles()
def execute(self, context):
self.bake_armature(context)
self.armature_update_values(context)
self.calc_poles(context)
self.report({'INFO'}, "Baking done")
return{'FINISHED'}
# Reset Constraints Operator
class ARMATURE_OT_reset_constraints(bpy.types.Operator):
bl_label = "BlenRig 6 Reset Constraints"
bl_idname = "blenrig.reset_constraints"
bl_description = "Reset all posebone constraints"
@classmethod
def poll(cls, context):
if not bpy.context.object:
return False
else:
return (bpy.context.object.type=='ARMATURE' and \
context.mode=='POSE')
def execute(self, context):
context.object.data.pose_position = 'REST'
pbones = context.active_object.pose.bones
edit_bones = context.active_object.data.edit_bones
if len(pbones) < 1:
self.report({'INFO'}, "No bones found")
return{'FINISHED'}
amount = 0
arm = bpy.context.object.data
for pbone in pbones:
for con in pbone.constraints:
if con.type == 'LIMIT_DISTANCE':
amount += 1
con.distance = 0
elif con.type == 'STRETCH_TO':
amount += 1
con.rest_length = 0
#elif con.type == 'CHILD_OF':
#bpy.ops.object.mode_set(mode='EDIT')
#arm.edit_bones.active = arm.edit_bones[pbone.name]
#bpy.ops.object.mode_set(mode='POSE')
#print ('"{}"'.format(con.name))
#bpy.ops.constraint.childof_clear_inverse(constraint=con.name, owner='BONE')
#bpy.ops.constraint.childof_set_inverse(constraint=con.name, owner='BONE')
## somehow it only works if you run it twice
#bpy.ops.constraint.childof_set_inverse(constraint=con.name, owner='BONE')
#bpy.ops.object.mode_set(mode='EDIT')
#arm.edit_bones[b.name].select = False
#bpy.ops.object.mode_set(mode='POSE')
context.object.data.pose_position = 'POSE'
self.report({'INFO'}, str(amount) + " constraints reset")
return{'FINISHED'}