The code below works well. It loads a new image by creating a new material and assigns it to the mesh.
However, by creating a new material all of my settings are lost (Glossiness).
How would I edit the code below to just update the diffuse image and retain all the original material settings?
Thank you.
// initialize code called once per entity
Load.prototype.initialize = function() {
var self = this;
var image = new Image();
image.crossOrigin = "anonymous";
image.onload = function () {
var texture = new pc.Texture(self.app.graphicsDevice);
texture.setSource(image);
var material = new pc.StandardMaterial();
material.diffuseMap = texture;
material.update();
pc.app.root.findByName(myProduct).model.meshInstances[myMeshNumber].material = material;
};
myLoad = function(myImage){
image.src = myURL + myFolder + myImageFolder + myImage;
};
};
I thought this might be correct but it’s not.
image.onload = function () {
var texture = new pc.Texture(self.app.graphicsDevice);
texture.setSource(image);
mesh = pc.app.root.findByName(myProduct).model.meshInstances[myMeshNumber];
mesh.material.diffuseMap = texture;
mesh.material.update();
};