Collisions with thin instances

How can I set checkCollisions for thin instances? In the docs, it it mentioned that thin instances support collisions. However, I couldn’t find any example on how to enable them. What I tried is setting mesh.checkCollisions = true on the mesh that I then call mesh.thinInstanceAdd() on. However, this didn’t work for me.

For picking, there’s an example in the article where picking is enabled by doing

box.isPickable = true;
box.thinInstanceEnablePicking = true;

However, I couldn’t find a similar attribute for enabling thinInstanceCheckCollsions.
One thing I found is thinInstanceRegisterAttribute and thinInstanceSetAttributeAt. However, I have no idea if I can use those to enable collisions.

I have just set up an example PG, if this is what you look for, like docs say it only uses one boundingInfo for all thinInstances:

So there’s no way to checkCollisions with the individual instances, right? This occured to me too when I looked at boundingBox of my thinInstance and it was a box that contained every instance.
Sadly that is not enough for my use case, since they’re spread all over the scene, but I think I have another idea that might work for my scene.

As a follow-up question: The thin instances in my scene are spread throughout the scene, but they are clustered, so there are a few points where there’s alot of them and in the rest of the scene, there’s none. Is there any way to “draw an invisible box / bounding-box” around each cluster (I know the position of the clusters). I suppose I could just create a normal box and set it’s alpha to 0, but I’m sure there’s a better way.

The collider box mesh idea is very used, I’d go with that :grin: And Mesh only supports one Bounding Box so you can’t set multiple of them

Instead alpha = 0, won’t isVisible = false be better in terms of performance?

Or this might help in deeper section: Drawing Bounding Boxes | Babylon.js Documentation

I have had similar issues with “clusters” of meshes and the accuracy of my collision detection has been limited by the bounding boxes being cuboids.

I have resorted to doing collision detection via CSG intersections. It’s reliable but for large number of meshes or meshes with a lot of facets it may be slow:

    const csg1 = BABYLON.CSG.FromMesh(mesh1);
    const csg2 = BABYLON.CSG.FromMesh(mesh2);
    const intersecting =  (csg1.intersect(csg2) as any).polygons.length > 0

polygons is not exposed in the API which is why the ‘as any’ it there.

To make cluster meshes do unionInPlace

I hope that’s useful.

-Flex

Great, that’w how I implemented it now. I was wondering how that would impact performance/FPS. Do you think this could have a noticable effect on my scene? I have approximately n/6 collider boxes (set to invisible) for n meshes and n instanced meshes. I didn’t really notice any performance decrease when just viewing the scene.

Yeah that’s a good point, isVisible does seem like the better fit for this. I ended up using it over alpha, so thank you for the suggestion.

It won’t impact anything at GPU level since invisible meshes are not passed, so if you’re not CPU bound it’s going to be just fine :smiley:

Great, thank you!