Performance optimisation of a scene with hundred of thousands of cubes

Hello,

I want to create a scene with a maximum number of cubes without lag. I already use meshBasicMaterial as they seem the less expensive way to make cubes with colors. I was thinking of making invisible/removing objects that are not visible in front of the camera, but I’m not sure if this is efficient and how I can achieve this the most optimally possible. Some cubes will also disappear forever after certain actions so maybe is it better to remove them?)
I don’t know if there is any other technique to improve the performance?

edit: An additional piece of information that could be useful, the cubes are immobile most of the time, but we are supposed to be able to move the camera around them.

instance them. Instances - CodeSandbox if you want to go into the extreme you can move things at the shader level, here’s 1 million animated cubes no sweat with three.bas THREE.js BufferAnimationSystem btw three automatically culls non visible objects, you don’t need to do a thing.

1 Like

Thanks for your answer, this is exactly what I was looking for. if I may just ask. If I want some mesh to have other materials. Do I have to create a new instantiated mesh? Or is there a more optimal way to do that?

yes. you would make a new instance.

1 Like