从
documentation
,the
array
参数必须是
TypedArray
。所以,如果你正在与
Vector3
顶点,您可以考虑使用
Float32Array
.
TypedArray必须是平坦的
itemSize
参数表示每个组件的大小(
矢量3
即3)。所以第一个顶点是
[vertices[0], vertices[1], vertices[2]]
第二个顶点是
[vertices[3], vertices[4], vertices[5]]
以此类推。这样的东西应该奏效:
const pcGeom = new THREE.BufferGeometry();
const rows = 100;
const columns = 3;
const vertices = new Float32Array(rows * columns);
for(let i = 0; i < rows; i++) {
for (let j = 0; j < columns; j++) {
vertices[i * columns + j] = Math.random() * (2 - 0) + 0;
}
}
pcGeom.setAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
const material = new THREE.MeshBasicMaterial( { color: 0xff0000 } );
const pointCloud = new THREE.Mesh( pcGeom, material );