Hello
I have a problem when creating InstancedMesh that has array of materials.
If I create InstancedMesh with one material like this, it works fine
const material = new THREE.MeshBasicMaterial({ color: 0xff0000 });
const boxG = new THREE.BoxGeometry(10, 10, 10);
const mesh = new THREE.InstancedMesh(boxG, material, 1);
const dummy = new THREE.Object3D();
dummy.position.set(20, 0, -20);
dummy.updateMatrix();
mesh.setMatrixAt(0, dummy.matrix);
mesh.instanceMatrix.needUpdate = true;
scene.add(mesh);
When I try to create InstancedMesh with different materials for each face then it breaks.
const materialA = new THREE.MeshBasicMaterial({ color: 0x0000ff });
const materialB = new THREE.MeshBasicMaterial({ color: 0xff0000 });
const boxG = new THREE.BoxGeometry(10, 10, 10);
boxG.faces.forEach((face, i) => {
face.materialIndex = i % 2;
});
const mesh = new THREE.InstancedMesh(boxG, [materialA, materialB], 1);
const dummy = new THREE.Object3D();
dummy.position.set(-20, 0, -20);
dummy.updateMatrix();
mesh.setMatrixAt(0, dummy.matrix);
mesh.instanceMatrix.needUpdate = true;
scene.add(mesh);
If I use simple Mesh in similar fashion then everything works fine
Checkout this demo
Does InstancedMesh support an array of materials?