diff options
Diffstat (limited to 'release/scripts/modules/rigify/__init__.py')
-rw-r--r-- | release/scripts/modules/rigify/__init__.py | 109 |
1 files changed, 98 insertions, 11 deletions
diff --git a/release/scripts/modules/rigify/__init__.py b/release/scripts/modules/rigify/__init__.py index 262508c9a84..895afd20d59 100644 --- a/release/scripts/modules/rigify/__init__.py +++ b/release/scripts/modules/rigify/__init__.py @@ -12,7 +12,7 @@ # # 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # # ##### END GPL LICENSE BLOCK ##### @@ -29,7 +29,7 @@ LAYER_TYPES = "main", "extra", "ik", "fk" ORG_LAYERS = [n==31 for n in range(0,32)] MCH_LAYERS = [n==30 for n in range(0,32)] DEF_LAYERS = [n==29 for n in range(0,32)] -ROOT_LAYERS = [n==28 for n in range(0,32)] +ROOT_LAYERS = [n==28 for n in range(0,32)] ORG_PREFIX = "ORG-" MCH_PREFIX = "MCH-" @@ -155,6 +155,8 @@ def generate_rig(context, obj_orig, prefix="ORG-", META_DEF=True): import rigify_utils reload(rigify_utils) + print("Begin...") + # Not needed but catches any errors before duplicating validate_rig(context, obj_orig) @@ -164,24 +166,106 @@ def generate_rig(context, obj_orig, prefix="ORG-", META_DEF=True): rest_backup = obj_orig.data.pose_position obj_orig.data.pose_position = 'REST' - bpy.ops.object.mode_set(mode='OBJECT') scene = context.scene - # copy object and data + # Check if the generated rig already exists, so we can + # regenerate in the same object. If not, create a new + # object to generate the rig in. + print("Fetch rig.") + try: + name = obj_orig["rig_object_name"] + except KeyError: + name = "rig" + + try: + obj = scene.objects[name] + except KeyError: + obj = bpy.data.objects.new(name, bpy.data.armatures.new(name)) + scene.objects.link(obj) + + obj.data.pose_position = 'POSE' + + # Get rid of anim data in case the rig already existed + print("Clear rig animation data.") + obj.animation_data_clear() + + # Select generated rig object obj_orig.selected = False - obj = obj_orig.copy() - obj.data = obj_orig.data.copy() - scene.objects.link(obj) + obj.selected = True scene.objects.active = obj + + # Remove all bones from the generated rig armature. + bpy.ops.object.mode_set(mode='EDIT') + for bone in obj.data.edit_bones: + obj.data.edit_bones.remove(bone) + bpy.ops.object.mode_set(mode='OBJECT') + + # Create temporary duplicates for merging + temp_rig_1 = obj_orig.copy() + temp_rig_1.data = obj_orig.data.copy() + scene.objects.link(temp_rig_1) + + temp_rig_2 = obj_orig.copy() + temp_rig_2.data = obj.data + scene.objects.link(temp_rig_2) + + # Select the temp rigs for merging + for objt in scene.objects: + objt.selected = False # deselect all objects + temp_rig_1.selected = True + temp_rig_2.selected = True + scene.objects.active = temp_rig_2 + + # Merge the temporary rigs + bpy.ops.object.join(context) + + # Delete the second temp rig + bpy.ops.object.delete() + + # Select the generated rig + for objt in scene.objects: + objt.selected = False # deselect all objects obj.selected = True + scene.objects.active = obj + + # Copy over the pose_bone properties + for bone in obj_orig.pose.bones: + bone_gen = obj.pose.bones[bone.name] + + # Rotation mode and transform locks + bone_gen.rotation_mode = bone.rotation_mode + bone_gen.lock_rotation = tuple(bone.lock_rotation) + bone_gen.lock_rotation_w = bone.lock_rotation_w + bone_gen.lock_rotations_4d = bone.lock_rotations_4d + bone_gen.lock_location = tuple(bone.lock_location) + bone_gen.lock_scale = tuple(bone.lock_scale) + # Custom properties + for prop in bone.keys(): + bone_gen[prop] = bone[prop] + + # Copy over bone properties + for bone in obj_orig.data.bones: + bone_gen = obj.data.bones[bone.name] + + # B-bone stuff + bone_gen.bbone_segments = bone.bbone_segments + bone_gen.bbone_in = bone.bbone_in + bone_gen.bbone_out = bone.bbone_out + + + # Create proxy deformation rig + # TODO: remove this if META_DEF: obj_def = obj_orig.copy() obj_def.data = obj_orig.data.copy() scene.objects.link(obj_def) + scene.update() + print("On to the real work.") + arm = obj.data # prepend the ORG prefix to the bones, and create the base_names mapping @@ -255,7 +339,7 @@ def generate_rig(context, obj_orig, prefix="ORG-", META_DEF=True): # for pbone in obj.pose.bones: for pbone in bones_sorted: bone_name = pbone.name - + print(bone_name) if bone_name not in bone_typeinfos: continue @@ -268,6 +352,7 @@ def generate_rig(context, obj_orig, prefix="ORG-", META_DEF=True): bone_names_pre = {bone.name for bone in arm.bones} for type_name, type_func in bone_typeinfos[bone_name]: + print(" " + type_name) # this bones definition of the current typeinfo definition = bone_def_dict[type_name] options = get_bone_type_options(pbone, type_name) @@ -386,8 +471,11 @@ def generate_rig(context, obj_orig, prefix="ORG-", META_DEF=True): bpy.ops.object.mode_set(mode=mode_orig) obj_orig.data.pose_position = rest_backup obj.data.pose_position = 'POSE' + obj_orig.data.pose_position = 'POSE' context.user_preferences.edit.global_undo = global_undo + print("Done.\n") + return obj @@ -398,9 +486,8 @@ def generate_test(context, metarig_type="", GENERATE_FINAL=True): scene = context.scene def create_empty_armature(name): - obj_new = bpy.data.objects.new(name, 'ARMATURE') armature = bpy.data.armatures.new(name) - obj_new.data = armature + obj_new = bpy.data.objects.new(name, armature) scene.objects.link(obj_new) scene.objects.active = obj_new for obj in scene.objects: @@ -431,7 +518,7 @@ def generate_test(context, metarig_type="", GENERATE_FINAL=True): else: new_objects.append((obj, None)) else: - print("note: rig type '%s' has no metarig_template(), can't test this", module_name) + print("note: rig type '%s' has no metarig_template(), can't test this" % module_name) return new_objects |