Closed alvarosabu closed 1 month ago
Hi @Tresjs/core team, this PR is the result of the latest meeting and the discussion on Discord, please let me know if there is any further questions or feedback, I will wait until final agreement on the contracts to create the documentation.
I added tests as well.
@alvarosabu ,
Hi @Tresjs/core team, this PR is the result of the latest meeting and the discussion on Discord, please let me know if there is any further questions or feedback, I will wait until final agreement on the contracts to create the documentation.
You're looking for a review of code/demos? Or not yet?
Hi @andretchen0 since we had the call only the 3 of us we wanted to have your opinion about this approach, I added examples for take over mode and fbo in the advance section.
I know also @Tinoooo wanted to discuss further the pause Render so I added the methods but didn't expose them yet.
@Tinoooo 's explanation of the design is ok by me.
Glad to review whenever. Let me know.
Hey @alvarosabu ,
This doesn't appear to implement the API from here. In particular, there doesn't seem to be a way to
off
callbacks. Is that right?
Let me confirm with him why he added an off
method on that interface. We didn't discuss anything related to that haha that's why is not implemented š
Ok @andretchen0 I just confirmed with @Tinoooo is a method to unsubscribe the callback inspired by https://vueuse.org/shared/createEventHook/
I will need to implement it.
Ok @andretchen0 I just confirmed with @Tinoooo is a method to unsubscribe the callback inspired by https://vueuse.org/shared/createEventHook/
I will need to implement it.
If you'd like, you can do the following on your branch:
git fetch
git checkout fix/use-render-loop src/utils/createPriorityEventHook{.test,}.ts
Then you'll have src/utils/createPriorityEventHook.ts
, which I'd written for the POC.
It works like createEventHook
, including implementing off
. It accepts a priority and sorts events according priority/insertion order.
It's got pretty good test coverage. I didn't write any documentation, but you can see examples in createPriorityEventHook.test.ts
If you like, you can use it in the place of the Map
s.
Otherwise, no worries if you want to use a different implementation.
Ok @andretchen0 I just confirmed with @Tinoooo is a method to unsubscribe the callback inspired by https://vueuse.org/shared/createEventHook/ I will need to implement it.
If you'd like, you can do the following on your branch:
git fetch git checkout fix/use-render-loop src/utils/createPriorityEventHook{.test,}.ts
Then you'll have
src/utils/createPriorityEventHook.ts
, which I'd written for the POC.It works like
createEventHook
, including implementingoff
. It accepts a priority and sorts events according priority/insertion order.It's got pretty good test coverage. I didn't write any documentation, but you can see examples in
createPriorityEventHook.test.ts
If you like, you can use it in the place of the
Map
s.Otherwise, no worries if you want to use a different implementation.
Hi @andretchen0 this was really helpful thanks a lot for this, I just pushed a refactor that uses the utility you provided instead of the subscriber's map, works like a charm so no need for Array.from
, I also updated the tests for callback registration similar to the ones on the createPriorityEventhook.test.ts
I also tested a few more things, like registering the same callback twice etc and everything seems to be covered, let me know if there is anything else pending.
Question for you both @Tinoooo @andretchen0 , should I add the usage of off
to the docs?
const { off, on, trigger, ...} = onBeforeRender()
I'm not sure we should expose on
and trigger
tho š¤
onBeforeRender
Yes, it should be in the docs. I guess on
and trigger
should not be exposed. I cannot think of a use case that makes these useful.
I agree with @Tinoooo . off
should be documented. on
and trigger
shouldn't be returned.
I agree with @Tinoooo .
off
should be documented.on
andtrigger
shouldn't be returned.
Awesome @andretchen0 , I already made the changes on the return and documented the off
method
Hopefully Closes #633
Based on the team discussion. This PR introduces a new API
useLoop
This composable allows you to execute a callback on every frame, similar to
useRenderLoop
but unique to each TresCanvas instance and with access to the context.Usage
Register update callbacks
The user can register update callbacks (such as animations, fbo, etc) using the
onBeforeRender
Take over the render loop
The user can take over the render loop callback by using the
render
methodRegister after render callbacks (ex physics calculations)
The user can also register after rendering callbacks using the
onAfterRender
Priority mechanism
Both
useBeforeRender
anduseAfteRender
provide an optional priority index. This indexes could be any from[Number.NEGATIVE_INFINITY ... 0 ... Number.NEGATIVE_INFINITY]
For example, to use Frame Object Buffer (FBO) is convenient to use a very big number to ensure that all updates happen before the FBO callback and the last one just before the scene render.
Pausing and resuming the loop
The end user can use
pause
andresume
methods:Pausing and resuming the render
You can use
pauseRender
andresumeRender
methods:Pending