Quadear Posted September 14, 2016 Share Posted September 14, 2016 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. Quote Link to comment Share on other sites More sharing options...
royibernthal Posted September 14, 2016 Share Posted September 14, 2016 Try using BABYLON.Tools.LoadFile to load the text file, once loaded use AssetsManager to load the urls listed in it. You can see it in action in the Sponza demo found in bjs samples. Quote Link to comment Share on other sites More sharing options...
Quadear Posted September 15, 2016 Author Share Posted September 15, 2016 Hi, Try using BABYLON.Tools.LoadFile => already doing that. The problem is that once the file is loaded, it triggers the "on finish" event of the loader before reading the text file and loading other textures. I will look at the sponza démo, ty Quote Link to comment Share on other sites More sharing options...
Quadear Posted September 15, 2016 Author Share Posted September 15, 2016 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. Quote Link to comment Share on other sites More sharing options...
Athelios Posted September 15, 2016 Share Posted September 15, 2016 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(); } Quote Link to comment Share on other sites More sharing options...
Quadear Posted September 15, 2016 Author Share Posted September 15, 2016 Hello, Yup, that's what I'm using right now, but ty. I wanted to have something more automatic thoug Quote Link to comment Share on other sites More sharing options...
royibernthal Posted September 15, 2016 Share Posted September 15, 2016 Hi, yes I understood what you meant. Check babylon.demo.ts in Samples-mater/Demos/Sponza. It does exactly what you want, just replace SceneLoader with AssetsManager. Quote Link to comment Share on other sites More sharing options...
Quadear Posted September 15, 2016 Author Share Posted September 15, 2016 Hi, Yeah, Ty. 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.