Changeset View
Changeset View
Standalone View
Standalone View
rigify/ui.py
| Show All 13 Lines | |||||
| # along with this program; if not, write to the Free Software Foundation, | # along with this program; if not, write to the Free Software Foundation, | ||||
| # 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> | ||||
| import bpy | import bpy | ||||
| from bpy.props import StringProperty | from bpy.props import ( | ||||
| BoolProperty, | |||||
| IntProperty, | |||||
| EnumProperty, | |||||
| StringProperty | |||||
| ) | |||||
| from mathutils import Color | from mathutils import Color | ||||
| from .utils import get_rig_type, MetarigError | from .utils import get_rig_type, MetarigError | ||||
| from .utils import write_metarig, write_widget | from .utils import write_metarig, write_widget | ||||
| from .utils import unique_name | from .utils import unique_name | ||||
| from .utils import upgradeMetarigTypes, outdated_types | from .utils import upgradeMetarigTypes, outdated_types | ||||
| from .utils import get_keyed_frames, bones_in_frame | from .utils import get_keyed_frames, bones_in_frame | ||||
| from .utils import overwrite_prop_animation | from .utils import overwrite_prop_animation | ||||
| ▲ Show 20 Lines • Show All 198 Lines • ▼ Show 20 Lines | def draw(self, context): | ||||
| col = col2.column() | col = col2.column() | ||||
| if i != 28: | if i != 28: | ||||
| row = col.row(align=True) | row = col.row(align=True) | ||||
| icon = 'RESTRICT_VIEW_OFF' if arm.layers[i] else 'RESTRICT_VIEW_ON' | icon = 'RESTRICT_VIEW_OFF' if arm.layers[i] else 'RESTRICT_VIEW_ON' | ||||
| row.prop(arm, "layers", index=i, text="", toggle=True, icon=icon) | row.prop(arm, "layers", index=i, text="", toggle=True, icon=icon) | ||||
| #row.prop(arm, "layers", index=i, text="Layer %d" % (i + 1), toggle=True, icon=icon) | #row.prop(arm, "layers", index=i, text="Layer %d" % (i + 1), toggle=True, icon=icon) | ||||
| row.prop(rigify_layer, "name", text="") | row.prop(rigify_layer, "name", text="") | ||||
| row.prop(rigify_layer, "row", text="UI Row") | row.prop(rigify_layer, "row", text="UI Row") | ||||
| icon = 'RADIOBUT_ON' if rigify_layer.set else 'RADIOBUT_OFF' | icon = 'RADIOBUT_ON' if rigify_layer.selset else 'RADIOBUT_OFF' | ||||
| row.prop(rigify_layer, "set", text="", toggle=True, icon=icon) | row.prop(rigify_layer, "selset", text="", toggle=True, icon=icon) | ||||
| row.prop(rigify_layer, "group", text="Bone Group") | row.prop(rigify_layer, "group", text="Bone Group") | ||||
| else: | else: | ||||
| row = col.row(align=True) | row = col.row(align=True) | ||||
| icon = 'RESTRICT_VIEW_OFF' if arm.layers[i] else 'RESTRICT_VIEW_ON' | icon = 'RESTRICT_VIEW_OFF' if arm.layers[i] else 'RESTRICT_VIEW_ON' | ||||
| row.prop(arm, "layers", index=i, text="", toggle=True, icon=icon) | row.prop(arm, "layers", index=i, text="", toggle=True, icon=icon) | ||||
| # row.prop(arm, "layers", index=i, text="Layer %d" % (i + 1), toggle=True, icon=icon) | # row.prop(arm, "layers", index=i, text="Layer %d" % (i + 1), toggle=True, icon=icon) | ||||
| row1 = row.split(align=True).row(align=True) | row1 = row.split(align=True).row(align=True) | ||||
| row1.prop(rigify_layer, "name", text="") | row1.prop(rigify_layer, "name", text="") | ||||
| row1.prop(rigify_layer, "row", text="UI Row") | row1.prop(rigify_layer, "row", text="UI Row") | ||||
| row1.enabled = False | row1.enabled = False | ||||
| icon = 'RADIOBUT_ON' if rigify_layer.set else 'RADIOBUT_OFF' | icon = 'RADIOBUT_ON' if rigify_layer.selset else 'RADIOBUT_OFF' | ||||
| row.prop(rigify_layer, "set", text="", toggle=True, icon=icon) | row.prop(rigify_layer, "selset", text="", toggle=True, icon=icon) | ||||
| row.prop(rigify_layer, "group", text="Bone Group") | row.prop(rigify_layer, "group", text="Bone Group") | ||||
| if rigify_layer.group == 0: | if rigify_layer.group == 0: | ||||
| row.label(text='None') | row.label(text='None') | ||||
| else: | else: | ||||
| row.label(text=arm.rigify_colors[rigify_layer.group-1].name) | row.label(text=arm.rigify_colors[rigify_layer.group-1].name) | ||||
| col = col2.column() | col = col2.column() | ||||
| col.label(text="Reserved:") | col.label(text="Reserved:") | ||||
| ▲ Show 20 Lines • Show All 130 Lines • ▼ Show 20 Lines | def execute(self, context): | ||||
| return {'FINISHED'} | return {'FINISHED'} | ||||
| class DATA_OT_rigify_bone_group_add_theme(bpy.types.Operator): | class DATA_OT_rigify_bone_group_add_theme(bpy.types.Operator): | ||||
| bl_idname = "armature.rigify_bone_group_add_theme" | bl_idname = "armature.rigify_bone_group_add_theme" | ||||
| bl_label = "Rigify Add Bone Group color set from Theme" | bl_label = "Rigify Add Bone Group color set from Theme" | ||||
| bl_options = {"REGISTER", "UNDO"} | bl_options = {"REGISTER", "UNDO"} | ||||
| theme = bpy.props.EnumProperty(items=(('THEME01', 'THEME01', ''), | theme: EnumProperty(items=( | ||||
| ('THEME01', 'THEME01', ''), | |||||
| ('THEME02', 'THEME02', ''), | ('THEME02', 'THEME02', ''), | ||||
| ('THEME03', 'THEME03', ''), | ('THEME03', 'THEME03', ''), | ||||
| ('THEME04', 'THEME04', ''), | ('THEME04', 'THEME04', ''), | ||||
| ('THEME05', 'THEME05', ''), | ('THEME05', 'THEME05', ''), | ||||
| ('THEME06', 'THEME06', ''), | ('THEME06', 'THEME06', ''), | ||||
| ('THEME07', 'THEME07', ''), | ('THEME07', 'THEME07', ''), | ||||
| ('THEME08', 'THEME08', ''), | ('THEME08', 'THEME08', ''), | ||||
| ('THEME09', 'THEME09', ''), | ('THEME09', 'THEME09', ''), | ||||
| ('THEME10', 'THEME10', ''), | ('THEME10', 'THEME10', ''), | ||||
| ('THEME11', 'THEME11', ''), | ('THEME11', 'THEME11', ''), | ||||
| ('THEME12', 'THEME12', ''), | ('THEME12', 'THEME12', ''), | ||||
| ('THEME13', 'THEME13', ''), | ('THEME13', 'THEME13', ''), | ||||
| ('THEME14', 'THEME14', ''), | ('THEME14', 'THEME14', ''), | ||||
| ('THEME15', 'THEME15', ''), | ('THEME15', 'THEME15', ''), | ||||
| ('THEME16', 'THEME16', ''), | ('THEME16', 'THEME16', ''), | ||||
| ('THEME17', 'THEME17', ''), | ('THEME17', 'THEME17', ''), | ||||
| ('THEME18', 'THEME18', ''), | ('THEME18', 'THEME18', ''), | ||||
| ('THEME19', 'THEME19', ''), | ('THEME19', 'THEME19', ''), | ||||
| ('THEME20', 'THEME20', '') | ('THEME20', 'THEME20', '') | ||||
| ), | ), | ||||
| name='Theme') | name='Theme') | ||||
| @classmethod | @classmethod | ||||
| def poll(cls, context): | def poll(cls, context): | ||||
| return context.object.type == 'ARMATURE' | return context.object.type == 'ARMATURE' | ||||
| def execute(self, context): | def execute(self, context): | ||||
| obj = context.object | obj = context.object | ||||
| armature = obj.data | armature = obj.data | ||||
| Show All 15 Lines | def execute(self, context): | ||||
| return {'FINISHED'} | return {'FINISHED'} | ||||
| class DATA_OT_rigify_bone_group_remove(bpy.types.Operator): | class DATA_OT_rigify_bone_group_remove(bpy.types.Operator): | ||||
| bl_idname = "armature.rigify_bone_group_remove" | bl_idname = "armature.rigify_bone_group_remove" | ||||
| bl_label = "Rigify Remove Bone Group color set" | bl_label = "Rigify Remove Bone Group color set" | ||||
| idx = bpy.props.IntProperty() | idx: IntProperty() | ||||
| @classmethod | @classmethod | ||||
| def poll(cls, context): | def poll(cls, context): | ||||
| return context.object.type == 'ARMATURE' | return context.object.type == 'ARMATURE' | ||||
| def execute(self, context): | def execute(self, context): | ||||
| obj = context.object | obj = context.object | ||||
| obj.data.rigify_colors.remove(self.idx) | obj.data.rigify_colors.remove(self.idx) | ||||
| ▲ Show 20 Lines • Show All 329 Lines • ▼ Show 20 Lines | def invoke(self, context, event): | ||||
| return context.window_manager.invoke_confirm(self, event) | return context.window_manager.invoke_confirm(self, event) | ||||
| def execute(self, context): | def execute(self, context): | ||||
| bpy.context.user_preferences.addons['rigify'].preferences.legacy_mode = True | bpy.context.user_preferences.addons['rigify'].preferences.legacy_mode = True | ||||
| return {'FINISHED'} | return {'FINISHED'} | ||||
| class Sample(bpy.types.Operator): | class Sample(bpy.types.Operator): | ||||
| """Create a sample metarig to be modified before generating """ \ | """Create a sample metarig to be modified before generating the final rig""" | ||||
| """the final rig""" | |||||
| bl_idname = "armature.metarig_sample_add" | bl_idname = "armature.metarig_sample_add" | ||||
| bl_label = "Add a sample metarig for a rig type" | bl_label = "Add a sample metarig for a rig type" | ||||
| bl_options = {'UNDO'} | bl_options = {'UNDO'} | ||||
| metarig_type = StringProperty( | metarig_type: StringProperty( | ||||
| name="Type", | name="Type", | ||||
| description="Name of the rig type to generate a sample of", | description="Name of the rig type to generate a sample of", | ||||
| maxlen=128, | maxlen=128, | ||||
| ) | ) | ||||
| def execute(self, context): | def execute(self, context): | ||||
| if context.mode == 'EDIT_ARMATURE' and self.metarig_type != "": | if context.mode == 'EDIT_ARMATURE' and self.metarig_type != "": | ||||
| 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: | ||||
| rig = get_rig_type(self.metarig_type) | rig = get_rig_type(self.metarig_type) | ||||
| create_sample = rig.create_sample | create_sample = rig.create_sample | ||||
| ▲ Show 20 Lines • Show All 252 Lines • ▼ Show 20 Lines | for b in pbones: | ||||
| bpy.ops.anim.keyframe_insert_menu(type='BUILTIN_KSI_VisualLocRot') | bpy.ops.anim.keyframe_insert_menu(type='BUILTIN_KSI_VisualLocRot') | ||||
| bpy.ops.anim.keyframe_insert_menu(type='Scaling') | bpy.ops.anim.keyframe_insert_menu(type='Scaling') | ||||
| bpy.ops.pose.select_all(action='DESELECT') | bpy.ops.pose.select_all(action='DESELECT') | ||||
| limb_generated_names.pop(group) | limb_generated_names.pop(group) | ||||
| break | break | ||||
| def clearAnimation(act, type, names): | def clearAnimation(act, anim_type, names): | ||||
| bones = [] | bones = [] | ||||
| for group in names: | for group in names: | ||||
| if names[group]['limb_type'] == 'arm': | if names[group]['limb_type'] == 'arm': | ||||
| if type == 'IK': | if anim_type == 'IK': | ||||
| bones.extend([names[group]['controls'][0], names[group]['controls'][4]]) | bones.extend([names[group]['controls'][0], names[group]['controls'][4]]) | ||||
| elif type == 'FK': | elif anim_type == 'FK': | ||||
| bones.extend([names[group]['controls'][1], names[group]['controls'][2], names[group]['controls'][3]]) | bones.extend([names[group]['controls'][1], names[group]['controls'][2], names[group]['controls'][3]]) | ||||
| else: | else: | ||||
| if type == 'IK': | if anim_type == 'IK': | ||||
| bones.extend([names[group]['controls'][0], names[group]['controls'][6], names[group]['controls'][5], | bones.extend([names[group]['controls'][0], names[group]['controls'][6], names[group]['controls'][5], | ||||
| names[group]['controls'][4]]) | names[group]['controls'][4]]) | ||||
| elif type == 'FK': | elif anim_type == 'FK': | ||||
| bones.extend([names[group]['controls'][1], names[group]['controls'][2], names[group]['controls'][3], | bones.extend([names[group]['controls'][1], names[group]['controls'][2], names[group]['controls'][3], | ||||
| names[group]['controls'][4]]) | names[group]['controls'][4]]) | ||||
| FCurves = [] | FCurves = [] | ||||
| for fcu in act.fcurves: | for fcu in act.fcurves: | ||||
| words = fcu.data_path.split('"') | words = fcu.data_path.split('"') | ||||
| if (words[0] == "pose.bones[" and | if (words[0] == "pose.bones[" and | ||||
| words[1] in bones): | words[1] in bones): | ||||
| FCurves.append(fcu) | FCurves.append(fcu) | ||||
| ▲ Show 20 Lines • Show All 167 Lines • ▼ Show 20 Lines | def execute(self, context): | ||||
| return {'FINISHED'} | return {'FINISHED'} | ||||
| class OBJECT_OT_ClearAnimation(bpy.types.Operator): | class OBJECT_OT_ClearAnimation(bpy.types.Operator): | ||||
| bl_idname = "rigify.clear_animation" | bl_idname = "rigify.clear_animation" | ||||
| bl_label = "Clear Animation" | bl_label = "Clear Animation" | ||||
| bl_description = "Clear Animation For FK or IK Bones" | bl_description = "Clear Animation For FK or IK Bones" | ||||
| type = StringProperty() | |||||
| anim_type: StringProperty() | |||||
| 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: | ||||
| rig = context.object | rig = context.object | ||||
| scn = context.scene | scn = context.scene | ||||
| if not rig.animation_data: | if not rig.animation_data: | ||||
| return {'FINISHED'} | return {'FINISHED'} | ||||
| act = rig.animation_data.action | act = rig.animation_data.action | ||||
| if not act: | if not act: | ||||
| return {'FINISHED'} | return {'FINISHED'} | ||||
| clearAnimation(act, self.type, names=get_limb_generated_names(rig)) | clearAnimation(act, self.anim_type, names=get_limb_generated_names(rig)) | ||||
| 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 OBJECT_OT_Rot2Pole(bpy.types.Operator): | class OBJECT_OT_Rot2Pole(bpy.types.Operator): | ||||
| bl_idname = "rigify.rotation_pole" | bl_idname = "rigify.rotation_pole" | ||||
| 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='') | |||||
| window = bpy.props.StringProperty(default='ALL') | bone_name: StringProperty(default='') | ||||
| toggle = bpy.props.BoolProperty(default=True) | window: StringProperty(default='ALL') | ||||
| value = bpy.props.BoolProperty(default=True) | toggle: BoolProperty(default=True) | ||||
| bake = bpy.props.BoolProperty(default=True) | value: BoolProperty(default=True) | ||||
| bake: BoolProperty(default=True) | |||||
| 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 | ||||
| rotPoleToggle(rig, window=self.window, toggle=self.toggle, value=self.value, bake=self.bake) | rotPoleToggle(rig, window=self.window, toggle=self.toggle, value=self.value, bake=self.bake) | ||||
| return {'FINISHED'} | return {'FINISHED'} | ||||
| ### Registering ### | |||||
| classes = ( | |||||
| DATA_OT_rigify_add_bone_groups, | |||||
| DATA_OT_rigify_use_standard_colors, | |||||
| DATA_OT_rigify_apply_selection_colors, | |||||
| DATA_OT_rigify_bone_group_add, | |||||
| DATA_OT_rigify_bone_group_add_theme, | |||||
| DATA_OT_rigify_bone_group_remove, | |||||
| DATA_OT_rigify_bone_group_remove_all, | |||||
| DATA_UL_rigify_bone_groups, | |||||
| DATA_MT_rigify_bone_groups_specials, | |||||
| DATA_PT_rigify_bone_groups, | |||||
| DATA_PT_rigify_layer_names, | |||||
| DATA_PT_rigify_buttons, | |||||
| BONE_PT_rigify_buttons, | |||||
| VIEW3D_PT_rigify_animation_tools, | |||||
| VIEW3D_PT_tools_rigify_dev, | |||||
| LayerInit, | |||||
| Generate, | |||||
| UpgradeMetarigTypes, | |||||
| SwitchToLegacy, | |||||
| Sample, | |||||
| EncodeMetarig, | |||||
| EncodeMetarigSample, | |||||
| EncodeWidget, | |||||
| OBJECT_OT_GetFrameRange, | |||||
| OBJECT_OT_FK2IK, | |||||
| OBJECT_OT_IK2FK, | |||||
| OBJECT_OT_TransferFKtoIK, | |||||
| OBJECT_OT_TransferIKtoFK, | |||||
| OBJECT_OT_ClearAnimation, | |||||
| OBJECT_OT_Rot2Pole, | |||||
| ) | |||||
| def register(): | def register(): | ||||
| from bpy.utils import register_class | |||||
| bpy.utils.register_class(DATA_OT_rigify_add_bone_groups) | # Classes. | ||||
| bpy.utils.register_class(DATA_OT_rigify_use_standard_colors) | for cls in classes: | ||||
| bpy.utils.register_class(DATA_OT_rigify_apply_selection_colors) | register_class(cls) | ||||
| bpy.utils.register_class(DATA_OT_rigify_bone_group_add) | |||||
| bpy.utils.register_class(DATA_OT_rigify_bone_group_add_theme) | |||||
| bpy.utils.register_class(DATA_OT_rigify_bone_group_remove) | |||||
| bpy.utils.register_class(DATA_OT_rigify_bone_group_remove_all) | |||||
| bpy.utils.register_class(DATA_UL_rigify_bone_groups) | |||||
| bpy.utils.register_class(DATA_MT_rigify_bone_groups_specials) | |||||
| bpy.utils.register_class(DATA_PT_rigify_bone_groups) | |||||
| bpy.utils.register_class(DATA_PT_rigify_layer_names) | |||||
| bpy.utils.register_class(DATA_PT_rigify_buttons) | |||||
| bpy.utils.register_class(BONE_PT_rigify_buttons) | |||||
| bpy.utils.register_class(VIEW3D_PT_rigify_animation_tools) | |||||
| bpy.utils.register_class(VIEW3D_PT_tools_rigify_dev) | |||||
| bpy.utils.register_class(LayerInit) | |||||
| bpy.utils.register_class(Generate) | |||||
| bpy.utils.register_class(UpgradeMetarigTypes) | |||||
| bpy.utils.register_class(SwitchToLegacy) | |||||
| bpy.utils.register_class(Sample) | |||||
| bpy.utils.register_class(EncodeMetarig) | |||||
| bpy.utils.register_class(EncodeMetarigSample) | |||||
| bpy.utils.register_class(EncodeWidget) | |||||
| bpy.utils.register_class(OBJECT_OT_GetFrameRange) | |||||
| bpy.utils.register_class(OBJECT_OT_FK2IK) | |||||
| bpy.utils.register_class(OBJECT_OT_IK2FK) | |||||
| bpy.utils.register_class(OBJECT_OT_TransferFKtoIK) | |||||
| bpy.utils.register_class(OBJECT_OT_TransferIKtoFK) | |||||
| bpy.utils.register_class(OBJECT_OT_ClearAnimation) | |||||
| bpy.utils.register_class(OBJECT_OT_Rot2Pole) | |||||
| # Sub-modules. | |||||
| rot_mode.register() | rot_mode.register() | ||||
| def unregister(): | def unregister(): | ||||
| from bpy.utils import unregister_class | |||||
| bpy.utils.unregister_class(DATA_OT_rigify_add_bone_groups) | # Sub-modules. | ||||
| bpy.utils.unregister_class(DATA_OT_rigify_use_standard_colors) | |||||
| bpy.utils.unregister_class(DATA_OT_rigify_apply_selection_colors) | |||||
| bpy.utils.unregister_class(DATA_OT_rigify_bone_group_add) | |||||
| bpy.utils.unregister_class(DATA_OT_rigify_bone_group_add_theme) | |||||
| bpy.utils.unregister_class(DATA_OT_rigify_bone_group_remove) | |||||
| bpy.utils.unregister_class(DATA_OT_rigify_bone_group_remove_all) | |||||
| bpy.utils.unregister_class(DATA_UL_rigify_bone_groups) | |||||
| bpy.utils.unregister_class(DATA_MT_rigify_bone_groups_specials) | |||||
| bpy.utils.unregister_class(DATA_PT_rigify_bone_groups) | |||||
| bpy.utils.unregister_class(DATA_PT_rigify_layer_names) | |||||
| bpy.utils.unregister_class(DATA_PT_rigify_buttons) | |||||
| bpy.utils.unregister_class(BONE_PT_rigify_buttons) | |||||
| bpy.utils.unregister_class(VIEW3D_PT_rigify_animation_tools) | |||||
| bpy.utils.unregister_class(VIEW3D_PT_tools_rigify_dev) | |||||
| bpy.utils.unregister_class(LayerInit) | |||||
| bpy.utils.unregister_class(Generate) | |||||
| bpy.utils.unregister_class(UpgradeMetarigTypes) | |||||
| bpy.utils.unregister_class(SwitchToLegacy) | |||||
| bpy.utils.unregister_class(Sample) | |||||
| bpy.utils.unregister_class(EncodeMetarig) | |||||
| bpy.utils.unregister_class(EncodeMetarigSample) | |||||
| bpy.utils.unregister_class(EncodeWidget) | |||||
| bpy.utils.unregister_class(OBJECT_OT_GetFrameRange) | |||||
| bpy.utils.unregister_class(OBJECT_OT_FK2IK) | |||||
| bpy.utils.unregister_class(OBJECT_OT_IK2FK) | |||||
| bpy.utils.unregister_class(OBJECT_OT_TransferFKtoIK) | |||||
| bpy.utils.unregister_class(OBJECT_OT_TransferIKtoFK) | |||||
| bpy.utils.unregister_class(OBJECT_OT_ClearAnimation) | |||||
| bpy.utils.unregister_class(OBJECT_OT_Rot2Pole) | |||||
| rot_mode.unregister() | rot_mode.unregister() | ||||
| # Classes. | |||||
| for cls in classes: | |||||
| unregister_class(cls) | |||||