Async. serialization of textures loaded from url

I find that I in order to serialize textures (or scenes with textures) it is necessary to wait until textures are loaded and ready:

This is using the WhenAllReady callback. Is it possible to avoid using callbacks ?

SceneSerializer.SerializeAsync() seemed like an option as it returns a promise but I cannot get it to work (also see BABYLON.SceneSerializer.SerializeAsync usage).

I found scene.whenReadyAsync:

That seems promising as the promise resolves when all textures are loaded.

Any other hints or feedback very welcome.

1 Like

A little async wrapper like below could be useful if you’d rather use await instead of the callback. :slight_smile: Also scene.whenReadyAsync seems to be working in your PG (the textures are serialized in the materials that use them). :beers:

BABYLON.Texture.WhenAllReadyAsync = function (textures) {
    return new Promise(function (resolve) {
        BABYLON.Texture.WhenAllReady(textures, resolve);

1 Like

Thanks. Yes, a wrapper like this would work well, perhaps with onError/rejection handling. Although I feel it is early in the personal project, it may already time to extend existing functionality like this. Sofar I was trying to rely as much as possible on BJS itself.

1 Like

Hello @andreasplesch just checking in, do you have any more questions about this? :grinning_face_with_smiling_eyes:

Thanks for checking back. I think I ended up using scene.whenReadyAsync. I had to pivot a bit and hope to get back to that project rather sooner than later. Let me assign Blakes response as a solution to mark the question answered.

1 Like