[Bf-blender-cvs] [4b6fa4d897a] blender2.8: PyAPI: update scripts for matrix multiply operator

Campbell Barton noreply at git.blender.org
Sun Aug 12 07:31:11 CEST 2018


Commit: 4b6fa4d897a0bb3252b16383492b526d2cef3920
Author: Campbell Barton
Date:   Sun Aug 12 15:01:26 2018 +1000
Branches: blender2.8
https://developer.blender.org/rB4b6fa4d897a0bb3252b16383492b526d2cef3920

PyAPI: update scripts for matrix multiply operator

Operators:
- add torus
- align objects
- bake physics
- make dupli faces
- smart project

Templates:
- 3D view ray cast

Other:
- Methods for bones/edit-bones

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

M	release/scripts/modules/bpy_extras/object_utils.py
M	release/scripts/modules/bpy_extras/view3d_utils.py
M	release/scripts/modules/bpy_types.py
M	release/scripts/startup/bl_operators/add_mesh_torus.py
M	release/scripts/startup/bl_operators/clip.py
M	release/scripts/startup/bl_operators/object.py
M	release/scripts/startup/bl_operators/object_align.py
M	release/scripts/startup/bl_operators/rigidbody.py
M	release/scripts/startup/bl_operators/uvcalc_smart_project.py

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

diff --git a/release/scripts/modules/bpy_extras/object_utils.py b/release/scripts/modules/bpy_extras/object_utils.py
index fff73a4285a..c9ea684862d 100644
--- a/release/scripts/modules/bpy_extras/object_utils.py
+++ b/release/scripts/modules/bpy_extras/object_utils.py
@@ -100,7 +100,7 @@ def add_object_align_init(context, operator):
         if operator:
             properties.rotation = rotation.to_euler()
 
-    return location * rotation
+    return location @ rotation
 
 
 def object_data_add(context, obdata, operator=None, name=None):
diff --git a/release/scripts/modules/bpy_extras/view3d_utils.py b/release/scripts/modules/bpy_extras/view3d_utils.py
index a4834a4531c..a2e394b270f 100644
--- a/release/scripts/modules/bpy_extras/view3d_utils.py
+++ b/release/scripts/modules/bpy_extras/view3d_utils.py
@@ -54,7 +54,7 @@ def region_2d_to_vector_3d(region, rv3d, coord):
 
         w = out.dot(persinv[3].xyz) + persinv[3][3]
 
-        view_vector = ((persinv * out) / w) - viewinv.translation
+        view_vector = ((persinv @ out) / w) - viewinv.translation
     else:
         view_vector = -viewinv.col[2].xyz
 
@@ -179,7 +179,7 @@ def location_3d_to_region_2d(region, rv3d, coord, default=None):
     """
     from mathutils import Vector
 
-    prj = rv3d.perspective_matrix * Vector((coord[0], coord[1], coord[2], 1.0))
+    prj = rv3d.perspective_matrix @ Vector((coord[0], coord[1], coord[2], 1.0))
     if prj.w > 0.0:
         width_half = region.width / 2.0
         height_half = region.height / 2.0
diff --git a/release/scripts/modules/bpy_types.py b/release/scripts/modules/bpy_types.py
index d6d4ecd6fce..96193b047c6 100644
--- a/release/scripts/modules/bpy_types.py
+++ b/release/scripts/modules/bpy_types.py
@@ -205,21 +205,21 @@ class _GenericBone:
         """ Vector pointing down the x-axis of the bone.
         """
         from mathutils import Vector
-        return self.matrix.to_3x3() * Vector((1.0, 0.0, 0.0))
+        return self.matrix.to_3x3() @ Vector((1.0, 0.0, 0.0))
 
     @property
     def y_axis(self):
         """ Vector pointing down the y-axis of the bone.
         """
         from mathutils import Vector
-        return self.matrix.to_3x3() * Vector((0.0, 1.0, 0.0))
+        return self.matrix.to_3x3() @ Vector((0.0, 1.0, 0.0))
 
     @property
     def z_axis(self):
         """ Vector pointing down the z-axis of the bone.
         """
         from mathutils import Vector
-        return self.matrix.to_3x3() * Vector((0.0, 0.0, 1.0))
+        return self.matrix.to_3x3() @ Vector((0.0, 0.0, 1.0))
 
     @property
     def basename(self):
@@ -378,9 +378,9 @@ class EditBone(StructRNA, _GenericBone, metaclass=StructMetaPropGroup):
         :type roll: bool
         """
         from mathutils import Vector
-        z_vec = self.matrix.to_3x3() * Vector((0.0, 0.0, 1.0))
-        self.tail = matrix * self.tail
-        self.head = matrix * self.head
+        z_vec = self.matrix.to_3x3() @ Vector((0.0, 0.0, 1.0))
+        self.tail = matrix @ self.tail
+        self.head = matrix @ self.head
 
         if scale:
             scalar = matrix.median_scale
@@ -388,7 +388,7 @@ class EditBone(StructRNA, _GenericBone, metaclass=StructMetaPropGroup):
             self.tail_radius *= scalar
 
         if roll:
-            self.align_roll(matrix * z_vec)
+            self.align_roll(matrix @ z_vec)
 
 
 def ord_ind(i1, i2):
diff --git a/release/scripts/startup/bl_operators/add_mesh_torus.py b/release/scripts/startup/bl_operators/add_mesh_torus.py
index 4460af173ff..68f49acc186 100644
--- a/release/scripts/startup/bl_operators/add_mesh_torus.py
+++ b/release/scripts/startup/bl_operators/add_mesh_torus.py
@@ -46,10 +46,11 @@ def add_torus(major_rad, minor_rad, major_seg, minor_seg):
         for minor_index in range(minor_seg):
             angle = pi_2 * minor_index / minor_seg
 
-            vec = matrix * Vector((major_rad + (cos(angle) * minor_rad),
-                                   0.0,
-                                   sin(angle) * minor_rad,
-                                   ))
+            vec = matrix @ Vector((
+                major_rad + (cos(angle) * minor_rad),
+                0.0,
+                sin(angle) * minor_rad,
+            ))
 
             verts.extend(vec[:])
 
diff --git a/release/scripts/startup/bl_operators/clip.py b/release/scripts/startup/bl_operators/clip.py
index a94076ab61b..d05082b0dd8 100644
--- a/release/scripts/startup/bl_operators/clip.py
+++ b/release/scripts/startup/bl_operators/clip.py
@@ -300,7 +300,7 @@ class CLIP_OT_bundles_to_mesh(Operator):
             reconstruction = tracking_object.reconstruction
             framenr = scene.frame_current - clip.frame_start + 1
             reconstructed_matrix = reconstruction.cameras.matrix_from_frame(framenr)
-            matrix = camera.matrix_world * reconstructed_matrix.inverted()
+            matrix = camera.matrix_world @ reconstructed_matrix.inverted()
 
         for track in tracking_object.tracks:
             if track.has_bundle and track.select:
@@ -580,10 +580,12 @@ class CLIP_OT_setup_tracking_scene(Operator):
 
         scene.camera = camob
 
-        camob.matrix_local = (Matrix.Translation((7.481, -6.508, 5.344)) *
-                              Matrix.Rotation(0.815, 4, 'Z') *
-                              Matrix.Rotation(0.011, 4, 'Y') *
-                              Matrix.Rotation(1.109, 4, 'X'))
+        camob.matrix_local = (
+            Matrix.Translation((7.481, -6.508, 5.344)) @
+            Matrix.Rotation(0.815, 4, 'Z') @
+            Matrix.Rotation(0.011, 4, 'Y') @
+            Matrix.Rotation(1.109, 4, 'X')
+        )
 
         return camob
 
diff --git a/release/scripts/startup/bl_operators/object.py b/release/scripts/startup/bl_operators/object.py
index be379ec6089..c49591ff300 100644
--- a/release/scripts/startup/bl_operators/object.py
+++ b/release/scripts/startup/bl_operators/object.py
@@ -599,7 +599,7 @@ class MakeDupliFace(Operator):
             trans = matrix.to_translation()
             rot = matrix.to_3x3()  # also contains scale
 
-            return [(rot * b) + trans for b in base_tri]
+            return [(rot @ b) + trans for b in base_tri]
         scene = context.scene
         linked = {}
         for obj in context.selected_objects:
diff --git a/release/scripts/startup/bl_operators/object_align.py b/release/scripts/startup/bl_operators/object_align.py
index f627fd30162..60fb360480f 100644
--- a/release/scripts/startup/bl_operators/object_align.py
+++ b/release/scripts/startup/bl_operators/object_align.py
@@ -75,7 +75,7 @@ def worldspace_bounds_from_object_data(scene, obj):
     me = obj.to_mesh(scene=scene, apply_modifiers=True, settings='PREVIEW')
     verts = me.vertices
 
-    val = matrix_world * (verts[-1].co if verts else Vector((0.0, 0.0, 0.0)))
+    val = matrix_world @ (verts[-1].co if verts else Vector((0.0, 0.0, 0.0)))
 
     left, right, front, back, down, up = (
         val[0],
@@ -88,7 +88,7 @@ def worldspace_bounds_from_object_data(scene, obj):
 
     # Test against all other verts
     for v in verts:
-        vco = matrix_world * v.co
+        vco = matrix_world @ v.co
 
         # X Range
         val = vco[0]
@@ -146,7 +146,7 @@ def align_objects(context,
 
     for obj in context.selected_objects:
         matrix_world = obj.matrix_world.copy()
-        bb_world = [matrix_world * Vector(v) for v in obj.bound_box]
+        bb_world = [matrix_world @ Vector(v) for v in obj.bound_box]
         objects.append((obj, bb_world))
 
     if not objects:
@@ -216,7 +216,7 @@ def align_objects(context,
 
     for obj, bb_world in objects:
         matrix_world = obj.matrix_world.copy()
-        bb_world = [matrix_world * Vector(v[:]) for v in obj.bound_box]
+        bb_world = [matrix_world @ Vector(v[:]) for v in obj.bound_box]
 
         if bb_quality and obj.type == 'MESH':
             GBB = worldspace_bounds_from_object_data(scene, obj)
diff --git a/release/scripts/startup/bl_operators/rigidbody.py b/release/scripts/startup/bl_operators/rigidbody.py
index 6b76fb96b62..46f3d0a1436 100644
--- a/release/scripts/startup/bl_operators/rigidbody.py
+++ b/release/scripts/startup/bl_operators/rigidbody.py
@@ -149,7 +149,7 @@ class BakeToKeyframes(Operator):
                     mat = bake[i][j]
                     # convert world space transform to parent space, so parented objects don't get offset after baking
                     if (obj.parent):
-                        mat = obj.matrix_parent_inverse.inverted() * obj.parent.matrix_world.inverted() * mat
+                        mat = obj.matrix_parent_inverse.inverted() @ obj.parent.matrix_world.inverted() @ mat
 
                     obj.location = mat.to_translation()
 
diff --git a/release/scripts/startup/bl_operators/uvcalc_smart_project.py b/release/scripts/startup/bl_operators/uvcalc_smart_project.py
index fe15b9fa345..b01a50d5d6a 100644
--- a/release/scripts/startup/bl_operators/uvcalc_smart_project.py
+++ b/release/scripts/startup/bl_operators/uvcalc_smart_project.py
@@ -89,7 +89,7 @@ def pointInTri2D(v, v1, v2, v3):
 
         dict_matrix[key] = mtx
 
-    uvw = (v - v1) * mtx
+    uvw = (v - v1) @ mtx
     return 0 <= uvw[0] and 0 <= uvw[1] and uvw[0] + uvw[1] <= 1
 
 
@@ -258,7 +258,7 @@ def rotate_uvs(uv_points, angle):
     if angle != 0.0:
         mat = Matrix.Rotation(angle, 2)
         for uv in uv_points:
-            uv[:] = mat * uv
+            uv[:] = mat @ uv
 
 
 def optiRotateUvIsland(faces):
@@ -858,7 +858,7 @@ def main(context,
         # Initialize projectVecs
         if USER_VIEW_INIT:
             # Generate Projection
-            projectVecs = [Vector(Window.GetViewVector()) * ob.matrix_world.inverted().to_3x3()]  # We add to this along the way
+            projectVecs = [Vector(Window.GetViewVector()) @ ob.matrix_world.inverted().to_3x3()]  # We add to this along the way
         else:
             projectVecs = []
 
@@ -975,7 +975,7 @@ def main(context,
                 f_uv = f.uv
                 for j, v in enumerate(f.v):
                     # XXX - note, between mathutils in 2.4 and 2.5 the order changed.
-                    f_uv[j][:] = (MatQuat * v.co).xy
+                    f_uv[j][

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list