Jump to content

Calculate loading progress with assetsManager


Recommended Posts

Hello, everyone,

I am trying to make a custom loading screen without using the built-in loading UI.

So I set up an assetsManager:

const assetsManager = new BABYLON.AssetsManager(scene);
assetsManager.useDefaultLoadingScreen = false;
const meshTask = assetsManager.addMeshTask(
"load meshes",

and try to use:

assetsManager.onProgress = function(remainingCount, totalCount) {
// Some calculation logic and sent the result to other UI components...

It works but there are two problems:

1. The counting does not take the texture (related to the exported materials in the .babylon file) loading into consideration, so the loading process is not fully covered.

Do I need to set up textureTask for every single texture and re-assign them to the respective materials? I cannot wrap my mind around it...

The built-in loading UI seems to take texture loading into account and disappears after all the textures are loaded.

2. The counting is based on file number rather than file size.

I know in SceneLoader call back function there is an eval object that can calculate file size.

Is it possible to do something similar with assetsManager? 

Hope someone can point me to the right direction.

Thanks alot!


Link to comment
Share on other sites

Hi @hcmetal.  The assetsManager updates onProgress based on the number of remaining tasks, not necessarily on all the assets associated with a mesh.  When loading multiple meshes, it may not know how many textures or submeshes are associated with it until it gets to the task.  Though you may be able to query the number of meshes and materials present and use that in calculating your update, this wouldn't really handle file size, number of textures, etc. unless you already know how many textures and files you are expecting to load and can compare against that number.

Link to comment
Share on other sites

@kcoley, thanks for making it clear.

I am wondering, assetsManager aside, is there a more "wholesome" way to cover all the various loading scenarios?

For example, we need to load multiple .babylon files and additional texture files (not included in the .babylon files but later used in the scene, such as ao and lightmaps).

Is creating tasks for every single asset and counting the number of tasks the best we can do, or with some combination of techniques, a more idea way of calculating loading progress can be achieved.

By "idea" I mean evaluate loaded file size and show progress based on it. (for the sake of convenience let's suppose the total file size is known before hand)

From the users' perspective, most of the loading time is spent on networking (downloading various files from a remote-server).

Maybe this is an issue beyond Babylon and should be solved with some network magic (code) :)?


Link to comment
Share on other sites

On 10/19/2018 at 4:29 PM, hcmetal said:

Is creating tasks for every single asset and counting the number of tasks the best we can do

This is probably the best way to get an accurate number


Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...