properly sync intersectObjects array in useFollowCam hook #118
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.
This pull request adds child event listeners in the
useFollowCam
hook. TheuseFollowCam
hook now listens for "childadded" and "childremoved" events in the scene. When a child is added or removed, therender
state is updated, triggering a re-render. This ensures that the intersectObjects array is updated correctly when children are added or removed.the problem is that the useFollowCam relies on component render, so if you add or remove elements that aren't at the level ecctrl was invoked then it won't rerender ecctrl and useFollowCam wouldn't update the intersectObjects array
with this fix, intersectObjects array will be updated when the ecctrl component rerenders and when objects are added or removed the scene.
i'm also thinking about completely getting rid of recomputing on every render and instead rely solely on the event listeners and add or remove elements from the array respectively.
the current paradigm with recompute intersectObjects array on every render seems very wasteful in terms of performance.
closes #117