Issue with loading mesh and colliders and adding physics

Hello!

I’ve been trying for a couple of days now to add a bucket to my scene with box colliders, but I’m having a lot of trouble getting things to work properly. I’ve read the documentation carefully and tried to examine the babylonjs source code to understand what’s going on

This is my playground: Babylon.js Playground

  • I can’t seem to get the child colliders to scale properly, in the physics debug view it looks like the boxes are too big, what’s going on here?
  • The entire imposter is behaving weird, especially if I run it without the debug view open, should I not copy the position like I’m doing?
  • If I turn off the new PhysicsImposter lines (line 45 and 48), everything seems to align properly.

Any help is very much appreciated!!


this is where the bucket should be


this is what happens with imposters enabled

Adding @Cedric

I did a test with Cannon and Ammo

Bucket colliders | Babylon.js Playground

I changed parenting to make the compound and it works way better. I also did a few teaks to gravity/forces/position to see more clearly what’s happening.

I think there is a bug with physics debug display. The behavior looks like what’s supposed to be (bucket collision seems fine when colliding and falling on the ground) but it’s display doesn’t correspond to anything. I’m investigating …

1 Like

PR for the debug display is live : physics debug display box compound by CedricGuillemet · Pull Request #10305 · BabylonJS/Babylon.js · GitHub

3 Likes

@Cedric awesome! Thanks so much for investigating and taking the time to work through my problem. I’ll work on this wednesday and will report back.

1 Like

Hey @Cedric, thanks again for your time.

I’ve looked into the work you did and your solution is not what I was hoping for. You use bucketMesh.parent = null; which ignores the scaling introduced by the __root__ mesh from the gltf import. This effectively flips the mesh and not desired, which is not apparent in this simple bucket example.

I’ve also tried checking out master and testing your PR for fixing the debug display, but unfortunately it doesn’t look like it’s working yet:

image

I have experimented a bit more with my playground and I found a working solution which I’m happy with: #CUDJRH#6. It seems to work with AmmoJS and CannonJS. I’ve added a lot of comments explaining why I think all the steps are necessary.

With this I think there are still 3 issues which is making this all difficult:

  1. There is still a bug in the physics debug viewer
  2. The babylonjs PhysicsImposter doesn’t work with a mesh with mesh.scaling.y = -1 (see #10283)
  3. The compound PhysisImposter system doesn’t work with root.scaling.y = -1 (which you’ll run into when importing gtlf)

For the latter, I’m not sure if this is something babylonjs should support. If not, I think the only real solution is to create a new root mesh when building the compound physics object, which is actually also explained in the documentation (Authoring and loading a mesh with a collider mesh), although a bit outdated.

I would like to hear your thoughts! Thanks!

Related:
https://doc.babylonjs.com/extensions/Exporters/Blender_to_glTF
https://forum.babylonjs.com/t/how-to-correctly-import-gltf-and-add-physics/20234/2

  1. Yes, there is still a bug with debug viewer. I’m taking a look
  2. Strangely, it looks fine with Ammo but not Cannon
  3. I don’t know yet how to deal with that. When in doubts, always refer to the documentation :slight_smile:

So, there are, at least, 2 bugs: 1 for the debug display and one with negative scale for the physics engine. Cannon and Ammo do not behave the same.

Display should be fixed with this PR : fix last debug display of compound by CedricGuillemet · Pull Request #10331 · BabylonJS/Babylon.js · GitHub

2 Likes

Awesome! It looks like display is fixed! Thanks a lot @Cedric!

Working playground here (with 5.0.0-alpha.21): #CUDJRH#6

1 Like

I stumbled upon scene.useRightHandedSystem = true; which eliminates the -1 scaling issue when importing gltf… cool! I’m using this in my personal project now!

1 Like