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
This commit is contained in:
Campbell Barton 2018-08-12 15:01:26 +10:00
parent 444a0202d4
commit 4b6fa4d897
Notes: blender-bot 2023-02-14 09:03:55 +01:00
Referenced by issue #56348, Blender 2.8 crashes while render animation
Referenced by issue #56345, Outliner: The Child is not in the Parent.
Referenced by issue #56309, Freeze when switching to the Lookdev or Rendered (Eevee) view
Referenced by issue #56223, Crashing from copying bone properties
9 changed files with 32 additions and 29 deletions

View File

@ -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):

View File

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

View File

@ -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):

View File

@ -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[:])

View File

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

View File

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

View File

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

View File

@ -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()

View File

@ -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][:] = (MatQuat @ v.co).xy
if USER_SHARE_SPACE:
# Should we collect and pack later?