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

refactor(controllers): Refactored how Controllers interact w/ three #294

Merged
merged 15 commits into from Jul 26, 2023

Conversation

saitonakamura
Copy link
Sponsor Collaborator

@saitonakamura saitonakamura commented Jul 23, 2023

This a big refactor of controller and how they interact with three counterparts. The flow of events was very confusing, to say the least. This PR makes this flow much direct and does some other notable changes.

ControllerModel abstraction is removed

It's responsibilities are moved to Controllers, mainly to https://github.com/pmndrs/react-xr/pull/294/files#diff-f17a5c6c1d801f88dd02bbbcaacc32ee99c5630535d1db5f3d5527ddd84b89eaR85-R103

And Controllers now directly render XRControllerModel

So the flow now is

  1. XR creates a pair of XRController and subscribes to connected/disconnected events from three.js
  2. XRController call xr.getControler and others in constructor therefore creating a WebXRController instances in three.js. Both WebXRController and it's XRController counterparts will now be present for the lifetime of an app
  3. three.js WebXRManager react to inputsourceschange and populates it's state and dispatches connected event
  4. connected event is handled by XR and it populates state.controller with corresponding XRController
  5. handleControllerModel react to ref and calls modelFactory.initializeControllerModel which does all the 3d/profiles heavy lifting as previous

Previously, the 5th step was actually another multi-step flow which involved sending fake events and such

XRControllerModel moved to a separate file from XRControllersModelFactory

No notable changes inside it

InputSource on XRController can now be null

Now inputSource will become null if controller is disconnected, no real reason to hold on to outdated inputSource. This resulted in a bunch of null checks here and there, but nothing substantial

Whole bunch of unit tests added

We're still far from good coverage, but this is a big step forward

@codesandbox-ci
Copy link

codesandbox-ci bot commented Jul 23, 2023

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 4103966:

Sandbox Source
examples Configuration

@saitonakamura saitonakamura changed the title wip refactor(controllers): Refactored how Controllers interact w/ three Jul 23, 2023
@saitonakamura saitonakamura marked this pull request as ready for review July 23, 2023 17:15
@saitonakamura
Copy link
Sponsor Collaborator Author

@CodyJasonBennett I'd really appreciate any feedback on this

@CodyJasonBennett
Copy link
Member

I'm happy with the premise. Will give this a deeper review later today.

src/Controllers.tsx Outdated Show resolved Hide resolved
@saitonakamura saitonakamura merged commit 1031262 into master Jul 26, 2023
2 checks passed
@saitonakamura saitonakamura deleted the refactor/controllers branch July 26, 2023 07:24
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

2 participants