Three.js:将面法线从局部空间转换为世界空间 [英] Three.js: Convert face normal from local space to world space

查看:48
本文介绍了Three.js:将面法线从局部空间转换为世界空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 THREE.PlaneGeometry,带有 ComputeFaceNormals().我使用这个几何体创建了两个网格,并对它们应用了不同的旋转.我想计算相机和两个网格中心面法线之间的两个角度.应该是:

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

问题是我不知道如何使用three.js API在世界坐标(从几何和网格旋转)中获得网格法线

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

推荐答案

如果您想将面或顶点法线 normal 从局部空间转换为世界空间,您可以这样做:

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

three.js r.107

这篇关于Three.js:将面法线从局部空间转换为世界空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆