Three.js: Convert face normal from local space to world space

梦想与她 提交于 2019-11-30 23:10:15

If you want to convert a face or vertex normal, normal, from local space to world space, you do it like so:

var normalMatrix = new THREE.Matrix3(); // create once and reuse
var worldNormal = new THREE.Vector3(); // create once and reuse

...

normalMatrix.getNormalMatrix( object.matrixWorld );

worldNormal.copy( normal ).applyMatrix3( normalMatrix ).normalize();

three.js r.107

I finaly found an old post saying that THREE.js does not compute the world normal for you, so I did it by hand, and it works fine. Although, There might be nicer way to do it. In case other people are interested :

    var rotationMatrix = new THREE.Matrix4().extractRotation( this.mesh.matrixWorld );
    this.normalWorld = this.geometry.faces[0].normal.clone().applyMatrix4(rotationMatrix);

    var vLocalCamera = new THREE.Vector3();
    vLocalCamera.subVectors(wbEngine.wb_getCamera().getPosition(), this.mesh.position);
    var cosTheta = Math.abs(this.normalWorld.dot(vLocalCamera.normalize()));
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!