[Bf-extensions-cvs] [d860b3c7] master: Rigify: convert the palm rig and support controls for both sides.
Alexander Gavrilov
noreply at git.blender.org
Sun Sep 15 19:00:58 CEST 2019
Commit: d860b3c7e2fef6d9517cd1a8ca667a838eb869d0
Author: Alexander Gavrilov
Date: Sun Sep 15 20:00:05 2019 +0300
Branches: master
https://developer.blender.org/rBAd860b3c7e2fef6d9517cd1a8ca667a838eb869d0
Rigify: convert the palm rig and support controls for both sides.
===================================================================
M rigify/metarigs/Animals/cat.py
M rigify/rigs/limbs/super_palm.py
===================================================================
diff --git a/rigify/metarigs/Animals/cat.py b/rigify/metarigs/Animals/cat.py
index d3de1192..a065c432 100644
--- a/rigify/metarigs/Animals/cat.py
+++ b/rigify/metarigs/Animals/cat.py
@@ -1748,6 +1748,10 @@ def create(obj):
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [False, False, False, False, False, True, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False]
+ try:
+ pbone.rigify_parameters.palm_both_sides = True
+ except AttributeError:
+ pass
pbone = obj.pose.bones[bones['r_palm.002.L']]
pbone.rigify_type = ''
pbone.lock_location = (False, False, False)
@@ -1765,7 +1769,6 @@ def create(obj):
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [False, False, False, False, False, True, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False]
pbone = obj.pose.bones[bones['r_palm.004.L']]
- pbone.rigify_type = 'limbs.super_palm'
pbone.lock_location = (False, False, False)
pbone.lock_rotation = (False, False, False)
pbone.lock_rotation_w = False
@@ -1780,6 +1783,10 @@ def create(obj):
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [False, False, False, False, False, True, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False]
+ try:
+ pbone.rigify_parameters.palm_both_sides = True
+ except AttributeError:
+ pass
pbone = obj.pose.bones[bones['r_palm.002.R']]
pbone.rigify_type = ''
pbone.lock_location = (False, False, False)
@@ -1797,7 +1804,6 @@ def create(obj):
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [False, False, False, False, False, True, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False]
pbone = obj.pose.bones[bones['r_palm.004.R']]
- pbone.rigify_type = 'limbs.super_palm'
pbone.lock_location = (False, False, False)
pbone.lock_rotation = (False, False, False)
pbone.lock_rotation_w = False
@@ -2313,7 +2319,6 @@ def create(obj):
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [True, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False]
pbone = obj.pose.bones[bones['f_palm.004.L']]
- pbone.rigify_type = 'limbs.super_palm'
pbone.lock_location = (False, False, False)
pbone.lock_rotation = (False, False, False)
pbone.lock_rotation_w = False
@@ -2328,6 +2333,10 @@ def create(obj):
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [False, False, False, False, False, True, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False]
+ try:
+ pbone.rigify_parameters.palm_both_sides = True
+ except AttributeError:
+ pass
pbone = obj.pose.bones[bones['f_palm.002.L']]
pbone.rigify_type = ''
pbone.lock_location = (False, False, False)
@@ -2345,7 +2354,6 @@ def create(obj):
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [False, False, False, False, False, True, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False]
pbone = obj.pose.bones[bones['f_palm.004.R']]
- pbone.rigify_type = 'limbs.super_palm'
pbone.lock_location = (False, False, False)
pbone.lock_rotation = (False, False, False)
pbone.lock_rotation_w = False
@@ -2360,6 +2368,10 @@ def create(obj):
pbone.lock_scale = (False, False, False)
pbone.rotation_mode = 'QUATERNION'
pbone.bone.layers = [False, False, False, False, False, True, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False]
+ try:
+ pbone.rigify_parameters.palm_both_sides = True
+ except AttributeError:
+ pass
pbone = obj.pose.bones[bones['f_palm.002.R']]
pbone.rigify_type = ''
pbone.lock_location = (False, False, False)
diff --git a/rigify/rigs/limbs/super_palm.py b/rigify/rigs/limbs/super_palm.py
index 8cde6648..a7b322aa 100644
--- a/rigify/rigs/limbs/super_palm.py
+++ b/rigify/rigs/limbs/super_palm.py
@@ -18,21 +18,22 @@
# <pep8 compliant>
+import bpy
import re
+
from math import cos, pi
+from itertools import count, repeat
-import bpy
+from rigify.utils.naming import strip_org, make_derived_name
+from rigify.utils.widgets import create_widget
+from rigify.utils.misc import map_list
-from ...utils import MetarigError
-from ...utils import copy_bone
-from ...utils import strip_org, deformer
-from ...utils import create_widget
+from rigify.base_rig import BaseRig, stage
def bone_siblings(obj, bone):
""" Returns a list of the siblings of the given bone.
This requires that the bones has a parent.
-
"""
parent = obj.data.bones[bone].parent
@@ -48,133 +49,92 @@ def bone_siblings(obj, bone):
return bones
-def bone_distance(obj, bone1, bone2):
- """ Returns the distance between two bones.
-
- """
- vec = obj.data.bones[bone1].head - obj.data.bones[bone2].head
- return vec.length
-
-
-class Rig:
+class Rig(BaseRig):
""" A "palm" rig. A set of sibling bones that bend with each other.
This is a control and deformation rig.
-
"""
- def __init__(self, obj, bone, params):
- """ Gather and validate data about the rig.
- """
- self.obj = obj
- self.params = params
- siblings = bone_siblings(obj, bone)
-
- if len(siblings) == 0:
- raise MetarigError(
- "RIGIFY ERROR: Bone '%s': must have a parent and at least one sibling" %
- (strip_org(bone)))
+ def find_org_bones(self, bone):
+ base_head = bone.bone.head
+ siblings = bone_siblings(self.obj, bone.name)
# Sort list by name and distance
siblings.sort()
- siblings.sort(key=lambda b: bone_distance(obj, bone, b))
+ siblings.sort(key=lambda b: (self.get_bone(b).bone.head - base_head).length)
- self.org_bones = [bone] + siblings
+ return [bone.name] + siblings
- # Get rig parameters
- self.palm_rotation_axis = params.palm_rotation_axis
+ def initialize(self):
+ if len(self.bones.org) <= 1:
+ self.raise_error('The palm rig must have a parent and at least one sibling')
- def generate(self):
- """ Generate the rig.
- Do NOT modify any of the original bones, except for adding constraints.
- The main armature should be selected and active before this is called.
+ self.palm_rotation_axis = self.params.palm_rotation_axis
+ self.make_secondary = self.params.palm_both_sides
- """
- bpy.ops.object.mode_set(mode='EDIT')
+ self.order = 'YXZ' if 'X' in self.palm_rotation_axis else 'YZX'
# Figure out the name for the control bone (remove the last .##)
- last_bone = self.org_bones[-1:][0]
- ctrl_name = re.sub("([0-9]+\.)", "", strip_org(last_bone)[::-1], count=1)[::-1]
-
- # Make control bone
- ctrl = copy_bone(self.obj, last_bone, ctrl_name)
-
- # Make deformation bones
- def_bones = []
- for bone in self.org_bones:
- b = copy_bone(self.obj, bone, deformer(strip_org(bone)))
- def_bones += [b]
-
- # Parenting
- eb = self.obj.data.edit_bones
-
- # turn off inherit scale for all ORG-bones to prevent undesired transformations
-
- for o in self.org_bones:
- eb[o].inherit_scale = 'NONE'
-
- for d, b in zip(def_bones, self.org_bones):
- eb[d].use_connect = False
- eb[d].parent = eb[b]
-
- # Get ORG parent bone
- org_parent = eb[self.org_bones[0]].parent.name
-
- # Get DEF parent from ORG parent
- def_parent = deformer(strip_org(org_parent))
-
- # Switch parent
- if def_parent in eb.keys():
- parent_to = def_parent
- else:
- parent_to = org_parent
- for o in self.org_bones:
- eb[o].parent = eb[parent_to]
- eb[ctrl].parent = eb[parent_to]
-
- # Constraints
- bpy.ops.object.mode_set(mode='OBJECT')
- pb = self.obj.pose.bones
-
- i = 0
- div = len(self.org_bones) - 1
- for b in self.org_bones:
- con = pb[b].constraints.new('COPY_TRANSFORMS')
- con.name = "copy_transforms"
- con.target = self.obj
- con.subtarget = ctrl
- con.target_space = 'LOCAL'
- con.owner_space = 'LOCAL'
- con.influence = i / div
-
- con = pb[b].constraints.new('COPY_SCALE')
- con.name = "copy_scale"
- con.target = self.obj
- con.subtarget = parent_to
- con.target_space = 'WORLD'
- con.owner_space = 'WORLD'
- con.influence = 1
-
- con = pb[b].constraints.new('COPY_ROTATION')
- con.name = "copy_rotation"
- con.target = self.obj
- con.subtarget = ctrl
- con.target_space = 'LOCAL'
- con.owner_space = 'LOCAL'
- if 'X' in self.palm_rotation_axis:
- con.invert_x = True
- con.use_x = True
- con.use_z = False
- else:
-
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list