andrewxxtheone Posted December 28, 2015 Share Posted December 28, 2015 Hey guys! I'd like to cache my textures into IndexedDB, I saw that Babylon.js is capable of it, but my case is that, I don't have a "scene mesh babylon" file, I just create a simple Babylon.Scene and add some custom meshes, with textures. And I'd like to cache those textures, is there a workaround to "make babylon.js believe it is a scene loaded from a file and force checking manifest and force using indexed db for textures"? Quote Link to comment Share on other sites More sharing options...
jdurrant Posted September 28, 2017 Share Posted September 28, 2017 I realize this question is very old, but I'm interested in doing the same thing. Did you ever find a solution? Thanks! Quote Link to comment Share on other sites More sharing options...
RaananW Posted September 28, 2017 Share Posted September 28, 2017 Hi, even if it's an old question, it is still a valid one There is currently no way of doing that cleanly without a scene file, BUT, there is a nice way to get it to work. The database requires a manifest file in order to initialize. All you need to do is to serve a manifest file with a specific name (let's say scene.manifest). Your manifest should have the 3 elements, just like a regular manifest file: { "version" : 1, "enableSceneOffline" : true, "enableTexturesOffline" : true } You then need to set the scene's database object: scene.database = new BABYLON.Database('scene', function() {}); Right after creating your scene, before loading your textures. Notice the "scene" as first variable. This is the filename you chose to use. From now on, the scene will cache all resources into the indexedDB instance. meteoritool and GameMonetize 2 Quote Link to comment Share on other sites More sharing options...
jdurrant Posted October 8, 2017 Share Posted October 8, 2017 Thanks, @RaananW ! Very helpful. Quote Link to comment Share on other sites More sharing options...
dbawel Posted October 8, 2017 Share Posted October 8, 2017 Keep in mind that you may have issues with the scene initializing before all textures and assets are loaded. My workaround for this is to creat a couple of "dummy" textures and load them last, so that when the scene sometimes initializes before everything is loaded, it loads in sequence so the missing assets are never missed as they were never meant to be used. So FYI - the issue I often find in your case is that I wait for the assets manager to verify that everything is loaded before initializing; however, setting your scene up the way that @RaananW suggests sometimes causes odd behaviors in initializing before the loader has completed - even though it reports that the assets Manager is finished. Just a heads up. DB Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted October 9, 2017 Share Posted October 9, 2017 On 10/8/2017 at 3:15 AM, dbawel said: Keep in mind that you may have issues with the scene initializing before all textures and assets are loaded. My workaround for this is to creat a couple of "dummy" textures and load them last, so that when the scene sometimes initializes before everything is loaded, it loads in sequence so the missing assets are never missed as they were never meant to be used. So FYI - the issue I often find in your case is that I wait for the assets manager to verify that everything is loaded before initializing; however, setting your scene up the way that @RaananW suggests sometimes causes odd behaviors in initializing before the loader has completed - even though it reports that the assets Manager is finished. Just a heads up. DB I do not use the stuff talked about in this topic, but wouldn't asset manager work with scene.executeWhenReady()? Example where renderloop is not even assigned till nothing outstanding: scene.executeWhenReady(function () { // Once the scene is loaded, register a render loop engine.runRenderLoop(function() { scene.render(); }); }); Quote Link to comment Share on other sites More sharing options...
RaananW Posted October 9, 2017 Share Posted October 9, 2017 It would also know what doesn't work. If you can reproduce it, we will be happy to fix it. This is actually a bit of a hack - Babylon doesn't officially supports what I showed, but it should be working. Quote Link to comment Share on other sites More sharing options...
dbawel Posted October 10, 2017 Share Posted October 10, 2017 13 hours ago, JCPalmer said: I do not use the stuff talked about in this topic, but wouldn't asset manager work with scene.executeWhenReady()? Example where renderloop is not even assigned till nothing outstanding: Hi @JCPalmer @RaananW - Your description above is how the Asset Manager is supposed to function, but as previously mentioned when loading many assets, the Asset Manager often returned true without all assets loaded. And it's not that the Asset Manager continued to load after returning true, but failed to complete loading assets following the return of true to report that all assets have been loaded. However, I just tried loading a heavy scene which has consistently failed to load all textures for the GUI, as all textures are loaded though the Asset Manager. But loading the scene multiple times this evening with the "dummy" textures removed, the scene loaded correctly every time. However, I am using an updated babylon.js file, whereas when I had problems previously, I was using the then current versions of 2.2 and prior. So perhaps the bug I regularly encountered using the Asset Manager has been fixed. I'll test further, but am currently not able to repro the bug I used to find consistently. I simply got in the habit of adding "dummy" assets to load as a routine action; but it appears this is not necessary any longer. I'll report to the forum if I see this again, however, it's been a while since I've needed to use the Asset Manager as I've recently been working outside of WebGL for the most part. If the problem no longer exists, then ignore my recent posts. Thanks for following up on this, as I would not have realized that perhaps this particular bug has been fixed. I'm still not entirely confident, but since I'm not able to repro anymore, I have to assume it's no longer an issue. Thanks, DB 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.