Skip to content

Commit

Permalink
Adding support for XREnvironmentBlendMode & XRInteractionMode
Browse files Browse the repository at this point in the history
Summary: Adding support for XREnvironmentBlendMode & XRInteractionMode per spec: https://www.w3.org/TR/webxr-ar-module-1/

Reviewed By: zjm-meta

Differential Revision:
D61364096

Privacy Context Container: L1233623

fbshipit-source-id: 6ae0ca3d8080283d85c69af9f52de066f1743247
  • Loading branch information
felixtrz authored and facebook-github-bot committed Aug 20, 2024
1 parent cf69144 commit fce70b6
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 15 deletions.
24 changes: 18 additions & 6 deletions src/device/XRDevice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ import {
} from '../spaces/XRSpace.js';
import { Quaternion, Vector3 } from '../utils/Math.js';
import { XRController, XRControllerConfig } from './XRController.js';
import {
XREnvironmentBlendMode,
XRInteractionMode,
PRIVATE as XRSESSION_PRIVATE,
XRSession,
XRSessionMode,
XRVisibilityState,
} from '../session/XRSession.js';
import { XREye, XRView } from '../views/XRView.js';
import { XRHandInput, oculusHandConfig } from './XRHandInput.js';
import {
Expand All @@ -25,12 +33,6 @@ import {
XRReferenceSpace,
XRReferenceSpaceType,
} from '../spaces/XRReferenceSpace.js';
import {
PRIVATE as XRSESSION_PRIVATE,
XRSession,
XRSessionMode,
XRVisibilityState,
} from '../session/XRSession.js';
import {
PRIVATE as XRSYSTEM_PRIVATE,
XRSystem,
Expand Down Expand Up @@ -78,6 +80,10 @@ export interface XRDeviceConfig {
supportedFrameRates: number[];
isSystemKeyboardSupported: boolean;
internalNominalFrameRate: number;
environmentBlendModes: Partial<{
[sessionMode in XRSessionMode]: XREnvironmentBlendMode;
}>;
interactionMode: XRInteractionMode;
userAgent: string;
}

Expand Down Expand Up @@ -113,6 +119,10 @@ export class XRDevice {
supportedFrameRates: number[];
isSystemKeyboardSupported: boolean;
internalNominalFrameRate: number;
environmentBlendModes: Partial<{
[sessionMode in XRSessionMode]: XREnvironmentBlendMode;
}>;
interactionMode: XRInteractionMode;
userAgent: string;

// device state
Expand Down Expand Up @@ -212,6 +222,8 @@ export class XRDevice {
supportedFrameRates: deviceConfig.supportedFrameRates,
isSystemKeyboardSupported: deviceConfig.isSystemKeyboardSupported,
internalNominalFrameRate: deviceConfig.internalNominalFrameRate,
environmentBlendModes: deviceConfig.environmentBlendModes,
interactionMode: deviceConfig.interactionMode,
userAgent: deviceConfig.userAgent,

position:
Expand Down
27 changes: 25 additions & 2 deletions src/device/configs/headset/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@
*/

import { WebXRFeatures, XRDeviceConfig } from '../../XRDevice.js';
import {
XREnvironmentBlendMode,
XRInteractionMode,
XRSessionMode,
} from '../../../session/XRSession.js';
import {
metaQuestTouchPlus,
metaQuestTouchPro,
oculusTouchV2,
oculusTouchV3,
} from '../controller/meta.js';

import { XRSessionMode } from '../../../session/XRSession.js';

export const oculusQuest1: XRDeviceConfig = {
name: 'Oculus Quest 1',
controllerConfig: oculusTouchV2,
Expand All @@ -36,6 +39,11 @@ export const oculusQuest1: XRDeviceConfig = {
supportedFrameRates: [72, 80, 90],
isSystemKeyboardSupported: true,
internalNominalFrameRate: 72,
environmentBlendModes: {
[XRSessionMode.ImmersiveVR]: XREnvironmentBlendMode.Opaque,
[XRSessionMode.ImmersiveAR]: XREnvironmentBlendMode.AlphaBlend,
},
interactionMode: XRInteractionMode.WorldSpace,
userAgent:
'Mozilla/5.0 (X11; Linux x86_64; Quest 1) AppleWebKit/537.36 (KHTML, like Gecko) OculusBrowser/33.0.0.x.x.x Chrome/126.0.6478.122 VR Safari/537.36',
};
Expand Down Expand Up @@ -63,6 +71,11 @@ export const metaQuest2: XRDeviceConfig = {
supportedFrameRates: [72, 80, 90, 120],
isSystemKeyboardSupported: true,
internalNominalFrameRate: 72,
environmentBlendModes: {
[XRSessionMode.ImmersiveVR]: XREnvironmentBlendMode.Opaque,
[XRSessionMode.ImmersiveAR]: XREnvironmentBlendMode.AlphaBlend,
},
interactionMode: XRInteractionMode.WorldSpace,
userAgent:
'Mozilla/5.0 (X11; Linux x86_64; Quest 2) AppleWebKit/537.36 (KHTML, like Gecko) OculusBrowser/33.0.0.x.x.x Chrome/126.0.6478.122 VR Safari/537.36',
};
Expand Down Expand Up @@ -90,6 +103,11 @@ export const metaQuestPro: XRDeviceConfig = {
supportedFrameRates: [72, 80, 90, 120],
isSystemKeyboardSupported: true,
internalNominalFrameRate: 90,
environmentBlendModes: {
[XRSessionMode.ImmersiveVR]: XREnvironmentBlendMode.Opaque,
[XRSessionMode.ImmersiveAR]: XREnvironmentBlendMode.AlphaBlend,
},
interactionMode: XRInteractionMode.WorldSpace,
userAgent:
'Mozilla/5.0 (X11; Linux x86_64; Quest Pro) AppleWebKit/537.36 (KHTML, like Gecko) OculusBrowser/33.0.0.x.x.x Chrome/126.0.6478.122 VR Safari/537.36',
};
Expand Down Expand Up @@ -118,6 +136,11 @@ export const metaQuest3: XRDeviceConfig = {
supportedFrameRates: [72, 80, 90, 120],
isSystemKeyboardSupported: true,
internalNominalFrameRate: 90,
environmentBlendModes: {
[XRSessionMode.ImmersiveVR]: XREnvironmentBlendMode.Opaque,
[XRSessionMode.ImmersiveAR]: XREnvironmentBlendMode.AlphaBlend,
},
interactionMode: XRInteractionMode.WorldSpace,
userAgent:
'Mozilla/5.0 (X11; Linux x86_64; Quest 3) AppleWebKit/537.36 (KHTML, like Gecko) OculusBrowser/33.0.0.x.x.x Chrome/126.0.6478.122 VR Safari/537.36',
};
23 changes: 23 additions & 0 deletions src/session/XRSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@ export type XRSessionInit = {
optionalFeatures?: string[];
};

export enum XREnvironmentBlendMode {
Opaque = 'opaque',
AlphaBlend = 'alpha-blend',
Additive = 'additive',
}

export enum XRInteractionMode {
ScreenSpace = 'screen-space',
WorldSpace = 'world-space',
}

type XRFrameRequestCallback = (
time: DOMHighResTimeStamp,
frame: XRFrame,
Expand Down Expand Up @@ -368,6 +379,18 @@ export class XRSession extends EventTarget {
return this[PRIVATE].isSystemKeyboardSupported;
}

get environmentBlendMode(): XREnvironmentBlendMode {
return (
this[PRIVATE].device[XRDEVICE_PRIVATE].environmentBlendModes[
this[PRIVATE].mode
] ?? XREnvironmentBlendMode.Opaque
);
}

get interactionMode(): XRInteractionMode {
return this[PRIVATE].device[XRDEVICE_PRIVATE].interactionMode;
}

updateRenderState(state: XRRenderStateInit = {}): void {
if (this[PRIVATE].ended) {
throw new DOMException(
Expand Down
16 changes: 15 additions & 1 deletion tests/initialization/XRSystem.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@
*/

import { WebXRFeatures, XRDevice } from '../../src/device/XRDevice';
import {
XREnvironmentBlendMode,
XRInteractionMode,
XRSessionMode,
} from '../../src/session/XRSession';

import { XRSessionMode } from '../../src/session/XRSession';
import { XRSystem } from '../../src/initialization/XRSystem';
import { metaQuestTouchPlus } from '../../src/device/configs/controller/meta';

Expand All @@ -31,6 +35,11 @@ describe('XRSystem', () => {
supportedFrameRates: [72, 80, 90, 120],
isSystemKeyboardSupported: true,
internalNominalFrameRate: 90,
environmentBlendModes: {
[XRSessionMode.ImmersiveVR]: XREnvironmentBlendMode.Opaque,
[XRSessionMode.ImmersiveAR]: XREnvironmentBlendMode.AlphaBlend,
},
interactionMode: XRInteractionMode.WorldSpace,
userAgent: 'Test user agent',
};

Expand All @@ -42,6 +51,11 @@ describe('XRSystem', () => {
supportedFrameRates: arvrDeviceConfig.supportedFrameRates,
isSystemKeyboardSupported: true,
internalNominalFrameRate: 90,
environmentBlendModes: {
[XRSessionMode.ImmersiveVR]: XREnvironmentBlendMode.Opaque,
[XRSessionMode.ImmersiveAR]: XREnvironmentBlendMode.AlphaBlend,
},
interactionMode: XRInteractionMode.WorldSpace,
userAgent: 'Test user agent',
};

Expand Down
36 changes: 30 additions & 6 deletions tests/session/XRSession.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ import {
XRDevice,
XRDeviceConfig,
} from '../../src/device/XRDevice';
import {
XREnvironmentBlendMode,
XRInteractionMode,
XRSession,
XRSessionMode,
XRVisibilityState,
} from '../../src/session/XRSession';
import {
XRReferenceSpace,
XRReferenceSpaceType,
Expand All @@ -18,11 +25,6 @@ import {
XRRenderState,
XRRenderStateInit,
} from '../../src/session/XRRenderState';
import {
XRSession,
XRSessionMode,
XRVisibilityState,
} from '../../src/session/XRSession';

import { XRFrame } from '../../src/frameloop/XRFrame';
import { XRInputSourceArray } from '../../src/input/XRInputSource';
Expand Down Expand Up @@ -71,7 +73,11 @@ describe('XRSession', () => {
const testDeviceConfig: XRDeviceConfig = {
name: 'Test Device',
controllerConfig: metaQuestTouchPlus,
supportedSessionModes: [XRSessionMode.Inline, XRSessionMode.ImmersiveVR],
supportedSessionModes: [
XRSessionMode.Inline,
XRSessionMode.ImmersiveVR,
XRSessionMode.ImmersiveAR,
],
supportedFeatures: [
WebXRFeatures.Viewer,
WebXRFeatures.Local,
Expand All @@ -80,6 +86,11 @@ describe('XRSession', () => {
supportedFrameRates: [72, 80, 90, 120],
isSystemKeyboardSupported: true,
internalNominalFrameRate: 90,
environmentBlendModes: {
[XRSessionMode.ImmersiveVR]: XREnvironmentBlendMode.Opaque,
[XRSessionMode.ImmersiveAR]: XREnvironmentBlendMode.AlphaBlend,
},
interactionMode: XRInteractionMode.WorldSpace,
userAgent: 'Test user agent',
};
xrDevice = new XRDevice(testDeviceConfig);
Expand Down Expand Up @@ -339,4 +350,17 @@ describe('XRSession', () => {
expect(mockOnSqueezeStart).toHaveBeenCalled();
expect(mockOnSqueezeEnd).toHaveBeenCalled();
});

test('XRSession.environmentBlendMode returns the correct value', async () => {
expect(xrSession.environmentBlendMode).toBe(XREnvironmentBlendMode.Opaque);
xrSession.end();
xrSession = await xrSystem.requestSession(XRSessionMode.ImmersiveAR);
expect(xrSession.environmentBlendMode).toBe(
XREnvironmentBlendMode.AlphaBlend,
);
});

test('XRSession.interactionMode returns the correct value', async () => {
expect(xrSession.interactionMode).toBe(XRInteractionMode.WorldSpace);
});
});

0 comments on commit fce70b6

Please sign in to comment.