Skip to content

Commit 5575a74

Browse files
angavriloveigen-value
authored andcommitted
Replace the IK_follow hack for not parenting bones to the root bone.
Instead of looking for a magic driver variable name, allow returning an explicit list from the rig using the new dictionary return format.
1 parent 6489112 commit 5575a74

File tree

5 files changed

+15
-21
lines changed

5 files changed

+15
-21
lines changed

README

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ There is one final stage to rig generation. Rigify checks all of the bones
6565
for "DEF-", "MCH-", and "ORG-" prefixes, and moves those bones to their own
6666
layers. It also sets all of the "DEF-" bones to deform, and sets all other
6767
bones to _not_ deform. And finally, it looks for any bone that does not have
68-
a parent, and sets the root bone (which Rigify creates) as their parent.
68+
a parent, and sets the root bone (which Rigify creates) as their parent,
69+
with the exception of 'noparent_bones' described below.
6970

7071

7172
THE GUTS OF A RIG TYPE, BASIC
@@ -241,7 +242,7 @@ Implementation classes are shown in the metarig samples list and generate a samp
241242
GENERATING A PYTHON UI
242243
----------------------
243244
The generate() method can also, optionally, return a dictionary with data
244-
used for generating the python UI. The dictionary may have the following
245+
mainly used for generating the python UI. The dictionary may have the following
245246
keys (all optional):
246247

247248
'script': python code as list of strings.
@@ -264,6 +265,10 @@ keys (all optional):
264265

265266
These are used in generating the register() and unregister() functions.
266267

268+
'noparent_bones': list of bone names.
269+
270+
These bones are not implicitly parented to the root bone if they have no parent.
271+
267272
The 'utilities', 'imports' and 'register' lists returned by all rigs are concatenated
268273
and filtered for duplicates before use, in order to allow easy sharing of utility
269274
functions and classes: all that is needed is to ensure that shared code is included

generate.py

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ def generate_rig(context, metarig):
345345
ui_imports = UI_IMPORTS.copy()
346346
ui_utilities = UI_UTILITIES.copy()
347347
ui_register = UI_REGISTER.copy()
348+
noparent_bones = []
348349
for rig in rigs:
349350
# Go into editmode in the rig armature
350351
bpy.ops.object.mode_set(mode='OBJECT')
@@ -361,6 +362,8 @@ def generate_rig(context, metarig):
361362
ui_utilities += scripts['utilities']
362363
if 'register' in scripts:
363364
ui_register += scripts['register']
365+
if 'noparent_bones' in scripts:
366+
noparent_bones += scripts['noparent_bones']
364367
elif scripts is not None:
365368
ui_scripts += [scripts[0]]
366369
t.tick("Generate rigs: ")
@@ -381,25 +384,8 @@ def generate_rig(context, metarig):
381384
# Get a list of all the bones in the armature
382385
bones = [bone.name for bone in obj.data.bones]
383386

384-
# Parent any free-floating bones to the root excluding bones with child of constraint.
385-
pbones = obj.pose.bones
386-
387-
388-
ik_follow_drivers = []
389-
390-
if obj.animation_data:
391-
for drv in obj.animation_data.drivers:
392-
for var in drv.driver.variables:
393-
if 'IK_follow' == var.name:
394-
ik_follow_drivers.append(drv.data_path)
395-
396-
noparent_bones = []
397-
for bone in bones:
398-
# if 'IK_follow' in pbones[bone].keys():
399-
# noparent_bones += [bone]
400-
for d in ik_follow_drivers:
401-
if bone in d:
402-
noparent_bones += [bone]
387+
# Parent any free-floating bones to the root excluding noparent_bones
388+
noparent_bones = dict.fromkeys(noparent_bones)
403389

404390
bpy.ops.object.mode_set(mode='EDIT')
405391
for bone in bones:

rigs/limbs/arm.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,6 +1072,7 @@ def generate(self):
10721072
'script': [script],
10731073
'utilities': UTILITIES_RIG_ARM,
10741074
'register': REGISTER_RIG_ARM,
1075+
'noparent_bones': [bones['ik']['mch_hand'][i] for i in [0,1]],
10751076
}
10761077

10771078

rigs/limbs/leg.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1395,6 +1395,7 @@ def generate(self):
13951395
'script': [script],
13961396
'utilities': UTILITIES_RIG_LEG,
13971397
'register': REGISTER_RIG_LEG,
1398+
'noparent_bones': [bones['ik']['mch_foot'][i] for i in [0,1]],
13981399
}
13991400

14001401

rigs/limbs/paw.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,6 +1223,7 @@ def generate(self):
12231223
'script': [script],
12241224
'utilities': UTILITIES_RIG_LEG,
12251225
'register': REGISTER_RIG_LEG,
1226+
'noparent_bones': [bones['ik']['mch_foot'][i] for i in [0,1]],
12261227
}
12271228

12281229

0 commit comments

Comments
 (0)