As a newcomer to using three.js
, I've been attempting to apply two different materials to a single object and toggle between them using a visibility flag, but so far, I've had no luck. Is there an alternative method to achieving this, or is it even possible?
var materials = [
new THREE.MeshPhongMaterial( { color: 0x00ff00, visible:true, shininess: 1 } ),
new THREE.MeshPhongMaterial( { color: 0xff0000, visible:false, shininess: 1 } )
];
obj= THREE.SceneUtils.createMultiMaterialObject( geometry, materials );
scene.add(obj);
scene.traverse(function (node){
if(node instanceof THREE.Mesh) {
node.visible = !node.visible;
}
});
This technique will eventually be applied to all objects within the scene, which is why I am utilizing scene.traverse.