首页 > 解决方案 > THREE.IcosahedronGeometry 没有顶点数组

问题描述

我正在关注 Matt DesLauriersd 的 WebGL 和着色器高级创意编码课程https://frontendmasters.com/courses/webgl-shaders/ 和一个视频,他通过这样做提取了 icosahedronGeometry 对象的顶点数组:


const geometry = new THREE.SphereGeometry(1, 32, 16);
  const baseGeometry = new THREE.IcosahedronGeometry(1, 1);


  const points = baseGeometry.vertices;
  console.log(points)

但是当我这样做时,它是未定义的

链接到 jsfiddle:https ://jsfiddle.net/18hd3jge/

标签: javascriptthree.js

解决方案


该教程已过时。由于r125所有几何生成器都喜欢SphereGeometry产生BufferGeometryGeometry同一版本还从库中删除了前者。

如果要访问缓冲区几何图形的顶点,则必须使用position缓冲区属性。典型的代码如下所示:

const geometry = new THREE.SphereGeometry(1, 32, 16);
const positionAttribute = geometry.getAttribute( 'position' );

const vertex = new THREE.Vector3();

for ( let vertexIndex = 0; vertexIndex < positionAttribute.count; vertexIndex ++ ) {

    vertex.fromBufferAttribute( positionAttribute, vertexIndex );

    // now do something with vertex

}

有关Geometry此处删除的更多信息:https ://discourse.threejs.org/t/three-geometry-will-be-removed-from-core-with-r125/22401


推荐阅读