I’m trying to create a class to implement physics in complex geometries, this example uses the object’s triangles to create physics that works. I’m still going to do another one that will use bvh calculations with bounding boxes
the physics class is in:
https://didisoftwares.ddns.net/7/js/physics.js
simple apply physisc by:
physics.createObj(model1,‘mesh’,‘obj’,null,mass);
If anyone has more examples of physics in complex models, post them there
Nice approach. Using the triangle mesh directly from the geometry is usually the easiest way to get accurate collision on complex models, especially for things like buildings or terrain.
One thing worth mentioning for anyone trying this is that triangle mesh shapes in ammo.js should normally be used only for static objects. If you try to use them for dynamic bodies the performance can drop very quickly and the simulation becomes unstable. For moving objects it’s usually better to convert the geometry to a convex hull or a combination of simple primitives.
Another trick for complex scenes is splitting a large model into several smaller collision meshes instead of one huge triangle mesh. The broadphase collision detection works better that way and you get fewer heavy collision checks.
Your helper function physics.createObj(model1,'mesh','obj',null,mass); is a nice idea because it makes adding physics to imported models much simpler. A lot of people struggle with the Ammo setup code so wrapping it in a class like that is pretty useful.
If you end up implementing the BVH version later it would be interesting to compare the performance between triangle mesh shapes and BVH-based collision for big environments.