Changeset View
Changeset View
Standalone View
Standalone View
rigify/__init__.py
| Show All 16 Lines | |||||
| #======================= END GPL LICENSE BLOCK ======================== | #======================= END GPL LICENSE BLOCK ======================== | ||||
| # <pep8 compliant> | # <pep8 compliant> | ||||
| bl_info = { | bl_info = { | ||||
| "name": "Rigify", | "name": "Rigify", | ||||
| "version": (0, 5, 1), | "version": (0, 5, 1), | ||||
| "author": "Nathan Vegdahl, Lucio Rossi, Ivan Cappiello", | "author": "Nathan Vegdahl, Lucio Rossi, Ivan Cappiello", | ||||
| "blender": (2, 80, 0), | "blender": (2, 81, 0), | ||||
| "description": "Automatic rigging from building-block components", | "description": "Automatic rigging from building-block components", | ||||
| "location": "Armature properties, Bone properties, View3d tools panel, Armature Add menu", | "location": "Armature properties, Bone properties, View3d tools panel, Armature Add menu", | ||||
| "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.5/Py/" | "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.5/Py/" | ||||
| "Scripts/Rigging/Rigify", | "Scripts/Rigging/Rigify", | ||||
| "category": "Rigging"} | "category": "Rigging"} | ||||
| if "bpy" in locals(): | if "bpy" in locals(): | ||||
| import importlib | import importlib | ||||
| importlib.reload(generate) | # Don't reload base_rig or base_generate, because it would break issubclass checks, | ||||
| importlib.reload(ui) | # unless _all_ modules with classes inheriting from BaseRig are also reloaded. | ||||
| importlib.reload(utils) | importlib.reload(utils) | ||||
| importlib.reload(rig_ui_template) | |||||
| importlib.reload(feature_set_list) | importlib.reload(feature_set_list) | ||||
| importlib.reload(metarig_menu) | |||||
| importlib.reload(rig_lists) | importlib.reload(rig_lists) | ||||
| importlib.reload(generate) | |||||
| importlib.reload(ui) | |||||
| importlib.reload(metarig_menu) | |||||
| else: | else: | ||||
| from . import (utils, feature_set_list, rig_lists, generate, ui, metarig_menu) | from . import (utils, base_rig, base_generate, rig_ui_template, feature_set_list, rig_lists, generate, ui, metarig_menu) | ||||
| import bpy | import bpy | ||||
| import sys | import sys | ||||
| import os | import os | ||||
| from bpy.types import AddonPreferences | from bpy.types import AddonPreferences | ||||
| from bpy.props import ( | from bpy.props import ( | ||||
| BoolProperty, | BoolProperty, | ||||
| IntProperty, | IntProperty, | ||||
| ▲ Show 20 Lines • Show All 208 Lines • ▼ Show 20 Lines | active: FloatVectorProperty( | ||||
| min=0.0, max=1.0, | min=0.0, max=1.0, | ||||
| description="color picker" | description="color picker" | ||||
| ) | ) | ||||
| class RigifyParameters(bpy.types.PropertyGroup): | class RigifyParameters(bpy.types.PropertyGroup): | ||||
| name: StringProperty() | name: StringProperty() | ||||
| # Parameter update callback | |||||
| in_update = False | |||||
| def update_callback(prop_name): | |||||
| from .utils.rig import get_rigify_type | |||||
| def callback(params, context): | |||||
| global in_update | |||||
| # Do not recursively call if the callback updates other parameters | |||||
| if not in_update: | |||||
| try: | |||||
| in_update = True | |||||
| bone = context.active_pose_bone | |||||
| if bone and bone.rigify_parameters == params: | |||||
| rig_info = rig_lists.rigs.get(get_rigify_type(bone), None) | |||||
| if rig_info: | |||||
| rig_cb = getattr(rig_info["module"].Rig, 'on_parameter_update', None) | |||||
| if rig_cb: | |||||
| rig_cb(context, bone, params, prop_name) | |||||
| finally: | |||||
| in_update = False | |||||
| return callback | |||||
| # Remember the initial property set | # Remember the initial property set | ||||
| RIGIFY_PARAMETERS_BASE_DIR = set(dir(RigifyParameters)) | RIGIFY_PARAMETERS_BASE_DIR = set(dir(RigifyParameters)) | ||||
| RIGIFY_PARAMETER_TABLE = {'name': ('DEFAULT', StringProperty())} | RIGIFY_PARAMETER_TABLE = {'name': ('DEFAULT', StringProperty())} | ||||
| def clear_rigify_parameters(): | def clear_rigify_parameters(): | ||||
| for name in list(dir(RigifyParameters)): | for name in list(dir(RigifyParameters)): | ||||
| ▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | def __setattr__(self, name, val): | ||||
| cur_rig, cur_info = self.__prop_table[name] | cur_rig, cur_info = self.__prop_table[name] | ||||
| if val != cur_info: | if val != cur_info: | ||||
| print("!!! RIGIFY RIG %s: REDEFINING PARAMETER %s AS:\n\n %s\n" % (self.__rig_name, name, format_property_spec(val))) | print("!!! RIGIFY RIG %s: REDEFINING PARAMETER %s AS:\n\n %s\n" % (self.__rig_name, name, format_property_spec(val))) | ||||
| print("!!! PREVIOUS DEFINITION BY %s:\n\n %s\n" % (cur_rig, format_property_spec(cur_info))) | print("!!! PREVIOUS DEFINITION BY %s:\n\n %s\n" % (cur_rig, format_property_spec(cur_info))) | ||||
| # actually defining the property modifies the dictionary with new parameters, so copy it now | # actually defining the property modifies the dictionary with new parameters, so copy it now | ||||
| new_def = (val[0], val[1].copy()) | new_def = (val[0], val[1].copy()) | ||||
| # inject a generic update callback that calls the appropriate rig classmethod | |||||
| val[1]['update'] = update_callback(name) | |||||
| setattr(self.__params, name, val) | setattr(self.__params, name, val) | ||||
| self.__prop_table[name] = (self.__rig_name, new_def) | self.__prop_table[name] = (self.__rig_name, new_def) | ||||
| class RigifyArmatureLayer(bpy.types.PropertyGroup): | class RigifyArmatureLayer(bpy.types.PropertyGroup): | ||||
| def get_group(self): | def get_group(self): | ||||
| if 'group_prop' in self.keys(): | if 'group_prop' in self.keys(): | ||||
| ▲ Show 20 Lines • Show All 118 Lines • ▼ Show 20 Lines | def register(): | ||||
| IDStore.rigify_rig_basename = StringProperty(name="Rigify Rig Name", | IDStore.rigify_rig_basename = StringProperty(name="Rigify Rig Name", | ||||
| description="Defines the name of the Rig. If unset, in 'new' mode 'rig' will be used, in 'overwrite' mode the target rig name will be used", | description="Defines the name of the Rig. If unset, in 'new' mode 'rig' will be used, in 'overwrite' mode the target rig name will be used", | ||||
| default="") | default="") | ||||
| IDStore.rigify_transfer_only_selected = BoolProperty( | IDStore.rigify_transfer_only_selected = BoolProperty( | ||||
| name="Transfer Only Selected", | name="Transfer Only Selected", | ||||
| description="Transfer selected bones only", default=True) | description="Transfer selected bones only", default=True) | ||||
| IDStore.rigify_transfer_start_frame = IntProperty( | |||||
| name="Start Frame", | |||||
| description="First Frame to Transfer", default=0, min= 0) | |||||
| IDStore.rigify_transfer_end_frame = IntProperty( | |||||
| name="End Frame", | |||||
| description="Last Frame to Transfer", default=0, min= 0) | |||||
| # Update legacy on restart or reload. | # Update legacy on restart or reload. | ||||
| if (ui and 'legacy' in str(ui)) or bpy.context.preferences.addons['rigify'].preferences.legacy_mode: | if (ui and 'legacy' in str(ui)) or bpy.context.preferences.addons['rigify'].preferences.legacy_mode: | ||||
| bpy.context.preferences.addons['rigify'].preferences.legacy_mode = True | bpy.context.preferences.addons['rigify'].preferences.legacy_mode = True | ||||
| bpy.context.preferences.addons['rigify'].preferences.update_external_rigs() | bpy.context.preferences.addons['rigify'].preferences.update_external_rigs() | ||||
| # Add rig parameters | # Add rig parameters | ||||
| register_rig_parameters() | register_rig_parameters() | ||||
| def register_rig_parameters(): | def register_rig_parameters(): | ||||
| if bpy.context.preferences.addons['rigify'].preferences.legacy_mode: | if bpy.context.preferences.addons['rigify'].preferences.legacy_mode: | ||||
| for rig in rig_lists.rig_list: | for rig in rig_lists.rig_list: | ||||
| r = utils.get_rig_type(rig) | r = utils.get_rig_type(rig) | ||||
| try: | try: | ||||
| r.add_parameters(RigifyParameterValidator(RigifyParameters, rig, RIGIFY_PARAMETER_TABLE)) | r.add_parameters(RigifyParameterValidator(RigifyParameters, rig, RIGIFY_PARAMETER_TABLE)) | ||||
| except AttributeError: | except AttributeError: | ||||
| pass | pass | ||||
| else: | else: | ||||
| for rig in rig_lists.rigs: | for rig in rig_lists.rigs: | ||||
| r = rig_lists.rigs[rig]['module'] | rig_module = rig_lists.rigs[rig]['module'] | ||||
| rig_class = rig_module.Rig | |||||
| r = rig_class if hasattr(rig_class, 'add_parameters') else rig_module | |||||
| try: | try: | ||||
| r.add_parameters(RigifyParameterValidator(RigifyParameters, rig, RIGIFY_PARAMETER_TABLE)) | r.add_parameters(RigifyParameterValidator(RigifyParameters, rig, RIGIFY_PARAMETER_TABLE)) | ||||
| except AttributeError: | except Exception: | ||||
| pass | import traceback | ||||
| traceback.print_exc() | |||||
| def unregister(): | def unregister(): | ||||
| from bpy.utils import unregister_class | from bpy.utils import unregister_class | ||||
| # Properties on PoseBones and Armature. | # Properties on PoseBones and Armature. | ||||
| del bpy.types.PoseBone.rigify_type | del bpy.types.PoseBone.rigify_type | ||||
| del bpy.types.PoseBone.rigify_parameters | del bpy.types.PoseBone.rigify_parameters | ||||
| Show All 15 Lines | def unregister(): | ||||
| del IDStore.rigify_generate_mode | del IDStore.rigify_generate_mode | ||||
| del IDStore.rigify_force_widget_update | del IDStore.rigify_force_widget_update | ||||
| del IDStore.rigify_target_rig | del IDStore.rigify_target_rig | ||||
| del IDStore.rigify_target_rigs | del IDStore.rigify_target_rigs | ||||
| del IDStore.rigify_rig_uis | del IDStore.rigify_rig_uis | ||||
| del IDStore.rigify_rig_ui | del IDStore.rigify_rig_ui | ||||
| del IDStore.rigify_rig_basename | del IDStore.rigify_rig_basename | ||||
| del IDStore.rigify_transfer_only_selected | del IDStore.rigify_transfer_only_selected | ||||
| del IDStore.rigify_transfer_start_frame | |||||
| del IDStore.rigify_transfer_end_frame | |||||
| # Classes. | # Classes. | ||||
| for cls in classes: | for cls in classes: | ||||
| unregister_class(cls) | unregister_class(cls) | ||||
| clear_rigify_parameters() | clear_rigify_parameters() | ||||
| # Sub-modules. | # Sub-modules. | ||||
| metarig_menu.unregister() | metarig_menu.unregister() | ||||
| ui.unregister() | ui.unregister() | ||||
| feature_set_list.unregister() | feature_set_list.unregister() | ||||