[英]Imported mesh falls through the ground in BabylonJS
I'm trying to use physics (AmmoJS) in BabylonJS for an imported mesh.我正在尝试将 BabylonJS 中的物理 (AmmoJS) 用于导入的网格。 For meshes I create on the fly everything works fine, but when I import a mesh it falls through the ground.
对于我即时创建的网格,一切正常,但是当我导入网格时,它会从地面掉落。
const ground = BABYLON.MeshBuilder.CreateBox("ground",
{ width: 10, height: 1, depth: 10}, scene);
ground.receiveShadows = true;
ground.checkCollisions = true;
ground.physicsImpostor = new BABYLON.PhysicsImpostor(ground , BABYLON.PhysicsImpostor.BoxImpostor, { mass: 0, friction: 0.5, restitution: 0.5 }, scene);
BABYLON.SceneLoader.ImportMesh(["car9"], "models/", "Policecar.glb", scene, function (meshes, particleSystems, skeletons) {
for (let i in meshes) {
meshes[i].checkCollisions = true;
}
let policecar = meshes[0];
policecar.physicsImpostor = new BABYLON.PhysicsImpostor(policecar, BABYLON.PhysicsImpostor.MeshImpostor, { mass: 10, friction: 0.5, restitution: 0.5 });
policecar.position = new BABYLON.Vector3(0, 10, 0);
policecar.scaling = new BABYLON.Vector3(scale, scale, scale);
});
When I change the restition
of the policecar to 0 or 1, it doesn't fall through the ground, but bounces weirdly a few times and falls on it's side.当我将警车的
restition
更改为 0 或 1 时,它不会从地面掉落,而是奇怪地弹跳几次并倒在一边。 With a BoxImpostor
instead of MeshImpostor
it falls straight through.使用
BoxImpostor
而不是MeshImpostor
,它会直接掉落。
Any ideas?有任何想法吗?
You have to consider that.glb-files use right handed system, while BabylonJS uses left handed system.您必须考虑 .glb 文件使用右手系统,而 BabylonJS 使用左手系统。 So I would recommend to set BabylonJS to right handed and don't scale by absolute values.
所以我建议将 BabylonJS 设置为右手,不要按绝对值缩放。
scene.useRightHandedSystem = true;
...
policecar.scaling.scaleInPlace(scale);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.