webXRFeaturesManager.d.ts 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. import type { WebXRSessionManager } from "./webXRSessionManager";
  2. import type { IDisposable } from "../scene";
  3. import type { Observable } from "../Misc/observable.js";
  4. /**
  5. * Defining the interface required for a (webxr) feature
  6. */
  7. export interface IWebXRFeature extends IDisposable {
  8. /**
  9. * Is this feature attached
  10. */
  11. attached: boolean;
  12. /**
  13. * Should auto-attach be disabled?
  14. */
  15. disableAutoAttach: boolean;
  16. /**
  17. * Attach the feature to the session
  18. * Will usually be called by the features manager
  19. *
  20. * @param force should attachment be forced (even when already attached)
  21. * @returns true if successful.
  22. */
  23. attach(force?: boolean): boolean;
  24. /**
  25. * Detach the feature from the session
  26. * Will usually be called by the features manager
  27. *
  28. * @returns true if successful.
  29. */
  30. detach(): boolean;
  31. /**
  32. * This function will be executed during before enabling the feature and can be used to not-allow enabling it.
  33. * Note that at this point the session has NOT started, so this is purely checking if the browser supports it
  34. *
  35. * @returns whether or not the feature is compatible in this environment
  36. */
  37. isCompatible(): boolean;
  38. /**
  39. * Was this feature disposed;
  40. */
  41. isDisposed: boolean;
  42. /**
  43. * The name of the native xr feature name, if applicable (like anchor, hit-test, or hand-tracking)
  44. */
  45. xrNativeFeatureName?: string;
  46. /**
  47. * A list of (Babylon WebXR) features this feature depends on
  48. */
  49. dependsOn?: string[];
  50. /**
  51. * If this feature requires to extend the XRSessionInit object, this function will return the partial XR session init object
  52. */
  53. getXRSessionInitExtension?: () => Promise<Partial<XRSessionInit>>;
  54. /**
  55. * Triggered when the feature is attached
  56. */
  57. onFeatureAttachObservable: Observable<IWebXRFeature>;
  58. /**
  59. * Triggered when the feature is detached
  60. */
  61. onFeatureDetachObservable: Observable<IWebXRFeature>;
  62. }
  63. /**
  64. * A list of the currently available features without referencing them
  65. */
  66. export declare class WebXRFeatureName {
  67. /**
  68. * The name of the anchor system feature
  69. */
  70. static readonly ANCHOR_SYSTEM = "xr-anchor-system";
  71. /**
  72. * The name of the background remover feature
  73. */
  74. static readonly BACKGROUND_REMOVER = "xr-background-remover";
  75. /**
  76. * The name of the hit test feature
  77. */
  78. static readonly HIT_TEST = "xr-hit-test";
  79. /**
  80. * The name of the mesh detection feature
  81. */
  82. static readonly MESH_DETECTION = "xr-mesh-detection";
  83. /**
  84. * physics impostors for xr controllers feature
  85. */
  86. static readonly PHYSICS_CONTROLLERS = "xr-physics-controller";
  87. /**
  88. * The name of the plane detection feature
  89. */
  90. static readonly PLANE_DETECTION = "xr-plane-detection";
  91. /**
  92. * The name of the pointer selection feature
  93. */
  94. static readonly POINTER_SELECTION = "xr-controller-pointer-selection";
  95. /**
  96. * The name of the teleportation feature
  97. */
  98. static readonly TELEPORTATION = "xr-controller-teleportation";
  99. /**
  100. * The name of the feature points feature.
  101. */
  102. static readonly FEATURE_POINTS = "xr-feature-points";
  103. /**
  104. * The name of the hand tracking feature.
  105. */
  106. static readonly HAND_TRACKING = "xr-hand-tracking";
  107. /**
  108. * The name of the image tracking feature
  109. */
  110. static readonly IMAGE_TRACKING = "xr-image-tracking";
  111. /**
  112. * The name of the near interaction feature
  113. */
  114. static readonly NEAR_INTERACTION = "xr-near-interaction";
  115. /**
  116. * The name of the DOM overlay feature
  117. */
  118. static readonly DOM_OVERLAY = "xr-dom-overlay";
  119. /**
  120. * The name of the movement feature
  121. */
  122. static readonly MOVEMENT = "xr-controller-movement";
  123. /**
  124. * The name of the light estimation feature
  125. */
  126. static readonly LIGHT_ESTIMATION = "xr-light-estimation";
  127. /**
  128. * The name of the eye tracking feature
  129. */
  130. static readonly EYE_TRACKING = "xr-eye-tracking";
  131. /**
  132. * The name of the walking locomotion feature
  133. */
  134. static readonly WALKING_LOCOMOTION = "xr-walking-locomotion";
  135. /**
  136. * The name of the composition layers feature
  137. */
  138. static readonly LAYERS = "xr-layers";
  139. /**
  140. * The name of the depth sensing feature
  141. */
  142. static readonly DEPTH_SENSING = "xr-depth-sensing";
  143. /**
  144. * The name of the WebXR Space Warp feature
  145. */
  146. static readonly SPACE_WARP = "xr-space-warp";
  147. /**
  148. * The name of the WebXR Raw Camera Access feature
  149. */
  150. static readonly RAW_CAMERA_ACCESS = "xr-raw-camera-access";
  151. }
  152. /**
  153. * Defining the constructor of a feature. Used to register the modules.
  154. */
  155. export type WebXRFeatureConstructor = (xrSessionManager: WebXRSessionManager, options?: any) => () => IWebXRFeature;
  156. /**
  157. * The WebXR features manager is responsible of enabling or disabling features required for the current XR session.
  158. * It is mainly used in AR sessions.
  159. *
  160. * A feature can have a version that is defined by Babylon (and does not correspond with the webxr version).
  161. */
  162. export declare class WebXRFeaturesManager implements IDisposable {
  163. private _xrSessionManager;
  164. private static readonly _AvailableFeatures;
  165. private _features;
  166. /**
  167. * The key is the feature to check and the value is the feature that conflicts.
  168. */
  169. private static readonly _ConflictingFeatures;
  170. /**
  171. * constructs a new features manages.
  172. *
  173. * @param _xrSessionManager an instance of WebXRSessionManager
  174. */
  175. constructor(_xrSessionManager: WebXRSessionManager);
  176. /**
  177. * Used to register a module. After calling this function a developer can use this feature in the scene.
  178. * Mainly used internally.
  179. *
  180. * @param featureName the name of the feature to register
  181. * @param constructorFunction the function used to construct the module
  182. * @param version the (babylon) version of the module
  183. * @param stable is that a stable version of this module
  184. */
  185. static AddWebXRFeature(featureName: string, constructorFunction: WebXRFeatureConstructor, version?: number, stable?: boolean): void;
  186. /**
  187. * Returns a constructor of a specific feature.
  188. *
  189. * @param featureName the name of the feature to construct
  190. * @param version the version of the feature to load
  191. * @param xrSessionManager the xrSessionManager. Used to construct the module
  192. * @param options optional options provided to the module.
  193. * @returns a function that, when called, will return a new instance of this feature
  194. */
  195. static ConstructFeature(featureName: string, version: number | undefined, xrSessionManager: WebXRSessionManager, options?: any): () => IWebXRFeature;
  196. /**
  197. * Can be used to return the list of features currently registered
  198. *
  199. * @returns an Array of available features
  200. */
  201. static GetAvailableFeatures(): string[];
  202. /**
  203. * Gets the versions available for a specific feature
  204. * @param featureName the name of the feature
  205. * @returns an array with the available versions
  206. */
  207. static GetAvailableVersions(featureName: string): string[];
  208. /**
  209. * Return the latest unstable version of this feature
  210. * @param featureName the name of the feature to search
  211. * @returns the version number. if not found will return -1
  212. */
  213. static GetLatestVersionOfFeature(featureName: string): number;
  214. /**
  215. * Return the latest stable version of this feature
  216. * @param featureName the name of the feature to search
  217. * @returns the version number. if not found will return -1
  218. */
  219. static GetStableVersionOfFeature(featureName: string): number;
  220. /**
  221. * Attach a feature to the current session. Mainly used when session started to start the feature effect.
  222. * Can be used during a session to start a feature
  223. * @param featureName the name of feature to attach
  224. */
  225. attachFeature(featureName: string): void;
  226. /**
  227. * Can be used inside a session or when the session ends to detach a specific feature
  228. * @param featureName the name of the feature to detach
  229. */
  230. detachFeature(featureName: string): void;
  231. /**
  232. * Used to disable an already-enabled feature
  233. * The feature will be disposed and will be recreated once enabled.
  234. * @param featureName the feature to disable
  235. * @returns true if disable was successful
  236. */
  237. disableFeature(featureName: string | {
  238. Name: string;
  239. }): boolean;
  240. /**
  241. * dispose this features manager
  242. */
  243. dispose(): void;
  244. /**
  245. * Enable a feature using its name and a version. This will enable it in the scene, and will be responsible to attach it when the session starts.
  246. * If used twice, the old version will be disposed and a new one will be constructed. This way you can re-enable with different configuration.
  247. *
  248. * @param featureName the name of the feature to load or the class of the feature
  249. * @param version optional version to load. if not provided the latest version will be enabled
  250. * @param moduleOptions options provided to the module. Ses the module documentation / constructor
  251. * @param attachIfPossible if set to true (default) the feature will be automatically attached, if it is currently possible
  252. * @param required is this feature required to the app. If set to true the session init will fail if the feature is not available.
  253. * @returns a new constructed feature or throws an error if feature not found or conflicts with another enabled feature.
  254. */
  255. enableFeature(featureName: string | {
  256. Name: string;
  257. }, version?: number | string, moduleOptions?: any, attachIfPossible?: boolean, required?: boolean): IWebXRFeature;
  258. /**
  259. * get the implementation of an enabled feature.
  260. * @param featureName the name of the feature to load
  261. * @returns the feature class, if found
  262. */
  263. getEnabledFeature(featureName: string): IWebXRFeature;
  264. /**
  265. * Get the list of enabled features
  266. * @returns an array of enabled features
  267. */
  268. getEnabledFeatures(): string[];
  269. /**
  270. * This function will extend the session creation configuration object with enabled features.
  271. * If, for example, the anchors feature is enabled, it will be automatically added to the optional or required features list,
  272. * according to the defined "required" variable, provided during enableFeature call
  273. * @param xrSessionInit the xr Session init object to extend
  274. *
  275. * @returns an extended XRSessionInit object
  276. */
  277. _extendXRSessionInitObject(xrSessionInit: XRSessionInit): Promise<XRSessionInit>;
  278. }