WebXRAbstractFeature.d.ts 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import type { IWebXRFeature } from "../webXRFeaturesManager";
  2. import type { EventState } from "../../Misc/observable";
  3. import { Observable } from "../../Misc/observable";
  4. import type { WebXRSessionManager } from "../webXRSessionManager";
  5. /**
  6. * This is the base class for all WebXR features.
  7. * Since most features require almost the same resources and callbacks, this class can be used to simplify the development
  8. * Note that since the features manager is using the `IWebXRFeature` you are in no way obligated to use this class
  9. */
  10. export declare abstract class WebXRAbstractFeature implements IWebXRFeature {
  11. protected _xrSessionManager: WebXRSessionManager;
  12. private _attached;
  13. private _removeOnDetach;
  14. /**
  15. * Is this feature disposed?
  16. */
  17. isDisposed: boolean;
  18. /**
  19. * Should auto-attach be disabled?
  20. */
  21. disableAutoAttach: boolean;
  22. protected _xrNativeFeatureName: string;
  23. /**
  24. * The name of the native xr feature name (like anchor, hit-test, or hand-tracking)
  25. */
  26. get xrNativeFeatureName(): string;
  27. set xrNativeFeatureName(name: string);
  28. /**
  29. * Observers registered here will be executed when the feature is attached
  30. */
  31. onFeatureAttachObservable: Observable<IWebXRFeature>;
  32. /**
  33. * Observers registered here will be executed when the feature is detached
  34. */
  35. onFeatureDetachObservable: Observable<IWebXRFeature>;
  36. /**
  37. * The dependencies of this feature, if any
  38. */
  39. dependsOn?: string[];
  40. /**
  41. * Construct a new (abstract) WebXR feature
  42. * @param _xrSessionManager the xr session manager for this feature
  43. */
  44. constructor(_xrSessionManager: WebXRSessionManager);
  45. /**
  46. * Is this feature attached
  47. */
  48. get attached(): boolean;
  49. /**
  50. * attach this feature
  51. *
  52. * @param force should attachment be forced (even when already attached)
  53. * @returns true if successful, false is failed or already attached
  54. */
  55. attach(force?: boolean): boolean;
  56. /**
  57. * detach this feature.
  58. *
  59. * @returns true if successful, false if failed or already detached
  60. */
  61. detach(): boolean;
  62. /**
  63. * Dispose this feature and all of the resources attached
  64. */
  65. dispose(): void;
  66. /**
  67. * This function will be executed during before enabling the feature and can be used to not-allow enabling it.
  68. * Note that at this point the session has NOT started, so this is purely checking if the browser supports it
  69. *
  70. * @returns whether or not the feature is compatible in this environment
  71. */
  72. isCompatible(): boolean;
  73. /**
  74. * This is used to register callbacks that will automatically be removed when detach is called.
  75. * @param observable the observable to which the observer will be attached
  76. * @param callback the callback to register
  77. * @param insertFirst should the callback be executed as soon as it is registered
  78. */
  79. protected _addNewAttachObserver<T>(observable: Observable<T>, callback: (eventData: T, eventState: EventState) => void, insertFirst?: boolean): void;
  80. /**
  81. * Code in this function will be executed on each xrFrame received from the browser.
  82. * This function will not execute after the feature is detached.
  83. * @param _xrFrame the current frame
  84. */
  85. protected abstract _onXRFrame(_xrFrame: XRFrame): void;
  86. }