Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/rigify
diff options
context:
space:
mode:
authorAlexander Gavrilov <angavrilov@gmail.com>2019-10-23 13:18:38 +0300
committerAlexander Gavrilov <angavrilov@gmail.com>2019-10-23 13:18:38 +0300
commit69ada355ca003733ac0e69ec1e884f3e2199e97f (patch)
tree8f5b89ab1ed3fbe98d72b9f93024fa5b1dd05895 /rigify
parent4625dfb9e74a317c072389357cda89d2a0605d7e (diff)
Rigify: support tags in SwitchParentBuilder for default selection.
Allow tagging parents with arbitrary strings to be later used in selecting the best default parent for a child control. Also add a tagged parent point at the limb IK control.
Diffstat (limited to 'rigify')
-rw-r--r--rigify/rigs/limbs/arm.py2
-rw-r--r--rigify/rigs/limbs/leg.py2
-rw-r--r--rigify/rigs/limbs/limb_rigs.py5
-rw-r--r--rigify/rigs/limbs/paw.py2
-rw-r--r--rigify/rigs/spines/spine_rigs.py6
-rw-r--r--rigify/rigs/spines/super_head.py2
-rw-r--r--rigify/utils/switch_parent.py19
7 files changed, 28 insertions, 10 deletions
diff --git a/rigify/rigs/limbs/arm.py b/rigify/rigs/limbs/arm.py
index 98a3c50f..1ac979d0 100644
--- a/rigify/rigs/limbs/arm.py
+++ b/rigify/rigs/limbs/arm.py
@@ -62,7 +62,7 @@ class Rig(BaseLimbRig):
def register_switch_parents(self, pbuilder):
super().register_switch_parents(pbuilder)
- pbuilder.register_parent(self, self.bones.org.main[2], exclude_self=True)
+ pbuilder.register_parent(self, self.bones.org.main[2], exclude_self=True, tags={'limb_end'})
def make_ik_ctrl_widget(self, ctrl):
create_hand_widget(self.obj, ctrl)
diff --git a/rigify/rigs/limbs/leg.py b/rigify/rigs/limbs/leg.py
index 35e68f58..99610a6a 100644
--- a/rigify/rigs/limbs/leg.py
+++ b/rigify/rigs/limbs/leg.py
@@ -145,7 +145,7 @@ class Rig(BaseLimbRig):
def register_switch_parents(self, pbuilder):
super().register_switch_parents(pbuilder)
- pbuilder.register_parent(self, self.bones.org.main[2], exclude_self=True)
+ pbuilder.register_parent(self, self.bones.org.main[2], exclude_self=True, tags={'limb_end'})
def make_ik_ctrl_widget(self, ctrl):
obj = create_foot_widget(self.obj, ctrl)
diff --git a/rigify/rigs/limbs/limb_rigs.py b/rigify/rigs/limbs/limb_rigs.py
index 86fc6be4..dee9a6f4 100644
--- a/rigify/rigs/limbs/limb_rigs.py
+++ b/rigify/rigs/limbs/limb_rigs.py
@@ -375,6 +375,11 @@ class BaseLimbRig(BaseRig):
if self.rig_parent_bone:
pbuilder.register_parent(self, self.rig_parent_bone)
+ pbuilder.register_parent(
+ self, self.get_ik_control_output(), name=self.bones.ctrl.ik,
+ exclude_self=True, tags={'limb_ik'},
+ )
+
def build_ik_parent_switch(self, pbuilder):
ctrl = self.bones.ctrl
diff --git a/rigify/rigs/limbs/paw.py b/rigify/rigs/limbs/paw.py
index a13348d1..28374eec 100644
--- a/rigify/rigs/limbs/paw.py
+++ b/rigify/rigs/limbs/paw.py
@@ -107,7 +107,7 @@ class Rig(BaseLimbRig):
def register_switch_parents(self, pbuilder):
super().register_switch_parents(pbuilder)
- pbuilder.register_parent(self, self.bones.org.main[3], exclude_self=True)
+ pbuilder.register_parent(self, self.bones.org.main[3], exclude_self=True, tags={'limb_end'})
def make_ik_ctrl_widget(self, ctrl):
create_foot_widget(self.obj, ctrl)
diff --git a/rigify/rigs/spines/spine_rigs.py b/rigify/rigs/spines/spine_rigs.py
index 9f62595a..25450717 100644
--- a/rigify/rigs/spines/spine_rigs.py
+++ b/rigify/rigs/spines/spine_rigs.py
@@ -99,7 +99,7 @@ class BaseSpineRig(TweakChainRig):
org_parent = self.get_bone_parent(self.bones.org[0])
parents = [org_parent] if org_parent else []
- pbuilder.register_parent(self, self.get_master_control_output, name='Torso')
+ pbuilder.register_parent(self, self.get_master_control_output, name='Torso', tags={'torso'})
pbuilder.build_child(
self, master_name, exclude_self=True,
extra_parents=parents, select_parent=org_parent,
@@ -110,8 +110,8 @@ class BaseSpineRig(TweakChainRig):
self.register_parent_bones(pbuilder)
def register_parent_bones(self, pbuilder):
- pbuilder.register_parent(self, self.bones.org[0], name='Hips', exclude_self=True)
- pbuilder.register_parent(self, self.bones.org[-1], name='Chest', exclude_self=True)
+ pbuilder.register_parent(self, self.bones.org[0], name='Hips', exclude_self=True, tags={'hips'})
+ pbuilder.register_parent(self, self.bones.org[-1], name='Chest', exclude_self=True, tags={'chest'})
@stage.parent_bones
def parent_master_control(self):
diff --git a/rigify/rigs/spines/super_head.py b/rigify/rigs/spines/super_head.py
index 9b85e5b5..65db79cc 100644
--- a/rigify/rigs/spines/super_head.py
+++ b/rigify/rigs/spines/super_head.py
@@ -322,7 +322,7 @@ class Rig(BaseHeadTailRig):
def register_parent_bones(self):
rig = self.rigify_parent or self
builder = SwitchParentBuilder(self.generator)
- builder.register_parent(rig, self.bones.org[-1], name='Head', exclude_self=True)
+ builder.register_parent(rig, self.bones.org[-1], name='Head', exclude_self=True, tags={'head'})
@stage.configure_bones
def configure_bbone_chain(self):
diff --git a/rigify/utils/switch_parent.py b/rigify/utils/switch_parent.py
index a0a6b0ea..bb2d9045 100644
--- a/rigify/utils/switch_parent.py
+++ b/rigify/utils/switch_parent.py
@@ -51,7 +51,7 @@ class SwitchParentBuilder(GeneratorPlugin, MechanismUtilityMixin):
##############################
# API
- def register_parent(self, rig, bone, *, name=None, is_global=False, exclude_self=False):
+ def register_parent(self, rig, bone, *, name=None, is_global=False, exclude_self=False, tags=None):
"""
Registers a bone of the specified rig as a possible parent.
@@ -61,6 +61,7 @@ class SwitchParentBuilder(GeneratorPlugin, MechanismUtilityMixin):
name Name of the parent for mouse-over hint.
is_global The parent is accessible to all rigs, instead of just children of owner.
exclude_self The parent is invisible to the owner rig itself.
+ tags Set of tags to use for default parent selection.
Lazy creation:
The bone parameter may be a function creating the bone on demand and
@@ -71,7 +72,7 @@ class SwitchParentBuilder(GeneratorPlugin, MechanismUtilityMixin):
assert isinstance(bone, str) or callable(bone)
entry = {
- 'rig': rig, 'bone': bone, 'name': name,
+ 'rig': rig, 'bone': bone, 'name': name, 'tags': tags,
'is_global': is_global, 'exclude_self': exclude_self, 'used': False,
}
@@ -91,6 +92,7 @@ class SwitchParentBuilder(GeneratorPlugin, MechanismUtilityMixin):
extra_parents List of bone names or (name, user_name) pairs to use as additional parents.
use_parent_mch Create an intermediate MCH bone for the constraints and parent the child to it.
select_parent Select the specified bone instead of the last one.
+ select_tags List of parent tags to try for default selection.
ignore_global Ignore the is_global flag of potential parents.
exclude_self Ignore parents registered by the rig itself.
context_rig Rig to use for selecting parents.
@@ -155,7 +157,8 @@ class SwitchParentBuilder(GeneratorPlugin, MechanismUtilityMixin):
child_option_table = {
'extra_parents': None,
'prop_bone': None, 'prop_id': None, 'prop_name': None, 'controls': None,
- 'select_parent': None, 'ignore_global': False, 'exclude_self': False, 'context_rig': None,
+ 'select_parent': None, 'ignore_global': False, 'exclude_self': False,
+ 'context_rig': None, 'select_tags': None,
'ctrl_bone': None,
'no_fix_location': False, 'no_fix_rotation': False, 'no_fix_scale': False,
'copy_location': None, 'copy_rotation': None, 'copy_scale': None,
@@ -243,10 +246,13 @@ class SwitchParentBuilder(GeneratorPlugin, MechanismUtilityMixin):
# Build the final list of parent bone names
parent_map = dict()
+ parent_tags = defaultdict(set)
for parent in child['parents']:
if parent['bone'] not in parent_map:
parent_map[parent['bone']] = parent['name']
+ if parent['tags']:
+ parent_tags[parent['bone']] |= parent['tags']
last_main_parent_bone = child['parents'][-1]['bone']
num_main_parents = len(parent_map.items())
@@ -262,6 +268,7 @@ class SwitchParentBuilder(GeneratorPlugin, MechanismUtilityMixin):
# Find which bone to select
select_bone = force_lazy(child['select_parent']) or last_main_parent_bone
+ select_tags = force_lazy(child['select_tags']) or []
select_index = num_main_parents
try:
@@ -269,6 +276,12 @@ class SwitchParentBuilder(GeneratorPlugin, MechanismUtilityMixin):
except StopIteration:
print("RIGIFY ERROR: Can't find bone '%s' to select as default parent of '%s'\n" % (select_bone, bone))
+ for tag in select_tags:
+ matching = [ i for i, (bone, _) in enumerate(parent_bones) if tag in parent_tags[bone] ]
+ if len(matching) > 0:
+ select_index = 1 + matching[-1]
+ break
+
# Create the controlling property
prop_bone = child['prop_bone'] = force_lazy(child['prop_bone']) or bone
prop_name = child['prop_name'] or child['prop_id'] or 'Parent Switch'