Jump to content

Assets Manager conditional load


Quadear
 Share

Recommended Posts

Hi Everyone !

I'm currently trying to use the babylon assets manager to do some conditionnal loading. I want to to this:

- Load a text file using the assets manager

---Read the text file and find some urls inside it.

-----Load these urls as textures using the babylon assets manager

-----When loaded, trigger the on finish event in the loader

 

Right now, I can do easily those parts separatly, but when i try to mix them, the onFinish event from the assets loader triggers when the text file is loaded (logic, it's the only thing in the loader at the moment). I want to delay it, if it's possible, until I've found the new things to put in the loading queue.

 

Anyway, I can do this un an "ugly" way, but there is probably a more elegant build-in way of using the Babylon assets loader to fill this purpose.

Link to comment
Share on other sites

Hello,

I haven't found what i was looking for on the sponza demo.

This is an exemple of what I want :

this._assets["task1"] = this._assetsManager.addTextFileTask("resourcesmap", http://localhost/api/" + "resourcesmap");
this._assets["task1"].onSuccess = function(task) {
    let json = JSON.parse(task["text"]);
    for(let i = 0; i < json.length; i ++) {
        let current = json[i];
        let textureUrl = current.textureUrl;

        if (textureUrl) {
            let id = current.id;

            self._assets[id] = self._assetsManager.addTextureTask(id, "http://localhost/textures/" + textureUrl, true, false);
        }
    }
};

this._assetsManager.load();
this._assetsManager.onFinish = function () {
    window.dispatchEvent(new CustomEvent("All Assets Loaded"));
};

The behaviour I would like to have is the following :

- Task1 loads and end

- the json is parsed

- the textures are loaded

- the custom event All Assets Loaded is triggered

 

The behaviour I have is the following:

- Task1 loads and end

- the custom event All Assets Loaded is triggered

- the textures are never loaded

 

The problem comes from : 

In the assets Manager, the load function checks the length of all the tasks and never refreshes it. I don't think I have a clean solution to solve that problem, I'm going to extend the class and craft something myself. If anyone is interested by it, say it and I will share it.

Link to comment
Share on other sites

Hi!

@Quadear I was able to do this by code:

var assets = loader.addTextFileTask("", "/static/assets.json")
loader.load();
loader.onFinish = function (tasks) {
    assets = JSON.parse(assets.text);
    load();
};

load = function() {
    for (var i in assets.textures) {
        assets.textures[i] = loader.addTextureTask("", "/static/"+assets.textures[i]);
    }
    loader.onFinish = function (tasks) {
        console.log("Done! Textures loaded!");
    };
    loader.load();
}

 

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