@@ -14,6 +14,7 @@ import {SoundOptions} from '../sound/SoundOptions';
1414import { deepMerge } from '../utils/OptionsUtils' ;
1515import { DeepPartial , DeepReadonly } from '../utils/Types' ;
1616import { 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 /**
0 commit comments