question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

InstancedMesh with multiple materials looks broken

See original GitHub issue

Describe the bug

InstancedMesh with simple geometry and multiple materials doesn’t render correctly

This is probably hardware specific or OS specific issue, because it is reproducible on my macOS machine, but not on my Windows machine

To Reproduce

Steps to reproduce the behavior:

  1. Create InstancedMesh with BoxGeometry and an array of MeshBasicMaterial
  2. Render
  3. See weird behavior

or alternatively check live example

Code

    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);

Live example

https://jsfiddle.net/khjownq1/4/

Expected behavior

Code from Code section should produce a box with red and blue faces

Screenshots

initial position of camera Screenshot 2020-12-11 at 16 01 41

when rotated there is some weirdness Screenshot 2020-12-11 at 18 11 37

gif with scene rotation Screen Recording 2020-12-11 at 17 49 43

Platform:

  • Device: Desktop 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 Firefox 82.0.3 (64-bit) Safari Version 14.0 (identical behavior)
  • Three.js version: r123

Note: It works as expected on Windows machine

  • Device: Desktop
  • OS: Windows 10 64-bit
  • Browser: Google Chrome Version 87.0.4280.88
  • Three.js version: r123

screenshot of expected behavior Capture

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
mrdoobcommented, Dec 22, 2020

It does work? Surprising… 😅

1reaction
mrdoobcommented, Dec 21, 2020

I don’t think we can add multi-material support to InstancedMesh. Probably better to update docs and d.ts to clarify.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Problem with multiple materials for InstancedMesh - Questions
Hello I have a problem when creating InstancedMesh that has array of materials. If I create InstancedMesh with one material like this, it...
Read more >
InstancedMesh with unique texture per instance - Stack Overflow
I am looking for a way to draw several objects with unique textures. I came across this old question about instancedMesh where someone...
Read more >
Troubleshooting InstancedMesh in Three.js | by Leanne Werner
According to the Three.js docs, you should use an instancedMesh when creating a lot of objects with the same geometry and material but...
Read more >
I'm trying to position instances of InstancedMesh with ... - Reddit
It's the shader material you're using. Three materials have routines build in that handle instanced meshes, the instancing is done in shaders ;)....
Read more >
InstancedMesh | Babylon.js Documentation
https://doc.babylonjs.com/features/featuresDeepDive/materials/advanced/ ... and if occlusionRetryCount is reached and the query is broken show the mesh.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found