react-three-fiber icon indicating copy to clipboard operation
react-three-fiber copied to clipboard

Suggestion: Separate "overriding the render loop" from "renderPriority" in useFrame

Open gkjohnson opened this issue 11 months ago • 4 comments

Currently when you pass a positive render priority to useFrame the built-in render functionality is disabled and it becomes the components responsibility to render the full scene in addition to whatever else the component wants to do. The issue is that there are plenty of use cases that don't require completely taking over the render loop (screen ui components for example) and there's no way to know if another component has already claimed responsibility for.

Image

This leads to scenarios where end users need to explicitly disable render loop overriding where it shouldn't really be necessary if multiple components are doing so. The 3d tiles renderer project, for example, provides a CompassGizmo that just displays an icon in the bottom right and in no way requires changes to the built in render loop. However because of the requirement that the component also be able to render the full scene due the priority, when another component is added that does the same (like EffectComposer) the components, confusingly, break (unless the user knows to change the override flag).

Suggestion

My suggestion is to separate the logic for cancelling the render loop so renderPriority just changes the order of execution, as the name implies, rather than overloading the field to do both tasks. This can be done by passing an extra argument to useFrame:

useFrame( () => {

  /* render stuff after the render to canvas */

}, renderPriority, overrideRenderLoop );

This can be done in a backwards compatible way by defaulting overrideRenderLoop to its current behavior.

gkjohnson avatar Feb 03 '25 04:02 gkjohnson

@krispya, this is something we have designed for v10, but I don't see mention in #2688.

CodyJasonBennett avatar Feb 03 '25 22:02 CodyJasonBennett

The proposed fix is more of a bandaid. We could do it, but I would rather complete a robust scheduling API like we mocked up a couple of times and have one migration event instead of multiple.

krispya avatar Feb 03 '25 22:02 krispya

@CodyJasonBennett

this is something we have designed for v10

If there's a brief write up or anything on how this would work I can take a look to see how it would fit into the components I'm working it.

gkjohnson avatar Feb 04 '25 00:02 gkjohnson

I’ll see if there is a surviving API doc for React, but the internals are being worked on here: https://github.com/pmndrs/directed

I think there will need to be a robust API redesign that we could work on in the open.

krispya avatar Feb 04 '25 01:02 krispya