【问题标题】:Imported mesh falls through the ground in BabylonJS导入的网格在 BabylonJS 中从地面掉落
【发布时间】:2023-01-30 23:44:20
【问题描述】:

我正在尝试将 BabylonJS 中的物理 (AmmoJS) 用于导入的网格。 对于我即时创建的网格,一切正常,但是当我导入网格时,它会从地面掉落。

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);
});

当我把警车的restition改成0或1时,它没有掉在地上,但奇怪地反弹了几次,然后倒在了它的一边。使用 BoxImpostor 而不是 MeshImpostor 它会直接掉落。

有任何想法吗?

【问题讨论】:

    标签: mesh babylonjs physics-engine ammo.js


    【解决方案1】:

    您必须考虑 .glb 文件使用右手系统,而 BabylonJS 使用左手系统。所以我建议将 BabylonJS 设置为右手,不要按绝对值缩放。

    scene.useRightHandedSystem = true;
    
    ...
    
    policecar.scaling.scaleInPlace(scale);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-01-15
      • 1970-01-01
      • 1970-01-01
      • 2018-11-28
      • 1970-01-01
      • 2013-06-25
      • 2017-03-20
      • 1970-01-01
      相关资源
      最近更新 更多