Quantcast
Viewing all articles
Browse latest Browse all 388

GLTF axis conversion and physics

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

    }
});

Viewing all articles
Browse latest Browse all 388

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>