Hi! I have a problem about asset loading, I would like to load one or more assets, and then create some instances of the asset; I am trying to use AssetManager.
My code look like this:
manager=AssetManager
console.log(loading...)
for each asset:
task=manager.addMeshTask(asset)
task.onSuccess(){
save asset in a data structure
console.log(loaded asset)
}
manager.load()
console.log(loading done)
generateMesh(...)
Now the problem is that I get an error (mesh is undefined) when I call generateMesh because the mesh is not loaded; in fact the log in the console look like this:
loading…
loading done
error!
loaded asset
How is possible to first load all the meshes and then start the scene?
I also tried to put that part of code into the init function like this:
initFunction().then() => {
*all the loading*
manager.onFinish= {
engine.runRenderLoop( scene.render() )
}
}
But I don’t know if this is a correct approach and the problem still persists.
I know it’s possible to use generateMesh inside task.OnSuccess() but I would like to have a different behaviour for each asset and in this way I should put an if for each asset type.
I think is useful to point out that everything works if the asset is generated after some time because the asset is loaded.
Any help is welcome