Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Commit

Permalink
add impl and todo for XRReferenceSpaceEvent handling
Browse files Browse the repository at this point in the history
  • Loading branch information
HexaField committed Oct 30, 2023
1 parent bb12fdc commit 509ff8c
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions packages/engine/src/xr/XRSessionFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,20 @@ export const getReferenceSpaces = (xrSession: XRSession) => {
worldOriginTransform.position.copy(rigidBody.position)
worldOriginTransform.rotation.copy(rigidBody.rotation).multiply(quat180y)

const onLocalFloorReset = (ev: XRReferenceSpaceEvent) => {
/** @todo ev.transform is not yet implemented on the Quest browser */
// if (ev.transform) {
// ReferenceSpace.localFloor = ev.referenceSpace.getOffsetReferenceSpace(ev.transform)
// if (ReferenceSpace.localFloor && 'addEventListener' in ReferenceSpace.localFloor)
// ReferenceSpace.localFloor.addEventListener('reset', onLocalFloorReset, { once: true, passive: true })
// }
setTrackingSpace()
}

/** the world origin is an offset to the local floor, so as soon as we have the local floor, define the origin reference space */
xrSession.requestReferenceSpace('local-floor').then((space) => {
xrSession.requestReferenceSpace('local-floor').then((space: XRReferenceSpace | XRBoundedReferenceSpace) => {
// WebXR Emulator does not support XRReferenceSpace events
if ('addEventListener' in space)
space.addEventListener('reset', (ev) => {
/** @todo we need to use the event's `transform` property to modify our origin reference space to align with the space prior to the reset event */
setTrackingSpace()
})
if ('addEventListener' in space) space.addEventListener('reset', onLocalFloorReset, { once: true, passive: true })
ReferenceSpace.localFloor = space
computeAndUpdateWorldOrigin()
})
Expand Down

0 comments on commit 509ff8c

Please sign in to comment.