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), | "version": (0, 5), | ||||
| "author": "Nathan Vegdahl, Lucio Rossi, Ivan Cappiello", | "author": "Nathan Vegdahl, Lucio Rossi, Ivan Cappiello", | ||||
| "blender": (2, 78, 0), | "blender": (2, 79, 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) | importlib.reload(generate) | ||||
| importlib.reload(ui) | importlib.reload(ui) | ||||
| importlib.reload(utils) | importlib.reload(utils) | ||||
| importlib.reload(metarig_menu) | importlib.reload(metarig_menu) | ||||
| importlib.reload(rig_lists) | importlib.reload(rig_lists) | ||||
| else: | else: | ||||
| from . import utils, rig_lists, generate, ui, metarig_menu | from . import utils, 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 BoolProperty | from bpy.props import ( | ||||
| BoolProperty, | |||||
| IntProperty, | |||||
| EnumProperty, | |||||
| StringProperty, | |||||
| FloatVectorProperty, | |||||
| PointerProperty, | |||||
| CollectionProperty, | |||||
| ) | |||||
| class RigifyPreferences(AddonPreferences): | class RigifyPreferences(AddonPreferences): | ||||
| # this must match the addon name, use '__package__' | # this must match the addon name, use '__package__' | ||||
| # when defining this in a submodule of a python package. | # when defining this in a submodule of a python package. | ||||
| bl_idname = __name__ | bl_idname = __name__ | ||||
| def update_legacy(self, context): | def update_legacy(self, context): | ||||
| ▲ Show 20 Lines • Show All 57 Lines • ▼ Show 20 Lines | def update_legacy(self, context): | ||||
| globals()['utils'] = utils | globals()['utils'] = utils | ||||
| globals()['rig_lists'] = rig_lists | globals()['rig_lists'] = rig_lists | ||||
| globals()['generate'] = generate | globals()['generate'] = generate | ||||
| globals()['ui'] = ui | globals()['ui'] = ui | ||||
| globals()['metarig_menu'] = metarig_menu | globals()['metarig_menu'] = metarig_menu | ||||
| register() | register() | ||||
| legacy_mode = BoolProperty( | legacy_mode: BoolProperty( | ||||
| name='Rigify Legacy Mode', | name='Rigify Legacy Mode', | ||||
| description='Select if you want to use Rigify in legacy mode', | description='Select if you want to use Rigify in legacy mode', | ||||
| default=False, | default=False, | ||||
| update=update_legacy | update=update_legacy | ||||
| ) | ) | ||||
| show_expanded: BoolProperty() | |||||
| show_expanded = BoolProperty() | |||||
| def draw(self, context): | def draw(self, context): | ||||
| layout = self.layout | layout = self.layout | ||||
| column = layout.column() | column = layout.column() | ||||
| box = column.box() | box = column.box() | ||||
| # first stage | # first stage | ||||
| expand = getattr(self, 'show_expanded') | expand = getattr(self, 'show_expanded') | ||||
| Show All 16 Lines | def draw(self, context): | ||||
| split.label('Description:') | split.label('Description:') | ||||
| split.label(text='When enabled the add-on will run in legacy mode using the old 2.76b feature set.') | split.label(text='When enabled the add-on will run in legacy mode using the old 2.76b feature set.') | ||||
| row = layout.row() | row = layout.row() | ||||
| row.label("End of Rigify Preferences") | row.label("End of Rigify Preferences") | ||||
| class RigifyName(bpy.types.PropertyGroup): | class RigifyName(bpy.types.PropertyGroup): | ||||
| name = bpy.props.StringProperty() | name: StringProperty() | ||||
| class RigifyColorSet(bpy.types.PropertyGroup): | class RigifyColorSet(bpy.types.PropertyGroup): | ||||
| name = bpy.props.StringProperty(name="Color Set", default=" ") | name: StringProperty(name="Color Set", default=" ") | ||||
| active = bpy.props.FloatVectorProperty( | active: FloatVectorProperty( | ||||
| name="object_color", | name="object_color", | ||||
| subtype='COLOR', | subtype='COLOR', | ||||
| default=(1.0, 1.0, 1.0), | default=(1.0, 1.0, 1.0), | ||||
| min=0.0, max=1.0, | min=0.0, max=1.0, | ||||
| description="color picker" | description="color picker" | ||||
| ) | ) | ||||
| normal = bpy.props.FloatVectorProperty( | normal: FloatVectorProperty( | ||||
| name="object_color", | name="object_color", | ||||
| subtype='COLOR', | subtype='COLOR', | ||||
| default=(1.0, 1.0, 1.0), | default=(1.0, 1.0, 1.0), | ||||
| min=0.0, max=1.0, | min=0.0, max=1.0, | ||||
| description="color picker" | description="color picker" | ||||
| ) | ) | ||||
| select = bpy.props.FloatVectorProperty( | select: FloatVectorProperty( | ||||
| name="object_color", | name="object_color", | ||||
| subtype='COLOR', | subtype='COLOR', | ||||
| default=(1.0, 1.0, 1.0), | default=(1.0, 1.0, 1.0), | ||||
| min=0.0, max=1.0, | min=0.0, max=1.0, | ||||
| description="color picker" | description="color picker" | ||||
| ) | ) | ||||
| standard_colors_lock = bpy.props.BoolProperty(default=True) | standard_colors_lock: BoolProperty(default=True) | ||||
| class RigifySelectionColors(bpy.types.PropertyGroup): | class RigifySelectionColors(bpy.types.PropertyGroup): | ||||
| select = bpy.props.FloatVectorProperty( | select: FloatVectorProperty( | ||||
| name="object_color", | name="object_color", | ||||
| subtype='COLOR', | subtype='COLOR', | ||||
| default=(0.314, 0.784, 1.0), | default=(0.314, 0.784, 1.0), | ||||
| min=0.0, max=1.0, | min=0.0, max=1.0, | ||||
| description="color picker" | description="color picker" | ||||
| ) | ) | ||||
| active = bpy.props.FloatVectorProperty( | active: FloatVectorProperty( | ||||
| name="object_color", | name="object_color", | ||||
| subtype='COLOR', | subtype='COLOR', | ||||
| default=(0.549, 1.0, 1.0), | default=(0.549, 1.0, 1.0), | ||||
| 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 = bpy.props.StringProperty() | name: StringProperty() | ||||
| 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(): | ||||
| return self['group_prop'] | return self['group_prop'] | ||||
| else: | else: | ||||
| return 0 | return 0 | ||||
| def set_group(self, value): | def set_group(self, value): | ||||
| arm = bpy.context.object.data | arm = bpy.context.object.data | ||||
| if value > len(arm.rigify_colors): | if value > len(arm.rigify_colors): | ||||
| self['group_prop'] = len(arm.rigify_colors) | self['group_prop'] = len(arm.rigify_colors) | ||||
| else: | else: | ||||
| self['group_prop'] = value | self['group_prop'] = value | ||||
| name = bpy.props.StringProperty(name="Layer Name", default=" ") | name: StringProperty(name="Layer Name", default=" ") | ||||
| row = bpy.props.IntProperty(name="Layer Row", default=1, min=1, max=32, description='UI row for this layer') | row: IntProperty(name="Layer Row", default=1, min=1, max=32, description='UI row for this layer') | ||||
| set = bpy.props.BoolProperty(name="Selection Set", default=False, description='Add Selection Set for this layer') | selset: BoolProperty(name="Selection Set", default=False, description='Add Selection Set for this layer') | ||||
| group = bpy.props.IntProperty(name="Bone Group", default=0, min=0, max=32, | group: IntProperty(name="Bone Group", default=0, min=0, max=32, | ||||
| get=get_group, set=set_group, description='Assign Bone Group to this layer') | get=get_group, set=set_group, description='Assign Bone Group to this layer') | ||||
| ##### REGISTER ##### | ##### REGISTER ##### | ||||
| classes = ( | |||||
| RigifyName, | |||||
| RigifyParameters, | |||||
| RigifyColorSet, | |||||
| RigifySelectionColors, | |||||
| RigifyArmatureLayer, | |||||
| RigifyPreferences, | |||||
| ) | |||||
| def register(): | def register(): | ||||
| from bpy.utils import register_class | |||||
| # Sub-modules. | |||||
| ui.register() | ui.register() | ||||
| metarig_menu.register() | metarig_menu.register() | ||||
| bpy.utils.register_class(RigifyName) | # Classes. | ||||
| bpy.utils.register_class(RigifyParameters) | for cls in classes: | ||||
| register_class(cls) | |||||
| bpy.utils.register_class(RigifyColorSet) | # Properties. | ||||
| bpy.utils.register_class(RigifySelectionColors) | bpy.types.Armature.rigify_layers = CollectionProperty(type=RigifyArmatureLayer) | ||||
| bpy.utils.register_class(RigifyArmatureLayer) | |||||
| bpy.utils.register_class(RigifyPreferences) | |||||
| bpy.types.Armature.rigify_layers = bpy.props.CollectionProperty(type=RigifyArmatureLayer) | |||||
| bpy.types.PoseBone.rigify_type = bpy.props.StringProperty(name="Rigify Type", description="Rig type for this bone") | bpy.types.PoseBone.rigify_type = StringProperty(name="Rigify Type", description="Rig type for this bone") | ||||
| bpy.types.PoseBone.rigify_parameters = bpy.props.PointerProperty(type=RigifyParameters) | bpy.types.PoseBone.rigify_parameters = PointerProperty(type=RigifyParameters) | ||||
| bpy.types.Armature.rigify_colors = bpy.props.CollectionProperty(type=RigifyColorSet) | bpy.types.Armature.rigify_colors = CollectionProperty(type=RigifyColorSet) | ||||
| bpy.types.Armature.rigify_selection_colors = bpy.props.PointerProperty(type=RigifySelectionColors) | bpy.types.Armature.rigify_selection_colors = PointerProperty(type=RigifySelectionColors) | ||||
| bpy.types.Armature.rigify_colors_index = bpy.props.IntProperty(default=-1) | bpy.types.Armature.rigify_colors_index = IntProperty(default=-1) | ||||
| bpy.types.Armature.rigify_colors_lock = bpy.props.BoolProperty(default=True) | bpy.types.Armature.rigify_colors_lock = BoolProperty(default=True) | ||||
| bpy.types.Armature.rigify_theme_to_add = bpy.props.EnumProperty(items=(('THEME01', 'THEME01', ''), | bpy.types.Armature.rigify_theme_to_add = 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') | ||||
| IDStore = bpy.types.WindowManager | IDStore = bpy.types.WindowManager | ||||
| IDStore.rigify_collection = bpy.props.EnumProperty(items=rig_lists.col_enum_list, default="All", | IDStore.rigify_collection = EnumProperty(items=rig_lists.col_enum_list, default="All", | ||||
| name="Rigify Active Collection", | name="Rigify Active Collection", | ||||
| description="The selected rig collection") | description="The selected rig collection") | ||||
| IDStore.rigify_types = bpy.props.CollectionProperty(type=RigifyName) | IDStore.rigify_types = CollectionProperty(type=RigifyName) | ||||
| IDStore.rigify_active_type = bpy.props.IntProperty(name="Rigify Active Type", description="The selected rig type") | IDStore.rigify_active_type = IntProperty(name="Rigify Active Type", description="The selected rig type") | ||||
| IDStore.rigify_advanced_generation = bpy.props.BoolProperty(name="Advanced Options", | IDStore.rigify_advanced_generation = BoolProperty(name="Advanced Options", | ||||
| description="Enables/disables advanced options for Rigify rig generation", | description="Enables/disables advanced options for Rigify rig generation", | ||||
| default=False) | default=False) | ||||
| def update_mode(self, context): | def update_mode(self, context): | ||||
| if self.rigify_generate_mode == 'new': | if self.rigify_generate_mode == 'new': | ||||
| self.rigify_force_widget_update = False | self.rigify_force_widget_update = False | ||||
| IDStore.rigify_generate_mode = bpy.props.EnumProperty(name="Rigify Generate Rig Mode", | IDStore.rigify_generate_mode = EnumProperty(name="Rigify Generate Rig Mode", | ||||
| description="'Generate Rig' mode. In 'overwrite' mode the features of the target rig will be updated as defined by the metarig. In 'new' mode a new rig will be created as defined by the metarig. Current mode", | description="'Generate Rig' mode. In 'overwrite' mode the features of the target rig will be updated as defined by the metarig. In 'new' mode a new rig will be created as defined by the metarig. Current mode", | ||||
| update=update_mode, | update=update_mode, | ||||
| items=(('overwrite', 'overwrite', ''), | items=( ('overwrite', 'overwrite', ''), | ||||
| ('new', 'new', ''))) | ('new', 'new', ''))) | ||||
| IDStore.rigify_force_widget_update = bpy.props.BoolProperty(name="Force Widget Update", | IDStore.rigify_force_widget_update = BoolProperty(name="Force Widget Update", | ||||
| description="Forces Rigify to delete and rebuild all the rig widgets. if unset, only missing widgets will be created", | description="Forces Rigify to delete and rebuild all the rig widgets. if unset, only missing widgets will be created", | ||||
| default=False) | default=False) | ||||
| IDStore.rigify_target_rigs = bpy.props.CollectionProperty(type=RigifyName) | IDStore.rigify_target_rigs = CollectionProperty(type=RigifyName) | ||||
| IDStore.rigify_target_rig = bpy.props.StringProperty(name="Rigify Target Rig", | IDStore.rigify_target_rig = StringProperty(name="Rigify Target Rig", | ||||
| description="Defines which rig to overwrite. If unset, a new one called 'rig' will be created", | description="Defines which rig to overwrite. If unset, a new one called 'rig' will be created", | ||||
| default="") | default="") | ||||
| IDStore.rigify_rig_uis = bpy.props.CollectionProperty(type=RigifyName) | IDStore.rigify_rig_uis = CollectionProperty(type=RigifyName) | ||||
| IDStore.rigify_rig_ui = bpy.props.StringProperty(name="Rigify Target Rig UI", | IDStore.rigify_rig_ui = StringProperty(name="Rigify Target Rig UI", | ||||
| description="Defines the UI to overwrite. It should always be the same as the target rig. If unset, 'rig_ui.py' will be used", | description="Defines the UI to overwrite. It should always be the same as the target rig. If unset, 'rig_ui.py' will be used", | ||||
| default="") | default="") | ||||
| IDStore.rigify_rig_basename = bpy.props.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 = bpy.props.BoolProperty(name="Transfer Only Selected", description="Transfer selected bones only", default=True) | IDStore.rigify_transfer_only_selected = BoolProperty( | ||||
| IDStore.rigify_transfer_start_frame = bpy.props.IntProperty(name="Start Frame", description="First Frame to Transfer", default=0, min= 0) | name="Transfer Only Selected", | ||||
| IDStore.rigify_transfer_end_frame = bpy.props.IntProperty(name="End Frame", description="Last Frame to Transfer", default=0, min= 0) | 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. | |||||
| if (ui and 'legacy' in str(ui)) or bpy.context.user_preferences.addons['rigify'].preferences.legacy_mode: | if (ui and 'legacy' in str(ui)) or bpy.context.user_preferences.addons['rigify'].preferences.legacy_mode: | ||||
| # update legacy on restart or reload | |||||
| bpy.context.user_preferences.addons['rigify'].preferences.legacy_mode = True | bpy.context.user_preferences.addons['rigify'].preferences.legacy_mode = True | ||||
| # Add rig parameters | # Add rig parameters | ||||
| 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(RigifyParameters) | r.add_parameters(RigifyParameters) | ||||
| except AttributeError: | except AttributeError: | ||||
| pass | pass | ||||
| def unregister(): | def unregister(): | ||||
| from bpy.utils import unregister_class | |||||
| # Properties. | |||||
| del bpy.types.PoseBone.rigify_type | del bpy.types.PoseBone.rigify_type | ||||
| del bpy.types.PoseBone.rigify_parameters | del bpy.types.PoseBone.rigify_parameters | ||||
| IDStore = bpy.types.WindowManager | IDStore = bpy.types.WindowManager | ||||
| del IDStore.rigify_collection | del IDStore.rigify_collection | ||||
| del IDStore.rigify_types | del IDStore.rigify_types | ||||
| del IDStore.rigify_active_type | del IDStore.rigify_active_type | ||||
| del IDStore.rigify_advanced_generation | del IDStore.rigify_advanced_generation | ||||
| 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_start_frame | ||||
| del IDStore.rigify_transfer_end_frame | del IDStore.rigify_transfer_end_frame | ||||
| bpy.utils.unregister_class(RigifyName) | # Classes. | ||||
| bpy.utils.unregister_class(RigifyParameters) | for cls in classes: | ||||
| unregister_class(cls) | |||||
| bpy.utils.unregister_class(RigifyColorSet) | |||||
| bpy.utils.unregister_class(RigifySelectionColors) | |||||
| bpy.utils.unregister_class(RigifyArmatureLayer) | |||||
| bpy.utils.unregister_class(RigifyPreferences) | |||||
| # Sub-modules. | |||||
| metarig_menu.unregister() | metarig_menu.unregister() | ||||
| ui.unregister() | ui.unregister() | ||||