UNPKG

playcanvas

Version:

Open-source WebGL/WebGPU 3D engine for the web

92 lines (91 loc) 2.76 kB
var __defProp = Object.defineProperty; var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value); import { platform } from "../../core/platform.js"; class XrDomOverlay { /** * Create a new XrDomOverlay instance. * * @param {XrManager} manager - WebXR Manager. * @ignore */ constructor(manager) { /** * @type {XrManager} * @private */ __publicField(this, "_manager"); /** * @type {boolean} * @private */ __publicField(this, "_supported", platform.browser && !!window.XRDOMOverlayState); /** * @type {Element|null} * @private */ __publicField(this, "_root", null); this._manager = manager; } /** * True if DOM Overlay is supported. * * @type {boolean} */ get supported() { return this._supported; } /** * True if DOM Overlay is available. This information becomes available only when the session has * started and a valid root DOM element has been provided. * * @type {boolean} */ get available() { return this._supported && this._manager.active && this._manager._session.domOverlayState !== null; } /** * State of the DOM Overlay, which defines how the root DOM element is rendered. Can be: * * - `screen` - indicates that the DOM element is covering the whole physical screen, matching * XR viewports. * - `floating` - indicates that the underlying platform renders the DOM element as floating in * space, which can move during the WebXR session or allow the application to move the element. * - `head-locked` - indicates that the DOM element follows the user's head movement * consistently, appearing similar to a helmet heads-up display. * * @type {"screen"|"floating"|"head-locked"|null} */ get state() { if (!this._supported || !this._manager.active || !this._manager._session.domOverlayState) { return null; } return this._manager._session.domOverlayState.type; } /** * Sets the DOM element to be used as the root for DOM Overlay. Can be changed only when the XR * session is not running. * * @type {Element|null} * @example * app.xr.domOverlay.root = element; * app.xr.start(camera, XRTYPE_AR, XRSPACE_LOCALFLOOR); */ set root(value) { if (!this._supported || this._manager.active) { return; } this._root = value; } /** * Gets the DOM element to be used as the root for DOM Overlay. * * @type {Element|null} */ get root() { return this._root; } } export { XrDomOverlay };