I’m trying to add colliders (aka “impostors” in Babylon) with the default CannonJS implementation, and it’s messing up the locations and rotations of all my objects from the original scene.
From what I understand, this is a side effect stemming from the impostor creation system only working on objects in local space, meaning they have to be unparented. (For context, every GLTF or GLB scene has all its mesh objects parented to a single __root__ node by default.)
I used this solution that unparents each mesh, adds the collider/impostor, and then reparents it. Unfortunately, unparenting the mesh from __root__ seems to make it lose its original placement, and I have to hard-code its location and rotation back into my scene.
Is there a more efficient way to implement physics on a multi-object .gltf/.glb scene? Maybe there’s a method to implementing a physics engine like Rapier or cannon-es that doesn’t have the local space-only requirement of Babylon impostor objects? Thanks for reading
The __root__ parent is only created to convert between GLTF and Babylon’s different handednesses, so you could alternatively just bake the transform in instead and not worry with parenting: Babylon.js Playground (babylonjs.com)
@carolhmj@bghgary Thank you for the great solutions! I love how thin the code gets from being able to bake or discard one of the two handedness systems.
I’m going to try implementing all the suggestions in this thread (while also switching to Ammo.js since it seems to have more active maintainers and Babylon features,) and I’ll post here again later (either with any more issues I run into, or the finished Playground of everything in this thread successfully put together)