javascript - 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/
解决方案
该教程已过时。由于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
推荐阅读
- php - 返回哪个更好:null 还是 false?
- summernote - 标记自定义
- javascript - jquery判断上传的图片为空时,让其父节点隐藏
- c# - 多项目解决方案“无法加载文件或程序集'System.Web.Mvc,版本 = 5.2.4.0”,未给出项目名称
- python - 连接具有不同行数和列数的两个数据框
- php - 从更多输入单选按钮值中获取总和
- android - Gradle 同步需要很长时间才能完成解决依赖关系
- php - 无法将文件移动到挂载的网络共享文件夹
- postgresql - 如何在 Postgresql 查询中最小化 CTE 的使用
- .htaccess - .htaccess 和多个意外重定向