In this playground, how can I make the onParsedObservable work with AppendAsync given that Append has been deprecated? I need to parse and react to metadata stored in the gltf extras prior to the model being added to the scene.
AppendAsync is promise-based. it resolves when the model was loaded. so you can either use async/await or then:
does that answer your question?
Yes, thank you.
I have a question about loading multiple models:
If there is a list of models (multiple models), such as:
let modelList = [
{
url: 'a.glb',
name: 'one',
},
{
url: 'b.glb',
name: 'two',
},
{
url: 'c.glb',
name: 'three',
},
{
url: 'd.glb',
name: 'four',
},
];
modelList.forEach(item => {
ABYLON.SceneLoader.AppendAsync('http://wwwxxx/gltf/', item.url, scene).then((meshes) => {
});
});
BABYLON.SceneLoader.OnPluginActivatedObservable.addOnce(plugin => {
plugin.onParsedObservable.add(gltfBabylon => {
console.log("onParsedObservable", gltfBabylon);
});
});
So how do the elements in modelList correspond to gltfBabylon in onParsedObservable?
Nowadays with the new loading APIs, you should avoid using OnPluginActivatedObservable
and pass it directly as options to the appendSceneAsync
function. See the Advanced Usage section in the docs.
gltfloader test | Babylon.js Playground
This should make it easier to associate which model is being loaded.
FYI @ryantrem
@bghgary How do I know if the data in the bin file has been parsed? Is there a callback notification
The PG I sent has an example.
onParsed: (loaderData) => {
console.log("onParsed", loaderData, loaderData.json.extras);
}
Is this what you mean?
Yes, the loaderData.bin object cannot be printed in the onParsed function at the moment
This is by design. If you load a .gltf
, bin
will be null. If you load a .glb
, then it will be populated.
So how do I get bin data?
If you can explain why you want to get the bin data, that will help me answer better. A glTF
file can point to multiple bin files. The JSON contains information about how to read the bin file(s). Depending on what you are trying to do, a custom loader extension may be suitable.