snupas Posted August 20, 2018 Share Posted August 20, 2018 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. Quote Link to comment Share on other sites More sharing options...
Sebavan Posted August 20, 2018 Share Posted August 20, 2018 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 ? Quote Link to comment Share on other sites More sharing options...
snupas Posted August 20, 2018 Author Share Posted August 20, 2018 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. Quote Link to comment Share on other sites More sharing options...
Sebavan Posted August 20, 2018 Share Posted August 20, 2018 The manifest check is normal, but the material is weird, it does not repro at all in the playground. By stopping caching in the browser, I see first the body and then the cats all in correct order. It would be amazing if you could repro in the playground. https://playground.babylonjs.com/#ZJ6S91#1 Quote Link to comment Share on other sites More sharing options...
snupas Posted August 20, 2018 Author Share Posted August 20, 2018 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. Sebavan 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.