In my ThreeJS project, I have created a 3D wall and am attempting to change its color dynamically on a click event. However, the code doesn't seem to be working as expected. Can you help me identify the error in the following code snippet?
var materials = [ materialFront, materialSide ];
var material = new THREE.MeshFaceMaterial( materials );
if(path_type=="wall")
{
var mesh1 = new THREE.Mesh( geometry1, material );
object.add( mesh1 );
}
else {
var mesh2 = new THREE.Mesh( geometry1, material );
object.add( mesh2 );
}
object.rotation.x = Math.PI / 2;
object.position.y = parseInt(default_height*(floor_number-1));
scene.add( object );
The code for changing the color on click event is below:
function color_change(color){
mesh1.material.color = new THREE.Color( color );
mesh1.material.needsUpdate = true;
}
When executing this, I encounter the following error message:
mesh1 not defined