r65
Hello,
I am trying to switch from using a simple material to multi-material at runtime, but I am facing some difficulties. Could it be that I am overlooking something obvious?
Below is the test code I am working with (you can also view it on jsfiddle: http://jsfiddle.net/plotnik/8RtTy/3/). Initially, a simple material is assigned to the object, and then after the render() call, I attempt to assign a multi-material to simulate a runtime substitution.
var geom = new THREE.CubeGeometry(1, 1, 1);
var materialSimple = new THREE.MeshLambertMaterial({color: 0x020202});
// Multi-color
var materialMulti = new THREE.MeshFaceMaterial([
new THREE.MeshLambertMaterial( { color: 0xff0000 }),
new THREE.MeshLambertMaterial( { color: 0xffff00 }),
new THREE.MeshLambertMaterial( { color: 0xffffff }),
new THREE.MeshLambertMaterial( { color: 0x00ffff }),
new THREE.MeshLambertMaterial( { color: 0x0000ff }),
new THREE.MeshLambertMaterial( { color: 0x000000 })
]);
var mesh = new THREE.Mesh(geom, materialSimple);
scene.add(mesh);
var render = function () {
requestAnimationFrame(render);
mesh.rotation.x += 0.01;
mesh.rotation.y += 0.01;
renderer.render(scene, camera);
};
render();
// Switching to multi-material
mesh.material = materialMulti;
mesh.material.needsUpdate = true;
The code does not behave as expected. It seems that only materialMulti[0] (red color) is assigned to the entire mesh.
Your assistance in resolving this issue would be greatly appreciated.