如何正确的在BabylonJS中加载多个GLTF格式的模型

我应公司要求学习WebGL3D,从而接触到了BabylonJS,并了解到目前web中主流的Babylon模型和GLTF模型,因为两个模型我都使用过,最后决定以GLTF模型加载,现在公司需要我在场景中加载一整套模型,目测有10个以上,所以我想知道有没有什么适用的方法可以让我来实现我所需要的效果!
感谢各位的帮忙

你可以使用 SceneLoader.ImportMesh()SceneLoader.Append() 等多种方法,详细的接口搜下文档。

另外,最好用英文提问,否则老外看不懂怎么回答你?

you should speak English here.

Thank you!
but I know what you mean. I have used both the ImportMesh and the Append function. Loading a model is fine, but I need to load several different models, so I am wondering if there is a more efficient method

If you can serialize those models in one scene, then you can load the scene in one time.

SceneLoader.ImportMesh() can receive an array of meshes’ names as payload.

or you can run SceneLoader.ImportMesh() several times in a for(){} loop.

1 Like

I know what you mean. I also read some contents in BBS on the Internet, but most of them are simply stated, or all of them are cloned. I don’t know how to do it

Hi, @ranwei-001,
Welcome to the community!
You can check out assets manager:
https://doc.babylonjs.com/how_to/how_to_use_assetsmanager
If you have multiple gltf files, just add multiple meshTasks
It is pretty simple and intuitive
Let us know if you run into any other difficulties

2 Likes

Thank you for your reply!
I did it yesterday, but it would be a bit of a hassle. Every time I add a model, I have to write a meshTask

Nice!
An alternative method is to merge all models into a single gltf file and load it in.
Or consider a backend with file system to request / feed seperate gltf files in.
Anyway, automation comes with a bit of cost.

Thank you for your reply!

I’m just a beginner to this. As for what you just said, I have thought about merging all the files into a GLTF model before, but I haven’t found a method on the Internet, so I still don’t understand it