Skip to content

Commit f2d7cdf

Browse files
authored
Merge pull request #182 from dli7319/options
Add formFactor to Options
2 parents eff7778 + 2dec868 commit f2d7cdf

File tree

4 files changed

+53
-7
lines changed

4 files changed

+53
-7
lines changed

src/core/Core.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import {ScreenshotSynthesizer} from './components/ScreenshotSynthesizer';
3030
import {ScriptsManager} from './components/ScriptsManager';
3131
import {WaitFrame} from './components/WaitFrame';
3232
import {
33-
IMMERSIVE_AR,
3433
WebXRSessionEventType,
3534
WebXRSessionManager,
3635
} from './components/WebXRSessionManager';
@@ -318,7 +317,7 @@ export class Core {
318317
this.webXRSessionManager = new WebXRSessionManager(
319318
this.renderer,
320319
this.webXRSettings,
321-
IMMERSIVE_AR
320+
options.xrSessionMode
322321
);
323322
this.webXRSessionManager.addEventListener(
324323
WebXRSessionEventType.SESSION_START,

src/core/Options.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {SoundOptions} from '../sound/SoundOptions';
1414
import {deepMerge} from '../utils/OptionsUtils';
1515
import {DeepPartial, DeepReadonly} from '../utils/Types';
1616
import {WorldOptions} from '../world/WorldOptions';
17+
import {getUrlParameter} from '../utils/utils';
1718

1819
/**
1920
* Default options for XR controllers, which encompass hands by default in
@@ -53,6 +54,9 @@ export class XRTransitionOptions {
5354
defaultBackgroundColor = 0xffffff;
5455
}
5556

57+
const FORM_FACTORS = ['auto', 'xr', 'hud', 'vr', 'desktop', 'mobile'] as const;
58+
export type FormFactor = (typeof FORM_FACTORS)[number];
59+
5660
/**
5761
* A central configuration class for the entire XR Blocks system. It aggregates
5862
* all settings and provides chainable methods for enabling common features.
@@ -140,13 +144,59 @@ export class Options {
140144
microphone: false,
141145
};
142146

147+
xrSessionMode: XRSessionMode = 'immersive-ar';
148+
149+
private _formFactor: FormFactor = 'auto';
150+
151+
get formFactor() {
152+
return this._formFactor;
153+
}
154+
155+
/**
156+
* Form factor is a preset that configures the experience for a specific
157+
* device type. Currently it only controls whether the simulator is enabled
158+
* and should always be autostarted.
159+
*/
160+
set formFactor(formFactor: FormFactor) {
161+
this._formFactor = formFactor;
162+
this.enableSimulator =
163+
formFactor === 'desktop' ||
164+
formFactor === 'auto' ||
165+
formFactor === 'mobile';
166+
this.xrButton.alwaysAutostartSimulator = formFactor === 'desktop';
167+
if (formFactor === 'vr') {
168+
this.enableVR();
169+
}
170+
}
171+
143172
/**
144173
* Constructs the Options object by merging default values with provided
145174
* custom options.
146175
* @param options - A custom options object to override the defaults.
147176
*/
148177
constructor(options?: DeepReadonly<DeepPartial<Options>>) {
149178
deepMerge(this, options);
179+
this.parseUrlParams();
180+
}
181+
182+
protected parseUrlParams() {
183+
const formFactorUrlParam = getUrlParameter('formFactor');
184+
if (
185+
formFactorUrlParam &&
186+
FORM_FACTORS.includes(formFactorUrlParam as FormFactor)
187+
) {
188+
this.formFactor = formFactorUrlParam as FormFactor;
189+
}
190+
}
191+
192+
/**
193+
* Sets the session mode to VR and disables the simulator passthrough scene.
194+
*/
195+
enableVR() {
196+
this.xrSessionMode = 'immersive-vr';
197+
this.simulator.scenePath = null;
198+
this.simulator.scenePlanesPath = null;
199+
return this;
150200
}
151201

152202
/**

src/core/components/WebXRSessionManager.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import * as THREE from 'three';
22

3-
export const IMMERSIVE_AR = 'immersive-ar';
4-
export const IMMERSIVE_VR = 'immersive-vr';
5-
63
declare global {
74
interface XRSystem {
85
offerSession?: (

src/simulator/SimulatorOptions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ export interface SimulatorCustomInstruction {
2525

2626
export class SimulatorOptions {
2727
initialCameraPosition = {x: 0, y: 1.5, z: 0};
28-
scenePath?: string =
28+
scenePath: string | null =
2929
XR_BLOCKS_ASSETS_PATH + 'simulator/scenes/XREmulatorsceneV5_livingRoom.glb';
30-
scenePlanesPath?: string =
30+
scenePlanesPath: string | null =
3131
XR_BLOCKS_ASSETS_PATH +
3232
'simulator/scenes/XREmulatorsceneV5_livingRoom_planes.json';
3333
videoPath?: string = undefined;

0 commit comments

Comments
 (0)