Jump to content

Texture caching


andrewxxtheone
 Share

Recommended Posts

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"? :)

Link to comment
Share on other sites

  • 1 year later...

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.

Link to comment
Share on other sites

  • 2 weeks later...

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

Link to comment
Share on other sites

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();
    });
});

 

Link to comment
Share on other sites

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

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