When using a BufferGeometry to render thousands of cubes forming terrain, I encountered difficulty in updating the geometry when changing the position of a single cube. For instance, this is the code used to initialize the geometry: (My tests are based on an updated version of this example)
// 12 triangles per cube (6 quads)
var triangles = 12 * 150000;
var geometry = new THREE.BufferGeometry();
geometry.attributes = {
position: {
itemSize: 3,
array: new Float32Array( triangles * 3 * 3 ),
numItems: triangles * 3 * 3
},
normal: {
itemSize: 3,
array: new Float32Array( triangles * 3 * 3 ),
numItems: triangles * 3 * 3
},
color: {
itemSize: 3,
array: new Float32Array( triangles * 3 * 3 ),
numItems: triangles * 3 * 3
}
}
positions = geometry.attributes.position.array;
normals = geometry.attributes.normal.array;
colors = geometry.attributes.color.array;
After moving a cube, I have to set:
geometry.attributes.position.needsUpdate = true;
This operation causes a drop in FPS during the update process. I am looking for alternate methods to achieve this. It seems unnecessary for minor changes to one cube (12 triangles/36 vertices). I assume that setting `needsUpdate` sends the array to the shader again.
One solution I considered was dividing the geometry into separate smaller BufferGeometries, but I am unsure about the impact on overall performance. As far as I know, more geometries lead to lower FPS.
If anyone has any suggestions or ideas on how to tackle this issue, I would appreciate the assistance! Despite the update concerns, BufferGeometry appears to be the ideal solution for my needs. Thank you!