protectwise / troika

A JavaScript framework for interactive 3D and 2D visualizations
MIT License
1.61k stars 117 forks source link

R3F example: Instanced Uniforms Mesh error on later versions of Three #274

Open mokargas opened 1 year ago

mokargas commented 1 year ago

The R3F example with an updated stack (r154) https://codesandbox.io/s/instanceduniformsmesh-r3f-forked-nqvrvl?file=/src/index.js

TypeError
Cannot read properties of null (reading 'attributes')
get geometry [as geometry]
https://nqvrvl.csb.app/node_modules/three-instanced-uniforms-mesh/dist/three-instanced-uniforms-mesh.esm.js:94:55
    at attach (https://nqvrvl.csb.app/node_modules/
react-three/fiber/dist/index-27578f8f.esm.js:621:40
    at appendChild (https://nqvrvl.csb.app/node_modules/
react-three/fiber/dist/index-27578f8f.esm.js:278:9

Not sure where to begin with this one, but my current guess is the API has moved on

CodyJasonBennett commented 1 year ago

Geometry is not optional for InstancedUniformsMesh, you have to pass a non-null reference to its constructor. The surrounding design in three.js is notably awful since it has two optional arguments in front of a mandatory one, so you'll see [null, null, 1] passed to instanced mesh when used declaratively where mutably setting geometry/material is useful. That isn't the case here and they should be passed imperatively.

https://codesandbox.io/s/instanceduniformsmesh-r3f-forked-fsvdn7