How to make a physical object collide with the terrain of a loaded glb

Hi everyone,
I want to make physical objects collide with the complex terrain in the loaded glb file.
However, MeshImpostor does not cause collisions no matter which physics engine is used.
https://playground.babylonjs.com/#1NQ0JU

I considered the collision feature built into babylon.js, but I can’t reproduce bounces and such with moveWithCollisions.
Would I need to prepare a separate simple mesh to achieve collision?

1 Like

let me take a look.

yes, it’s difficult to debug with that much meshes ans so many triangles/vertices. Can you provide a simpler glb with less mesh, or merged meshes? The best would be to provide a simplified mesh for collision detection/physics. Even without physics enabled, rendering is slow.

Thank you for the reply.
I don’t know much about 3D models, as I’m mainly programming, but I’ll try to merge meshes using blender.

As an alternative, many meshes also collided when using moveWithCollisions.
https://playground.babylonjs.com/#Q7NQIM

Using this, is it possible to use babylon.js built-in collision function only for collision detection, and use physics engine for the rest?
If anyone has done something similar, please let me know.

1 Like

there 2 types of collisions:

The first one is (mostly) for camera/mesh collision detection and mesh/mesh collision detection.
The second one compute dynamics from collision detection.
It might be a bit delicate to mix both world. Usually, physics engine is favored because it allows more things like collision response.

3 Likes

Thanks for letting me know that mixing the 2 types of collisions is delicate.
I’m going to give up on mixing collisions and try to see if I can simplify the mesh to make it collide.

1 Like

I tried AmmoJSPlugin based on this post, and no collision occurred
https://playground.babylonjs.com/#PN9H6U

Is this a problem with Ammo.js rather than babylon.js?

1 Like

If you add the physics impostor to just the root mesh (i.e. meshes[0]) and the spheres then it works as expected I think.

https://playground.babylonjs.com/#PN9H6U#1

2 Likes

Thank you.
I’ll use this as a reference to debug the mesh.

I found a way to fix it.
I used AmmoJSPlugin to apply MeshImpostor to the root mesh, regardless of the number of getTotalVertices.
But, this will cause Out Of Memory (OOM), so we need to increase the memory used by Ammo.js.

Based on the descriptions here, I set TOTAL_MEMORY to 512MB, built, and used the created ammo.js, and a collision occurred.
I hope this helps someone out there!

1 Like