Skip to content

Commit d7e8520

Browse files
committed
fix rot2pole switch missing when rigify is disabled
1 parent 12312ba commit d7e8520

File tree

2 files changed

+110
-8
lines changed

2 files changed

+110
-8
lines changed

rig_ui_template.py

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,75 @@ def ik2fk_leg(obj, fk, ik):
520520
match_pole_target(thighi, shini, pole, thigh, (thighi.length + shini.length))
521521
522522
523+
################################
524+
## IK Rotation-Pole functions ##
525+
################################
526+
527+
def parse_bone_names(names_string):
528+
if names_string[0] == '[' and names_string[-1] == ']':
529+
return eval(names_string)
530+
else:
531+
return names_string
532+
533+
def rotPoleToggle(rig, limb_type, controls, ik_ctrl, fk_ctrl, parent, pole):
534+
535+
rig_id = rig.data['rig_id']
536+
leg_fk2ik = eval('bpy.ops.pose.rigify_leg_fk2ik_' + rig_id)
537+
arm_fk2ik = eval('bpy.ops.pose.rigify_arm_fk2ik_' + rig_id)
538+
leg_ik2fk = eval('bpy.ops.pose.rigify_leg_ik2fk_' + rig_id)
539+
arm_ik2fk = eval('bpy.ops.pose.rigify_arm_ik2fk_' + rig_id)
540+
541+
controls = parse_bone_names(controls)
542+
ik_ctrl = parse_bone_names(ik_ctrl)
543+
fk_ctrl = parse_bone_names(fk_ctrl)
544+
parent = parse_bone_names(parent)
545+
pole = parse_bone_names(pole)
546+
547+
pbones = bpy.context.selected_pose_bones
548+
bpy.ops.pose.select_all(action='DESELECT')
549+
550+
for b in pbones:
551+
552+
new_pole_vector_value = not rig.pose.bones[parent]['pole_vector']
553+
554+
if b.name in controls or b.name in ik_ctrl:
555+
if limb_type == 'arm':
556+
func1 = arm_fk2ik
557+
func2 = arm_ik2fk
558+
rig.pose.bones[controls[0]].bone.select = not new_pole_vector_value
559+
rig.pose.bones[controls[4]].bone.select = not new_pole_vector_value
560+
rig.pose.bones[parent].bone.select = not new_pole_vector_value
561+
rig.pose.bones[pole].bone.select = new_pole_vector_value
562+
563+
kwargs1 = {'uarm_fk': controls[1], 'farm_fk': controls[2], 'hand_fk': controls[3],
564+
'uarm_ik': controls[0], 'farm_ik': ik_ctrl[1],
565+
'hand_ik': controls[4]}
566+
kwargs2 = {'uarm_fk': controls[1], 'farm_fk': controls[2], 'hand_fk': controls[3],
567+
'uarm_ik': controls[0], 'farm_ik': ik_ctrl[1], 'hand_ik': controls[4],
568+
'pole': pole, 'main_parent': parent}
569+
else:
570+
func1 = leg_fk2ik
571+
func2 = leg_ik2fk
572+
rig.pose.bones[controls[0]].bone.select = not new_pole_vector_value
573+
rig.pose.bones[controls[6]].bone.select = not new_pole_vector_value
574+
rig.pose.bones[controls[5]].bone.select = not new_pole_vector_value
575+
rig.pose.bones[parent].bone.select = not new_pole_vector_value
576+
rig.pose.bones[pole].bone.select = new_pole_vector_value
577+
578+
kwargs1 = {'thigh_fk': controls[1], 'shin_fk': controls[2], 'foot_fk': controls[3],
579+
'mfoot_fk': controls[7], 'thigh_ik': controls[0], 'shin_ik': ik_ctrl[1],
580+
'foot_ik': ik_ctrl[2], 'mfoot_ik': ik_ctrl[2]}
581+
kwargs2 = {'thigh_fk': controls[1], 'shin_fk': controls[2], 'foot_fk': controls[3],
582+
'mfoot_fk': controls[7], 'thigh_ik': controls[0], 'shin_ik': ik_ctrl[1],
583+
'foot_ik': controls[6], 'pole': pole, 'footroll': controls[5], 'mfoot_ik': ik_ctrl[2],
584+
'main_parent': parent}
585+
586+
func1(**kwargs1)
587+
rig.pose.bones[parent]['pole_vector'] = new_pole_vector_value
588+
func2(**kwargs2)
589+
590+
bpy.ops.pose.select_all(action='DESELECT')
591+
523592
##############################
524593
## IK/FK snapping operators ##
525594
##############################
@@ -649,6 +718,31 @@ def execute(self, context):
649718
context.user_preferences.edit.use_global_undo = use_global_undo
650719
return {'FINISHED'}
651720
721+
###########################
722+
## IK Rotation Pole Snap ##
723+
###########################
724+
725+
class Rigify_Rot2PoleSwitch(bpy.types.Operator):
726+
bl_idname = "pose.rigify_rot2pole_" + rig_id
727+
bl_label = "Rotation - Pole toggle"
728+
bl_description = "Toggles IK chain between rotation and pole target"
729+
bone_name = bpy.props.StringProperty(default='')
730+
limb_type = bpy.props.StringProperty(name="Limb Type")
731+
controls = bpy.props.StringProperty(name="Controls string")
732+
ik_ctrl = bpy.props.StringProperty(name="IK Controls string")
733+
fk_ctrl = bpy.props.StringProperty(name="FK Controls string")
734+
parent = bpy.props.StringProperty(name="Parent name")
735+
pole = bpy.props.StringProperty(name="Pole name")
736+
737+
def execute(self, context):
738+
rig = context.object
739+
740+
if self.bone_name:
741+
bpy.ops.pose.select_all(action='DESELECT')
742+
rig.pose.bones[self.bone_name].bone.select = True
743+
744+
rotPoleToggle(rig, self.limb_type, self.controls, self.ik_ctrl, self.fk_ctrl, self.parent, self.pole)
745+
return {'FINISHED'}
652746
653747
###################
654748
## Rig UI Panels ##
@@ -752,6 +846,7 @@ def register():
752846
bpy.utils.register_class(Rigify_Arm_IK2FK)
753847
bpy.utils.register_class(Rigify_Leg_FK2IK)
754848
bpy.utils.register_class(Rigify_Leg_IK2FK)
849+
bpy.utils.register_class(Rigify_Rot2PoleSwitch)
755850
bpy.utils.register_class(RigUI)
756851
bpy.utils.register_class(RigLayers)
757852
@@ -760,6 +855,7 @@ def unregister():
760855
bpy.utils.unregister_class(Rigify_Arm_IK2FK)
761856
bpy.utils.unregister_class(Rigify_Leg_FK2IK)
762857
bpy.utils.unregister_class(Rigify_Leg_IK2FK)
858+
bpy.utils.register_class(Rigify_Rot2PoleSwitch)
763859
bpy.utils.unregister_class(RigUI)
764860
bpy.utils.unregister_class(RigLayers)
765861

rigs/limbs/ui.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,14 @@
2626
props.hand_ik = controls[4]
2727
props.pole = pole
2828
props.main_parent = parent
29-
props = layout.operator("rigify.rotation_pole", text="Switch Rotation-Pole")
29+
props = layout.operator("pose.rigify_rot2pole_" + rig_id, text="Switch Rotation-Pole")
3030
props.bone_name = controls[1]
31-
props.window = "CURRENT"
32-
props.toggle = True
33-
props.bake = False
31+
props.limb_type = "arm"
32+
props.controls = str(controls)
33+
props.ik_ctrl = str(ik_ctrl)
34+
props.fk_ctrl = str(fk_ctrl)
35+
props.parent = str(parent)
36+
props.pole = str(pole)
3437
3538
3639
# BBone rubber hose on each Respective Tweak
@@ -81,11 +84,14 @@
8184
props.footroll = controls[5]
8285
props.mfoot_ik = ik_ctrl[2]
8386
props.main_parent = parent
84-
props = layout.operator("rigify.rotation_pole", text="Toggle Rotation and Pole")
87+
props = layout.operator("pose.rigify_rot2pole_" + rig_id, text="Toggle Rotation and Pole")
8588
props.bone_name = controls[1]
86-
props.window = "CURRENT"
87-
props.toggle = True
88-
props.bake = False
89+
props.limb_type = "leg"
90+
props.controls = str(controls)
91+
props.ik_ctrl = str(ik_ctrl)
92+
props.fk_ctrl = str(fk_ctrl)
93+
props.parent = str(parent)
94+
props.pole = str(pole)
8995
9096
# BBone rubber hose on each Respective Tweak
9197
for t in tweaks:

0 commit comments

Comments
 (0)