webXRExperienceHelper.d.ts 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. import { Observable } from "../Misc/observable";
  2. import type { IDisposable, Scene } from "../scene";
  3. import { WebXRSessionManager } from "./webXRSessionManager";
  4. import { WebXRCamera } from "./webXRCamera";
  5. import type { WebXRRenderTarget } from "./webXRTypes";
  6. import { WebXRState } from "./webXRTypes";
  7. import { WebXRFeaturesManager } from "./webXRFeaturesManager";
  8. /**
  9. * Options for setting up XR spectator camera.
  10. */
  11. export interface WebXRSpectatorModeOption {
  12. /**
  13. * Expected refresh rate (frames per sec) for a spectator camera.
  14. */
  15. fps?: number;
  16. /**
  17. * The index of rigCameras array in a WebXR camera.
  18. */
  19. preferredCameraIndex?: number;
  20. }
  21. /**
  22. * Base set of functionality needed to create an XR experience (WebXRSessionManager, Camera, StateManagement, etc.)
  23. * @see https://doc.babylonjs.com/features/featuresDeepDive/webXR/webXRExperienceHelpers
  24. */
  25. export declare class WebXRExperienceHelper implements IDisposable {
  26. private _scene;
  27. private _nonVRCamera;
  28. private _attachedToElement;
  29. private _spectatorCamera;
  30. private _originalSceneAutoClear;
  31. private _supported;
  32. private _spectatorMode;
  33. private _lastTimestamp;
  34. /**
  35. * Camera used to render xr content
  36. */
  37. camera: WebXRCamera;
  38. /** A features manager for this xr session */
  39. featuresManager: WebXRFeaturesManager;
  40. /**
  41. * Observers registered here will be triggered after the camera's initial transformation is set
  42. * This can be used to set a different ground level or an extra rotation.
  43. *
  44. * Note that ground level is considered to be at 0. The height defined by the XR camera will be added
  45. * to the position set after this observable is done executing.
  46. */
  47. onInitialXRPoseSetObservable: Observable<WebXRCamera>;
  48. /**
  49. * Fires when the state of the experience helper has changed
  50. */
  51. onStateChangedObservable: Observable<WebXRState>;
  52. /** Session manager used to keep track of xr session */
  53. sessionManager: WebXRSessionManager;
  54. /**
  55. * The current state of the XR experience (eg. transitioning, in XR or not in XR)
  56. */
  57. state: WebXRState;
  58. /**
  59. * Creates a WebXRExperienceHelper
  60. * @param _scene The scene the helper should be created in
  61. */
  62. private constructor();
  63. /**
  64. * Creates the experience helper
  65. * @param scene the scene to attach the experience helper to
  66. * @returns a promise for the experience helper
  67. */
  68. static CreateAsync(scene: Scene): Promise<WebXRExperienceHelper>;
  69. /**
  70. * Disposes of the experience helper
  71. */
  72. dispose(): void;
  73. /**
  74. * Enters XR mode (This must be done within a user interaction in most browsers eg. button click)
  75. * @param sessionMode options for the XR session
  76. * @param referenceSpaceType frame of reference of the XR session
  77. * @param renderTarget the output canvas that will be used to enter XR mode
  78. * @param sessionCreationOptions optional XRSessionInit object to init the session with
  79. * @returns promise that resolves after xr mode has entered
  80. */
  81. enterXRAsync(sessionMode: XRSessionMode, referenceSpaceType: XRReferenceSpaceType, renderTarget?: WebXRRenderTarget, sessionCreationOptions?: XRSessionInit): Promise<WebXRSessionManager>;
  82. /**
  83. * Exits XR mode and returns the scene to its original state
  84. * @returns promise that resolves after xr mode has exited
  85. */
  86. exitXRAsync(): Promise<void>;
  87. /**
  88. * Enable spectator mode for desktop VR experiences.
  89. * When spectator mode is enabled a camera will be attached to the desktop canvas and will
  90. * display the first rig camera's view on the desktop canvas.
  91. * Please note that this will degrade performance, as it requires another camera render.
  92. * It is also not recommended to enable this in devices like the quest, as it brings no benefit there.
  93. * @param options giving WebXRSpectatorModeOption for specutator camera to setup when the spectator mode is enabled.
  94. */
  95. enableSpectatorMode(options?: WebXRSpectatorModeOption): void;
  96. /**
  97. * Disable spectator mode for desktop VR experiences.
  98. */
  99. disableSpecatatorMode(): void;
  100. private _switchSpectatorMode;
  101. private _nonXRToXRCamera;
  102. private _setState;
  103. }