Changeset View
Changeset View
Standalone View
Standalone View
rigify/ui.py
| Show All 22 Lines | from bpy.props import ( | ||||
| BoolProperty, | BoolProperty, | ||||
| IntProperty, | IntProperty, | ||||
| EnumProperty, | EnumProperty, | ||||
| StringProperty | StringProperty | ||||
| ) | ) | ||||
| from mathutils import Color | from mathutils import Color | ||||
| from .utils import get_rig_type, MetarigError | from .utils import 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 | ||||
| from .rigs.utils import get_limb_generated_names | from .rigs.utils import get_limb_generated_names | ||||
| from . import rig_lists | from . import rig_lists | ||||
| from . import generate | from . import generate | ||||
| from . import rot_mode | from . import rot_mode | ||||
| from . import feature_sets | |||||
| def build_type_list(context, rigify_types): | |||||
| rigify_types.clear() | |||||
| for r in sorted(rig_lists.rigs): | |||||
| if (context.object.data.active_feature_set in ('all', rig_lists.rigs[r]['feature_set']) | |||||
| or len(feature_sets.feature_set_items(context.scene, context)) == 2 | |||||
| ): | |||||
| a = rigify_types.add() | |||||
| a.name = r | |||||
| class DATA_PT_rigify_buttons(bpy.types.Panel): | class DATA_PT_rigify_buttons(bpy.types.Panel): | ||||
| bl_label = "Rigify Buttons" | bl_label = "Rigify Buttons" | ||||
| bl_space_type = 'PROPERTIES' | bl_space_type = 'PROPERTIES' | ||||
| bl_region_type = 'WINDOW' | bl_region_type = 'WINDOW' | ||||
| bl_context = "data" | bl_context = "data" | ||||
| Show All 11 Lines | def draw(self, context): | ||||
| WARNING = "Warning: Some features may change after generation" | WARNING = "Warning: Some features may change after generation" | ||||
| show_warning = False | show_warning = False | ||||
| show_update_metarig = False | show_update_metarig = False | ||||
| show_not_updatable = False | show_not_updatable = False | ||||
| check_props = ['IK_follow', 'root/parent', 'FK_limb_follow', 'IK_Stretch'] | check_props = ['IK_follow', 'root/parent', 'FK_limb_follow', 'IK_Stretch'] | ||||
| for obj in bpy.data.objects: | |||||
| if type(obj.data) != bpy.types.Armature: | |||||
| continue | |||||
| for bone in obj.pose.bones: | for bone in obj.pose.bones: | ||||
| if bone.bone.layers[30] and (list(set(bone.keys()) & set(check_props))): | if bone.bone.layers[30] and (list(set(bone.keys()) & set(check_props))): | ||||
| show_warning = True | show_warning = True | ||||
| break | break | ||||
| for b in obj.pose.bones: | for b in obj.pose.bones: | ||||
| if b.rigify_type in outdated_types.keys(): | if b.rigify_type in outdated_types.keys(): | ||||
| if outdated_types[b.rigify_type]: | if outdated_types[b.rigify_type]: | ||||
| show_update_metarig = True | show_update_metarig = True | ||||
| else: | else: | ||||
| show_update_metarig = False | show_update_metarig = False | ||||
| show_not_updatable = True | show_not_updatable = True | ||||
| break | break | ||||
| if show_warning: | if show_warning: | ||||
| layout.label(text=WARNING, icon='ERROR') | layout.label(text=WARNING, icon='ERROR') | ||||
| if show_not_updatable: | if show_not_updatable: | ||||
| layout.label(text="WARNING: This metarig contains deprecated rigify rig-types and cannot be upgraded automatically.", icon='ERROR') | layout.label(text="WARNING: This metarig contains deprecated rigify rig-types and cannot be upgraded automatically.", icon='ERROR') | ||||
| layout.label(text="If you want to use it anyway try enabling the legacy mode before generating again.") | layout.label(text="If you want to use it anyway try enabling the legacy mode before generating again.") | ||||
| layout.operator("pose.rigify_switch_to_legacy", text="Switch to Legacy") | layout.operator("pose.rigify_switch_to_legacy", text="Switch to Legacy") | ||||
| enable_generate_and_advanced = not (show_not_updatable or show_update_metarig) | enable_generate_and_advanced = not (show_not_updatable or show_update_metarig) | ||||
| if show_update_metarig: | if show_update_metarig: | ||||
| layout.label(text="This metarig contains old rig-types that can be automatically upgraded to benefit of rigify's new features.", icon='ERROR') | layout.label(text="This metarig contains old rig-types that can be automatically upgraded to benefit of rigify's new features.", icon='ERROR') | ||||
| layout.label(text="To use it as-is you need to enable legacy mode.",) | layout.label(text="To use it as-is you need to enable legacy mode.",) | ||||
| layout.operator("pose.rigify_upgrade_types", text="Upgrade Metarig") | layout.operator("pose.rigify_upgrade_types", text="Upgrade Metarig") | ||||
| row = layout.row() | row = layout.row() | ||||
| # Rig type field | |||||
| col = layout.column(align=True) | |||||
| col.active = (not 'rig_id' in C.object.data) | |||||
| col.separator() | |||||
| row = col.row() | |||||
| row.operator("pose.rigify_generate", text="Generate Rig", icon='POSE_HLT') | row.operator("pose.rigify_generate", text="Generate Rig", icon='POSE_HLT') | ||||
| row.enabled = enable_generate_and_advanced | row.enabled = enable_generate_and_advanced | ||||
| if id_store.rigify_advanced_generation: | if id_store.rigify_advanced_generation: | ||||
| icon = 'UNLOCKED' | icon = 'UNLOCKED' | ||||
| else: | else: | ||||
| icon = 'LOCKED' | icon = 'LOCKED' | ||||
| col = layout.column() | col = layout.column() | ||||
| ▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | def draw(self, context): | ||||
| row = col.row() | row = col.row() | ||||
| row.prop(id_store, "rigify_force_widget_update") | row.prop(id_store, "rigify_force_widget_update") | ||||
| if id_store.rigify_generate_mode == 'new': | if id_store.rigify_generate_mode == 'new': | ||||
| row.enabled = False | row.enabled = False | ||||
| elif obj.mode == 'EDIT': | elif obj.mode == 'EDIT': | ||||
| # Build types list | # Build types list | ||||
| collection_name = str(id_store.rigify_collection).replace(" ", "") | build_type_list(context, id_store.rigify_types) | ||||
| for i in range(0, len(id_store.rigify_types)): | if id_store.rigify_active_type > len(id_store.rigify_types): | ||||
| id_store.rigify_types.remove(0) | id_store.rigify_active_type = 0 | ||||
| for r in rig_lists.rig_list: | |||||
| if collection_name == "All": | |||||
| a = id_store.rigify_types.add() | |||||
| a.name = r | |||||
| elif r.startswith(collection_name + '.'): | |||||
| a = id_store.rigify_types.add() | |||||
| a.name = r | |||||
| elif (collection_name == "None") and ("." not in r): | |||||
| a = id_store.rigify_types.add() | |||||
| a.name = r | |||||
| # Rig type list | # Rig type list | ||||
| if len(feature_sets.feature_set_items(context.scene, context)) > 2: | |||||
| row = layout.row() | |||||
| row.prop(context.object.data, "active_feature_set") | |||||
| row = layout.row() | row = layout.row() | ||||
| row.template_list("UI_UL_list", "rigify_types", id_store, "rigify_types", id_store, 'rigify_active_type') | row.template_list("UI_UL_list", "rigify_types", id_store, "rigify_types", id_store, 'rigify_active_type') | ||||
| props = layout.operator("armature.metarig_sample_add", text="Add sample") | props = layout.operator("armature.metarig_sample_add", text="Add sample") | ||||
| props.metarig_type = id_store.rigify_types[id_store.rigify_active_type].name | props.metarig_type = id_store.rigify_types[id_store.rigify_active_type].name | ||||
| class DATA_PT_rigify_layer_names(bpy.types.Panel): | class DATA_PT_rigify_layer_names(bpy.types.Panel): | ||||
| ▲ Show 20 Lines • Show All 386 Lines • ▼ Show 20 Lines | def poll(cls, context): | ||||
| return context.object.type == 'ARMATURE' and context.active_pose_bone\ | return context.object.type == 'ARMATURE' and context.active_pose_bone\ | ||||
| and context.active_object.data.get("rig_id") is None | and context.active_object.data.get("rig_id") is None | ||||
| def draw(self, context): | def draw(self, context): | ||||
| C = context | C = context | ||||
| id_store = C.window_manager | id_store = C.window_manager | ||||
| bone = context.active_pose_bone | bone = context.active_pose_bone | ||||
| collection_name = str(id_store.rigify_collection).replace(" ", "") | |||||
| rig_name = str(context.active_pose_bone.rigify_type).replace(" ", "") | rig_name = str(context.active_pose_bone.rigify_type).replace(" ", "") | ||||
| layout = self.layout | layout = self.layout | ||||
| # Build types list | # Build types list | ||||
| for i in range(0, len(id_store.rigify_types)): | build_type_list(context, id_store.rigify_types) | ||||
| id_store.rigify_types.remove(0) | |||||
| for r in rig_lists.rig_list: | |||||
| if r in rig_lists.implementation_rigs: | |||||
| continue | |||||
| # collection = r.split('.')[0] # UNUSED | |||||
| if collection_name == "All": | |||||
| a = id_store.rigify_types.add() | |||||
| a.name = r | |||||
| elif r.startswith(collection_name + '.'): | |||||
| a = id_store.rigify_types.add() | |||||
| a.name = r | |||||
| elif collection_name == "None" and len(r.split('.')) == 1: | |||||
| a = id_store.rigify_types.add() | |||||
| a.name = r | |||||
| # Rig type field | # Rig type field | ||||
| if len(feature_sets.feature_set_items(context.scene, context)) > 2: | |||||
| row = layout.row() | |||||
| row.prop(context.object.data, "active_feature_set") | |||||
| row = layout.row() | row = layout.row() | ||||
| row.prop_search(bone, "rigify_type", id_store, "rigify_types", text="Rig type:") | row.prop_search(bone, "rigify_type", id_store, "rigify_types", text="Rig type") | ||||
| # Rig type parameters / Rig type non-exist alert | # Rig type parameters / Rig type non-exist alert | ||||
| if rig_name != "": | if rig_name != "": | ||||
| try: | try: | ||||
| rig = get_rig_type(rig_name) | rig = rig_lists.rigs[rig_name]['module'] | ||||
| rig.Rig | |||||
| except (ImportError, AttributeError): | except (ImportError, AttributeError): | ||||
| row = layout.row() | row = layout.row() | ||||
| box = row.box() | box = row.box() | ||||
| box.label(text="ALERT: type \"%s\" does not exist!" % rig_name) | box.label(text="ALERT: type \"%s\" does not exist!" % rig_name) | ||||
| else: | else: | ||||
| try: | try: | ||||
| rig.parameters_ui | rig.parameters_ui | ||||
| except AttributeError: | except AttributeError: | ||||
| Show All 11 Lines | class VIEW3D_PT_tools_rigify_dev(bpy.types.Panel): | ||||
| bl_space_type = 'VIEW_3D' | bl_space_type = 'VIEW_3D' | ||||
| bl_region_type = 'UI' | bl_region_type = 'UI' | ||||
| bl_category = 'View' | bl_category = 'View' | ||||
| @classmethod | @classmethod | ||||
| def poll(cls, context): | def poll(cls, context): | ||||
| return context.mode in ['EDIT_ARMATURE', 'EDIT_MESH'] | return context.mode in ['EDIT_ARMATURE', 'EDIT_MESH'] | ||||
| @classmethod | |||||
| def poll(cls, context): | |||||
| return context.mode in ['EDIT_ARMATURE', 'EDIT_MESH'] | |||||
| def draw(self, context): | def draw(self, context): | ||||
| obj = context.active_object | obj = context.active_object | ||||
| if obj is not None: | if obj is not None: | ||||
| if context.mode == 'EDIT_ARMATURE': | if context.mode == 'EDIT_ARMATURE': | ||||
| r = self.layout.row() | r = self.layout.row() | ||||
| r.operator("armature.rigify_encode_metarig", text="Encode Metarig to Python") | r.operator("armature.rigify_encode_metarig", text="Encode Metarig to Python") | ||||
| r = self.layout.row() | r = self.layout.row() | ||||
| r.operator("armature.rigify_encode_metarig_sample", text="Encode Sample to Python") | r.operator("armature.rigify_encode_metarig_sample", text="Encode Sample to Python") | ||||
| ▲ Show 20 Lines • Show All 161 Lines • ▼ Show 20 Lines | metarig_type: StringProperty( | ||||
| 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.preferences.edit.use_global_undo | use_global_undo = context.preferences.edit.use_global_undo | ||||
| context.preferences.edit.use_global_undo = False | context.preferences.edit.use_global_undo = False | ||||
| try: | try: | ||||
| rig = get_rig_type(self.metarig_type) | rig = rig_lists.rigs[self.metarig_type]["module"] | ||||
| create_sample = rig.create_sample | create_sample = rig.create_sample | ||||
| except (ImportError, AttributeError): | except (ImportError, AttributeError): | ||||
| raise Exception("rig type '" + self.metarig_type + "' has no sample.") | raise Exception("rig type '" + self.metarig_type + "' has no sample.") | ||||
| else: | else: | ||||
| create_sample(context.active_object) | create_sample(context.active_object) | ||||
| finally: | finally: | ||||
| context.preferences.edit.use_global_undo = use_global_undo | context.preferences.edit.use_global_undo = use_global_undo | ||||
| bpy.ops.object.mode_set(mode='EDIT') | bpy.ops.object.mode_set(mode='EDIT') | ||||
| ▲ Show 20 Lines • Show All 551 Lines • Show Last 20 Lines | |||||