Three.js: chaotic mesh rotation after applyMatrix

两盒软妹~` 提交于 2019-12-08 07:56:58

问题


After applying a matrix to mesh I print its rotation parameters. After resetting mesh rotation, scale and position and re-applying the same matrix - rotation parameters aren't equal to previous ones.

var ctm1 = new THREE.Matrix4();
var ctm2 = new THREE.Matrix4();
ctm1.set(...............);
ctm2.set(...............);

function reset(mesh)
{
  mesh.position.set(0,0,0);
  mesh.scale.set(5,5,5);
  mesh.rotation.set(0,0,0);
}

reset(myMesh);
myMesh.applyMatrix(ctm1);
console.log(myMesh.rotation.x);

reset(myMesh);
myMesh.applyMatrix(ctm2);

reset(myMesh);
myMesh.applyMatrix(ctm1);
console.log(myMesh.rotation.x); //Isn't equal to previous output !!!

Three.js r.58


回答1:


The three.js renderer handles updating the object matrix, so that the matrix is consistent with the object's position, rotation, and scale.

Since you do not make a render() call, you need to add mesh.updateMatrix() as the last line of your reset() function.

three.js r.58



来源:https://stackoverflow.com/questions/17221738/three-js-chaotic-mesh-rotation-after-applymatrix

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