Large mesh collisions (Cameras/Collisions/Theoretical)

Hi everyone!

I have a mesh with thousands of vertices (Building). I also have FreeCamera.

I want the camera and mesh to collide. I have tested several options and now I have a few questions.

  1. Camera ellipse - works, but when approaching the mesh, everything starts to lag very much. It becomes very small fps.
  2. Using Ammo.js and creating a MeshImpostor for it. The result is Out Of Memory (OOM).
  3. Ray collisions - Just like in the case of the camera ellipse, everything starts to lag.

What are the options for solving these problems for all three types of collisions?

Adding @Cedric and @RaananW as they are amazing with physics and I am stupid with it :slight_smile:

1 Like

If it is a very large mesh with many vertices it will require some heavy computation to check for collisions against it. even for a well optimized physics engine.
Some physics engines can support a convex hull, which will be a better approximation of the mesh’s shape. There is a short discussion about it here - Ammo.js convex mesh hull - #3 by MackeyK24

A different approach would be to collide against the bounding sphere or bounding box, depending on the mesh you are colliding against. Another one would be to separate the mesh into smaller meshes.
The reason that would work is the algorithm that is used to check for collisions. It inspects every triangle until it finds one that collides against the player. If you are “lucky” and it is one of the first triangles then it will be rather quick. but most of the time (because that’s how things are :slight_smile: ) the colliding triangle will be deep in the positions array. now checking 100, 200, 1000 of those - that is fast and can be done every frame. but when it gets to be very big - the performance goes bad.

Of course, the best solution IMO is making your mesh more low-end friendly. But that’s not the nicest solution is a lot of cases. It really depends on your usecase.

3 Likes

In this example (it takes a long time to load 25MB) I am trying to create a ConvexHullImpostor for a building.

As a result:

  1. On the babylon playground, the impostor, apparently, is not created at all. (Judging by the sphere flying through the mesh)
  2. Locally in the project, the browser page freezes so much that you have to close the browser :slight_smile:

So all I can do is split one big mesh into smaller meshes (like cubes - apartments and rooms of a building)?

Surely there is no other way to make this impostor automatically?

Best approach to me is to have meshes for rendering and meshes for collision detection. Basically, build a low-res version mesh that will not be rendered but only used for collision.
If it’s a few hundred triangles, you’ll be able to use it for camera ellipse or trimesh with Ammojs.
Maybe you can try to use a convex hull with Ammo from your rendered geometry but I think it will be counter productive to convert a geometry that big at load time. Moreover, it will be convex so a lot of detail will be missing. Making it look more like a box.
So, I’ll all for a simplified geometry!

2 Likes

As I understand it, this is a general approach for creating impostors for large geometry. That is, this approach is not exclusively for babylon or for browser based 3D?

Correct! It’s one of the core concepts of realtime rendering/games. Like voxelizing a scene to do global illumation computation. Or using triangles to render continuous surfaces. Use a simpler representation to do fast computation. It won’t be exact but close and good enough.

1 Like

If we look into the future, to theorize… What are the possible solutions to the problem of large impostors for large geometry? Is anything being done in the world for this, and if so, what? Is it possible to read about it somewhere?

Or does it all ultimately come down to increasing the performance of computers?

What about using quadtree to minimalize the meshes to be checked?
And the optimisation from Cedric

1 Like

Hard to tell. Maybe in the future meshes will be ahiearchy of signed distance field with a raymarching for rendering and SDF for collision detection…or not :slight_smile:
No need to bet on distant future for today’s software.
For now, a bounding volume hierarchy and simple primitives or trimesh seems fine.

1 Like

If you mean Auto LOD, then it works very slowly on such large meshes. In addition, for certain reasons, I cannot reduce the number of vertices in the mesh or change them in any way. Even if the mesh can be optimized manually and automatically, this cannot be done.

Okay, thanks for the replies. If anyone sees this post in the future feel free to add something.