import { AssetReference } from "../../engine/engine_addressables.js"; import { type NeedleXREventArgs } from "../../engine/engine_xr.js"; import { Behaviour } from "../Component.js"; /** * The WebARSessionRoot is the root object for a WebAR session and used to place the scene in AR. * It is also responsible for scaling the user in AR and to define the center of the AR scene. * If not present in the scene it will be created automatically by the WebXR component when entering an AR session. * * **Note**: If the WebXR component {@link WebXR.autoCenter} option is enabled the scene will be automatically centered based on the content in the scene. * * @example Callback when the scene has been placed in AR: * ```ts * WebARSessionRoot.onPlaced((args) => { * console.log("Scene has been placed in AR"); * }); * ``` * * @summary Root object for WebAR sessions, managing scene placement and user scaling in AR. * @category XR * @group Components */ export declare class WebARSessionRoot extends Behaviour { private static _eventListeners; /** * Event that is called when the scene has been placed in AR. * @param cb the callback that is called when the scene has been placed * @returns a function to remove the event listener */ static onPlaced(cb: (args: { instance: WebARSessionRoot; }) => void): () => void; private static _hasPlaced; /** * @returns true if the scene has been placed in AR by the user or automatic placement */ static get hasPlaced(): boolean; /** The scale of the user in AR. * **NOTE**: a large value makes the scene appear smaller * @default 1 */ get arScale(): number; set arScale(val: number); private _arScale; /** When enabled the placed scene forward direction will towards the XRRig * @deprecated * @default false */ invertForward: boolean; /** When assigned this asset will be loaded and visualize the placement while in AR * @default null */ customReticle?: AssetReference; /** Enable touch transform to translate, rotate and scale the scene in AR with multitouch * @default true */ arTouchTransform: boolean; /** When enabled the scene will be placed automatically when a point in the real world is found * @default false */ autoPlace: boolean; /** When enabled the scene center will be automatically calculated from the content in the scene */ autoCenter: boolean; /** When enabled a XR anchor is created at the scene placement position and the scene * stays at that anchored point while tracking refines during the XR session. * On platforms without WebXR anchor support this gracefully falls back to plain placement. * @default true **/ useXRAnchor: boolean; /** true if we're currently placing the scene */ private _isPlacing; /** This is the world matrix of the ar session root when entering webxr * it is applied when the scene has been placed (e.g. if the session root is x:10, z:10 we want this position to be the center of the scene) */ private readonly _startOffset; private _createdPlacementObject; private readonly _reparentedComponents; private readonly _placementScene; /** the reticles used for placement */ private readonly _reticle; /** reference-space hit poses, in sync with the reticles — captured while placing when {@link useXRAnchor} * is enabled, because hit test results can not be used outside the animation frame that produced them */ private readonly _hitRefPoses; private _placementStartTime; private _rigPlacementMatrix?; /** if useAnchor is enabled this is the anchor we have created on placing the scene using the placement hit */ private _anchor; /** the placement pose (reference space) waiting for anchor creation on the next animation frame */ private _pendingAnchorPose; /** the last anchor pose (in rig space) that has been applied to the rig */ private readonly _anchorLastLocalPose; /** user input is used for ar touch transform */ private userInput?; onEnable(): void; supportsXR(mode: XRSessionMode): boolean; onEnterXR(_args: NeedleXREventArgs): void; onLeaveXR(): void; onUpdateXR(args: NeedleXREventArgs): void; private updateReticleAndHits; private onPlaceScene; private onSetScale; private onRevertSceneChanges; /** * Deferred anchor creation and per-frame anchor tracking. Called from {@link onUpdateXR} after the scene has been placed. * * Creation can not happen during placement: `XRHitTestResult.createAnchor` only works while the animation * frame that produced the hit is active, and placement runs from an input event where that frame is already * over (`XRFrame.createAnchor` equally requires an active animation frame). So {@link onPlaceScene} only * records the reference-space pose and the anchor is created here, on the next animation frame. * * Once the anchor exists, its pose *changes* (delta in rig space) are applied to the XR rig: the world pose * of the anchored point stays constant while tracking refines, without discarding other rig modifications * ({@link arTouchTransform} user adjustments, {@link arScale}). */ private updateXRAnchor; private upVec; private lookPoint; private worldUpVec; private applyViewBasedTransform; private onApplyPose; }