Jump to content

GLTF axis conversion and physics


Recommended Posts

It seems there is some problem with the gltf model axis conversion.


I did a test with a few collada files exported either with y or z axis up and converted them in to the gltf format.

The converter always adds a dummy node to the models root ("Y_UP_Transform") wich has some matrix applied that solves the rotation but does no real axis conversion.


Big problem is that the model and dummy node imported to babylon still have the wrong axis up wich affects all pos/rot settings, breaks physics and flips the normals.


The code below shows how i loaded the test models and the errors with physics.

Maybe this could be solved at loader level?

BABYLON.SceneLoader.ImportMesh(null, assethost, source, scene, function (meshes, particleSystems, skeletons) {    for (var i = 0; i < meshes.length; i++){        var mesh = meshes[i];        // we want to import meshes only, so just dispose everything else than the transform node.        if (!mesh.geometry && mesh.name != "Y_UP_Transform") {            mesh.dispose(true)        } else if (mesh.name == "Y_UP_Transform") {            // set the position of the root/transform node            mesh.position = new BABYLON.Vector3(0,5,0); // up axis is flipped here (z was changed)        } else {            mesh.material = _materialLoader.get(scene, material);            mesh.renderingGroupId = 1;            mesh.receiveShadows = true;            shadowGenerator.getShadowMap().renderList.push(mesh);            // enable physics            // returns errors: .faceNormals[38] = Vec3(0.16052952624529215,0.8138526506383952,-0.5584569224679018) looks like it points into the shape? The vertices follow. Make sure they are ordered CCW around the normal, using the right hand rule.            mesh.setPhysicsState(BABYLON.PhysicsEngine.MeshImpostor, { mass: 1, friction: .1, restitution: .01 });            mesh.checkCollisions = true;        }    }    for (var j = 0; j < skeletons.length; j++){        var skeleton = skeletons[j];        // do something with skeletons    }});
Link to comment
Share on other sites

I just commited a new MeshImpostor implementation, using a different shape type. This should fix those errors. I haven't updated the preview build yet, will do it in a sec - you can then try with it and see how it works.

A small note - it can only collide with spheres and planes. So setting mass: 0 might be better, otherwise it will fall forever. (or put a plane underneath :-) )

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...