Up until now I have been using uncompressed textures, but looking at the documentation it seems like using compressed textures will really help with vRAM efficiency. The issue is that while the in-editor compressed files work great, there is no documentation on how to load correct textures via my own JS. I can load a pvr or dxt file individually, but I can’t find any documentation on how the system Asset class loads AssetVariants class with the correct data via the constructor (or any other interface for that matter).
I am currently loading our uncompressed textures as such:
var asset_handle = new pc.Asset("asset_"+resource_name, "texture", { url: "https://s3.us-east-2.amazonaws.com/"+resource_uri});
How would I go about changing this call to specify the variations? I thought of using device.extCompressedTextureS3TC / device.extCompressedTextureETC / etc etc… but that seems messy considering you guys already have that detection logic working. Anything I’m missing?
Thanks for the help. I looked through the codebase and it seems like they never made a generic way to let people load fallback variants through pc.Asset. Fortunately, it’s not too difficult to do on your own! Here is my method in case someone wants to do the same thing.
First, I put in a GPU capabilities check in the loader. I do that within my loading screen-
pc.script.createLoadingScreen(function (app) {}
On my server, my images are all stored as
https://<CDN URI>/<RESOURCE ID>-<EXTENSION PART>
So for example, my different formats for an image foobar.jpg would be
Then when I’m loading my assets, I do something like this-
var index = ...
var foobar = ...
var ename = ".jpg";
if(this.app.ename) {
ename = this.app.ename;
}
var _asset_handle = new pc.Asset("asset_"+index, "texture", { url: "https://foobar.com/"+foobar[index].uri+ename });
Works well for me. Hope it helps somebody else! (And it would be nice if something like this were added to PC itself to abstract this away)