I have 3D models that perform fine in most of the devices, they require 500MB of memory. To get better performance on mobiles, I would like to reduce the memory allocation to 200MB or less. I manually generate several versions of these models for each device type to accomplish better performance, but in some cases, I would like to reduce texture images in runtime in order to fit device needs.
I thought I could downscale the loaded textures in runtime, by example from 2048x2048 to 512x512 when needed.
Which would be the best way to reduce texture images in runtime? The 3D models are gltf and the source images are png and jpg.
Here is how I have figured it out in case somebody else is looking for a possible solution.
Once the 3D models are loaded, I traverse all the objects looking for materials and their textures. For each texture, I override the image property by one rescaled down. Yes, I mutate the texture object. Since the 3D models are not added yet to the scene seems that they can be updated without side effects.
In addition to the image, the size properties must also be updated for the new ones.