diff --git a/__init__.py b/__init__.py index 1bff025..4344e56 100644 --- a/__init__.py +++ b/__init__.py @@ -37,11 +37,9 @@ importlib.reload(utils) importlib.reload(metarig_menu) importlib.reload(rig_lists) - importlib.reload(template_list) importlib.reload(feature_sets) else: - from . import (utils, rig_lists, template_list, - generate, ui, metarig_menu, feature_sets) + from . import (utils, rig_lists, generate, ui, metarig_menu, feature_sets) import bpy import sys @@ -139,10 +137,6 @@ def update_external_rigs(self): print('Reloading external metarigs...') metarig_menu.get_external_metarigs(feature_sets_path) - # Reload templates - print('Reloading external templates...') - template_list.get_external_templates(feature_sets_path) - legacy_mode = BoolProperty( name='Rigify Legacy Mode', description='Select if you want to use Rigify in legacy mode', @@ -260,10 +254,6 @@ class RigifySelectionColors(bpy.types.PropertyGroup): ) -class RigifyTemplate(bpy.types.PropertyGroup): - name = bpy.props.StringProperty() - - class RigifyParameters(bpy.types.PropertyGroup): name = bpy.props.StringProperty() @@ -349,7 +339,6 @@ def register(): metarig_menu.register() bpy.utils.register_class(RigifyName) - bpy.utils.register_class(RigifyTemplate) bpy.utils.register_class(RigifyParameters) bpy.utils.register_class(RigifyColorSet) @@ -444,8 +433,6 @@ def update_mode(self, context): # update legacy on restart or reload bpy.context.user_preferences.addons['rigify'].preferences.legacy_mode = True IDStore = bpy.types.Armature - IDStore.rigify_templates = bpy.props.CollectionProperty(type=RigifyTemplate) - IDStore.rigify_active_template = bpy.props.IntProperty(name="Rigify Active Template", description="The selected ui template", default=0) bpy.context.user_preferences.addons['rigify'].preferences.update_external_rigs() @@ -487,11 +474,8 @@ def unregister(): del IDStore.rigify_transfer_end_frame IDStore = bpy.types.Armature - del IDStore.rigify_templates - del IDStore.rigify_active_template bpy.utils.unregister_class(RigifyName) - bpy.utils.unregister_class(RigifyTemplate) bpy.utils.unregister_class(RigifyParameters) bpy.utils.unregister_class(RigifyColorSet) diff --git a/generate.py b/generate.py index c4afd88..3b1845b 100644 --- a/generate.py +++ b/generate.py @@ -33,7 +33,7 @@ from .utils import copy_attributes from .utils import gamma_correct from . import rig_lists -from . import template_list +from . import rig_ui_template RIG_MODULE = "rigs" ORG_LAYER = [n == 31 for n in range(0, 32)] # Armature layer that original bones should be moved to. @@ -341,17 +341,13 @@ def generate_rig(context, metarig): # Generate all the rigs. armature_store = context.armature - if len(template_list.templates) > 1: - template_name = armature_store.rigify_templates[armature_store.rigify_active_template].name - else: - template_name = 'rig_ui_template' - - template = template_list.templates[template_name] ui_scripts = [] - ui_imports = template.UI_IMPORTS.copy() - ui_utilities = template.UI_UTILITIES.copy() - ui_register = template.UI_REGISTER.copy() + ui_imports = rig_ui_template.UI_IMPORTS.copy() + ui_utilities = rig_ui_template.UI_UTILITIES.copy() + ui_register = rig_ui_template.UI_REGISTER.copy() + ui_register_drivers = [] + ui_register_props = [] noparent_bones = [] for rig in rigs: # Go into editmode in the rig armature @@ -369,6 +365,10 @@ def generate_rig(context, metarig): ui_utilities += scripts['utilities'] if 'register' in scripts: ui_register += scripts['register'] + if 'register_drivers' in scripts: + ui_register_drivers += scripts['register_drivers'] + if 'register_props' in scripts: + ui_register_props += scripts['register_props'] if 'noparent_bones' in scripts: noparent_bones += scripts['noparent_bones'] elif scripts is not None: @@ -504,20 +504,32 @@ def generate_rig(context, metarig): for s in OrderedDict.fromkeys(ui_imports): script.write(s + "\n") - script.write(template.UI_BASE_UTILITIES % rig_id) + script.write(rig_ui_template.UI_BASE_UTILITIES % rig_id) for s in OrderedDict.fromkeys(ui_utilities): script.write(s + "\n") - script.write(template.UI_SLIDERS) + script.write(rig_ui_template.UI_SLIDERS) for s in ui_scripts: script.write("\n " + s.replace("\n", "\n ") + "\n") - script.write(template.layers_ui(vis_layers, layer_layout)) + script.write(rig_ui_template.layers_ui(vis_layers, layer_layout)) + script.write("\ndef register():\n") ui_register = OrderedDict.fromkeys(ui_register) for s in ui_register: script.write(" bpy.utils.register_class("+s+");\n") + ui_register_drivers = OrderedDict.fromkeys(ui_register_drivers) + for s in ui_register_drivers: + script.write(" bpy.app.driver_namespace['"+s+"'] = "+s+"\n") + ui_register_props = OrderedDict.fromkeys(ui_register_props) + for s in ui_register_props: + script.write(" bpy.types.%s = %s\n " % (*s,)) + script.write("\ndef unregister():\n") + for s in ui_register_props: + script.write(" del bpy.types.%s\n" % s[0]) for s in ui_register: script.write(" bpy.utils.unregister_class("+s+");\n") + for s in ui_register_drivers: + script.write(" del bpy.app.driver_namespace['"+s+"']\n") script.write("\nregister()\n") script.use_module = True diff --git a/metarig_menu.py b/metarig_menu.py index 12615df..af68293 100644 --- a/metarig_menu.py +++ b/metarig_menu.py @@ -25,7 +25,6 @@ import bpy from . import utils -from . import template_list class ArmatureSubMenu(bpy.types.Menu): @@ -90,8 +89,6 @@ def execute(self, context): bones = context.active_object.data.edit_bones bones.remove(bones[0]) - template_list.fill_ui_template_list(obj) - # Create metarig m.create(obj) diff --git a/ui_templates/rig_ui_template.py b/rig_ui_template.py similarity index 100% rename from ui_templates/rig_ui_template.py rename to rig_ui_template.py diff --git a/rigs/limbs/arm.py b/rigs/limbs/arm.py index 8092914..a2b45ca 100644 --- a/rigs/limbs/arm.py +++ b/rigs/limbs/arm.py @@ -9,7 +9,7 @@ from ...utils import make_mechanism_name from ...utils import create_limb_widget, connected_children_names from ...utils import align_bone_x_axis, align_bone_z_axis -from ...ui_templates.rig_ui_template import UTILITIES_RIG_ARM, REGISTER_RIG_ARM +from ...rig_ui_template import UTILITIES_RIG_ARM, REGISTER_RIG_ARM from ...utils import ControlLayersOption from rna_prop_ui import rna_idprop_ui_prop_get from ..widgets import create_ikarrow_widget @@ -1549,4 +1549,4 @@ def create_sample(obj): if __name__ == "__main__": - create_sample(bpy.context.active_object) \ No newline at end of file + create_sample(bpy.context.active_object) diff --git a/rigs/limbs/leg.py b/rigs/limbs/leg.py index b6944d3..1c3819c 100644 --- a/rigs/limbs/leg.py +++ b/rigs/limbs/leg.py @@ -10,7 +10,7 @@ from ...utils import MetarigError, make_mechanism_name from ...utils import create_limb_widget, connected_children_names from ...utils import align_bone_y_axis, align_bone_x_axis, align_bone_z_axis -from ...ui_templates.rig_ui_template import UTILITIES_RIG_LEG, REGISTER_RIG_LEG +from ...rig_ui_template import UTILITIES_RIG_LEG, REGISTER_RIG_LEG from ...utils import ControlLayersOption from rna_prop_ui import rna_idprop_ui_prop_get from ..widgets import create_ikarrow_widget @@ -1577,4 +1577,4 @@ def create_sample(obj): if __name__ == "__main__": - create_sample(bpy.context.active_object) \ No newline at end of file + create_sample(bpy.context.active_object) diff --git a/rigs/limbs/paw.py b/rigs/limbs/paw.py index 54ee992..54ac7ab 100644 --- a/rigs/limbs/paw.py +++ b/rigs/limbs/paw.py @@ -8,7 +8,7 @@ from ...utils import MetarigError, make_mechanism_name from ...utils import create_limb_widget, connected_children_names from ...utils import align_bone_x_axis, align_bone_z_axis -from ...ui_templates.rig_ui_template import UTILITIES_RIG_LEG, REGISTER_RIG_LEG +from ...rig_ui_template import UTILITIES_RIG_LEG, REGISTER_RIG_LEG from ...utils import ControlLayersOption from rna_prop_ui import rna_idprop_ui_prop_get from ..widgets import create_ikarrow_widget, create_gear_widget @@ -1575,4 +1575,4 @@ def create_sample(obj): if __name__ == "__main__": - create_sample(bpy.context.active_object) \ No newline at end of file + create_sample(bpy.context.active_object) diff --git a/template_list.py b/template_list.py deleted file mode 100644 index 9315887..0000000 --- a/template_list.py +++ /dev/null @@ -1,68 +0,0 @@ -#====================== BEGIN GPL LICENSE BLOCK ====================== -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software Foundation, -# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -# -#======================= END GPL LICENSE BLOCK ======================== - -import os - -from . import utils - - -def get_templates(base_path, path): - """ Searches for template types, and returns a list. - """ - templates = {} - - files = os.listdir(os.path.join(base_path, path)) - files.sort() - - for f in files: - if f.endswith(".py"): - f = f[:-3] - module_name = os.path.join(path, f).replace(os.sep, ".") - template = utils.get_resource(module_name, base_path=base_path) - templates[f] = template - return templates - - -def fill_ui_template_list(obj): - """Fill rig's UI template list - """ - armature = obj.data - for i in range(0, len(armature.rigify_templates)): - armature.rigify_templates.remove(0) - - for t in templates: - a = armature.rigify_templates.add() - a.name = t - - -# Public variables -MODULE_DIR = os.path.dirname(os.path.dirname(__file__)) - -templates = get_templates(MODULE_DIR, os.path.join(os.path.basename(os.path.dirname(__file__)), utils.TEMPLATE_DIR, '')) - - -def get_external_templates(feature_sets_path): - # Clear and get internal templates - templates.clear() - templates.update(get_templates(MODULE_DIR, os.path.join(os.path.basename(os.path.dirname(__file__)), utils.TEMPLATE_DIR, ''))) - - # Get external templates - for feature_set in os.listdir(feature_sets_path): - if feature_set: - external_templates_list = get_templates(feature_sets_path, os.path.join(feature_set, utils.TEMPLATE_DIR)) - templates.update(external_templates_list) diff --git a/ui.py b/ui.py index 05187db..c05eaab 100644 --- a/ui.py +++ b/ui.py @@ -30,7 +30,6 @@ from .utils import overwrite_prop_animation from .rigs.utils import get_limb_generated_names from . import rig_lists -from . import template_list from . import generate from . import rot_mode from . import feature_sets @@ -47,16 +46,6 @@ def build_type_list(context, rigify_types): a.name = r -class DATA_UL_rigify_template_list(bpy.types.UIList): - """UIList subclass, to disable renaming in UI""" - def draw_item(self, context, layout, data, item, icon, active_data, active_propname): - ob = data - template = item - if template: - layout.label(text=template.name, translate=False, icon_value=icon) - else: - layout.label(text="", translate=False, icon_value=icon) - class DATA_PT_rigify_buttons(bpy.types.Panel): bl_label = "Rigify Buttons" bl_space_type = 'PROPERTIES' @@ -119,16 +108,9 @@ def draw(self, context): col = layout.column(align=True) col.active = (not 'rig_id' in C.object.data) - if len(template_list.templates) > 1: - if len(context.object.data.rigify_templates) == 0: - col.operator("pose.rigify_template_init") - else: - col.label("UI template for rig:") - col.template_list("DATA_UL_rigify_template_list", "rigify_templates", armature_id_store, "rigify_templates", armature_id_store, "rigify_active_template") col.separator() row = col.row() - row.active = len(context.object.data.rigify_templates) != 0 or len(template_list.templates) == 1 row.operator("pose.rigify_generate", text="Generate Rig", icon='POSE_HLT') row.enabled = enable_generate_and_advanced @@ -200,7 +182,6 @@ def draw(self, context): row = layout.row() row.prop(context.object.data, "active_feature_set") row = layout.row() - 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.metarig_type = id_store.rigify_types[id_store.rigify_active_type].name @@ -748,18 +729,6 @@ def execute(self, context): return {'FINISHED'} -class TemplateInit(bpy.types.Operator): - """Initialize armature rigify ui templates""" - - bl_idname = "pose.rigify_template_init" - bl_label = "Add Rigify UI Templates" - bl_options = {'UNDO'} - - def execute(self, context): - template_list.fill_ui_template_list(context.object) - return {'FINISHED'} - - class Generate(bpy.types.Operator): """Generates a rig from the active metarig armature""" @@ -1337,7 +1306,6 @@ def execute(self, context): def register(): - bpy.utils.register_class(DATA_UL_rigify_template_list) bpy.utils.register_class(DATA_OT_rigify_add_bone_groups) bpy.utils.register_class(DATA_OT_rigify_use_standard_colors) bpy.utils.register_class(DATA_OT_rigify_apply_selection_colors) @@ -1354,7 +1322,6 @@ def register(): 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(TemplateInit) bpy.utils.register_class(Generate) bpy.utils.register_class(UpgradeMetarigTypes) bpy.utils.register_class(SwitchToLegacy) @@ -1375,7 +1342,6 @@ def register(): def unregister(): - bpy.utils.unregister_class(DATA_UL_rigify_template_list) bpy.utils.unregister_class(DATA_OT_rigify_add_bone_groups) bpy.utils.unregister_class(DATA_OT_rigify_use_standard_colors) bpy.utils.unregister_class(DATA_OT_rigify_apply_selection_colors) @@ -1392,7 +1358,6 @@ def unregister(): 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(TemplateInit) bpy.utils.unregister_class(Generate) bpy.utils.unregister_class(UpgradeMetarigTypes) bpy.utils.unregister_class(SwitchToLegacy)