How i can create interactive Texture Change


#1

Hello, I have seen this product “https://playcanv.as/p/RqJJ9oU9/?overlay=false” changing its texture in run time. I want to learn how can I do so.

Please help me!


#2

This example shows how to change the material of an entity by clicking the button. Material change occurs in the ui.js script starting at 49 lines.

var obj = pc.app.root.findByName('chamferbox');
if (obj && obj.model && obj.model.model) {
    var material = obj.model.model.meshInstances[0].material;
    if (material) {
        material.diffuse.set(Math.random(), Math.random(), Math.random());
        material.update();
    }
}

This is where the entity is accessed, checked for the existence of a component of the model for the entity and the material. If the condition is successful, then the generation and assignment of a new random diffuse color occurs. Other properties for color maps can be found here.