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

properly sync intersectObjects array in useFollowCam hook #118

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

hichemfantar
Copy link

@hichemfantar hichemfantar commented Oct 12, 2024

This pull request adds child event listeners in the useFollowCam hook. The useFollowCam hook now listens for "childadded" and "childremoved" events in the scene. When a child is added or removed, the render 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

@hichemfantar hichemfantar changed the title Add child event listeners in useFollowCam hook properly sync intersectObjects array in useFollowCam hook Oct 12, 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.

bug: follow cam doesn't register objects newly added or removed from scene
1 participant