Creating ThinInstance after merging Mesh using MergedMesh causes the origin to exceed frustum

Because of the title of the previous question, I need to create a new topic.

The problem now is that when I create ThinInstance using the merged Mesh, if the ThinInstance Matrix is offset too much, it will disappear, but not at the origin, because the Mesh that created ThinInstance is at the origin, And what the surrounding box shows is normal.


Moreover, Z-fighting appears in the model, which also explains the problem that the origin of the model is far away but close to the camera.

If I’m understanding your question correctly, this is normal behavior, because the bounding box of a thin instanced mesh is the box surrounding all of the thin instances. So if one mesh is instanced very far away, the box will be big.

1 Like

Yeah, you’re right. But according to my experience, Thin Instance does not support single Thin Instance culling. Since my thininstances are scattered all over the scene, all of my Thin instances should be displayed when the camera sees the bounding box. But here’s the thing: My thin instances will only show up if my camera contains the origin mesh.


The camera does not contain the origin mesh in this view, so my thin instance is not shown.

I want thin instance to display. My other mesh is fine because it has only one mesh so there is no need to merge. The thin instance that doesn’t show up is because I used the MergedMesh function.

@carolhmj Stupid solution to this problem: Keeping the origin mesh inside the camera at all times. requires switching to WebGPU mode because I used ReverseDepthBuffer :joy:

But I believe there are better solutions than this one :smiling_face_with_three_hearts:

You can use alwaysSelectAsActiveMesh

1 Like

This PR will fix the problem with the far mesh not appearing:

The problem (bug in Babylon) in your first PG is that a mesh with thin instances doesn’t maintain a bounding info per submesh and uses the bounding info of the original submesh (without thin instance). The PR will fix that.

Regarding the z-fighting problem, try to use bigger minZ values (like 1 or 10).

2 Likes

Feeling, when the PR is merged and released, I will set this reply as solution.