可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
I have a THREE.PlaneGeometry, with ComputeFaceNormals(). I create two meshes using this geometry, with different rotations applied to them. I want to compute the two angles between the camera and the two meshes central face normal. It should be :
vLocalCamera = vCamera.position - mesh1.position; mesh1.normal() . vLocalCamera = cos(angle);
The problem is that I don't know how to get the mesh normal in world coordinate (from geometry and mesh rotation) with three.js API
回答1:
If you want to convert a face normal, normal, from local space to world space, you do it like so:
var normalMatrix = new THREE.Matrix3().getNormalMatrix( object.matrixWorld ); var worldNormal = normal.clone().applyMatrix3( normalMatrix ).normalize();
three.js r.58
回答2:
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()));