@babylonjs/core
Version:
Getting started? Play directly with the Babylon.js API using our [playground](https://playground.babylonjs.com/). It also contains a lot of samples to learn how to use it.
87 lines (86 loc) • 3.39 kB
TypeScript
import type { IWebXRFeature } from "../webXRFeaturesManager.js";
import type { EventState } from "../../Misc/observable.js";
import { Observable } from "../../Misc/observable.js";
import type { WebXRSessionManager } from "../webXRSessionManager.js";
/**
* This is the base class for all WebXR features.
* Since most features require almost the same resources and callbacks, this class can be used to simplify the development
* Note that since the features manager is using the `IWebXRFeature` you are in no way obligated to use this class
*/
export declare abstract class WebXRAbstractFeature implements IWebXRFeature {
protected _xrSessionManager: WebXRSessionManager;
private _attached;
private _removeOnDetach;
/**
* Is this feature disposed?
*/
isDisposed: boolean;
/**
* Should auto-attach be disabled?
*/
disableAutoAttach: boolean;
protected _xrNativeFeatureName: string;
/**
* The name of the native xr feature name (like anchor, hit-test, or hand-tracking)
*/
get xrNativeFeatureName(): string;
set xrNativeFeatureName(name: string);
/**
* Observers registered here will be executed when the feature is attached
*/
onFeatureAttachObservable: Observable<IWebXRFeature>;
/**
* Observers registered here will be executed when the feature is detached
*/
onFeatureDetachObservable: Observable<IWebXRFeature>;
/**
* The dependencies of this feature, if any
*/
dependsOn?: string[];
/**
* Construct a new (abstract) WebXR feature
* @param _xrSessionManager the xr session manager for this feature
*/
constructor(_xrSessionManager: WebXRSessionManager);
/**
* Is this feature attached
*/
get attached(): boolean;
/**
* attach this feature
*
* @param force should attachment be forced (even when already attached)
* @returns true if successful, false is failed or already attached
*/
attach(force?: boolean): boolean;
/**
* detach this feature.
*
* @returns true if successful, false if failed or already detached
*/
detach(): boolean;
/**
* Dispose this feature and all of the resources attached
*/
dispose(): void;
/**
* This function will be executed during before enabling the feature and can be used to not-allow enabling it.
* Note that at this point the session has NOT started, so this is purely checking if the browser supports it
*
* @returns whether or not the feature is compatible in this environment
*/
isCompatible(): boolean;
/**
* This is used to register callbacks that will automatically be removed when detach is called.
* @param observable the observable to which the observer will be attached
* @param callback the callback to register
* @param insertFirst should the callback be executed as soon as it is registered
*/
protected _addNewAttachObserver<T>(observable: Observable<T>, callback: (eventData: T, eventState: EventState) => void, insertFirst?: boolean): void;
/**
* Code in this function will be executed on each xrFrame received from the browser.
* This function will not execute after the feature is detached.
* @param _xrFrame the current frame
*/
protected abstract _onXRFrame(_xrFrame: XRFrame): void;
}