Problem with multiple materials for InstancedMesh

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?

It looks like your fiddle is working for me :

It may depend on hardware ? If so it would be useful to know some information about your system and browser.

Thanks for reply
It is very interesting
I am using
MacBook Pro (13-inch, 2017, Two Thunderbolt 3 ports)
Processor 2,3 GHz Dual-Core Intel Core i5
Memory 8 GB 2133 MHz LPDDR3
Graphics Intel Iris Plus Graphics 640 1536 MB
OS macOS Catalina version 10.15.6

Browser Google Chrome Version 87.0.4280.88
or Firefox 82.0.3 (64-bit)
or Safari Version 14.0
(scene behave identical in these browsers)

Here is screenshot

And also video (it look strange when rotating scene)

I also checked this on my Windows machine and yes, you right - it works fine
Could this be an issue with OS?

Yes this is weird…

In my opinion you should file a bug on Github

Give all the information you sent here, including the pictures, videos and fiddle.

Thanks a lot for your help
I’ve created a bug report https://github.com/mrdoob/three.js/issues/20882

1 Like

This is actually a Webkit bug: