Vertices of THREE.BufferGeometry



自r125起,THREE.Geometry已弃用。我们现在正在更新我们的代码库,我们遇到了一些我们不知道如何修复的错误。

我们创建一个球体,并在球体上使用光线投射器来获得相交点。

worldSphere = new THREE.SphereGeometry(
worldSize,
worldXSegments,
worldYSegments
);
...
const intersect = raycaster.intersectObjects([worldGlobe])[0];
...
if (intersect) {
let a = worldSphere.vertices[intersect.face.a];
let b = worldSphere.vertices[intersect.face.b];
let c = worldSphere.vertices[intersect.face.c];
}

现在,通常变量a将包含每个轴的3个值,即a.x, a.y, a.z,其他变量也是如此。然而,这段代码不再工作了。我们已经知道worldSphereTHREE.BufferGeometry类型,并且顶点存储在position属性中,但我们似乎无法使其工作。

解决问题的最好方法是什么?

应该是:

const positionAttribute = worldGlobe.geometry.getAttribute( 'position' );
const a = new THREE.Vector3();
const b = new THREE.Vector3();
const c = new THREE.Vector3();
// in your raycasting routine
a.fromBufferAttribute( positionAttribute, intersect.face.a );
b.fromBufferAttribute( positionAttribute, intersect.face.b );
c.fromBufferAttribute( positionAttribute, intersect.face.c );

BTW:如果你只对一个对象进行光线投射,请使用intersectObject()而不是intersectObjects()