【问题标题】:Babylon JS 3D File loading is not working巴比伦 JS 3D 文件加载不起作用
【发布时间】:2020-07-07 01:39:47
【问题描述】:

无论我尝试导入什么类型的文件,我都不会让它显示在我的画布中。

我尝试过的:

  • 在 3D 查看器、巴比伦沙箱和搅拌机中打开文件,那里 模型没有错
  • 使用加载器导入模型后上下缩放模型 (是的,导入成功,没有控制台错误和 onSuccess 回调被调用),因为我认为这可能只是方式 太大或太小,相机无法拍摄。
  • 不同的文件格式(.babylon、.glb、.obj)
  • 所有不同类型的 SceneLoader 函数,(导入网格、追加...)

这是我的代码:

import { SceneLoader, Scene } from "babylonjs";
import "babylonjs-loaders";

const importFile = (
  path: string,
  fileName: string,
  ext: string,
  scene: Scene
) => {
  console.log(SceneLoader.IsPluginForExtensionAvailable(ext));
  SceneLoader.ImportMeshAsync("", path, fileName + ext, scene).then((meshes) =>

   // this actually does log some object with a bunch of fields, which dont seem to help me
 identify the problem. Maybe someone knows what kind of info that could give me.
    console.log(meshes)
 );
};


//specific Model being loaded
export const createChessBoard = (scene: Scene) => {
  importFile("/home/tom/Models/", "ChessBoard", ".obj", scene);
};

这里被调用

// the rest of the scene 
const scene = new Scene(engine);

  const camera = new ArcRotateCamera(
    "Camera",
    Math.PI / 2,
    Math.PI / 2,
    2,
    Vector3.Zero(),
    scene
  );
  if (canvas) {
    camera.attachControl(canvas, true);
  }

  const light1 = new HemisphericLight(
    "ambientlight",
    new Vector3(1, 1, 0),
    scene
  );
  const light2 = new PointLight("spotlight", new Vector3(0, 1, -1), scene);

  createChessBoard(scene);

使用 MeshBuilder 创建相机、场景和所有这些或形状可以完美地工作。我在任何地方都找不到任何人在使用加载器时遇到问题......通常他们被高度赞扬为如此轻松地工作,我希望有人能帮助我解决这个问题,因为巴比伦看起来像一个很酷的图书馆

【问题讨论】:

    标签: babylonjs


    【解决方案1】:

    https://doc.babylonjs.com/api/classes/babylon.sceneloader#load

    ImportMesh 方法(而不是 ImportMeshAsync)允许可选的回调,如 onError、onComplete 等。

    这些会在出现问题或成功等时触发,以便您更好地调试问题

    函数 onError(e){ console.log(e) // 希望 e 中有一些有用的信息(可能是 e.message 或 e.error)

    }

    SceneLoader.ImportMesh("mesh1","./yourMeshFolder", onError);

    【讨论】:

      猜你喜欢
      • 2020-06-09
      • 2015-11-13
      • 2020-09-17
      • 2020-04-19
      • 2020-09-13
      • 1970-01-01
      • 1970-01-01
      • 2017-12-09
      • 1970-01-01
      相关资源
      最近更新 更多