When using pvr to compress texture, ios failed to call texture.setResource

As the title says,I put the picture in playcanvas and used pvr compression.
The approximate code is as follows, but it has no effect. If pvr compression is not used, it is no problem:

Ui360.attributes.add("Scene1_1_1", {type: "asset", title: "Scene1_1_1",assetType:'texture'});
var image = new Image();
image.src = this.Scene1_1_1.getFileUrl();
texture.setRresourece(image);
texture.upload();

Hi @Near_Lee and welcome,

When using the browser Image element you need to wait for the onload event before using it:

Ui360.attributes.add("Scene1_1_1", {type: "asset", title: "Scene1_1_1",assetType:'texture'});
var image = new Image();
image.load = function(){
   texture.setSource(image); // not setRresourece
   texture.upload();
}.bind(this);
image.src = this.Scene1_1_1.getFileUrl();

Though I am not sure if the **getFilreUrl()**will return the compressed texture variation depending on the platform, or the original raw texture resource.

Also note, that if you are using compression, the texture asset is based on a variant system where it contains reference to the original image and the PVR compressed asset.

If a hardware compressed format is valid for the platform you are on, getFileUrl will return the URL for the compressed texture which cannot be used in an Image.

You would be better off using the asset registry/asset APIs to load this:

this.Scene1_1_1.ready(function(asset) {
    // do something with the texture asset
}, this);

this.app.assets.load(this.Scene1_1_1);
1 Like