我正在学习使用 WebGL 和着色器进行高级创意编码类(class) https://frontendmasters.com/courses/webgl-shaders/ Matt DesLauriersd 和一个视频,他提取了 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/
最佳答案
该教程已过时。自 r125
以来,所有几何生成器(如 SphereGeometry
)都生成 BufferGeometry
。同一版本还从库中删除了以前的 Geometry
。
如果要访问缓冲区几何体的顶点,则必须使用 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
关于javascript - 三、二十面体几何没有顶点数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68128811/