Is it possible to dispose of one object from the InstancedMesh?

Is it possible to dispose of one object from the InstancedMesh?

@Konrad_Psiuk –

According to my limited experience with instanced meshes … there is only one object in it. For all the instances there are just some basic data (e.g. matrix, color, and whatever instance attributes the user defines).

So, formally, you cannot dispose one instance and keep all the rest.

However, if you have 10000 instances and you want to dispose 1000 of them and draw only the rest 9000, you can move the disposed instances at the end of all buffers and reduce the number of drawn instances (i.e. property count). This will not reduce the memory used for buffers.

If you need to also reduce the allocated buffers, I suppose you have to allocate new buffers, copy the data, and then dispose the old buffers. In many cases this might kill any performance gain from using instances.

– Pavel

2 Likes

Thanks, Pavel, Great help!

1 Like

Also, since each object in the mesh has its own position/rotation/scale matrix, you can move some objects outside the camera frustum (via their matrix) and they won’t be rendered.

1 Like