@needle-tools/engine
Version:
Needle Engine is a web-based runtime for 3D apps. It runs on your machine for development with great integrations into editors like Unity or Blender - and can be deployed onto any device! It is flexible, extensible and networking and XR are built-in.
99 lines (98 loc) • 3.8 kB
TypeScript
/// <reference types="webxr" />
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 optionally creating a XR anchor for the scene placement.
* @example
* ```ts
* WebARSessionRoot.onPlaced((args) => {
* console.log("Scene has been placed 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;
/** Experimental: When enabled we will create a XR anchor for the scene placement
* and make sure the scene is at that anchored point during a XR session
* @default false
**/
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;
/** needs to be in sync with the reticles */
private readonly _hits;
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;
/** 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;
private onCreateAnchor;
private upVec;
private lookPoint;
private worldUpVec;
private applyViewBasedTransform;
private onApplyPose;
}