Loading gltf and physics not working, what am I missing?

I have playground

I try to enable physics and add impostor to meshes. But physics is not working.

What am I missing?
What is root mesh and why gltf have it ?

Is better to have gltf or glb ?


Here is my 2 cents…

I have been trying to tell folks for quite some time about GLTF meshes and Physics and PARENT containers. They are screwy… and in GLTF … everything has a parent … up to the root node.

Anyways… You need a function like this:

var createPhysicsImpostor = function(scene, entity, impostor, options, reparent) {
    if (entity == null) return;
    entity.checkCollisions = false;
    const parent = entity.parent;
    if (reparent === true) entity.parent = null;
    entity.physicsImpostor = new BABYLON.PhysicsImpostor(entity, impostor, options, scene);
    if (reparent === true) entity.parent = parent;

And dont do mesh.physicsImpsoter = new BABYLON.PhysicsImposter

call you function instead:

newMeshes.map(mesh => {
            if (mesh.name.includes("BoxCollider")) {
                console.log("Dodaj Box Collider/Impostor --> ",mesh.id);
                //mesh.physicsImpostor = new BABYLON.PhysicsImpostor(mesh, BABYLON.PhysicsImpostor.BoxImpostor, { mass: 0, restitution: 0.9 }, scene);
                createPhysicsImpostor(scene, mesh, BABYLON.PhysicsImpostor.BoxImpostor, { mass: 0, restitution: 0.9 }, true);

        newMeshes.map(mesh => {
            if (mesh.name == "Ball") { //  || mesh.name === "Sphere"
                console.log("Dodaj Ball Collider/Impostor --> ", mesh.name);
                //mesh.physicsImpostor = new BABYLON.PhysicsImpostor(mesh, BABYLON.PhysicsImpostor.SphereImpostor, { mass: 0.5, friction: 0.5, restitution: 0 }, scene);
                createPhysicsImpostor(scene, mesh, BABYLON.PhysicsImpostor.SphereImpostor, { mass: 0.5, friction: 0.5, restitution: 0 }, true);
                _playBall = mesh; // damo mesh v kolekcijo boxColliders
                _playBall.position.y = +10;

Try it out on this AMMOJS playground: https://playground.babylonjs.com/#97FMLC#2

And this CANNONJS playground as well: https://playground.babylonjs.com/#97FMLC#3


Hi guys!

Hah, Mackey, I beat you with PG #1, but I was slow to post, and you have a cooler parent adjuster.

I just removed the parents in lines 22 and 38. :slight_smile:

Ian, if you activate lines 54 and 55 on my #1 playground, you can see that a red mesh called “CrossComponent” is causing the z-fighting jaggies when camera is panned. I don’t know how/why that mesh is arriving… but it is. Line 57 will disable it… if wanted.

Use the playground’s Inspector feature… to see how root node is doing its hierarchy stuff.

Party on, guys.

1 Like

Thank you @MackeyK24 to help me explain/solve this problem
Are those things explain anywhere in Babylon Docs?

Just tested exporter gltf and glb from Blender.

Why exactly exporter make “root” node and we have to remove it from “root
parent if we want set physics impostors on meshes ?

Is this any convention of gltf/glb ?
Can we have more nodes like “root” and rename them?
Where/How can we do that wit blender before we export to gltf/glb ?


I have no info on that. glTF-Blender-Exporter/user.md at master · KhronosGroup/glTF-Blender-Exporter · GitHub

Does THAT look familiar?

Scroll-down to Export Settings area of that doc.

See picture with “Nodes” checkboxes?

Have you tried “Export Selected Only” checkbox? Maybe select only the 6 main objects, and try that checkbox… then try new export?

Maybe more to learn in Blender docs and forums. Teach us what you learn, please. :slight_smile:

I don’t know who is custodian for BJS gltf importer… sorry. Maybe others know who are experts.

The root node is not really the problem. If you don’t like it you can remove with script… just don’t dispose the children . The physics issue is with the entity having any parent… it can be nested way down in hierarchy… a root or not at the top level makes no difference…, unless your object was directly under the root.

Anyways I always create physics imposters in my Pro Physics SDK for Babylon Toolkit… that create physics imposter functions is a Javascript port of one my utility helpers to always create physics imposter on any entity no matter where it is in the scene hierarchy… and keep it original parent child relationship… but with physics applied :slightly_smiling_face:

1 Like

I don’t really know Blender … so I can’t help wit that… I’m more the Unity Exporter guy