import bpy
import bmesh
from mathutils import Matrix

def create_box(matrix=None):
    mesh = bpy.data.meshes.new('Box')
    bm = bmesh.new()
    bmesh.ops.create_cube(bm, size=1, matrix=matrix or Matrix())

    obj = bpy.data.objects.new('Box', mesh)

    return obj

mat = Matrix()
mat[0] = 0.2836, -0.0000, -13.6324, -12.8478
mat[1] = -0.1045,  0.0020, -37.4530,  40.9696
mat[2] = 0.0000,  0.1394,   0.0000, -53.2379
mat[3] = 0.0000,  0.0000,   0.0000,   1.0000

# Matrix applied directly to mesh
# Set transformation matrix
obj = create_box()
obj.matrix_world = mat

The code above creates a cube using the bmesh.ops.create_cube operator. The first time I pass in the matrix to the operator, therefore, applying the matrix directly to the mesh itself. The next time I just set the object's transformation matrix. The results, however, are different for some reason when they should be the same. You can paste this code in the Blender script editor to see for yourself.

I have tried decomposing the matrix and setting each transform individually to no avail. I have also noticed that, if instead of passing in the matrix to the operator I run obj.data.transform(mat) it has the same result as passing in the matrix to the operator.

Notice how the meshes do not line up: box meshes in blender not lining up

I retrieved this matrix from a file I imported as a part of an i/o addon I am working on. I can confirm that when applying the matrix directly to the mesh (the first create_box call) I get the correct result.


1 Answer 1


Turns out it's because the matrix is not orthogonal. This is a result of some of my calculations on import.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .