How to turn back the original color of a mesh

Hello guys,

I export a blender file in BJS, and I get a mesh by name where I want to change color uner a condition (clicked button):

 MyMesh= scene.getMeshByName("group_72");
 boxMaterial = new BABYLON.StandardMaterial("material", scene);
 boxMaterial.diffuseColor= new BABYLON.Color3(1,0,0);

and to apply color I use :

 $("#btn1").click(function(){
        MyMesh.material=boxMaterial;
}); 

So I want when I click to another button I turn back the original mesh color of (original texture)

Thanks

Anes

I tried to recover the original material and apply it again but it doesn’t work

OriginalMaterial = scene.getMaterialByID("coffrageLightBis1.Multimaterial#2");
MyMesh.material=OriginalMaterial;

Hi.

Are you sure that’s the ID of the material. Or the name. If it is the name then you need to use

scene.getMaterialByName(“yourMaterialName”);

@nogalo no it’s the ID, the name is “_0040_Peru”, I already try it and it doesn’t work

Can you create a playground with your mesh imported? It will help to narrow down the problem.

Here is how you can reference external resources (your mesh) into playground.
https://doc.babylonjs.com/resources/external_pg_assets

I recreate a new material in blender and it works now.

OriginalMaterial = scene.getMaterialByID("coffrageLightBis1._0040_Peru");
2 Likes