Skip to content

Commit

Permalink
Rigify: make uniform limb scaling optional and hide the constraint.
Browse files Browse the repository at this point in the history
Since this feauture is likely only useful for some cartoon-style
characters, make it optional.

Also, move the copy scale constraint from the IK control to a new
child bone; additional complexity is mitigated by being optional.
  • Loading branch information
angavrilov committed Jul 10, 2022
1 parent 6fb43c4 commit 7ea2e74
Showing 1 changed file with 38 additions and 12 deletions.
50 changes: 38 additions & 12 deletions rigify/rigs/limbs/limb_rigs.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def initialize(self):
self.segments = self.params.segments
self.bbone_segments = self.params.bbones
self.use_ik_pivot = self.params.make_custom_pivot
self.use_uniform_scale = self.params.limb_uniform_scale

rot_axis = self.params.rotation_axis

Expand Down Expand Up @@ -144,6 +145,8 @@ def vector_without_z(vector):
# FK chain parents (or None)
# ik_pivot
# Custom IK pivot result (optional).
# ik_scale
# Helper bone that implements uniform scaling.
# ik_swing
# Bone that tracks ik_target to manually handle limb swing.
# ik_target
Expand Down Expand Up @@ -178,14 +181,15 @@ def configure_master_control(self):
bone = self.get_bone(self.bones.ctrl.master)
bone.lock_location = (True, True, True)
bone.lock_rotation = (True, True, True)
bone.lock_scale = (False, False, False)
bone.lock_scale = (not self.use_uniform_scale,) * 3
bone.lock_rotation_w = True

@stage.rig_bones
def rig_master_control(self):
mch = self.bones.mch
self.make_constraint(mch.master, 'COPY_SCALE', 'root', use_make_uniform=True)
self.make_constraint(mch.master, 'COPY_SCALE', self.bones.ctrl.master, use_offset=True, space='LOCAL')
if self.use_uniform_scale:
self.make_constraint(mch.master, 'COPY_SCALE', self.bones.ctrl.master, use_offset=True, space='LOCAL')

@stage.generate_widgets
def make_master_control_widget(self):
Expand Down Expand Up @@ -221,10 +225,12 @@ def rig_mch_follow_bone(self):
mch = self.bones.mch.follow

self.make_constraint(mch, 'COPY_SCALE', 'root', use_make_uniform=True)
self.make_constraint(
mch, 'COPY_SCALE', self.bones.ctrl.master,
use_make_uniform=True, use_offset=True, space='LOCAL'
)

if self.use_uniform_scale:
self.make_constraint(
mch, 'COPY_SCALE', self.bones.ctrl.master,
use_make_uniform=True, use_offset=True, space='LOCAL'
)

con = self.make_constraint(mch, 'COPY_ROTATION', 'root')

Expand Down Expand Up @@ -361,9 +367,12 @@ def make_ik_controls(self):

self.bones.ctrl.ik_base = self.make_ik_base_bone(orgs)
self.bones.ctrl.ik_pole = self.make_ik_pole_bone(orgs)
self.bones.ctrl.ik = ik_name = self.make_ik_control_bone(orgs)
self.bones.ctrl.ik = ik_name = parent = self.make_ik_control_bone(orgs)

if self.use_uniform_scale:
self.bones.mch.ik_scale = parent = self.make_ik_scale_bone(ik_name, orgs)

self.component_ik_pivot = self.build_ik_pivot(ik_name)
self.component_ik_pivot = self.build_ik_pivot(ik_name, parent=parent)
self.build_ik_parent_switch(SwitchParentBuilder(self.generator))

def make_ik_base_bone(self, orgs):
Expand All @@ -382,13 +391,18 @@ def make_ik_pole_bone(self, orgs):
def make_ik_control_bone(self, orgs):
return self.copy_bone(orgs[2], make_derived_name(orgs[2], 'ctrl', '_ik'))

def make_ik_scale_bone(self, ctrl, orgs):
return self.copy_bone(ctrl, make_derived_name(orgs[2], 'mch', '_ik_scale'), scale=1/2)

def build_ik_pivot(self, ik_name, **args):
if self.use_ik_pivot:
return CustomPivotControl(self, 'ik_pivot', ik_name, parent=ik_name, **args)
return CustomPivotControl(self, 'ik_pivot', ik_name, **args)

def get_ik_control_output(self):
if self.component_ik_pivot:
return self.component_ik_pivot.output
elif self.use_uniform_scale:
return self.bones.mch.ik_scale
else:
return self.bones.ctrl.ik

Expand Down Expand Up @@ -430,6 +444,9 @@ def parent_ik_controls(self):
else:
self.set_bone_parent(self.bones.ctrl.ik_base, self.bones.mch.ik_swing)

if self.use_uniform_scale:
self.set_bone_parent(self.bones.mch.ik_scale, self.bones.ctrl.ik)

self.set_ik_local_location(self.bones.ctrl.ik)
self.set_ik_local_location(self.bones.ctrl.ik_pole)

Expand All @@ -445,11 +462,13 @@ def configure_ik_controls(self):
@stage.rig_bones
def rig_ik_controls(self):
self.rig_hide_pole_control(self.bones.ctrl.ik_pole)
self.rig_ik_control_scale(self.bones.ctrl.ik)

def rig_ik_control_scale(self, ctrl):
if self.use_uniform_scale:
self.rig_ik_control_scale(self.bones.mch.ik_scale)

def rig_ik_control_scale(self, mch):
self.make_constraint(
ctrl, 'COPY_SCALE', self.bones.ctrl.master,
mch, 'COPY_SCALE', self.bones.ctrl.master,
use_make_uniform=True, use_offset=True, space='LOCAL',
)

Expand Down Expand Up @@ -937,6 +956,12 @@ def add_parameters(self, params):
description = "Specifies the value of the Local Location option for IK controls, which decides if the location channels are aligned to the local control orientation or world",
)

params.limb_uniform_scale = bpy.props.BoolProperty(
name = "Support Uniform Scaling",
default = False,
description = "Suport uniformly scaling the limb via the gear control at the base"
)

# Setting up extra layers for the FK and tweak
ControlLayersOption.FK.add_parameters(params)
ControlLayersOption.TWEAK.add_parameters(params)
Expand All @@ -958,6 +983,7 @@ def parameters_ui(self, layout, params, end='End'):
r = layout.row()
r.prop(params, "bbones")

layout.prop(params, 'limb_uniform_scale')
layout.prop(params, 'make_custom_pivot', text="Custom IK Pivot")
layout.prop(params, 'ik_local_location')

Expand Down

0 comments on commit 7ea2e74

Please sign in to comment.