How to reapply the original texture on model after a texture change?

Hi,

I am relatively new to Babylon JS. My question is regarding how to change the texture back to the first texture of the uploaded model. I changed texture using updateURL() method. Now I want to change the texture to earlier texture.

I have attached the PG that I tried this.

Thanks in advance

This is a bit of an issue when it comes to glbs a GLB has the images integrated. They are converted to blobs that have a unique URL in your browser. Technically you can catch each blob creation, see what the assigned URL is, make sure they are not disposed, and reuse them.
A simpler approach would be to create a new texture and switch between the glb textures and the new texture. A little more memory usage, but no hassle at all.

4 Likes

Hi Thanks for the help. I was able to add the feature to the project. I tried with animating models too. :slight_smile:

here is the important steps I did,

            const assetBlob = new Blob([container.textures[i]._buffer]);
            const assetUrl = URL.createObjectURL(assetBlob);
            container.textures[i].updateURL(assetUrl);

here is the sample PG for future reference

1 Like

Careful with this. Using underscore properties (i.e., ._buffer) is not guaranteed to work in future versions.

2 Likes

So should we create a new texture ? container.textures[I].clone() is not getting executed in PG. Is it the right way to clone it?

What do you mean by this?