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

做~自己de王妃 提交于 2019-12-23 05:28:03

问题


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 }

回答1:


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.



来源:https://stackoverflow.com/questions/22571364/threejs-matrix-from-z-up-coordinate-system-to-y-up-coordinate-system

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!