I need some help, i’m loading a texture from web and i want to apply it on a new material (created from code or not), but i have the same error :
TypeError: material.update is not a function
the code:
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 = pc.app.assets.find("material_to_mod");
material.diffuseMap = texture;
material.update();
setMaterial("obj_name",material);
};
image.src = "..img_path..";
function setMaterial(obj_name,materialAsset){
pc.app.root.findByName(obj_name).model.meshInstances[0].material = materialAsset.resource;
}
Don’t make things with the pc.material class. It appears to be a base class for the other two.
Use the standard material if you have doubts about where to start.
Oh. OK. I think my reply is misleading then. I will delete it. I am only trying to clarify things and Ive got it wrong.
So you’re saying the usual case is to use pc.material and not the other two ?
var image = new Image();
/*image.crossOrigin = "anonymous";*/
image.onload = function () {
var texture = new pc.Texture(app.graphicsDevice);
texture.setSource(image);
var material = new pc.StandardMaterial();
material.diffuseMap = texture;
material.update();
pc.app.root.findByName("target_entity").model.meshInstances[0].material=material;
};
image.src = "external/path/for/example.jpg"; // Remember CORS