【问题标题】:THREE.js CylinderGeometry.attributes not definedTHREE.js CylinderGeometry.attributes 未定义
【发布时间】: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 之前的版本,那么 CylinderGeometryGeometry,而不是 BufferGeometry。尝试使用CylinderBufferGeometry

标签: javascript three.js threejs-editor


【解决方案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 或更早版本,则生成的几何图形过去的结构会有所不同。此方法现已弃用,因此建议您更新到较新的版本。

【讨论】:

    猜你喜欢
    • 2020-06-13
    • 1970-01-01
    • 2015-05-22
    • 2016-02-20
    • 2018-03-28
    • 2020-07-28
    • 2018-06-01
    • 2017-04-26
    • 2017-08-31
    相关资源
    最近更新 更多