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
feat: create AR/VR buttons in react, bypass context for session init #142
Conversation
Coming with a feedback about session configuration. We stopped using react-xr buttons a while ago and we're creating the session manually so here are the things we're currently doing with comments how it can relate to this pr
|
Reference space and foveation would be good config options. Not sure about accessing the session outside of react-xr context. I have a global zustand store to pass around the XRSession since it's assumed that only one XRCanvas will be used at a time, but I'm not sure if/how that should be exposed at all. |
I have a way to do the latter in #143, but that's v4-only. This PR would have to be merged first and picked to v3, or mirrored against the v3 branch. |
Exactly the same thought |
What do you think about |
I'd want to also add |
src/XR.tsx
Outdated
export type XRCanvasEventType = 'sessionstart' | 'sessionend' | 'visibilitychange' | 'inputsourceschange' | ||
export class XRCanvasEvent extends Event { | ||
readonly session: XRSession | ||
|
||
constructor(type: XRCanvasEventType, session: XRSession) { | ||
super(type) | ||
this.session = session | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a little annoying. Three doesn't emulate XRSessionEvent
in its WebXRManager and XREvents.tsx exports an interface called XREvent
which would more appropriately be XRControllerEvent
.
I think I'll rename these in v4 so XREvent
becomes more generic and extends to XRControllerEvent
. This should also maybe be an interface/object instead of an Event
, as its methods aren't effectful.
Continues #76
Refactors the internal
XRButton
andXRCanvas
to exist in React and init session state outside of XR context, so buttons can exist outside of the canvas. This is fully backwards compatible with previous versions that utilize three'sVRButton
&ARButton
.Additionally,
XRButton
andXRCanvas
are now exported to enable more composition options. For example, this would be equivalent toVRCanvas
:Furthermore, session events are exposed as props, and reference space can be configured on the XRCanvas: