When I change a material from MeshBasic to MeshPhong, the meshes in the scene don’t change.
here is an example where I create a material and assign it to variable material… then when I change it, the meshes don’t update with the new material.
I have many meshes in my scene (not the jsfiddle), as well as meshes that aren’t in the scene… How can I update all of them when the material is overwritten with the new one?
Because you are creating a new object. By doing so, any reference to original object becomes a deep copy of original object ( Not a reference anymore ).
But if you were to modify its properties, you get what you aimed for.
var camera, scene, renderer;
var geometry, material, mesh;
var material;
init();
animate();
function init() {
camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 0.01, 10 );
camera.position.z = 1;
scene = new THREE.Scene();
geometry = new THREE.BoxGeometry( 0.2, 0.2, 0.2 );
material = new THREE.MeshNormalMaterial();
mesh = new THREE.Mesh( geometry, material );
scene.add( mesh );
setTimeout( function() {
material.wireframe = !0;
}, 1000 );
renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
}
function animate() {
requestAnimationFrame( animate );
mesh.rotation.x += 0.01;
mesh.rotation.y += 0.02;
renderer.render( scene, camera );
}