How to optimise my voxel engine code

I think the SolidParticleSystem might be the answer to your troubles, in combination with some smart algorithms to re-use & only render visible boxes.

// 10k boxes
https://playground.babylonjs.com/#LXXL6Y#22

// SPS docs
https://doc.babylonjs.com/how_to/solid_particles

  • By re-use i mean that you shouldn’t need 65k boxes in your scene,
    superset a position array saying “at position x/y/z, a box is located with this uv(texture)”, then re-use geometry, move them around depending on your player’s position.

  • Minimalize the original box if possible, remove any meshData you don’t need. (it’s replicated in the SPS mesh, bloating memory that isn’t used)

Edit; wrong PG.