My app uses <Canvas invalidateFrameloop={true}/>
in react-three-fiber to avoid rendering every frame, because most of the time the scene is static (it's a virtual gaming space for tabletop roleplaying games, and if no-one is moving anything around, there's no need to consume power by re-rendering the scene).
I'm adding physics-based dice rolling using use-cannon, but obviously when the physics simulation is running the app needs to re-render every frame. At the moment, the dice's render()
methods call useFrame(({invalidate}) => {invalidate();});
so they cause the app to render every frame while they are mounted.
use-cannon
defaults to useSleep={true}
, so presumably when the die/dice settle, the physics simulation goes to sleep. However, I can't find a way to query the sleep state of the simulation from user-land, so my useFrame call can stop calling invalidate()
. If such a getter is not available, I'd like to request that it be added (presumably to the WorkerAPI).
Given that your physics state is hidden away in the workers, it might be hard to make a getter of the sleep status available through the API. As an alternative, since invalidateFrameloop
is a standard (if seldom used) feature of react-three-fiber, perhaps a similar prop could be added to <Physics/>
, defaulting to false, but if true, use-cannon itself could call invalidate()
each frame that the physics sim is not sleeping, and stop calling it when it sleeps.