我是 Three.js 的新手,所以也许我不会以最佳方式解决这个问题,
我创建的几何图形如下,
const geo = new THREE.PlaneBufferGeometry(10,0);
然后我对其进行旋转
geo.applyMatrix( new THREE.Matrix4().makeRotationX( Math.PI * 0.5 ) );
然后我从中创建一个网格
const open = new THREE.Mesh( geo, materialNormal);
然后,我对网格应用一系列操作以正确定位它,如下所示:
open.position.copy(v2(10,20);
open.position.z = 0.5*10
open.position.x -= 20
open.position.y -= 10
open.rotation.z = angle;
现在,在位置更改之前和之后获取网格顶点的最佳方法是什么?我惊讶地发现网格的顶点没有内置到 Three.js 中。
任何提示和代码示例将不胜感激。
我认为您被有关 Three.js 对象的一些语义所困扰。
1) A Mesh
没有顶点。 AMesh
包含对Geometry
/BufferGeometry
, and Material
(是)。顶点包含在Mesh
's geometry
属性/对象。
2)你正在使用PlaneBufferGeometry
,这意味着一个实现BufferGeometry
目的。BufferGeometry
将其顶点保留在position
属性 (mesh.geometry.attributes.position
)。请记住,顶点顺序可能会受到index
财产 (mesh.geometry.index
).
现在回答你的问题,几何原点也是它的父元素Mesh
的原点,因此您的“网格变换之前”顶点位置与创建网格时完全相同。只需按原样读出它们即可。
要获得“网格变换后”顶点位置,您需要获取每个顶点,并将其从Mesh
的局部空间,进入世界空间。幸运的是, Three.js 有一个方便的函数可以做到这一点:
var tempVertex = new THREE.Vector3();
// set tempVertex based on information from mesh.geometry.attributes.position
mesh.localToWorld(tempVertex);
// tempVertex is converted from local coordinates into world coordinates,
// which is its "after mesh transformation" position
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)