Three.js: [TS] InstancedMesh do not accept Material[] anymore

Created on 29 May 2020  Â·  4Comments  Â·  Source: mrdoob/three.js

r117 introduced generics for Meshes. It was supposed to be a non-breaking change and not much focus has been put on it in the release notes. Unfortunately, it is a breaking change : I have at least one codebase that compiles on r116 that doesn't compile on r117 due to this.

The compiler complains about InstancedMesh not accepting anymore an array of materials in the constructor. I checked the three.js codebase and it looks to me that nothing changed internally, i.e. array of materials was supported in r116 and should still be supported in r117. So I think this is an oversight in the InstancedMesh.d.ts file which lacks the Material | Material[] type definition.

I can submit a pull request with the trivial fix as soon as somebody closer to the development of the library confirms my assumptions. Thank you !

Three.js version
  • [X] >=r117
Browser
  • [x] All of them
  • [ ] Chrome
  • [ ] Firefox
  • [ ] Internet Explorer
OS
  • [x] All of them
  • [ ] Windows
  • [ ] macOS
  • [ ] Linux
  • [ ] Android
  • [ ] iOS
Hardware Requirements (graphics card, VR Device, ...)
  • [x] All of them
Bug TypeScript

Most helpful comment

The following live example demonstrates that InstancedMesh does support multiple materials.

https://jsfiddle.net/8uhr16gc/2/

All 4 comments

Your guess sounds right to me — could you confirm that Mesh is compiling with Material[] correctly, and it's just InstancedMesh that has this issue in TS?

If so a PR would be welcome, thanks!

(Assuming InstancedMesh really does support multiple materials? I haven't tested that...)

Well, I have InstancedMeshes with an array of two materials and it renders the InstancedMesh correctly. So I guess it qualifies as being "really supported" by three.js, right ?

The following live example demonstrates that InstancedMesh does support multiple materials.

https://jsfiddle.net/8uhr16gc/2/

Was this page helpful?
0 / 5 - 0 ratings

Related issues

akshaysrin picture akshaysrin  Â·  3Comments

seep picture seep  Â·  3Comments

jack-jun picture jack-jun  Â·  3Comments

Bandit picture Bandit  Â·  3Comments

yqrashawn picture yqrashawn  Â·  3Comments