How to choose between InstancedMesh and BatchedMesh?

Hi, I’ve been trying to draw some vertices and pick them. I noticed that BatchedMesh has a setVisibleAt method, which makes it convenient to change the visibility property. However, InstancedMesh doesn’t have this feature. Should I prioritize using InstancedMesh ? Does InstancedMesh offer better performance than BatchedMesh ? I know both can merge draw calls, but I’m curious about the trade-offs.

And I found that when instances of an InstancedMesh overlap in position, the setColorAt method fails to change the color properly. Could someone explain why this happens? The example I referenced is this.

Both InstancedMesh and BatchedMesh support a single material and render all instances in a single draw call. Where they differ is in how they handle multiple geometries:

  • If you’re using a single geometry, always use InstancedMesh.

  • If you have a few geometries (2–4) and many instances, you can still manage separate InstancedMesh for each geometry.

  • If you’re dealing with many geometries, BatchedMesh becomes the most efficient solution.

If you need more control over the official InstancedMesh, consider using InstancedMesh2, @agargaro did an amazing work at extending its capabilities (Visibility, sorting, frustum culling, LOD…)

5 Likes

Thanks, I’ll take a look.
Do you know why the color cannot change when positions overlap? Is it because of the rendering order?

If you have overlapping instances rendered in the wrong order, the result can appear visually incorrect due to improper depth sorting. You can check out this points particles example to see how particle indices are sorted based on depth:

You can also take a look at how depth sorting is handled in BatchedMesh for both opaque and transparent objects:

BatchedMesh used to implement a more complex Radix sort algorithm, which could be up to 7x faster for large datasets. I assume it was replaced for the sake of simplicity.

1 Like

Thanks a lot! I’ll take a look at it.

1 Like

I’ve included an example with radix sort also for InstancedMesh2 (based on BatchedMesh) :slight_smile:

4 Likes