Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Features
This PR adds the following features via a private composable
useTresReady
:onTresReady
hook@ready
emit fromTresCanvas
onTresReady
Note
Tres is "ready" when either:
TresContext
was created.Important
The 100 ms timeout above exists to keep Tres working as expected even in edge cases – like the user setting the canvas size to 0 x 0 explicitly.
Because of the timeout, it is not guaranteed that the canvas will be renderable when
@ready
.Playground
... then open http://localhost:5173/basic/ready
Problem
useLoop
calls user callbacks before THREE can actually render to the screen, e.g., in the default setup,<canvas>
will have a height/width of 0 whenuseLoop
starts.For debugging, this means that the developer needs to wait for a few frames to pass before they get "real" values in their logs/debugger.
Solution
Start the loop and trigger
ready
callbacks when Tres is "ready".Use case
DX, particularly debugging.
Problem
#572
Users had been asking for an easier way to get the context from a
TresCanvas
in a<script setup>
. It currently requires a few steps that users find non-obvious, as outlined in the issue above.Solution
@ready
emit that takes a callback and calls it withTresContext
when Tres is "ready"Use case
DX. Advanced users who want to write a bit less code in order to access
TresContext
.Problem
Child components can't take advantage of "ready" without registering a loop callback.
Solution
onTresReady
hookUse case
DX. Advanced users who want to be notified when Tres is "ready" in child components.
Meta
closes #595 – the present PR modifies
useLoop
notuseRenderLoop
as in the issue. ButuseRenderLoop
is no longer Tres' preferred looping methodcloses #572