ekatz
ekatz

Reputation: 1070

THREEJS: Matrix from Z-Up Coordinate System to Y-Up Coordinate System

I am trying to export a series of Transformation Matrices to animate objects in ThreeJS. These transformation are extracted from Rhino, a Z-Up Modeler and need to be placed into ThreeJS, which is Y-Up. I've found a similar question on this site, but the answer does not appear to be correct because my transformations don't carry over.

Can anyone translate the generic 4x4 matrix below from a Z-Up coordinate system to a Y-Up Coordinate System?

{ a, b, c, d }  
{ e, f, g, h }  
{ i, j, k, l }  
{ m, n, o, p }

Upvotes: 0

Views: 2507

Answers (1)

ekatz
ekatz

Reputation: 1070

Alright, I think I have a working solution:

If the geometry is exported as is from the Z Up Environment (you are not flipping the YZ in your settings), you can import it into THREEjs and correct the YZ Discrepancy with this matrix (link) :

        objectid.matrixWorldNeedsUpdate=true;                               
        objectid.matrix.set 
        (
            1,  0,  0,  0,
            0,  0,  1,  0,
            0,  -1, 0,  0,
            0,  0,  0,  1
        );
        objectid.updateMatrixWorld();  

After this tranformation, wrt this post, you're applying the transition to the imported transformation. This flips the second and third rows AND flips the second and third columns:

{ a, b, c, d }  
{ e, f, g, h }  
{ i, j, k, l }  
{ m, n, o, p }

to

{ a, c, b, d }  
{ i, k, j, l }  
{ e, g, f, h }  
{ m, o, n, p }

I was originally flipping the YZ when I exported the OBJ from Rhino, so the transformation was performing on different geometry. It's working now when the YZ flip is applied on the javascript side.

Upvotes: 1

Related Questions