Three.Js To Blender Export Using Transformation Matrix

Hello Everyone,

I am working on exporting my Three.js scene to Blender using the transformation matrix. I am converting the Three.js transformation matrix to Blender’s transformation matrix and trying to change the axis accordingly, but I’m encountering 90-degree offset in the result.

Has anyone faced this issue or have any tips on how to properly adjust the transformation matrix from Three.js to Blender without this offset?

Any help or insights would be greatly appreciated!

Python Blender Script

import bpy
import mathutils
import bpy_extras

# Transformation matrix from Three.js (row-major order)
matrix_values = [
    1,
    0,
    0,
    0,
    0,
    1,
    0,
    0,
    0,
    0,
    1,
    0,
    0,
    0,
    0,
    1
]
# Convert to Blender's column-major order
matrix = mathutils.Matrix((
    (matrix_values[0], matrix_values[4], matrix_values[8], matrix_values[12]),
    (matrix_values[1], matrix_values[5], matrix_values[9], matrix_values[13]),
    (matrix_values[2], matrix_values[6], matrix_values[10], matrix_values[14]),
    (matrix_values[3], matrix_values[7], matrix_values[11], matrix_values[15])
))

# Convert Three.js coordinate system to Blender coordinate system
axis_conversion_matrix = bpy_extras.io_utils.axis_conversion(
    from_forward='-Z',
    from_up='Y',
    to_forward='Y',
    to_up='Z'
).to_4x4()

# Apply coordinate system conversion
blender_matrix = axis_conversion_matrix @ matrix

# Apply transformation to the active object
obj = bpy.context.active_object
if obj:
    obj.matrix_world = blender_matrix
else:
    print("No active object found in Blender.")

extracting three.js transformation matrix values

     box.updateMatrixWorld(true);
        const matrixArray = box.matrixWorld.elements;   

        console.log(matrixArray);

Scene in Three.Js

Equivalent Scene in Blender

It seems like Three.js and Blender have different default “up” directions:

If you create a cylinder in Blender and don’t apply any rotations to it, its longitudinal axis will be the z-axis.
Three.js creates the same along the y-axis.

2 Likes

thanks @vielzutun.ch for your valuable insights,

i will try try to debug this case. from your perspective.

will let you know.

4 Likes

Saw your solution for exporting model from three.js env. by rotating extra +MATH.PI/2 in three.js in google notification thanks @manthrax for your valuable insights.

1 Like

thanks @PavelBoytchev

1 Like