Skip to main content

Class: WebXRSession

Defined in: src/core/WebXR.ts:100

Controller for an opt-in WebXR session bound to one scene.

Create it with enableXR. The session is inert until WebXRSession.enterXR runs, so constructing it has no effect on the default desktop render loop.

Constructors​

Constructor​

new WebXRSession(scene, options): WebXRSession

Defined in: src/core/WebXR.ts:119

Parameters​

scene​

XRSceneLike

The scene to render in the headset.

options​

WebXROptions = {}

Session configuration. See WebXROptions.

Returns​

WebXRSession

Accessors​

active​

Get Signature​

get active(): boolean

Defined in: src/core/WebXR.ts:136

Whether an immersive session is currently active.

Returns​

boolean


mode​

Get Signature​

get mode(): XRSessionMode

Defined in: src/core/WebXR.ts:131

The session mode this controller requests.

Returns​

XRSessionMode


session​

Get Signature​

get session(): XRSession

Defined in: src/core/WebXR.ts:141

The underlying WebXR session while active, otherwise null.

Returns​

XRSession

Methods​

createButton()​

createButton(options): HTMLButtonElement

Defined in: src/core/WebXR.ts:241

Build an "Enter VR/AR" toggle button, like three.js VRButton.

The button enters a session on first click and exits on the next. It disables itself when the mode is unsupported. Returns null when no DOM is present (CI, headless), so callers never need a typeof document guard.

Parameters​

options​

XRButtonOptions = {}

Button labels. See XRButtonOptions.

Returns​

HTMLButtonElement

The button element, or null without a DOM.


enterXR()​

enterXR(): Promise<boolean>

Defined in: src/core/WebXR.ts:164

Request an immersive session and switch the renderer to the XR render loop.

Sets renderer.xr.enabled = true, requests the session, selects the reference space, and drives rendering with renderer.setAnimationLoop (required by WebXR; the desktop requestAnimationFrame path is not used while presenting). Safe to call when already active (no-op).

Returns​

Promise<boolean>

true once the session is presenting; false when WebXR is unavailable or the request fails. Never throws for an unavailable device.


exitXR()​

exitXR(): Promise<void>

Defined in: src/core/WebXR.ts:219

End the active session and restore the desktop render state.

Clears the XR animation loop, restores the previous renderer.xr.enabled value, and ends the session. Safe to call when inactive (no-op). Cleanup also runs if the user exits from inside the headset, via the session's end event.

Returns​

Promise<void>


isSupported()​

isSupported(): Promise<boolean>

Defined in: src/core/WebXR.ts:149

Whether this controller's mode is supported in the current environment. Thin instance wrapper over isXRSupported.

Returns​

Promise<boolean>