Jump to content

AssetsManager, loading first model in the scene while others are still being imrpoted


snupas
 Share

Recommended Posts

I'm importing roughly 22 .obj models via the AssetsManager, but I want the user to be able to see the first model loaded in the scene while the others are being imported. I've tried separating the main mesh that's supposed to appear in a separate AssetsManager like so:

  var mainAssetsManager = new BABYLON.AssetsManager(scene);
  var secondaryAssetsManager = new BABYLON.AssetsManager(scene);
  var userId = "example";

        mainAssetsManager.useDefaultLoadingScreen = true;
        secondaryAssetsManager.useDefaultLoadingScreen = false;
        var mainMesh=mainAssetsManager.addMeshTask("mesh"+0,"","./dist/assets/",userId+"_"+0+".obj")
        var meshTasks = [];

        for(var x = 2; x<23; x++){
            if(x%2==0){
                meshTasks.push(secondaryAssetsManager.addMeshTask("mesh"+x,"","./dist/assets/",userId+"_"+x+".obj"));
                // meshTasks.onSuccess = function (task) {
                //     fatsos.push([task.loadedMashes[0],task.loadedMashes[1],task.loadedMashes[2]]);
                //     console.log("mesh"+x+" loaded succesfuly.");
                // }
            }
        }
       
        mainAssetsManager.load();
        secondaryAssetsManager.load();

The loading screen disappears after half a second, so I assume the first model gets loaded, but it doesn't appear in the scene until the rest of the models have been loaded, even though for the other models I've disabled the loading screen.

Link to comment
Share on other sites

The scene will not be ready until the full end of the loading sequence so using isReady, onReadyObservable or executeWhenReady to start the render loop will all be defered until the end of the loading.

Be careful as your scene might hang a bit while loading due to shader compilation being synchronous (so far) in the browsers.

Could you share the code on the playground so that we can take a deeper look at the root cause ?

Link to comment
Share on other sites

Sure.

This is the playground with the stripped down code and stock meshes:

https://playground.babylonjs.com/#ZJ6S91

And this is a gif video of my website loading the actual models.

https://i.imgur.com/Y0xcHCk.gifv

The first model should be an extremely skinny one, but it starts off with displaying a model loaded with the secondary assetsmanager. And as you can see it only loads the material at the end, even though all of the models come with a material. You can also see it first displays all the manifest errors for all of the models from both assetsmanagers before any model is loaded from either.

Link to comment
Share on other sites

It would be kinda hard to reproduce cause of the custom meshes and materials.

I sorta solved it though. Put the secondaryAssetsManager.load() function in the success callback of the mainAssetsManager like so:

var mainAssetsManager = new BABYLON.AssetsManager(scene);
        var secondaryAssetsManager = new BABYLON.AssetsManager(scene);
        mainAssetsManager.useDefaultLoadingScreen = false;
        secondaryAssetsManager.useDefaultLoadingScreen = false;
        var userId = "example";

        var mainMesh = mainAssetsManager.addMeshTask("mesh"+0,"","./dist/assets/",userId+"_"+0+".obj");
        var meshTasks = [];
        for(var x = 2; x<23; x++){
            if(x%2==0){
                meshTasks.push(secondaryAssetsManager.addMeshTask("mesh"+x,"","./dist/assets/",userId+"_"+x+".obj"));        
            }
        }
        mainMesh.onSuccess = function (task) {
                    console.log(task);
                    secondaryAssetsManager.load();
                }
      
        mainAssetsManager.load();

The loading looks like this now:

https://i.imgur.com/hNFXqk0.gifv

Makes sense since before the secondary assetsmanager was firing off right after the first in code, but not in execution.

Don't mind the lag as long as there's the initial mesh up in the scene with the correct material loaded.

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.

Guest
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.

Loading...
 Share

  • Recently Browsing   0 members

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