efxlab Posted February 9, 2018 Share Posted February 9, 2018 hey you are too fast ! Iam newbie yet, but Iam testing/learning it now. I post it if I see an issue. what I try to do : I want change PBR textures on fly after glTF Mesh/material has loaded. see you, thanks Quote Link to comment Share on other sites More sharing options...
Pierre Glibert Posted February 9, 2018 Author Share Posted February 9, 2018 @efxlab http://www.babylonjs-playground.com/#SBKGT0 If you are some others questions, open a new topic and ping me efxlab 1 Quote Link to comment Share on other sites More sharing options...
bghgary Posted February 9, 2018 Share Posted February 9, 2018 7 hours ago, Pierre Glibert said: So, if I understand you don't use engine.createTexture() because "onProgess" not exist on the returned internalTexture... That's why you created your own image loader ? If it's that, like you said, we need to add some observable on internalTexture : onProgess, onAborted, ... I think that it would be good to use same method for all loader ... What do you think ? These loaders are inherently very different, so using the same method might not make sense. I don't understand the use case for this. Why do you need the url? Quote Link to comment Share on other sites More sharing options...
Pierre Glibert Posted February 9, 2018 Author Share Posted February 9, 2018 Hello @bghgary For example, I need to reload texture with different size. Url : assets/myTexture.256.png assets/myTexture.1024.png assets/myTexture.2048.png With this url, I can capture "assets/texture" and add the size I want to reload We can do what you said : Keep the asset url, load with a Blob and update it when canceled or loaded ... Is it possible and easy to do for you ? Quote Link to comment Share on other sites More sharing options...
bghgary Posted February 14, 2018 Share Posted February 14, 2018 @Pierre Glibert I understand you want to replace the textures, but why do you want to replace the textures? Is replacing the textures for progressive loading so that the smaller texture loads faster? Is it for render LODs so that meshes that are farther away uses less resources? Something else? Quote Link to comment Share on other sites More sharing options...
Pierre Glibert Posted February 14, 2018 Author Share Posted February 14, 2018 Yes exactly. I work on the new optimizer that will replace the old. The easiest way to explain what I do is to read the doc. I should have told you before All doc is here : https://github.com/pierreglibert/Extensions/tree/master/gradingSceneOptimizer Little old demo : demo.mp4 Quote Link to comment Share on other sites More sharing options...
Guest Posted February 15, 2018 Share Posted February 15, 2018 "replace" or "complement" actually as the current one is widely used already Quote Link to comment Share on other sites More sharing options...
Pierre Glibert Posted February 19, 2018 Author Share Posted February 19, 2018 hi @Deltakosh I saw that assetManager use "IAssetsProgressEvent" for onProgress function : https://github.com/BabylonJS/Babylon.js/blob/master/src/Tools/babylon.assetsManager.ts#L149 It give us the number of task loaded but it will be cool to have the data loaded in stream like SceneLoaderProgressEvent : https://github.com/BabylonJS/Babylon.js/blob/a86a04b640f8f25bb4a1ed86067ce735a404979b/src/Loading/babylon.sceneLoader.ts#L2 https://github.com/BabylonJS/Babylon.js/blob/master/src/Tools/babylon.assetsManager.ts#L694 If we add onProgress (type : SceneLoaderProgressEvent ) on all task type and replace "IAssetsProgressEvent" on assetManager, it will be possible to do that. we need onAbort function too to cancel task. It's better for user experience. Do you think it's possible to change it ? Thanks in advance PS :https://doc.babylonjs.com/babylon101/particles#gpu-particles Awesoooooome work EDIT : I want to talk about performance with you. At this moment, BABYLON work like this : Material.diffuseTexture = texture // ( type texture ) why not use an index like this with a setter and getter : /** * in MATERIAL class */ private _cacheDiffuseTexture: number; private _scene: Scene; // setter set diffuseTexture(newTexture: Texture){ this._cacheDiffuseTexture = newTexture._cacheIndex; } // getter get diffuseTexture() { if(this._cacheDiffuseTexture) { return this._scene.textures[this._cacheDiffuseTexture]; } return null; } /** * in TEXTURE class */ private _cacheIndex: number; private _scene: Scene; // example of updateSize function updateSize(size: number, dispose? : boolean) { scene.textures[this._cacheIndex] = new BABYLON.Texture(...); this.dispose(); } With this method, we can easily switch texture on the fly. For exemple, if we need to update ALL textures, we just need to do this : for(var i = 0; i < scene.textures.length; i ++) { scene.textures[i] = scene.textures[i].updateSize(512); } I did the exemple with scene.textures but we can apply this on several things in BABYLON. Of course, It's just an idea. Perhaps, it's already done or wrong method In fact, I tell you that because I saw this : https://github.com/BabylonJS/Babylon.js/blob/master/src/Materials/Textures/babylon.internalTexture.ts#L341 Quote Link to comment Share on other sites More sharing options...
Guest Posted February 20, 2018 Share Posted February 20, 2018 Ok..So unfortunately I cannot allow any breaking changes But I'm absolutey ok to add more info to the IAssetsProgressEvent interface. Also we can add abort support without sacrificing the back compat:) Regarding the other question: I'm not sure to understand what you want to achieve Keep in mind that the Texture object does not contains data but just a link to the InternalTexture where the data belongs. So to your point you can just go through all textures from engine cache: engine..getLoadedTexturesCache(). This will return the list of internalTexture where you can then call .updateSize Pierre Glibert 1 Quote Link to comment Share on other sites More sharing options...
Pierre Glibert Posted February 23, 2018 Author Share Posted February 23, 2018 hello @Deltakosh I will simplify my code because I can't do what I want. I need too much solutions that will break the code. For exemple, the only solution to resize a texture is create all size of texture and update url at this moment. The tool createResizedTexture return a RTT ... So I need to make a loop in scene.materials and use it on all channels to apply it. ( Not really optimized compared to an array of textures) The risk is to optimize the same textures more that once time. To prevent this, I can create a new class to reference all textures to know if it's already optimized... But it's a new class above the texture class. That mean I need an Material observable that return the material and the channel updated if the user add a new textures on the fly. For me, it's not a solution. Perhaps later. Anyway, perhaps this will interest you : https://github.com/pierreglibert/Extensions/blob/master/gradingSceneOptimizer/ts-optimizer/userInfos.ts Thanks for your help during all of this time and happy 11000 posts ! Ps : On 19/02/2018 at 9:53 AM, Pierre Glibert said: // example of updateSize function updateSize(size: number, dispose? : boolean) { scene.textures[this._cacheIndex] = new BABYLON.Texture(...); this.dispose(); } In the previous post, the '.updateSize()' was an exemple of an new fonction to resize the texture and switch it directly. It was not the current updateSize that change the size of the texture and not the size of the content. Quote Link to comment Share on other sites More sharing options...
Guest Posted February 23, 2018 Share Posted February 23, 2018 Oh nice for the updateSize (did not notice that :)) Thank you very much for your time and passion! Quote Link to comment Share on other sites More sharing options...
Pierre Glibert Posted February 23, 2018 Author Share Posted February 23, 2018 39 minutes ago, Deltakosh said: Oh nice for the updateSize (did not notice that :)) Yes but impossible to do if the first part is not possible to apply ... That should be a big change and it break the code. It's a different way to link textures to material for rendering ... 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.