Im trying to highlight cloned object when clicked.
Everything works as expected as long as each mesh in object has one material assigned. When loading FBX often fbx.material is an array. When looping and replacing within the array all cloned meshes get higlighted.
this is my code so far:
let mesh = LoadFBX(path).clone();
mesh.traverse((mesh, i) => {
if (mesh.isMesh) {
if (mesh.material.length) {
for (let i = 0; i < mesh.material.length; i++) {
if (active) {
mesh.material[i] = new MeshStandardMaterial({
color: 0xf000f4,
});
} else {
let matTemp = new MeshStandardMaterial({
color: 0xffffff,
});
mesh.material[i] = matTemp;
}
}
} else {
if (active) {
mesh.material = new MeshStandardMaterial({
color: 0xf000f40,
});
} else {
let matTemp = new MeshStandardMaterial({
color: 0xffffff,
});
mesh.material = matTemp;
}
}
}
});