I am trying to change materials on a selected object, without affecting the material of its children, somehow the traverse function is not allowing me to return from the traverse function. I need this code to execute only on the first material found in the group (which in every case ‘should’ be the parent of the other objects.) However I can’t seem to find a way to cancel the traverse function. even with a return statement…
this.intersects is of type THREE.Intersection[].
ChangeColor(color: THREE.Color) {
if (this.intersects.length > 0) {
(this.intersects[0].object as THREE.Group).traverse((child: THREE.Mesh) => {
if (child.isMesh) {
(child.material as Material).color = color;
console.log('test');
return;
}
});
}
}