[Bf-extensions-cvs] [81640764] blender2.8: Rigify: More updates for 2.8 API

Dalai Felinto noreply at git.blender.org
Mon Oct 22 18:30:24 CEST 2018


Commit: 816407649aedfaa7836e3aca7629842db732e279
Author: Dalai Felinto
Date:   Mon Oct 22 15:13:13 2018 +0000
Branches: blender2.8
https://developer.blender.org/rBA816407649aedfaa7836e3aca7629842db732e279

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).

===================================================================

M	rigify/__init__.py
M	rigify/generate.py
M	rigify/legacy/generate.py
M	rigify/legacy/rigs/pitchipoy/limbs/limb_utils.py
M	rigify/legacy/rigs/pitchipoy/super_torso_turbo.py
M	rigify/legacy/utils.py
M	rigify/rig_ui_template.py
M	rigify/rigs/experimental/super_chain.py
M	rigify/rigs/limbs/limb_utils.py
M	rigify/rigs/spines/super_spine.py
M	rigify/utils.py

===================================================================

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
--- 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list