How to attach physics to imported mesh?

I hope that this is not a bug, just I am doing something wrong:
https://www.babylonjs-playground.com/#EHGYRF

Created mesh works as expected. For imported mesh gravity works, but mesh goes through ground.

1 Like

I think it has to do with the fact that your barrel mesh is composed of smaller meshes thus the impostor doesn’t apply correctly when you use it on the root node.

Probably, but how to fix? Create bounding transparent cylinder? Sounds CPU/GPU expensive and not elegant.

1 Like

For the current mesh probably merging the submeshes.

This is not a bug, but something odd about physics. Mesh impostors can only collide with spheres. I don’t know why.

Also, you don’t need the check collisions property if you are using a physics engine (like now). It is used for the camera’s built in physics.

Playground with sphere: https://www.babylonjs-playground.com/#EHGYRF#2

It collides but it bugs out.

Changing the ground to a thin box works (planes are always a physics problem). The root has no dimensions so the dimensions for a impostor on the root are suspect.

One way is to place the barrel over the cylinder as parent https://www.babylonjs-playground.com/#EHGYRF#3

Order of code is important.

2 Likes

Well, I fixed it in playground somehow, by changing plane to box (should not be very thin) and assigning BoxImpostor instead of CylinderImpostor: https://www.babylonjs-playground.com/#EHGYRF#4

This worked for playground but not in my app. I didn’t find any suitable coding solution.

So then I just imported .glb file to Blender and saved a texture from there in a separate file.
Then I created new Blender project with simple cylinder, edited UV map over texture that I saved before, removed camera and light (Blender adds them by default) and exported new barrel as .babylon file.
Then I put .babylon file and texture file in one folder in my app. During import to app .babylon file shows only one mesh (my cylinder), so I added a physics to it as usual and everything has started to work.