babylonjs - 巴比伦 JS 3D 文件加载不起作用
问题描述
无论我尝试导入什么类型的文件,我都不会让它出现在我的画布中。
我试过的:
- 在 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 创建相机、场景和所有这些或形状可以完美地工作。我在任何地方都找不到任何人在使用加载器时遇到问题......通常他们被高度赞扬为如此轻松地工作,我希望有人可以帮助我解决这个问题,因为巴比伦看起来像一个很酷的图书馆
解决方案
https://doc.babylonjs.com/api/classes/babylon.sceneloader#load
ImportMesh 方法(而不是 ImportMeshAsync)允许可选的回调,如 onError、onComplete 等。
这些将在出现问题或成功等时触发,以便您更好地调试问题
function onError(e){ console.log(e) // 希望 e 中有一些有用的信息(可能是 e.message 或 e.error)
}
SceneLoader.ImportMesh("mesh1","./yourMeshFolder", onError);
推荐阅读
- javascript - 努力让 axios 与 Rollup 一起工作
- microsoft-teams - 是否可以在频道@提及用户中发送消息
- javascript - 如何从这个构造中获得令牌?
- java - 如何在 MacBook 上修复 android 错误主要版本 53 比 52 更新
- docker - 从绝对路径复制文件
- javascript - 在反应本机useEffect()中获得无效的钩子调用
- graphql - 未连接数据的 Graphql 查询
- sql-server - 将行移动到列 SQL Server
- javascript - 将 this.variable 分配给未在 VueJS Axios 响应中分配的值
- python - 使用负载解析对python2.7的api响应时解析错误