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

匿名 (未验证) 提交于 2019-12-03 02:28:01

问题:

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())); 


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