除了 positions 属性中的 NaN 值之外还有哪些问题会导致 computeBoundingSphere 失败?
What issues besides NaN values in the positions attribute can cause computeBoundingSphere to fail?
我是第一次尝试使用 BufferGeormetry class。我有一个 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() doesn't require [] as its argument,BufferAttribute
s 也不行,因此您可以在 []:
之外单独传递任意数量的值
// 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]);
我是第一次尝试使用 BufferGeormetry class。我有一个 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() doesn't require [] as its argument,BufferAttribute
s 也不行,因此您可以在 []:
// 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]);