From f36789d8bc728bc7ec3c9738f1ca76e8f017ce7a Mon Sep 17 00:00:00 2001 From: Lucio Rossi Date: Sun, 14 May 2017 18:30:06 +0200 Subject: Rigify 0.5 with legacy mode --- rigify/generate.py | 80 ++++++++++++++++++++++++++---------------------------- 1 file changed, 39 insertions(+), 41 deletions(-) (limited to 'rigify/generate.py') diff --git a/rigify/generate.py b/rigify/generate.py index e519c13b..3fe4e3b8 100644 --- a/rigify/generate.py +++ b/rigify/generate.py @@ -32,7 +32,6 @@ from .utils import create_root_widget from .utils import random_id from .utils import copy_attributes from .rig_ui_template import UI_SLIDERS, layers_ui, UI_REGISTER -from .rig_ui_pitchipoy_template import UI_P_SLIDERS, layers_P_ui, UI_P_REGISTER RIG_MODULE = "rigs" @@ -258,11 +257,24 @@ def generate_rig(context, metarig): obj.data.edit_bones[root_bone].roll = 0 bpy.ops.object.mode_set(mode='OBJECT') obj.data.bones[root_bone].layers = ROOT_LAYER + # Put the rig_name in the armature custom properties rna_idprop_ui_prop_get(obj.data, "rig_id", create=True) obj.data["rig_id"] = rig_id t.tick("Create root bone: ") + + # Create Group widget + wgts_group_name = "WGTS" + if wgts_group_name not in scene.objects: + if wgts_group_name in bpy.data.objects: + bpy.data.objects[wgts_group_name].user_clear() + bpy.data.objects.remove(bpy.data.objects[wgts_group_name]) + mesh = bpy.data.meshes.new(wgts_group_name) + wgts_obj = bpy.data.objects.new(wgts_group_name, mesh) + scene.objects.link(wgts_obj) + t.tick("Create main WGTS: ") + #---------------------------------- try: # Collect/initialize all the rigs. @@ -302,10 +314,23 @@ def generate_rig(context, metarig): # Parent any free-floating bones to the root excluding bones with child of constraint. pbones = obj.pose.bones + + + ik_follow_drivers = [] + + if obj.animation_data: + for drv in obj.animation_data.drivers: + for var in drv.driver.variables: + if 'IK_follow' == var.name: + ik_follow_drivers.append(drv.data_path) + noparent_bones = [] for bone in bones: - if 'IK_follow' in pbones[bone].keys(): - noparent_bones += [bone] + # if 'IK_follow' in pbones[bone].keys(): + # noparent_bones += [bone] + for d in ik_follow_drivers: + if bone in d: + noparent_bones += [bone] bpy.ops.object.mode_set(mode='EDIT') for bone in bones: @@ -396,35 +421,18 @@ def generate_rig(context, metarig): print( l.name ) layer_layout += [(l.name, l.row)] - - if isPitchipoy(metarig): - - # Generate the UI Pitchipoy script - if "rig_ui.py" in bpy.data.texts: - script = bpy.data.texts["rig_ui.py"] - script.clear() - else: - script = bpy.data.texts.new("rig_ui.py") - script.write(UI_P_SLIDERS % rig_id) - for s in ui_scripts: - script.write("\n " + s.replace("\n", "\n ") + "\n") - script.write(layers_P_ui(vis_layers, layer_layout)) - script.write(UI_P_REGISTER) - script.use_module = True - + # Generate the UI script + if "rig_ui.py" in bpy.data.texts: + script = bpy.data.texts["rig_ui.py"] + script.clear() else: - # Generate the UI script - if "rig_ui.py" in bpy.data.texts: - script = bpy.data.texts["rig_ui.py"] - script.clear() - else: - script = bpy.data.texts.new("rig_ui.py") - script.write(UI_SLIDERS % rig_id) - for s in ui_scripts: - script.write("\n " + s.replace("\n", "\n ") + "\n") - script.write(layers_ui(vis_layers, layer_layout)) - script.write(UI_REGISTER) - script.use_module = True + script = bpy.data.texts.new("rig_ui.py") + script.write(UI_SLIDERS % rig_id) + for s in ui_scripts: + script.write("\n " + s.replace("\n", "\n ") + "\n") + script.write(layers_ui(vis_layers, layer_layout)) + script.write(UI_REGISTER) + script.use_module = True # Run UI script exec(script.as_string(), {}) @@ -479,13 +487,3 @@ def param_name(param_name, rig_type): """ Get the actual parameter name, sans-rig-type. """ return param_name[len(rig_type) + 1:] - -def isPitchipoy(metarig): - """ Returns True if metarig is type pitchipoy. - """ - pbones=metarig.pose.bones - for pb in pbones: - words = pb.rigify_type.partition('.') - if words[0] == 'pitchipoy': - return True - return False \ No newline at end of file -- cgit v1.2.3