felixmariotto / three-mesh-ui

⏹ Make VR user interfaces for Three.js
https://felixmariotto.github.io/three-mesh-ui/#basic_setup
MIT License
1.31k stars 138 forks source link

args as an object doesn't work with @react-three/fiber reconciler #82

Open saitonakamura opened 3 years ago

saitonakamura commented 3 years ago

Repro: press click in the sandbox

It has to do with the this piece of code in fiber reconciler. If the component is not a r3f instance (instance.__r3f.instance flag indicates it), then r3f assumes that args will be an array (because three js constructors usually have multiple arguments). Obviously it fails with an object.

What I don't understand is whether three-ui-component should be an instance or not. Instance components examples are OrbitControls, mesh, PerspectiveCamera. Non-instance are materials, ambientLight

saitonakamura commented 3 years ago

What is interesting is that createInstance (branch when instance.__r3f.instance is true) respects non-array args. Maybe it should be fixed in r3f?

felixmariotto commented 3 years ago

Hi @saitonakamura, I'm afraid I won't be able to help with this one, as I don't use r3f at all myself, and the lib is primarily intended for native three.js. If you find a solution involving updating three-mesh-ui, I'm happy to look into your PR.