InstancedMesh with multiple materials looks broken
See original GitHub issueDescribe 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:
- Create InstancedMesh with BoxGeometry and an array of MeshBasicMaterial
- Render
- 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
when rotated there is some weirdness
gif with scene rotation
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
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (2 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
It does work? Surprising… 😅
I don’t think we can add multi-material support to
InstancedMesh
. Probably better to update docs and d.ts to clarify.