How to know when SceneLoader.AppendAsync() has finished loading models?

Hi, I’m trying to render a model in a HDR environment and capture a screen shot after the model is loaded. At first I used synchronous append function:

await new Promise((resolve) => {
  SceneLoader.Append(modelRootPath, modelFileName, this[$scene], () => {
    captureScreenShots(); // a capture screenshots function I wrote by myself
    resolve();
  });
});

I thought this should be correct because I call captureScreenshots() in the onSuccess() argument, which means it should be called when model has been loaded? But in fact captureScreenShots is called before the model is loaded, and the screenshot just has a environment in it. So I tried the async version of append function:

await SceneLoader.AppendAsync(modelRootPath, modelFileName, this[$scene]).then(()=>{
  captureScreenShots();
})

But the result is still the same. I think the key is to know when SceneLoader.AppendAsync() has actually finished loading model. Thank you!
PS the model is rendered correctly, just the screenshot doesn’t have model in it.

so you should at least call render once before capturing or you will capture an empty canvas.

I think you need scene.executeWhenReady(callback): the callback (function) will be called when everything is ready in the scene (all effects created and ready, textures loaded, etc).

3 Likes

Yeah, that works, thanks!

I have already registered the render loop before loading the model, so i guess I don’t have to call render function before capture screenshot?
By the way, thank you for your quick response!

1 Like