Convert instances to thin instances issue

Hey!

I’m having an issue with one of my scenes. For one of the meshes I use quite a lot of the same geometry, so I converted some bits to duplicate meshes. So far so good, but that doesn’t fully cut it, so I needed to optimise further - that’s when I decided to convert normal instances into thin instances. At this point, the performance started to get better, but I’m still having some issues with the calculations, for example:
https://playground.babylonjs.com/#9GFSPZ#4

Now, I use that method in other places across my scene and it works fine in most places. In this place, however, it does not work as expected. I’m pretty sure that my matrixPosition calculation is off, but I can’t figure a way to fix it. It probably has something to do that the original mesh has a position, that isn’t 0,0,0, which would somehow need to be accounted, as with other meshes, they are all at position 0,0,0 and it works fine.

Thanks!

1 Like

The thin instance matrices of a mesh are relative to the mesh own local matrix, meaning the final local matrix of a thin instance is mesh_localmatrix * thininstance_localmatrix.

In your case, you need to set the local matrix of the mesh to the identity to avoid problems with thin instances positionning (lines 47-49):

https://playground.babylonjs.com/#9GFSPZ#5

Note that you also need to add the local matrix of the mesh itself into the list of thin instances for it to be rendered, it is not automatic (see lines 40-46).

4 Likes

Oh, that seemed much easier than I thought it would be. Thank you (again) for your help!