Jump to content

AssetManager & sceneOptimizer contribution


Pierre Glibert
 Share

Recommended Posts

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?

Link to comment
Share on other sites

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 ?

Link to comment
Share on other sites

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 :P

 

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

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

 

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