How to make rotation use 3X3 matrix in three.js

只愿长相守 提交于 2019-12-24 18:54:18

问题


I have a 3X3 matrix, like this:

[ a11  a12  a13 ]
[ a21  a22  a23 ]
[ a31  a32  a33 ]

but how can I make rotation use this matrix to a mesh in THREE.js.


回答1:


You want to specify a mesh's orientation via a matrix. To do so, you can use one of the following two patterns:

var matrix = new THREE.Matrix4(); // create once and reuse it

matrix.set(
    a11, a12, a13,  0,
    a21, a22, a23,  0,
    a31, a32, a33,  0,
      0,   0,   0,  1
);

If you know the matrix is a rotation matrix (i.e., no scaling involved),

mesh = new THREE.Mesh( geometry, material );

mesh.quaternion.setFromRotationMatrix( matrix );

Otherwise,

mesh = new THREE.Mesh( geometry, material );

mesh.applyMatrix( matrix );

three.js r.94



来源:https://stackoverflow.com/questions/51581023/how-to-make-rotation-use-3x3-matrix-in-three-js

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