diff options
author | Alexander Gavrilov <angavrilov@gmail.com> | 2019-10-21 18:01:03 +0300 |
---|---|---|
committer | Alexander Gavrilov <angavrilov@gmail.com> | 2019-11-02 11:57:47 +0300 |
commit | db3e15be7a0f7b403bedb5b762d79e1970a4fc59 (patch) | |
tree | 8e0d908db327825c0f22c7777d6da600ae8b42bc /rigify/rigs/limbs/arm.py | |
parent | b9a821bf6045f36c20c6a52f87a2f79e4bfde257 (diff) |
Rigify: implement an optional IK palm pivot control in the arm rig.
The control itself is simply a pivot around the end of the hand
bone, similar to those in the foot and paw. However, the main
point of it is that it allows future finger IK to use the IK
control as the parent, while still allowing the wrist to be moved
relative to it.
Diffstat (limited to 'rigify/rigs/limbs/arm.py')
-rw-r--r-- | rigify/rigs/limbs/arm.py | 67 |
1 files changed, 66 insertions, 1 deletions
diff --git a/rigify/rigs/limbs/arm.py b/rigify/rigs/limbs/arm.py index 1ac979d0..0eced859 100644 --- a/rigify/rigs/limbs/arm.py +++ b/rigify/rigs/limbs/arm.py @@ -21,12 +21,15 @@ import bpy from itertools import count +from mathutils import Matrix -from ...utils.bones import BoneDict, compute_chain_x_axis, align_bone_x_axis, align_bone_z_axis +from ...utils.bones import put_bone, compute_chain_x_axis, align_bone_x_axis, align_bone_z_axis from ...utils.naming import make_derived_name from ...utils.misc import map_list +from ...utils.widgets import adjust_widget_transform_mesh from ..widgets import create_hand_widget +from ...utils.widgets_basic import create_circle_widget from ...base_rig import stage @@ -42,6 +45,8 @@ class Rig(BaseLimbRig): super().initialize() + self.make_palm_pivot = self.params.make_ik_palm_pivot + def prepare_bones(self): orgs = self.bones.org.main @@ -68,10 +73,70 @@ class Rig(BaseLimbRig): create_hand_widget(self.obj, ctrl) #################################################### + # Palm Pivot + + def get_ik_input_bone(self): + if self.make_palm_pivot: + return self.bones.mch.ik_palm + else: + return self.get_ik_control_output() + + def get_extra_ik_controls(self): + controls = super().get_extra_ik_controls() + if self.make_palm_pivot: + controls += [self.bones.ctrl.ik_palm] + return controls + + @stage.generate_bones + def make_palm_pivot_control(self): + if self.make_palm_pivot: + org = self.bones.org.main[2] + self.bones.ctrl.ik_palm = self.make_palm_pivot_bone(org) + self.bones.mch.ik_palm = self.copy_bone(org, make_derived_name(org, 'mch'), scale=0.25) + + def make_palm_pivot_bone(self, org): + name = self.copy_bone(org, make_derived_name(org, 'ctrl', '_ik_palm'), scale=0.5) + put_bone(self.obj, name, self.get_bone(org).tail) + return name + + @stage.parent_bones + def parent_palm_pivot_control(self): + if self.make_palm_pivot: + ctrl = self.bones.ctrl.ik_palm + self.set_bone_parent(ctrl, self.get_ik_control_output()) + self.set_bone_parent(self.bones.mch.ik_palm, ctrl) + + @stage.generate_widgets + def make_palm_pivot_widget(self): + if self.make_palm_pivot: + ctrl = self.bones.ctrl.ik_palm + + if self.main_axis == 'x': + obj = create_circle_widget(self.obj, ctrl, head_tail=-0.3, head_tail_x=0.5) + else: + obj = create_circle_widget(self.obj, ctrl, head_tail=0.5, head_tail_x=-0.3) + + if obj: + org_bone = self.get_bone(self.bones.org.main[2]) + offset = org_bone.head - self.get_bone(ctrl).head + adjust_widget_transform_mesh(obj, Matrix.Translation(offset)) + + #################################################### # Settings @classmethod + def add_parameters(self, params): + super().add_parameters(params) + + params.make_ik_palm_pivot = bpy.props.BoolProperty( + name="IK Palm Pivot", default=False, + description="Make an extra IK hand control pivoting around the tip of the hand" + ) + + @classmethod def parameters_ui(self, layout, params): + layout.prop(params, "make_ik_palm_pivot") + super().parameters_ui(layout, params, 'Hand') |