fix: vendor and fix XRControllerModelFactory #239
Merged
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.
Following the discussion I vendored
XRControllerModelFactory
toreact-xr
along with some changes inside.The main point of this is to fix problems with connecting/disconnecting different or same controllers, turns out webxr world is crazy full of quirks (who'd have thought). It all started in pmndrs/three-stdlib#214: there I tried to fix a problem when you connect and disconnect controllers and it doesn't unsubscribe from
connected
event. Thing is, in three,WebXRController
are only created twice and never recreated, but they spew outconnected/disconnected
events. Connecting and disconnecting same or different controllers before this fix would result in ever more increasingconnected
event listeners each trying to load and add the scene. I've added the unsubscription fix, but it shot me in the foot in the most weird way. Turns out, SteamVR is connecting controllers in a peculiar way: it first dispatchesinputsourceschange
event withadded: [some input source data]
, then immediatelyinputsourceschange
withremoved: [the input source that was just added]
and theninputsourceschange
withadded: [proper input source]
. And with the fix, it just unsubscribes fromconnected
and never has a chance to resubscribe (cause it's kind of the same controller). With all that in mind I refactoredXRControllerModelFactory
,XRControllerModel
andControllerModel
into somewhat cohesive picture that works with all this quirks. We tested it on multiple devies including Oculus Go, Quest 1, 2 and Pro, Rift S, Valve Index, Vive Cosmos and the others and we've yet to find more problems with it, this works robust. I don't really like the way it looks now, because logic is bit scattered all over the place, but it's no worse than it was before IMOThe other thing I did in this PR is to add a few events that
XRControllerModel
now dispatches, namely,modelconnected/disconnected
andmotionconnected/disconnected
. They're not currently used inreact-xr
code, it's only used in our own app code to do 2 things:MotionController
to dispatch events such as button press/thumbstick move/etc. This is directly applicable toreact-xr
and I plan to expose it as an additional api surface toInteractive
react-xr
to take advantage of it right now, except for examples maybeI'm willing to move these events dispatch to a separate PR if it's any problem