Skip to content

Modular UI: driver namespaces and custom types #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: rigify_0.6_beta
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 1 addition & 17 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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)
Expand Down
38 changes: 25 additions & 13 deletions generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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

Expand Down
3 changes: 0 additions & 3 deletions metarig_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import bpy

from . import utils
from . import template_list


class ArmatureSubMenu(bpy.types.Menu):
Expand Down Expand Up @@ -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)

Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions rigs/limbs/arm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1549,4 +1549,4 @@ def create_sample(obj):


if __name__ == "__main__":
create_sample(bpy.context.active_object)
create_sample(bpy.context.active_object)
4 changes: 2 additions & 2 deletions rigs/limbs/leg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1577,4 +1577,4 @@ def create_sample(obj):


if __name__ == "__main__":
create_sample(bpy.context.active_object)
create_sample(bpy.context.active_object)
4 changes: 2 additions & 2 deletions rigs/limbs/paw.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1575,4 +1575,4 @@ def create_sample(obj):


if __name__ == "__main__":
create_sample(bpy.context.active_object)
create_sample(bpy.context.active_object)
68 changes: 0 additions & 68 deletions template_list.py

This file was deleted.

35 changes: 0 additions & 35 deletions ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"""

Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down