Changeset View
Changeset View
Standalone View
Standalone View
rigify/rig_ui_template.py
| Show All 14 Lines | |||||
| # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||||
| # | # | ||||
| #======================= END GPL LICENSE BLOCK ======================== | #======================= END GPL LICENSE BLOCK ======================== | ||||
| # <pep8 compliant> | # <pep8 compliant> | ||||
| UI_SLIDERS = ''' | UI_SLIDERS = ''' | ||||
| import bpy | import bpy | ||||
| from bpy.props import StringProperty | |||||
| from mathutils import Matrix, Vector | from mathutils import Matrix, Vector | ||||
| from math import acos, pi, radians | from math import acos, pi, radians | ||||
| rig_id = "%s" | rig_id = "%s" | ||||
| ############################ | ############################ | ||||
| ## Math utility functions ## | ## Math utility functions ## | ||||
| ▲ Show 20 Lines • Show All 564 Lines • ▼ Show 20 Lines | |||||
| class Rigify_Arm_FK2IK(bpy.types.Operator): | class Rigify_Arm_FK2IK(bpy.types.Operator): | ||||
| """ Snaps an FK arm to an IK arm. | """ Snaps an FK arm to an IK arm. | ||||
| """ | """ | ||||
| bl_idname = "pose.rigify_arm_fk2ik_" + rig_id | bl_idname = "pose.rigify_arm_fk2ik_" + rig_id | ||||
| bl_label = "Rigify Snap FK arm to IK" | bl_label = "Rigify Snap FK arm to IK" | ||||
| bl_options = {'UNDO'} | bl_options = {'UNDO'} | ||||
| uarm_fk = bpy.props.StringProperty(name="Upper Arm FK Name") | uarm_fk: StringProperty(name="Upper Arm FK Name") | ||||
| farm_fk = bpy.props.StringProperty(name="Forerm FK Name") | farm_fk: StringProperty(name="Forerm FK Name") | ||||
| hand_fk = bpy.props.StringProperty(name="Hand FK Name") | hand_fk: StringProperty(name="Hand FK Name") | ||||
| uarm_ik = bpy.props.StringProperty(name="Upper Arm IK Name") | uarm_ik: StringProperty(name="Upper Arm IK Name") | ||||
| farm_ik = bpy.props.StringProperty(name="Forearm IK Name") | farm_ik: StringProperty(name="Forearm IK Name") | ||||
| hand_ik = bpy.props.StringProperty(name="Hand IK Name") | hand_ik: StringProperty(name="Hand IK Name") | ||||
| @classmethod | @classmethod | ||||
| def poll(cls, context): | def poll(cls, context): | ||||
| return (context.active_object != None and context.mode == 'POSE') | return (context.active_object != None and context.mode == 'POSE') | ||||
| def execute(self, context): | def execute(self, context): | ||||
| use_global_undo = context.user_preferences.edit.use_global_undo | use_global_undo = context.user_preferences.edit.use_global_undo | ||||
| context.user_preferences.edit.use_global_undo = False | context.user_preferences.edit.use_global_undo = False | ||||
| try: | try: | ||||
| fk2ik_arm(context.active_object, fk=[self.uarm_fk, self.farm_fk, self.hand_fk], ik=[self.uarm_ik, self.farm_ik, self.hand_ik]) | fk2ik_arm(context.active_object, fk=[self.uarm_fk, self.farm_fk, self.hand_fk], ik=[self.uarm_ik, self.farm_ik, self.hand_ik]) | ||||
| finally: | finally: | ||||
| context.user_preferences.edit.use_global_undo = use_global_undo | context.user_preferences.edit.use_global_undo = use_global_undo | ||||
| return {'FINISHED'} | return {'FINISHED'} | ||||
| class Rigify_Arm_IK2FK(bpy.types.Operator): | class Rigify_Arm_IK2FK(bpy.types.Operator): | ||||
| """ Snaps an IK arm to an FK arm. | """ Snaps an IK arm to an FK arm. | ||||
| """ | """ | ||||
| bl_idname = "pose.rigify_arm_ik2fk_" + rig_id | bl_idname = "pose.rigify_arm_ik2fk_" + rig_id | ||||
| bl_label = "Rigify Snap IK arm to FK" | bl_label = "Rigify Snap IK arm to FK" | ||||
| bl_options = {'UNDO'} | bl_options = {'UNDO'} | ||||
| uarm_fk = bpy.props.StringProperty(name="Upper Arm FK Name") | uarm_fk: StringProperty(name="Upper Arm FK Name") | ||||
| farm_fk = bpy.props.StringProperty(name="Forerm FK Name") | farm_fk: StringProperty(name="Forerm FK Name") | ||||
| hand_fk = bpy.props.StringProperty(name="Hand FK Name") | hand_fk: StringProperty(name="Hand FK Name") | ||||
| uarm_ik = bpy.props.StringProperty(name="Upper Arm IK Name") | uarm_ik: StringProperty(name="Upper Arm IK Name") | ||||
| farm_ik = bpy.props.StringProperty(name="Forearm IK Name") | farm_ik: StringProperty(name="Forearm IK Name") | ||||
| hand_ik = bpy.props.StringProperty(name="Hand IK Name") | hand_ik: StringProperty(name="Hand IK Name") | ||||
| pole = bpy.props.StringProperty(name="Pole IK Name") | pole : StringProperty(name="Pole IK Name") | ||||
| main_parent = bpy.props.StringProperty(name="Main Parent", default="") | main_parent: StringProperty(name="Main Parent", default="") | ||||
| @classmethod | @classmethod | ||||
| def poll(cls, context): | def poll(cls, context): | ||||
| return (context.active_object != None and context.mode == 'POSE') | return (context.active_object != None and context.mode == 'POSE') | ||||
| def execute(self, context): | def execute(self, context): | ||||
| use_global_undo = context.user_preferences.edit.use_global_undo | use_global_undo = context.user_preferences.edit.use_global_undo | ||||
| context.user_preferences.edit.use_global_undo = False | context.user_preferences.edit.use_global_undo = False | ||||
| try: | try: | ||||
| ik2fk_arm(context.active_object, fk=[self.uarm_fk, self.farm_fk, self.hand_fk], ik=[self.uarm_ik, self.farm_ik, self.hand_ik, self.pole, self.main_parent]) | ik2fk_arm(context.active_object, fk=[self.uarm_fk, self.farm_fk, self.hand_fk], ik=[self.uarm_ik, self.farm_ik, self.hand_ik, self.pole, self.main_parent]) | ||||
| finally: | finally: | ||||
| context.user_preferences.edit.use_global_undo = use_global_undo | context.user_preferences.edit.use_global_undo = use_global_undo | ||||
| return {'FINISHED'} | return {'FINISHED'} | ||||
| class Rigify_Leg_FK2IK(bpy.types.Operator): | class Rigify_Leg_FK2IK(bpy.types.Operator): | ||||
| """ Snaps an FK leg to an IK leg. | """ Snaps an FK leg to an IK leg. | ||||
| """ | """ | ||||
| bl_idname = "pose.rigify_leg_fk2ik_" + rig_id | bl_idname = "pose.rigify_leg_fk2ik_" + rig_id | ||||
| bl_label = "Rigify Snap FK leg to IK" | bl_label = "Rigify Snap FK leg to IK" | ||||
| bl_options = {'UNDO'} | bl_options = {'UNDO'} | ||||
| thigh_fk = bpy.props.StringProperty(name="Thigh FK Name") | thigh_fk: StringProperty(name="Thigh FK Name") | ||||
| shin_fk = bpy.props.StringProperty(name="Shin FK Name") | shin_fk: StringProperty(name="Shin FK Name") | ||||
| foot_fk = bpy.props.StringProperty(name="Foot FK Name") | foot_fk: StringProperty(name="Foot FK Name") | ||||
| mfoot_fk = bpy.props.StringProperty(name="MFoot FK Name") | mfoot_fk: StringProperty(name="MFoot FK Name") | ||||
| thigh_ik = bpy.props.StringProperty(name="Thigh IK Name") | thigh_ik: StringProperty(name="Thigh IK Name") | ||||
| shin_ik = bpy.props.StringProperty(name="Shin IK Name") | shin_ik: StringProperty(name="Shin IK Name") | ||||
| foot_ik = bpy.props.StringProperty(name="Foot IK Name") | foot_ik: StringProperty(name="Foot IK Name") | ||||
| mfoot_ik = bpy.props.StringProperty(name="MFoot IK Name") | mfoot_ik: StringProperty(name="MFoot IK Name") | ||||
| @classmethod | @classmethod | ||||
| def poll(cls, context): | def poll(cls, context): | ||||
| return (context.active_object != None and context.mode == 'POSE') | return (context.active_object != None and context.mode == 'POSE') | ||||
| def execute(self, context): | def execute(self, context): | ||||
| use_global_undo = context.user_preferences.edit.use_global_undo | use_global_undo = context.user_preferences.edit.use_global_undo | ||||
| context.user_preferences.edit.use_global_undo = False | context.user_preferences.edit.use_global_undo = False | ||||
| try: | try: | ||||
| fk2ik_leg(context.active_object, fk=[self.thigh_fk, self.shin_fk, self.foot_fk, self.mfoot_fk], ik=[self.thigh_ik, self.shin_ik, self.foot_ik, self.mfoot_ik]) | fk2ik_leg(context.active_object, fk=[self.thigh_fk, self.shin_fk, self.foot_fk, self.mfoot_fk], ik=[self.thigh_ik, self.shin_ik, self.foot_ik, self.mfoot_ik]) | ||||
| finally: | finally: | ||||
| context.user_preferences.edit.use_global_undo = use_global_undo | context.user_preferences.edit.use_global_undo = use_global_undo | ||||
| return {'FINISHED'} | return {'FINISHED'} | ||||
| class Rigify_Leg_IK2FK(bpy.types.Operator): | class Rigify_Leg_IK2FK(bpy.types.Operator): | ||||
| """ Snaps an IK leg to an FK leg. | """ Snaps an IK leg to an FK leg. | ||||
| """ | """ | ||||
| bl_idname = "pose.rigify_leg_ik2fk_" + rig_id | bl_idname = "pose.rigify_leg_ik2fk_" + rig_id | ||||
| bl_label = "Rigify Snap IK leg to FK" | bl_label = "Rigify Snap IK leg to FK" | ||||
| bl_options = {'UNDO'} | bl_options = {'UNDO'} | ||||
| thigh_fk = bpy.props.StringProperty(name="Thigh FK Name") | thigh_fk: StringProperty(name="Thigh FK Name") | ||||
| shin_fk = bpy.props.StringProperty(name="Shin FK Name") | shin_fk: StringProperty(name="Shin FK Name") | ||||
| mfoot_fk = bpy.props.StringProperty(name="MFoot FK Name") | mfoot_fk: StringProperty(name="MFoot FK Name") | ||||
| foot_fk = bpy.props.StringProperty(name="Foot FK Name", default="") | foot_fk: StringProperty(name="Foot FK Name", default="") | ||||
| thigh_ik = bpy.props.StringProperty(name="Thigh IK Name") | thigh_ik: StringProperty(name="Thigh IK Name") | ||||
| shin_ik = bpy.props.StringProperty(name="Shin IK Name") | shin_ik: StringProperty(name="Shin IK Name") | ||||
| foot_ik = bpy.props.StringProperty(name="Foot IK Name") | foot_ik: StringProperty(name="Foot IK Name") | ||||
| footroll = bpy.props.StringProperty(name="Foot Roll Name") | footroll: StringProperty(name="Foot Roll Name") | ||||
| pole = bpy.props.StringProperty(name="Pole IK Name") | pole: StringProperty(name="Pole IK Name") | ||||
| mfoot_ik = bpy.props.StringProperty(name="MFoot IK Name") | mfoot_ik: StringProperty(name="MFoot IK Name") | ||||
| main_parent = bpy.props.StringProperty(name="Main Parent", default="") | main_parent: StringProperty(name="Main Parent", default="") | ||||
| @classmethod | @classmethod | ||||
| def poll(cls, context): | def poll(cls, context): | ||||
| return (context.active_object != None and context.mode == 'POSE') | return (context.active_object != None and context.mode == 'POSE') | ||||
| def execute(self, context): | def execute(self, context): | ||||
| use_global_undo = context.user_preferences.edit.use_global_undo | use_global_undo = context.user_preferences.edit.use_global_undo | ||||
| context.user_preferences.edit.use_global_undo = False | context.user_preferences.edit.use_global_undo = False | ||||
| try: | try: | ||||
| ik2fk_leg(context.active_object, fk=[self.thigh_fk, self.shin_fk, self.mfoot_fk, self.foot_fk], ik=[self.thigh_ik, self.shin_ik, self.foot_ik, self.footroll, self.pole, self.mfoot_ik, self.main_parent]) | ik2fk_leg(context.active_object, fk=[self.thigh_fk, self.shin_fk, self.mfoot_fk, self.foot_fk], ik=[self.thigh_ik, self.shin_ik, self.foot_ik, self.footroll, self.pole, self.mfoot_ik, self.main_parent]) | ||||
| finally: | finally: | ||||
| context.user_preferences.edit.use_global_undo = use_global_undo | context.user_preferences.edit.use_global_undo = use_global_undo | ||||
| return {'FINISHED'} | return {'FINISHED'} | ||||
| ########################### | ########################### | ||||
| ## IK Rotation Pole Snap ## | ## IK Rotation Pole Snap ## | ||||
| ########################### | ########################### | ||||
| class Rigify_Rot2PoleSwitch(bpy.types.Operator): | class Rigify_Rot2PoleSwitch(bpy.types.Operator): | ||||
| bl_idname = "pose.rigify_rot2pole_" + rig_id | bl_idname = "pose.rigify_rot2pole_" + rig_id | ||||
| bl_label = "Rotation - Pole toggle" | bl_label = "Rotation - Pole toggle" | ||||
| bl_description = "Toggles IK chain between rotation and pole target" | bl_description = "Toggles IK chain between rotation and pole target" | ||||
| bone_name = bpy.props.StringProperty(default='') | |||||
| limb_type = bpy.props.StringProperty(name="Limb Type") | bone_name: StringProperty(default='') | ||||
| controls = bpy.props.StringProperty(name="Controls string") | limb_type: StringProperty(name="Limb Type") | ||||
| ik_ctrl = bpy.props.StringProperty(name="IK Controls string") | controls: StringProperty(name="Controls string") | ||||
| fk_ctrl = bpy.props.StringProperty(name="FK Controls string") | ik_ctrl: StringProperty(name="IK Controls string") | ||||
| parent = bpy.props.StringProperty(name="Parent name") | fk_ctrl: StringProperty(name="FK Controls string") | ||||
| pole = bpy.props.StringProperty(name="Pole name") | parent: StringProperty(name="Parent name") | ||||
| pole: StringProperty(name="Pole name") | |||||
| def execute(self, context): | def execute(self, context): | ||||
| rig = context.object | rig = context.object | ||||
| if self.bone_name: | if self.bone_name: | ||||
| bpy.ops.pose.select_all(action='DESELECT') | bpy.ops.pose.select_all(action='DESELECT') | ||||
| rig.pose.bones[self.bone_name].bone.select = True | rig.pose.bones[self.bone_name].bone.select = True | ||||
| ▲ Show 20 Lines • Show All 92 Lines • ▼ Show 20 Lines | ''' | ||||
| code += "\n row = col.row()\n" | code += "\n row = col.row()\n" | ||||
| code += " row.prop(context.active_object.data, 'layers', index=28, toggle=True, text='Root')\n" | code += " row.prop(context.active_object.data, 'layers', index=28, toggle=True, text='Root')\n" | ||||
| return code | return code | ||||
| UI_REGISTER = ''' | UI_REGISTER = ''' | ||||
| classes = ( | |||||
| Rigify_Arm_FK2IK, | |||||
| Rigify_Arm_IK2FK, | |||||
| Rigify_Leg_FK2IK, | |||||
| Rigify_Leg_IK2FK, | |||||
| Rigify_Rot2PoleSwitch, | |||||
| RigUI, | |||||
| RigLayers, | |||||
| ) | |||||
| def register(): | def register(): | ||||
| bpy.utils.register_class(Rigify_Arm_FK2IK) | from bpy.utils import register_class | ||||
| bpy.utils.register_class(Rigify_Arm_IK2FK) | for cls in classes: | ||||
| bpy.utils.register_class(Rigify_Leg_FK2IK) | register_class(cls) | ||||
| bpy.utils.register_class(Rigify_Leg_IK2FK) | |||||
| bpy.utils.register_class(Rigify_Rot2PoleSwitch) | |||||
| bpy.utils.register_class(RigUI) | |||||
| bpy.utils.register_class(RigLayers) | |||||
| def unregister(): | def unregister(): | ||||
| bpy.utils.unregister_class(Rigify_Arm_FK2IK) | from bpy.utils import unregister_class | ||||
| bpy.utils.unregister_class(Rigify_Arm_IK2FK) | for cls in classes: | ||||
| bpy.utils.unregister_class(Rigify_Leg_FK2IK) | unregister_class(cls) | ||||
| bpy.utils.unregister_class(Rigify_Leg_IK2FK) | |||||
| bpy.utils.register_class(Rigify_Rot2PoleSwitch) | |||||
| bpy.utils.unregister_class(RigUI) | |||||
| bpy.utils.unregister_class(RigLayers) | |||||
| register() | register() | ||||
| ''' | ''' | ||||