webXREnterExitUI.d.ts 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. import type { Nullable } from "../types";
  2. import { Observable } from "../Misc/observable";
  3. import type { IDisposable, Scene } from "../scene";
  4. import type { WebXRExperienceHelper } from "./webXRExperienceHelper";
  5. import type { WebXRRenderTarget } from "./webXRTypes";
  6. /**
  7. * Button which can be used to enter a different mode of XR
  8. */
  9. export declare class WebXREnterExitUIButton {
  10. /** button element */
  11. element: HTMLElement;
  12. /** XR initialization options for the button */
  13. sessionMode: XRSessionMode;
  14. /** Reference space type */
  15. referenceSpaceType: XRReferenceSpaceType;
  16. /**
  17. * Creates a WebXREnterExitUIButton
  18. * @param element button element
  19. * @param sessionMode XR initialization session mode
  20. * @param referenceSpaceType the type of reference space to be used
  21. */
  22. constructor(
  23. /** button element */
  24. element: HTMLElement,
  25. /** XR initialization options for the button */
  26. sessionMode: XRSessionMode,
  27. /** Reference space type */
  28. referenceSpaceType: XRReferenceSpaceType);
  29. /**
  30. * Extendable function which can be used to update the button's visuals when the state changes
  31. * @param activeButton the current active button in the UI
  32. */
  33. update(activeButton: Nullable<WebXREnterExitUIButton>): void;
  34. }
  35. /**
  36. * Options to create the webXR UI
  37. */
  38. export declare class WebXREnterExitUIOptions {
  39. /**
  40. * User provided buttons to enable/disable WebXR. The system will provide default if not set
  41. */
  42. customButtons?: Array<WebXREnterExitUIButton>;
  43. /**
  44. * A reference space type to use when creating the default button.
  45. * Default is local-floor
  46. */
  47. referenceSpaceType?: XRReferenceSpaceType;
  48. /**
  49. * Context to enter xr with
  50. */
  51. renderTarget?: Nullable<WebXRRenderTarget>;
  52. /**
  53. * A session mode to use when creating the default button.
  54. * Default is immersive-vr
  55. */
  56. sessionMode?: XRSessionMode;
  57. /**
  58. * A list of optional features to init the session with
  59. */
  60. optionalFeatures?: string[];
  61. /**
  62. * A list of optional features to init the session with
  63. */
  64. requiredFeatures?: string[];
  65. /**
  66. * If set, the `sessiongranted` event will not be registered. `sessiongranted` is used to move seamlessly between WebXR experiences.
  67. * If set to true the user will be forced to press the "enter XR" button even if sessiongranted event was triggered.
  68. * If not set and a sessiongranted event was triggered, the XR session will start automatically.
  69. */
  70. ignoreSessionGrantedEvent?: boolean;
  71. /**
  72. * If defined, this function will be executed if the UI encounters an error when entering XR
  73. */
  74. onError?: (error: any) => void;
  75. }
  76. /**
  77. * UI to allow the user to enter/exit XR mode
  78. */
  79. export declare class WebXREnterExitUI implements IDisposable {
  80. private _scene;
  81. /** version of the options passed to this UI */
  82. options: WebXREnterExitUIOptions;
  83. private _activeButton;
  84. private _buttons;
  85. private _helper;
  86. private _renderTarget?;
  87. /**
  88. * The HTML Div Element to which buttons are added.
  89. */
  90. readonly overlay: HTMLDivElement;
  91. /**
  92. * Fired every time the active button is changed.
  93. *
  94. * When xr is entered via a button that launches xr that button will be the callback parameter
  95. *
  96. * When exiting xr the callback parameter will be null)
  97. */
  98. activeButtonChangedObservable: Observable<Nullable<WebXREnterExitUIButton>>;
  99. /**
  100. * Construct a new EnterExit UI class
  101. *
  102. * @param _scene babylon scene object to use
  103. * @param options (read-only) version of the options passed to this UI
  104. */
  105. constructor(_scene: Scene,
  106. /** version of the options passed to this UI */
  107. options: WebXREnterExitUIOptions);
  108. /**
  109. * Set the helper to be used with this UI component.
  110. * The UI is bound to an experience helper. If not provided the UI can still be used but the events should be registered by the developer.
  111. *
  112. * @param helper the experience helper to attach
  113. * @param renderTarget an optional render target (in case it is created outside of the helper scope)
  114. * @returns a promise that resolves when the ui is ready
  115. */
  116. setHelperAsync(helper: WebXRExperienceHelper, renderTarget?: WebXRRenderTarget): Promise<void>;
  117. /**
  118. * Creates UI to allow the user to enter/exit XR mode
  119. * @param scene the scene to add the ui to
  120. * @param helper the xr experience helper to enter/exit xr with
  121. * @param options options to configure the UI
  122. * @returns the created ui
  123. */
  124. static CreateAsync(scene: Scene, helper: WebXRExperienceHelper, options: WebXREnterExitUIOptions): Promise<WebXREnterExitUI>;
  125. private _enterXRWithButtonIndex;
  126. /**
  127. * Disposes of the XR UI component
  128. */
  129. dispose(): void;
  130. private _onSessionGranted;
  131. private _updateButtons;
  132. }