Class WebXRSessionManager
Implements
Index
Constructors
Properties
Accessors
Methods
Constructors
constructor
-
Constructs a WebXRSessionManager, this must be initialized within a user action before usage
Parameters
- scene: Scene
The scene which the session should be created for
Returns WebXRSessionManager
- scene: Scene
Properties
base Reference Space
The base reference space from which the session started. good if you want to reset your reference space
current Frame
Current XR frame
current Timestamp
WebXR timestamp updated every frame
default Height Compensation
Used just in case of a failure to initialize an immersive session. The viewer reference space is compensated using this height, creating a kind of "viewer-floor" reference space
in XR Frame Loop
Are we currently in the XR loop?
in XR Session
Are we in an XR session?
on World Scale Factor Changed Observable
{ newScaleFactor: number; previousScaleFactor: number },
> = ...
Observable raised when the world scale has changed
on XR Frame Observable
Fires every time a new xrFrame arrives which can be used to update the camera
on XR Ready
Fires when the session manager is rendering the first frame
on XR Reference Space Changed
Fires when the reference space changed
on XR Reference Space Initialized
Fires when the xr reference space has been initialized
on XR Session Ended
Fires when the xr session is ended either by the device or manually done
on XR Session Init
Fires when the xr session is initialized: right after requestSession was called and returned with a successful result
scene
The scene which the session should be created for
session
Underlying xr session
viewer Reference Space
The viewer (head position) reference space. This can be used to get the XR world coordinates or get the offset the player is currently at.
Accessors
current Frame Rate
-
get currentFrameRate(): number | undefined
The current frame rate as reported by the device
Returns number | undefined
enabled Features
-
Get the features enabled on the current session This is only available in-session!
Returns Nullable<string[]>
fixed Foveation
-
Get the fixed foveation currently set, as specified by the webxr specs If this returns null, then fixed foveation is not supported
Returns Nullable<number>
-
Set the fixed foveation to the specified value, as specified by the webxr specs This value will be normalized to be between 0 and 1, 1 being max foveation, 0 being no foveation
Parameters
- value: Nullable<number>
Returns void
is Fixed Foveation Supported
-
get isFixedFoveationSupported(): boolean
Check if fixed foveation is supported on this device
Returns boolean
is Native
-
get isNative(): boolean
Returns true if Babylon.js is using the BabylonNative backend, otherwise false
Returns boolean
reference Space
-
get referenceSpace(): XRReferenceSpace
The current reference space used in this session. This reference space can constantly change! It is mainly used to offset the camera's position.
Returns XRReferenceSpace
-
set referenceSpace(newReferenceSpace: XRReferenceSpace): void
Set a new reference space and triggers the observable
Parameters
- newReferenceSpace: XRReferenceSpace
Returns void
session Mode
-
get sessionMode(): XRSessionMode
The mode for the managed XR session
Returns XRSessionMode
supported Frame Rates
-
get supportedFrameRates(): Float32Array<ArrayBufferLike> | undefined
A list of supported frame rates (only available in-session!
Returns Float32Array<ArrayBufferLike> | undefined
world Scaling Factor
-
get worldScalingFactor(): number
Scale factor to apply to all XR-related elements (camera, controllers)
Returns number
-
set worldScalingFactor(value: number): void
Parameters
- value: number
Returns void
StaticIs Web GPUXR Supported
-
get IsWebGPUXRSupported(): boolean
ExperimentalReturns whether the runtime exposes the WebGPU-XR binding APIs required by Babylon.js.
This is an advisory check only. XR session negotiation can still fail for the active device, permissions, or adapter. A WebGPU engine intended for XR must also be created with
xrCompatible: true.Returns boolean
whether the required XRGPUBinding projection APIs are exposed WebGPU-XR support is experimental and may change.
Methods
dispose
-
Disposes of the session manager This should be called explicitly by the dev, if required.
Returns void
exit XR Async
-
Stops the xrSession and restores the render loop
Returns Promise<void>
Promise which resolves after it exits XR
get Recommended Viewport Scale
-
Gets the runtime-recommended viewport scale for the current XR view. A number is returned when the runtime has a recommendation,
nullwhen the API is supported but the runtime has no recommendation, andundefinedwhen the API is not supported. This method must be called during an active XR frame.Parameters
- viewIndex: number
the index of the view in the current viewer pose
Returns Nullable<number> | undefined
the recommended viewport scale,
nullwhen no recommendation is available, orundefinedwhen unsupported - viewIndex: number
get Render Target Texture For Eye
-
Gets the correct render target texture to be rendered this frame for this eye
Parameters
- eye: XREye
the eye for which to get the render target
Returns Nullable<RenderTargetTexture>
the render target for the specified eye or null if not available
- eye: XREye
get Render Target Texture For View
-
Gets the correct render target texture to be rendered this frame for this view
Parameters
- view: XRView
the view for which to get the render target
Returns Nullable<RenderTargetTexture>
the render target for the specified view or null if not available
- view: XRView
get Web XR Render Target
-
Creates a WebXRRenderTarget object for the XR session
Parameters
Optionaloptions: WebXRManagedOutputCanvasOptionsoptional options to provide when creating a new render target
Returns WebXRRenderTarget
a WebXR render target to which the session can render
initialize Async
-
Initializes the manager After initialization enterXR can be called to start an XR session
Returns Promise<void>
Promise which resolves after it is initialized
initialize Session Async
-
initializeSessionAsync(
xrSessionMode?: XRSessionMode,
xrSessionInit?: XRSessionInit,
): Promise<XRSession>Initializes an xr session
Parameters
- xrSessionMode: XRSessionMode = "immersive-vr"
mode to initialize
- xrSessionInit: XRSessionInit = {}
defines optional and required values to pass to the session builder
Returns Promise<XRSession>
a promise which will resolve once the session has been initialized
- xrSessionMode: XRSessionMode = "immersive-vr"
is Session Supported Async
-
Checks if a session would be supported for the creation options specified
Parameters
- sessionMode: XRSessionMode
session mode to check if supported eg. immersive-vr
Returns Promise<boolean>
A Promise that resolves to true if supported and false if not
- sessionMode: XRSessionMode
is Viewport Scale Supported
-
Checks whether the current XR view exposes the dynamic viewport scaling API. API availability does not guarantee that the active XR device will change the viewport dimensions. This method must be called during an active XR frame.
Parameters
- viewIndex: number
the index of the view in the current viewer pose
Returns boolean
whether dynamic viewport scaling is exposed for the view
- viewIndex: number
request Viewport Scale
-
Requests a viewport scale for the current XR view. The request is a hint to the runtime. Babylon uses the native viewport returned on subsequent frames and does not derive viewport dimensions from this value. Pass
1to restore the full viewport scale;nullfollows the native no-op behavior. Native ignored-value, clamping, and exception behavior is preserved. Requests made from an application observer ofonXRFrameObservableapply to a future frame because Babylon's camera acquires the current frame's viewport before notifying application observers. This method must be called during an active XR frame.Parameters
- viewIndex: number
the index of the view in the current viewer pose
- scale: Nullable<number>
the viewport scale requested from the runtime
Returns void
- viewIndex: number
reset Reference Space
-
Resets the reference space to the one started the session
Returns void
run In XR Frame
-
Run a callback in the xr render loop
Parameters
- callback: () => void
the callback to call when in XR Frame
- ignoreIfNotInSession: boolean = true
if no session is currently running, run it first thing on the next session
Returns void
- callback: () => void
run XR Render Loop
-
Starts rendering to the xr layer
Returns void
set Reference Space Type Async
-
Sets the reference space on the xr session
Parameters
- referenceSpaceType: XRReferenceSpaceType = "local-floor"
space to set
Returns Promise<XRReferenceSpace>
a promise that will resolve once the reference space has been set
- referenceSpaceType: XRReferenceSpaceType = "local-floor"
try Set Viewport For View
-
Attempts to set the framebuffer-size-normalized viewport to be rendered this frame for this view. In the event of a failure, the supplied viewport is not updated.
Parameters
- viewport: Viewport
the viewport to which the view will be rendered
- view: XRView
the view for which to set the viewport
Returns boolean
whether the operation was successful
- viewport: Viewport
update Render State
-
Updates the render state of the session
Parameters
- state: XRRenderStateInit
state to set
Returns void
- state: XRRenderStateInit
update Render State Async
update Target Frame Rate
-
Set the framerate of the session.
Parameters
- rate: number
the new framerate. This value needs to be in the supportedFrameRates array
Returns Promise<void>
a promise that resolves once the framerate has been set
- rate: number
StaticIs Session Supported Async
-
Returns a promise that resolves with a boolean indicating if the provided session mode is supported by this browser
Parameters
- sessionMode: XRSessionMode
defines the session to test
Returns Promise<boolean>
a promise with boolean as final value
- sessionMode: XRSessionMode
Manages an XRSession to work with Babylon's engine
See
https://doc.babylonjs.com/features/featuresDeepDive/webXR/webXRSessionManagers