Skip to content

Commit

Permalink
Allow XRDevice to override viewSpaces
Browse files Browse the repository at this point in the history
  • Loading branch information
Kai Ninomiya authored and toji committed Jan 14, 2021
1 parent 7dd87cb commit bd48d54
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
15 changes: 6 additions & 9 deletions src/api/XRSession.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import XRReferenceSpace, {
XRReferenceSpaceTypes
} from './XRReferenceSpace';
import XRRenderState from './XRRenderState';
import XRWebGLLayer from './XRWebGLLayer';
import XRInputSourceEvent from './XRInputSourceEvent';
import XRSessionEvent from './XRSessionEvent';
import XRSpace from './XRSpace';
Expand Down Expand Up @@ -63,6 +62,11 @@ export default class XRSession extends EventTarget {
inlineVerticalFieldOfView: immersive ? null : Math.PI * 0.5
});

const defaultViewSpaces = immersive ?
[new XRViewSpace('left'), new XRViewSpace('right')] :
[new XRViewSpace('none')];
Object.freeze(defaultViewSpaces);

this[PRIVATE] = {
device,
mode,
Expand All @@ -77,17 +81,10 @@ export default class XRSession extends EventTarget {
activeRenderState: initialRenderState,
pendingRenderState: null,
viewerSpace: new XRReferenceSpace("viewer"),
viewSpaces: [],
get viewSpaces() { return device.getViewSpaces(mode) || defaultViewSpaces; },
currentInputSources: []
};

if (immersive) {
this[PRIVATE].viewSpaces.push(new XRViewSpace('left'),
new XRViewSpace('right'));
} else {
this[PRIVATE].viewSpaces.push(new XRViewSpace('none'));
}

// Single handler for animation frames from the device. The spec says this must
// run on every candidate frame even if there are no callbacks queued up.
this[PRIVATE].onDeviceFrame = () => {
Expand Down
7 changes: 7 additions & 0 deletions src/devices/XRDevice.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,13 @@ export default class XRDevice extends EventTarget {
*/
endSession(sessionId) { throw new Error('Not implemented'); }

/**
* Allows the XRDevice to override the XRSession's view spaces.
*
* @param {XRSessionMode} mode
*/
getViewSpaces(mode) { return undefined; }

/**
* Takes a XREye and a target to apply properties of
* `x`, `y`, `width` and `height` on. Returns a boolean
Expand Down

0 comments on commit bd48d54

Please sign in to comment.