I have coded ‘switching texture asset sample’.
This is based on this topic.
I think it useful for Information banner and digital signage.
sample is below.
pc.script.create('bannerManager', function (app) {
// Creates a new BannerManager instance
var BannerManager = function (entity) {
this.entity = entity;
this.delta = 0;
this.index = 0;
};
BannerManager.prototype = {
// Called once after all resources are loaded and before the first update
initialize: function () {
},
// Called every frame, dt is time in seconds since last update
update: function (dt) {
//This sample change texture asset every 2 second past.
this.delta += dt;
if(this.delta > 2){
this.delta -= 2;
//seek asset by asset ID number
// var findKey = [1234567, 8901234, 5678901];
// var asset = app.assets.get(findKey[this.index]);
//seek asset by asset name
var findKey = ["banner_01.png", "banner_07.png"];
var asset = app.assets.find(findKey[this.index]);
if(asset){
var texture = asset.resource;
this.entity.model.material.diffuseMap = texture;
//If you want to not effect light to texture, you activate below 2 line
//It available for information banner,
this.entity.model.material.emissiveMap = texture;
this.entity.model.material.aoMap = texture;
this.entity.model.material.update();
}
this.index ++;
if(this.index >= findKey.length){
this.index = 0;
}
}
}
};
return BannerManager;
});