Dynamic Object Placement Without Intersections

I’m trying to build a dynamic placement system for a lot of objects like an asteroid field or a forest. I know I can loop through and create instances of these meshes and place them randomly but what is the most efficient way to ensure these objects are not intersecting with each other? Is there a generic way to detect if these meshes intersect or collide without having a ton of references to other meshes?

This section may be helpful - Mesh Intersections | Babylon.js Documentation
Basically, there is all that one may need to check if one mesh intersects other mesh. You just need to implement it in your random placement logic, that’s all :slight_smile:

I know of mesh intersections, but I wanted to know the most efficient way to utilize them if I’m creating something like an asteroid field. As far as I know, you can only check an intersection between two meshes (at once). So if I create 100 objects how could I ensure that none of these will intersect.

You may have an array of these objects and then check a new object if it intersect any previous element. If not, place it. If yes, do something with it (change position, skip etc.)
Another way, without intersections, is to create 3D array and, since you should know the bounding size of your objects, check every new object if it fits into your populated 3D matrix and doesn’t overlap other objects.

1 Like

Thanks, I think I have a few ways to approach this. I’m going to try to keep track of locations and check against them and see how well that works. Marking solution.