diff options
author | Dalai Felinto <dfelinto@gmail.com> | 2018-10-22 18:13:13 +0300 |
---|---|---|
committer | Dalai Felinto <dfelinto@gmail.com> | 2018-10-22 19:24:10 +0300 |
commit | 816407649aedfaa7836e3aca7629842db732e279 (patch) | |
tree | 201c08308821382d6847f10a0c03902faeb88870 /rigify | |
parent | 0e0e8de0de6022c23729e2d139b9aa47324d7122 (diff) |
Rigify: More updates for 2.8 API
With those changes the addon is working in some functional state.
Thus I'm bumping its version to 2.80.
TODOS:
* Handle collections (put all the new objects in a collection).
* We should also replace the old WGT_LAYERS with subcollections.
* Move toolshelf operators out of there (make tools or move to sidebar).
Diffstat (limited to 'rigify')
-rw-r--r-- | rigify/__init__.py | 2 | ||||
-rw-r--r-- | rigify/generate.py | 57 | ||||
-rw-r--r-- | rigify/legacy/generate.py | 32 | ||||
-rw-r--r-- | rigify/legacy/rigs/pitchipoy/limbs/limb_utils.py | 4 | ||||
-rw-r--r-- | rigify/legacy/rigs/pitchipoy/super_torso_turbo.py | 4 | ||||
-rw-r--r-- | rigify/legacy/utils.py | 5 | ||||
-rw-r--r-- | rigify/rig_ui_template.py | 28 | ||||
-rw-r--r-- | rigify/rigs/experimental/super_chain.py | 4 | ||||
-rw-r--r-- | rigify/rigs/limbs/limb_utils.py | 4 | ||||
-rw-r--r-- | rigify/rigs/spines/super_spine.py | 4 | ||||
-rw-r--r-- | rigify/utils.py | 7 |
11 files changed, 82 insertions, 69 deletions
diff --git a/rigify/__init__.py b/rigify/__init__.py index f4504c79..3c0efdfd 100644 --- a/rigify/__init__.py +++ b/rigify/__init__.py @@ -22,7 +22,7 @@ bl_info = { "name": "Rigify", "version": (0, 5), "author": "Nathan Vegdahl, Lucio Rossi, Ivan Cappiello", - "blender": (2, 79, 0), + "blender": (2, 80, 0), "description": "Automatic rigging from building-block components", "location": "Armature properties, Bone properties, View3d tools panel, Armature Add menu", "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.5/Py/" diff --git a/rigify/generate.py b/rigify/generate.py index 12ba51ce..9d0d6051 100644 --- a/rigify/generate.py +++ b/rigify/generate.py @@ -72,6 +72,8 @@ def generate_rig(context, metarig): bpy.ops.object.mode_set(mode='OBJECT') scene = context.scene + view_layer = context.view_layer + collection = scene.collection id_store = context.window_manager #------------------------------------------ # Create/find the rig object and set it up @@ -97,12 +99,12 @@ def generate_rig(context, metarig): name = rig_new_name or name obj = bpy.data.objects.new(name, bpy.data.armatures.new(name)) obj.display_type = 'WIRE' - scene.objects.link(obj) + collection.objects.link(obj) else: name = rig_new_name or "rig" obj = bpy.data.objects.new(name, bpy.data.armatures.new(name)) # in case name 'rig' exists it will be rig.001 obj.display_type = 'WIRE' - scene.objects.link(obj) + collection.objects.link(obj) id_store.rigify_target_rig = obj.name obj.data.pose_position = 'POSE' @@ -112,23 +114,29 @@ def generate_rig(context, metarig): obj.animation_data_clear() # Select generated rig object - metarig.select = False - obj.select = True - scene.objects.active = obj + metarig.select_set('DESELECT') + obj.select_set('SELECT') + view_layer.objects.active = obj # Remove wgts if force update is set wgts_group_name = "WGTS_" + (rig_old_name or obj.name) if wgts_group_name in scene.objects and id_store.rigify_force_widget_update: bpy.ops.object.select_all(action='DESELECT') + # TODO handle collections visibility WGT_LAYERS + """ for i, lyr in enumerate(WGT_LAYERS): if lyr: context.scene.layers[i] = True + """ for wgt in bpy.data.objects[wgts_group_name].children: - wgt.select = True + wgt.select_set('SELECT') bpy.ops.object.delete(use_global=False) + # TODO handle collections visibility WGT_LAYERS + """ for i, lyr in enumerate(WGT_LAYERS): if lyr: context.scene.layers[i] = False + """ if rig_old_name: bpy.data.objects[wgts_group_name].name = "WGTS_" + obj.name @@ -148,18 +156,18 @@ def generate_rig(context, metarig): # Create temporary duplicates for merging temp_rig_1 = metarig.copy() temp_rig_1.data = metarig.data.copy() - scene.objects.link(temp_rig_1) + collection.objects.link(temp_rig_1) temp_rig_2 = metarig.copy() temp_rig_2.data = obj.data - scene.objects.link(temp_rig_2) + collection.objects.link(temp_rig_2) # Select the temp rigs for merging for objt in scene.objects: - objt.select = False # deselect all objects - temp_rig_1.select = True - temp_rig_2.select = True - scene.objects.active = temp_rig_2 + objt.select_set('DESELECT') # deselect all objects + temp_rig_1.select_set('SELECT') + temp_rig_2.select_set('SELECT') + view_layer.objects.active = temp_rig_2 # Merge the temporary rigs bpy.ops.object.join() @@ -169,9 +177,9 @@ def generate_rig(context, metarig): # Select the generated rig for objt in scene.objects: - objt.select = False # deselect all objects - obj.select = True - scene.objects.active = obj + objt.select_set('DESELECT') # deselect all objects + obj.select_set('SELECT') + view_layer.objects.active = obj # Copy over bone properties for bone in metarig.data.bones: @@ -313,14 +321,15 @@ def generate_rig(context, metarig): 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) - wgts_obj.layers = WGT_LAYERS + collection.objects.link(wgts_obj) + # TODO MOVE objects to all WGT_LAYERS collection + #wgts_obj.layers = WGT_LAYERS t.tick("Create main WGTS: ") # # if id_store.rigify_generate_mode == 'new': # bpy.ops.object.select_all(action='DESELECT') # for wgt in bpy.data.objects[wgts_group_name].children: - # wgt.select = True + # wgt.select_set('SELECT') # for i, lyr in enumerate(WGT_LAYERS): # if lyr: # context.scene.layers[i] = True @@ -343,8 +352,8 @@ def generate_rig(context, metarig): for rig in rigs: # Go into editmode in the rig armature bpy.ops.object.mode_set(mode='OBJECT') - context.scene.objects.active = obj - obj.select = True + context.view_layer.objects.active = obj + obj.select_set('SELECT') bpy.ops.object.mode_set(mode='EDIT') scripts = rig.generate() if scripts is not None: @@ -536,9 +545,9 @@ def create_selection_sets(obj, metarig): bpy.ops.object.mode_set(mode='POSE') - bpy.context.scene.objects.active = obj - obj.select = True - metarig.select = False + bpy.context.view_layer.objects.active = obj + obj.select_set('SELECT') + metarig.select_set('DESELECT') pbones = obj.pose.bones for i, name in enumerate(metarig.data.rigify_layers.keys()): @@ -577,7 +586,7 @@ def create_bone_groups(obj, metarig): g_id = l.group - 1 name = groups[g_id].name if name not in obj.pose.bone_groups.keys(): - bg = obj.pose.bone_groups.new(name) + bg = obj.pose.bone_groups.new(name=name) bg.color_set = 'CUSTOM' bg.colors.normal = gamma_correct(groups[g_id].normal) bg.colors.select = gamma_correct(groups[g_id].select) diff --git a/rigify/legacy/generate.py b/rigify/legacy/generate.py index eb3c3112..4cc725b1 100644 --- a/rigify/legacy/generate.py +++ b/rigify/legacy/generate.py @@ -71,6 +71,8 @@ def generate_rig(context, metarig): bpy.ops.object.mode_set(mode='OBJECT') scene = context.scene + view_layer = context.view_layer + collection = scene.collection #------------------------------------------ # Create/find the rig object and set it up @@ -89,7 +91,7 @@ def generate_rig(context, metarig): except KeyError: obj = bpy.data.objects.new(name, bpy.data.armatures.new(name)) obj.display_type = 'WIRE' - scene.objects.link(obj) + collection.objects.link(obj) obj.data.pose_position = 'POSE' @@ -98,9 +100,9 @@ def generate_rig(context, metarig): obj.animation_data_clear() # Select generated rig object - metarig.select = False - obj.select = True - scene.objects.active = obj + metarig.select_set('DESELECT') + obj.select_set('SELECT') + view_layer.objects.active = obj # Remove all bones from the generated rig armature. bpy.ops.object.mode_set(mode='EDIT') @@ -111,18 +113,18 @@ def generate_rig(context, metarig): # Create temporary duplicates for merging temp_rig_1 = metarig.copy() temp_rig_1.data = metarig.data.copy() - scene.objects.link(temp_rig_1) + collection.objects.link(temp_rig_1) temp_rig_2 = metarig.copy() temp_rig_2.data = obj.data - scene.objects.link(temp_rig_2) + collection.objects.link(temp_rig_2) # Select the temp rigs for merging for objt in scene.objects: - objt.select = False # deselect all objects - temp_rig_1.select = True - temp_rig_2.select = True - scene.objects.active = temp_rig_2 + objt.select_set('DESELECT') # deselect all objects + temp_rig_1.select_set('SELECT') + temp_rig_2.select_set('SELECT') + view_layer.objects.active = temp_rig_2 # Merge the temporary rigs bpy.ops.object.join() @@ -132,9 +134,9 @@ def generate_rig(context, metarig): # Select the generated rig for objt in scene.objects: - objt.select = False # deselect all objects - obj.select = True - scene.objects.active = obj + objt.select_set('DESELECT') # deselect all objects + obj.select_set('SELECT') + view_layer.objects.active = obj # Copy over bone properties for bone in metarig.data.bones: @@ -277,8 +279,8 @@ def generate_rig(context, metarig): for rig in rigs: # Go into editmode in the rig armature bpy.ops.object.mode_set(mode='OBJECT') - context.scene.objects.active = obj - obj.select = True + context.view_layer.objects.active = obj + obj.select_set('SELECT') bpy.ops.object.mode_set(mode='EDIT') scripts = rig.generate() if scripts is not None: diff --git a/rigify/legacy/rigs/pitchipoy/limbs/limb_utils.py b/rigify/legacy/rigs/pitchipoy/limbs/limb_utils.py index b0b62d79..69449bb7 100644 --- a/rigify/legacy/rigs/pitchipoy/limbs/limb_utils.py +++ b/rigify/legacy/rigs/pitchipoy/limbs/limb_utils.py @@ -11,11 +11,11 @@ def orient_bone( cls, eb, axis, scale = 1.0, reverse = False ): setattr(v,axis,scale) if reverse: - tail_vec = v * cls.obj.matrix_world + tail_vec = v @ cls.obj.matrix_world eb.head[:] = eb.tail eb.tail[:] = eb.head + tail_vec else: - tail_vec = v * cls.obj.matrix_world + tail_vec = v @ cls.obj.matrix_world eb.tail[:] = eb.head + tail_vec eb.roll = 0.0 diff --git a/rigify/legacy/rigs/pitchipoy/super_torso_turbo.py b/rigify/legacy/rigs/pitchipoy/super_torso_turbo.py index 38d5887b..d9645adb 100644 --- a/rigify/legacy/rigs/pitchipoy/super_torso_turbo.py +++ b/rigify/legacy/rigs/pitchipoy/super_torso_turbo.py @@ -99,11 +99,11 @@ class Rig: setattr(v,axis,scale) if reverse: - tail_vec = v * self.obj.matrix_world + tail_vec = v @ self.obj.matrix_world eb.head[:] = eb.tail eb.tail[:] = eb.head + tail_vec else: - tail_vec = v * self.obj.matrix_world + tail_vec = v @ self.obj.matrix_world eb.tail[:] = eb.head + tail_vec diff --git a/rigify/legacy/utils.py b/rigify/legacy/utils.py index e3927ac3..35bbd7b9 100644 --- a/rigify/legacy/utils.py +++ b/rigify/legacy/utils.py @@ -416,11 +416,12 @@ def create_widget(rig, bone_name, bone_transform_name=None): # Create mesh object mesh = bpy.data.meshes.new(obj_name) obj = bpy.data.objects.new(obj_name, mesh) - scene.objects.link(obj) + collection.objects.link(obj) # Move object to bone position and set layers obj_to_bone(obj, rig, bone_transform_name) - obj.layers = WGT_LAYERS + # TODO move colleciton to all the WGT_LAYERS collections + # obj.layers = WGT_LAYERS return obj diff --git a/rigify/rig_ui_template.py b/rigify/rig_ui_template.py index bbbc06dc..8031ff3b 100644 --- a/rigify/rig_ui_template.py +++ b/rigify/rig_ui_template.py @@ -136,11 +136,11 @@ def get_pose_matrix_in_other_space(mat, pose_bone): par_rest = Matrix() # Get matrix in bone's current transform space - smat = rest_inv * (par_rest * (par_inv * mat)) + smat = rest_inv @ (par_rest @ (par_inv @ mat)) # Compensate for non-local location #if not pose_bone.bone.use_local_location: - # loc = smat.to_translation() * (par_rest.inverted() * rest).to_quaternion() + # loc = smat.to_translation() @ (par_rest.inverted() @ rest).to_quaternion() # smat.translation = loc return smat @@ -167,8 +167,8 @@ def set_pose_translation(pose_bone, mat): else: par_rest = Matrix() - q = (par_rest.inverted() * rest).to_quaternion() - pose_bone.location = q * loc + q = (par_rest.inverted() @ rest).to_quaternion() + pose_bone.location = q @ loc def set_pose_rotation(pose_bone, mat): @@ -284,11 +284,11 @@ def match_pole_target(ik_first, ik_last, pole, match_bone, length): angle = rotation_difference(ik_first.matrix, match_bone.matrix) # Try compensating for the rotation difference in both directions - pv1 = Matrix.Rotation(angle, 4, ikv) * pv + pv1 = Matrix.Rotation(angle, 4, ikv) @ pv set_pole(pv1) ang1 = rotation_difference(ik_first.matrix, match_bone.matrix) - pv2 = Matrix.Rotation(-angle, 4, ikv) * pv + pv2 = Matrix.Rotation(-angle, 4, ikv) @ pv set_pole(pv2) ang2 = rotation_difference(ik_first.matrix, match_bone.matrix) @@ -425,8 +425,8 @@ def fk2ik_leg(obj, fk, ik): match_pose_scale(shin, shini) # Foot position - mat = mfoot.bone.matrix_local.inverted() * foot.bone.matrix_local - footmat = get_pose_matrix_in_other_space(mfooti.matrix, foot) * mat + mat = mfoot.bone.matrix_local.inverted() @ foot.bone.matrix_local + footmat = get_pose_matrix_in_other_space(mfooti.matrix, foot) @ mat set_pose_rotation(foot, footmat) set_pose_scale(foot, footmat) bpy.ops.object.mode_set(mode='OBJECT') @@ -443,8 +443,8 @@ def fk2ik_leg(obj, fk, ik): match_pose_scale(shin, shini) # Foot position - mat = mfoot.bone.matrix_local.inverted() * foot.bone.matrix_local - footmat = get_pose_matrix_in_other_space(mfooti.matrix, foot) * mat + mat = mfoot.bone.matrix_local.inverted() @ foot.bone.matrix_local + footmat = get_pose_matrix_in_other_space(mfooti.matrix, foot) @ mat set_pose_rotation(foot, footmat) set_pose_scale(foot, footmat) bpy.ops.object.mode_set(mode='OBJECT') @@ -483,8 +483,8 @@ def ik2fk_leg(obj, fk, ik): set_pose_rotation(footroll, Matrix()) # Foot position - mat = mfooti.bone.matrix_local.inverted() * footi.bone.matrix_local - footmat = get_pose_matrix_in_other_space(foot.matrix, footi) * mat + mat = mfooti.bone.matrix_local.inverted() @ footi.bone.matrix_local + footmat = get_pose_matrix_in_other_space(foot.matrix, footi) @ mat set_pose_translation(footi, footmat) set_pose_rotation(footi, footmat) set_pose_scale(footi, footmat) @@ -509,8 +509,8 @@ def ik2fk_leg(obj, fk, ik): set_pose_rotation(footroll, Matrix()) # Foot position - mat = mfooti.bone.matrix_local.inverted() * footi.bone.matrix_local - footmat = get_pose_matrix_in_other_space(mfoot.matrix, footi) * mat + mat = mfooti.bone.matrix_local.inverted() @ footi.bone.matrix_local + footmat = get_pose_matrix_in_other_space(mfoot.matrix, footi) @ mat set_pose_translation(footi, footmat) set_pose_rotation(footi, footmat) set_pose_scale(footi, footmat) diff --git a/rigify/rigs/experimental/super_chain.py b/rigify/rigs/experimental/super_chain.py index 408bce3f..2b2c472b 100644 --- a/rigify/rigs/experimental/super_chain.py +++ b/rigify/rigs/experimental/super_chain.py @@ -115,11 +115,11 @@ class Rig: setattr(v,axis,scale) if reverse: - tail_vec = v * self.obj.matrix_world + tail_vec = v @ self.obj.matrix_world eb.head[:] = eb.tail eb.tail[:] = eb.head + tail_vec else: - tail_vec = v * self.obj.matrix_world + tail_vec = v @ self.obj.matrix_world eb.tail[:] = eb.head + tail_vec def create_pivot(self, bones=None, pivot=None): diff --git a/rigify/rigs/limbs/limb_utils.py b/rigify/rigs/limbs/limb_utils.py index 80588516..609da256 100644 --- a/rigify/rigs/limbs/limb_utils.py +++ b/rigify/rigs/limbs/limb_utils.py @@ -11,11 +11,11 @@ def orient_bone( cls, eb, axis, scale = 1.0, reverse = False ): setattr(v,axis,scale) if reverse: - tail_vec = v * cls.obj.matrix_world + tail_vec = v @ cls.obj.matrix_world eb.head[:] = eb.tail eb.tail[:] = eb.head + tail_vec else: - tail_vec = v * cls.obj.matrix_world + tail_vec = v @ cls.obj.matrix_world eb.tail[:] = eb.head + tail_vec eb.roll = 0.0 diff --git a/rigify/rigs/spines/super_spine.py b/rigify/rigs/spines/super_spine.py index 115d0450..6d28de69 100644 --- a/rigify/rigs/spines/super_spine.py +++ b/rigify/rigs/spines/super_spine.py @@ -123,11 +123,11 @@ class Rig: setattr(v, axis, scale) if reverse: - tail_vec = v * self.obj.matrix_world + tail_vec = v @ self.obj.matrix_world eb.head[:] = eb.tail eb.tail[:] = eb.head + tail_vec else: - tail_vec = v * self.obj.matrix_world + tail_vec = v @ self.obj.matrix_world eb.tail[:] = eb.head + tail_vec def create_pivot(self, pivot): diff --git a/rigify/utils.py b/rigify/utils.py index 0888f44e..fdb87013 100644 --- a/rigify/utils.py +++ b/rigify/utils.py @@ -420,7 +420,7 @@ def obj_to_bone(obj, rig, bone_name): bone = rig.data.bones[bone_name] - mat = rig.matrix_world * bone.matrix_local + mat = rig.matrix_world @ bone.matrix_local obj.location = mat.to_translation() @@ -440,6 +440,7 @@ def create_widget(rig, bone_name, bone_transform_name=None): obj_name = WGT_PREFIX + rig.name + '_' + bone_name scene = bpy.context.scene + collection = scene.collection #TODO WGT_LAYERS id_store = bpy.context.window_manager # Check if it already exists in the scene @@ -460,14 +461,14 @@ def create_widget(rig, bone_name, bone_transform_name=None): # Create mesh object mesh = bpy.data.meshes.new(obj_name) obj = bpy.data.objects.new(obj_name, mesh) - scene.objects.link(obj) + collection.objects.link(obj) # Move object to bone position and set layers obj_to_bone(obj, rig, bone_transform_name) wgts_group_name = 'WGTS_' + rig.name if wgts_group_name in bpy.data.objects.keys(): obj.parent = bpy.data.objects[wgts_group_name] - obj.layers = WGT_LAYERS + #obj.layers = WGT_LAYERS #TODO WGT_LAYERS return obj |