blender-python-stubs/conformance/5.0/test_mathutils_matrix.py
Joseph HENRY 8ef75df9eb Fix mypy compatibility and add 5.0 conformance tests
- Qualify bare "object" as builtins.object in bpy.types to avoid shadowing
  by Context.object and similar properties
- Use _Sequence alias import to fix mypy "collections.abc.Sequence not defined"
- Filter out variables that clash with submodule re-exports (e.g. bpy.app)
- Add 5.0 conformance tests from Blender 5.0 mathutils documentation

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-27 18:24:12 +01:00

36 lines
1.0 KiB
Python

import mathutils
import math
# Create a location matrix.
mat_loc = mathutils.Matrix.Translation((2.0, 3.0, 4.0))
# Create an identity matrix.
mat_sca = mathutils.Matrix.Scale(0.5, 4, (0.0, 0.0, 1.0))
# Create a rotation matrix.
mat_rot = mathutils.Matrix.Rotation(math.radians(45.0), 4, "X")
# Combine transformations.
mat_out = mat_loc @ mat_rot @ mat_sca
print(mat_out)
# Extract components back out of the matrix as two vectors and a quaternion.
loc, rot, sca = mat_out.decompose()
print(loc, rot, sca)
# Recombine extracted components.
mat_out2 = mathutils.Matrix.LocRotScale(loc, rot, sca)
print(mat_out2)
# It can also be useful to access components of a matrix directly.
mat = mathutils.Matrix()
mat[0][0], mat[1][0], mat[2][0] = 0.0, 1.0, 2.0
mat[0][0:3] = 0.0, 1.0, 2.0
# Each item in a matrix is a vector so vector utility functions can be used.
mat[0].xyz = 0.0, 1.0, 2.0
# Direct buffer access is supported at runtime via C buffer protocol
# but not expressible in type stubs (requires Python 3.12+ __buffer__).