change material on mesh

Is it possible to trigger an even that will change the material assignment of the mesh?

I want to swap a phong shader:

phongMaterial = [new THREE.MeshPhongMaterial( { ambient: 0x555555, color: 0x555555, specular: 0xffffff, shininess: 50, shading: THREE.SmoothShading }  )];

with this basic material:

basicMaterial = [new THREE.MeshBasicMaterial( { vertexColors: THREE.FaceColors } ),new THREE.MeshBasicMaterial({color: 0xffffff, opacity: 1, wireframe: true} ) ]

when a certain event is triggered I switch using this code:

myMesh.materials = basicMaterial

and switching back:

myMesh.materials = phongMaterial

however when I switch from the phong to the basic the mesh just disappears (it comes back when I switch back)

Author: Fantashit

1 thought on “change material on mesh

  1. Try this (there are no more multi-materials, also more complex material must be first one that gets rendered, if you use some vertex colors, they must be present / absent in both materials):

    phongMaterial = new THREE.MeshPhongMaterial( { ambient: 0x555555, color: 0x555555, specular: 0xffffff, shininess: 50, shading: THREE.SmoothShading } );
    basicMaterial = new THREE.MeshBasicMaterial( { color: 0xffffff, opacity: 1, wireframe: true } );
    
    myMesh.material = phongMaterial;
    
    myMesh.material = basicMaterial;

Comments are closed.