-
hi all i am having a problem with a workflow i am trying to use to keep my # of draw calls low. i need to instance some glbs on demand. so maybe there is 1 instance until a user causes another instance to be created in a new position by clicking something, so then there are 2 instances with their own unique positions. then another click would add another instance, and so on up to the limit i have set. i'm using drei's Instances and Instance by the way, so the limit is passed directly to Instances like this for example: limit={100} and each Instance receives its own position (via mapping through the array of Instances). so i know i am not going over the instance limit. it is kind of working- instances are being added to the scene, but a glitch is causing the new instance to initially render at (0, 0, 0) a.k.a. the world origin instead of the correct position that has been given to it. the new instance will SOMETIMES stay at (0, 0, 0) until i interact with one of the instances, and then the incorrect instance will teleport instantly to the correct location. other times, the new instance will render at (0, 0, 0) but almost immediately snap to the correct position. i can't tell what causes the difference in these behaviors. so my first approach to fixing this was to call invalidate() from useThree in an effect that has the Instances array as a dependency. i figured if the Instances array changes, the effect would cause the component to re-render and all instances would be in the correct position. but it didn't fix the problem calling invalidate, so i also tried assigning a ref to Instances and using ref.current.instanceMatrix.needsUpdate = true; before calling invalidate() but these two combined still isn't working. so i'm really stuck for now. is changing the number of instances and their positions on demand possible without glitching? i'm sure there must be a way... thanks! edit: in case it helps anyone, i noticed that removing the limit arg i was passing to Drei's Instances and switching from using useLayoutEffect to useEffect for the invalidate() calling effect seems to help with new instances that were stuck at (0, 0, 0) until i interact with them. now the only issue i am having seems to be the first few frames after creating a new instance where the instance is at (0, 0, 0) until snaps to the correct location. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 8 replies
-
Shoot, sorry I see that you tried this. |
Beta Was this translation helpful? Give feedback.
-
pmndrs/drei#815 new version of drei fixes this issue |
Beta Was this translation helpful? Give feedback.
pmndrs/drei#815 new version of drei fixes this issue