除了positions属性中的NaN值之外,还有什么问题会导致computeBoundingSphere失败



我第一次尝试使用BufferGeormetry类。我有一个x,y值的闭合路径,我正试图将其变成一个具有任意基本形状的金字塔。

for (let i = 0; i < this.nodelist.length - 1; i++) {
node = this.nodelist[i];
next_node = this.nodelist[i + 1];
positions.push([node[0], 0, node[1]]);
positions.push([center[0], elevation, center[1]]);
positions.push([next_node[0], 0, next_node[1]]);
}
const geometry = new THREE.BufferGeometry();
const positionNumComponents = 3;
geometry.setAttribute(
'position',
new THREE.BufferAttribute(new Float32Array(positions), positionNumComponents)
);

在我的参考系中,x是左右,z是前后,y是上下。所以我做了一个三角形序列,从一个基点到中心,再到下一个基点。然后下一个从第二个基点继续,回到中间,到第三个基点。节点数组在位置0和末尾具有相同的点。

错误消息为:

THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN.
The "position" attribute is likely to have NaN values.

我检查了位置数组,没有NaN值。我还应该看什么?有更好的方法来实现这一点吗?

我正在使用以下源库:

https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js

问题是将数组插入到数组中,从而导致嵌套数组。Array.push((不需要[]作为其参数,BufferAttributes也不需要,因此您可以在[]:之外单独传递所需的任意多个值

// You are nesting an array inside your array
positions.push( [node[0], 0, node[1]] );
// Instead, just add 3 shallow values
positions.push(node[0], 0, node[1]);

最新更新