Replies: 4 comments 2 replies
-
i think thats easy to do in userland import throttle from 'lodash-es/throttle'
function A() {
const foo = useCallback(throttle(state => {...}, 200), [])
useFrame(foo) i thought about maybe offereing sth like this in r3f, but it's kind of at the threshold of getting bloaty right now, im trying to cut out functionality rather than adding. |
Beta Was this translation helpful? Give feedback.
-
btw, i once forked raycaster and made it skip the detailed steps. it first checks bounds, which is often precise enough for many cases. if we had something like a configurable raycaster in if you want to look into it, it's this function: https://github.com/mrdoob/three.js/blob/dev/src/objects/Mesh.js#L128 it could work like ... import { cheapRaycast } from 'drei'
...
return <mesh raycast={cheapRaycast} ... /> |
Beta Was this translation helpful? Give feedback.
-
ha, it seems to work: https://codesandbox.io/s/r3f-basic-demo-8fpip?file=/src/index.js for meshes at least. |
Beta Was this translation helpful? Give feedback.
-
i added it to drei :-) i need this too! https://codesandbox.io/s/r3f-basic-demo-8fpip?file=/src/index.js |
Beta Was this translation helpful? Give feedback.
-
Throttling certain checks inside
useFrame
might be useful for performance reasons. In the case of UI interactions (tracking raycaster hits etc.), not everything needs to be checked every single frame. In my "tracked" 3D asset code block that's using a context with references to XR controllers I ended up adding this for emulating a pseudo-hover:Planning to look into wrapping with
_.debounce
or_.throttle
but haven't toyed with it further. Any thoughts on a more idiomatic way? How would that work with the seconduseFrame
param (priority
)?Beta Was this translation helpful? Give feedback.
All reactions