@threlte/xr
Version:
Tools to more easily create VR and AR experiences with Threlte
82 lines (81 loc) • 3.5 kB
TypeScript
declare global {
interface XRSystem {
offerSession?: XRSystem['requestSession'];
}
}
import type { WebXRManager, Event as ThreeEvent } from 'three';
import type { XRHandModelFactory } from 'three/examples/jsm/webxr/XRHandModelFactory.js';
import type { XRControllerModelFactory } from 'three/examples/jsm/webxr/XRControllerModelFactory.js';
import { type Snippet } from 'svelte';
interface Props {
/**
* Enables foveated rendering. Default is `1`, the three.js default.
*
* 0 = no foveation, full resolution
*
* 1 = maximum foveation, the edges render at lower resolution
*/
foveation?: number;
/**
* The target framerate for the XRSystem. Smaller rates give more CPU headroom at the cost of responsiveness.
* Recommended range is `72`-`120`. Default is unset and left to the device.
* @note If your experience cannot effectively reach the target framerate, it will be subject to frame reprojection
* which will halve the effective framerate. Choose a conservative estimate that balances responsiveness and
* headroom based on your experience.
* @see https://developer.mozilla.org/en-US/docs/Web/API/WebXR_Device_API/Rendering#refresh_rate_and_frame_rate
*/
frameRate?: number | undefined;
/** Type of WebXR reference space to use. Default is `local-floor` */
referenceSpace?: XRReferenceSpaceType;
fallback?: Snippet;
children?: Snippet;
/** Called as an XRSession is started */
onsessionstart?: (event: ThreeEvent<'sessionstart', WebXRManager>) => void;
/** Called after an XRSession is ended */
onsessionend?: (event: XRSessionEvent) => void;
/** Optionally provide custom XRHandModelFactory */
handFactory?: XRHandModelFactory;
/** Optionally provide custom XRControllerModelFactory */
controllerFactory?: XRControllerModelFactory;
/** Called when an XRSession is hidden or unfocused. */
onvisibilitychange?: (event: XRSessionEvent) => void;
/** Called when available inputsources change */
oninputsourceschange?: (event: XRSessionEvent) => void;
/** Called when the session frame rate changes. */
onframeratechange?: (event: XRSessionEvent) => void;
/**
* Auto-enter a session when the OS grants one without an explicit request
* (e.g. when the user puts on a headset). Pass `false` to disable, or an
* array of modes to restrict which modes are eligible.
* @default true
*/
enterGrantedSession?: boolean | XRSessionMode[];
/**
* Pre-offer a session via `navigator.xr.offerSession` so the browser can
* show its own entry UI (e.g. Vision Pro). When `true`, offers AR if
* supported, otherwise VR. Pass a specific mode to restrict. Pass `false`
* to disable.
* @default true
*/
offerSession?: boolean | XRSessionMode;
}
/**
* `<XR />` is a WebXR manager that configures your scene for XR rendering and interaction.
*
* This should be placed within a Threlte `<Canvas />`.
*
* ```svelte
* <XR
* foveation={1}
* frameRate={90}
* referenceSpace='local-floor'
* onsessionstart={(event: XREvent<XRManagerEvent>) => {}}
* onsessionend={(event: XREvent<XRManagerEvent>) => {}}
* onvisibilitychange={(event: XREvent<XRSessionEvent>) => {}}
* oninputsourceschange={(event: XREvent<XRSessionEvent>) => {}}
* />
* ```
*/
declare const Xr: import("svelte").Component<Props, {}, "">;
type Xr = ReturnType<typeof Xr>;
export default Xr;