Advanced uses
Since 0.6.0
rafDriversrafDriver
s allow you to control when and how often computations in Theatre tick forward. (raf stands for requestAnimationFrame
).
The default rafDriver
in Theatre creates a raf
loop and ticks forward on each frame. You can create your own rafDriver
, which enables the following use-cases:
- When using Theatre.js alongside other animation libs (
@react-three/fiber
/gsap
/lenis
/etc
), you'd want all animation libs to use a singleraf
loop to keep the libraries in sync and also to get better performance. - In XR sessions, you'd want Theatre to tick forward using
xr.requestAnimationFrame()
. - In some advanced cases, you'd just want to manually tick forward (many ticks per frame, or skipping many frames, etc). This is useful for recording an animation, rendering to a file, testing an animation, running benchmarks, etc.
Here is how you'd create a custom rafDriver
:
Now, any time you set up an onChange()
listener, pass your custom rafDriver
:
You can optionally make studio use this rafDriver
. This means the parts of the studio that tick based on raf, will now tick at 5fps. This is only useful if you're doing something crazy like running the studio (and not the core) in an XR frame.
rafDriver
s can optionally provide a start/stop
callback. Theatre will call start()
when it actually has computations scheduled, and will call stop
if there is nothing to update after a few ticks:
@theatre/r3f
rafDrivers inYou can instruct @theatre/r3f
to use your custom rafDriver
by wrapping your react tree in <RafDriverProvider>
:
Was this article helpful to you?
Last edited on November 07, 2024.
Edit this page