1
$\begingroup$

It seems like the Blender Python API lets you set certain transform attributes, like .matrix_world, using NumPy matrices.

However, it seems like there may be some disagreement on ordering, possibly row-major vs. column major, between setting the matrix and getting the matrix.

In both Blender 2.80 and 2.81-8c9e6f123a2b, I have to transpose the incoming matrix to ensure that it's set correctly.

Is this expected behavior (should I do this differently), or is it possibly a bug?

Example code, which can be run in the "Scripting" workspace of the default blend file:

import numpy as np

X_WO = np.eye(4)
X_WO[:3, :3] = [
    [0, 1, 0],
    [-1, 0, 0],
    [0, 0, 1]]
X_WO[:3, 3] = [1, 2, 3]

# Direct usage with Matrix: GOOD
matrix_WO = Matrix(X_WO)
print(np.asarray(matrix_WO) - X_WO)

obj = bpy.data.objects["Cube"]
# Set `.matrix_world` with `Matrix`: GOOD
obj.matrix_world = Matrix(X_WO)
print(np.asarray(obj.matrix_world) - X_WO)

# Set `.matrix_world` with `ndarray`: BAD?
obj.matrix_world = X_WO
print(np.asarray(obj.matrix_world) - X_WO)

# Set `.matrix_world` with `ndarray.T`: GOOD?
obj.matrix_world = X_WO.T
print(np.asarray(obj.matrix_world) - X_WO)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.