So in the project, I have the material version Im trying to achieve. What I want to do is change the blue
texture to something else. Basically, I will create a scrollview with many different texture buttons
The UI elements share the same material that has a custom shader on it and therefore have shader parameters to set the color and opacity maps.
So you either have to go through the same parameters which requires going to private API:
var Test = pc.createScript('test');
Test.attributes.add('textureAsset', { type: 'asset', assetType: 'texture'});
// initialize code called once per entity
Test.prototype.initialize = function() {
this.entity.element._image._renderable.setParameter('texture_opacityMap', this.textureAsset.resource);
};
Or creating a new material at runtime
var Test2 = pc.createScript('test2');
Test2.attributes.add('colortextureAsset', { type: 'asset', assetType: 'texture'});
Test2.attributes.add('opacitytextureAsset', { type: 'asset', assetType: 'texture'});
// initialize code called once per entity
Test2.prototype.initialize = function() {
/** @type {pc.StandardMaterial} */
const m = new pc.StandardMaterial();
m.blendType = pc.BLEND_NORMAL;
m.opacityMap = this.opacitytextureAsset.resource;
m.opacity = 1;
m.opacityMapChannel = 'a';
m.alphaTest = 0.634;
m.emissiveMap = this.colortextureAsset.resource;
this.entity.element.material = m;
m.update();
this.on('destroy', () => {
m.destroy();
});
};
Or do what you are currently doing with the material asset assignment.