I simply want to make the glTF model fall using a physics engine.
My current code is like below. The current example is the Physics API V1+ammo.js example.
Physics seems to work correctly, but the eraser label and CD boombox display are displayed backwards.
I think it’s probably because I set the root node to null, but I don’t think the physics calculations will work if I don’t do that.
What is the best way to do both physics and display correctly?
I tried porting to Physics API V2 + Havok.
However, this time it started penetrating through the floor.
// NG : Go through the floor. Resetting the scaling makes physics work.
BABYLON.SceneLoader.ImportMesh("", "https://cx20.github.io/generated-model-sandbox/models/gltf/Eraser/glTF-Binary/", "Eraser.glb", scene, function (meshes) {
const mesh = meshes[1];
mesh.parent = null;
mesh.position.y = 3;
//mesh.physicsImpostor = new BABYLON.PhysicsImpostor(mesh, BABYLON.PhysicsImpostor.BoxImpostor, {mass: 1, restitution: 0.6}, scene);
new BABYLON.PhysicsAggregate(mesh, BABYLON.PhysicsShapeType.BOX, {mass: 1, friction: 0.5, restitution: 0.6}, scene);
});
Apparently the physics engine doesn’t seem to recognize the thickness of the eraser.
As a test, I reset the scaling and it worked. It seems that the problem of label orientation has also been improved.
However, I don’t know if this is the correct method.
I checked the shogi pieces model, and it has a rotationQuaternion set, so it needed to be nulled first before cloning, or the clones would get the rotation from the quaternion too. And when you set mesh.rotation, it does exactly that.
I see. I don’t think it was in quaternion mode when the model was created, but it may have been converted to quaternion mode when exported in glTF format.
Now that we know the cause of the problem, we can move on to the next step. thank you very much.