THREE.js CylinderGeometry.attributes 未定义
Posted
技术标签:
【中文标题】THREE.js CylinderGeometry.attributes 未定义【英文标题】:THREE.js CylinderGeometry.attributes not defined 【发布时间】:2022-01-24 00:05:40 【问题描述】:我无法访问 THREE.js 中任何类型几何的 .attributes.position。基本上,控制台错误是 'Uncaught TypeError: Cannot read properties of undefined (reading 'position')'。
const cylinderGeometry = new THREE.CylinderGeometry( 5, 5, 5, 5, 15, 5, 30 );
const position = cylinderGeometry.attributes.position;
const vertex = new THREE.Vector3();
作为参考,sn-p 取自https://threejs.org/docs/#api/en/objects/SkinnedMesh。
知道为什么会发生这种情况吗?会不会和我使用的 THREE.js 版本有关?
【问题讨论】:
如果您使用的是 r125 之前的版本,那么CylinderGeometry
是 Geometry
,而不是 BufferGeometry
。尝试使用CylinderBufferGeometry
。
【参考方案1】:
如果你使用 Three.js 版本 r125 或更高版本,你应该可以获取任意几何图形的位置属性with the .getAttribute()
method.:
const cylinderGeometry = new THREE.CylinderGeometry( 5, 5, 5, 5, 15, 5, 30 );
const posAttribute = cylinderGeometry.getAttribute("position");
const posArray = posAttribute.array;
如果您使用的是 r124 或更早版本,则生成的几何图形过去的结构会有所不同。此方法现已弃用,因此建议您更新到较新的版本。
【讨论】:
以上是关于THREE.js CylinderGeometry.attributes 未定义的主要内容,如果未能解决你的问题,请参考以下文章
使用Three.js 心得系列一 如何创建三维网格三使用Three.js 心得系列三 Three.js 如何加载GlTF文件