Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(useRenderLoop): allow separate instances POC #646

Draft
wants to merge 11 commits into
base: v4
Choose a base branch
from

Conversation

andretchen0
Copy link
Contributor

@andretchen0 andretchen0 commented Apr 16, 2024

Problem

useRenderLoop currently spawns only a single loop used by all instances of <TresCanvas />. Among other things, this means an individual canvas can't be paused without pausing all canvases:

Solution

For a component subtree, provide/inject a unique loop.

Context

As discussed on the Discord, this is a POC preserving the current useRenderLoop interface, but with separate instances of the render loop per <TresCanvas />. As with the current code, the POC works in <script setup> above a <template><TresCanvas /></template>.

Current shortcomings

  1. A TresCanvas currently needs to be alone in the provider subtree; e.g., two canvases in the same file will use the same provider. So http://localhost:5173/basic/multiple was split into three files.
  2. Directives – afaik – don't "live in" the component tree and don't get provide/inject. So http://localhost:5173/basic/lights doesn't work out of the box.

I have a transparent-to-the-user solution in mind for 1. There could be a transparent or explicit workaround for 2, but I'd like to discuss these with the team on the Discord.

Taking over the render loop isn't implemented; I'd like to diverge from R3F's API here. I'll bring it up on the Discord.

Playground

Since this modifies useRenderLoop all the playground demos are using it. Except for directives, they all work, at least at first glance.

@andretchen0 andretchen0 changed the title fix(useRenderLoop): allow separate instances fix(useRenderLoop): allow separate instances POC Apr 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant