audioSceneComponent.d.ts 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. import { Sound } from "./sound";
  2. import { SoundTrack } from "./soundTrack";
  3. import type { Nullable } from "../types";
  4. import { Vector3 } from "../Maths/math.vector";
  5. import type { ISceneSerializableComponent } from "../sceneComponent";
  6. import { Scene } from "../scene";
  7. import { AbstractScene } from "../abstractScene";
  8. import "./audioEngine";
  9. declare module "../abstractScene" {
  10. interface AbstractScene {
  11. /**
  12. * The list of sounds used in the scene.
  13. */
  14. sounds: Nullable<Array<Sound>>;
  15. }
  16. }
  17. declare module "../scene" {
  18. interface Scene {
  19. /**
  20. * @internal
  21. * Backing field
  22. */
  23. _mainSoundTrack: SoundTrack;
  24. /**
  25. * The main sound track played by the scene.
  26. * It contains your primary collection of sounds.
  27. */
  28. mainSoundTrack: SoundTrack;
  29. /**
  30. * The list of sound tracks added to the scene
  31. * @see https://doc.babylonjs.com/features/featuresDeepDive/audio/playingSoundsMusic
  32. */
  33. soundTracks: Nullable<Array<SoundTrack>>;
  34. /**
  35. * Gets a sound using a given name
  36. * @param name defines the name to search for
  37. * @returns the found sound or null if not found at all.
  38. */
  39. getSoundByName(name: string): Nullable<Sound>;
  40. /**
  41. * Gets or sets if audio support is enabled
  42. * @see https://doc.babylonjs.com/features/featuresDeepDive/audio/playingSoundsMusic
  43. */
  44. audioEnabled: boolean;
  45. /**
  46. * Gets or sets if audio will be output to headphones
  47. * @see https://doc.babylonjs.com/features/featuresDeepDive/audio/playingSoundsMusic
  48. */
  49. headphone: boolean;
  50. /**
  51. * Gets or sets custom audio listener position provider
  52. * @see https://doc.babylonjs.com/features/featuresDeepDive/audio/playingSoundsMusic
  53. */
  54. audioListenerPositionProvider: Nullable<() => Vector3>;
  55. /**
  56. * Gets or sets custom audio listener rotation provider
  57. * @see https://doc.babylonjs.com/features/featuresDeepDive/audio/playingSoundsMusic
  58. */
  59. audioListenerRotationProvider: Nullable<() => Vector3>;
  60. /**
  61. * Gets or sets a refresh rate when using 3D audio positioning
  62. */
  63. audioPositioningRefreshRate: number;
  64. }
  65. }
  66. /**
  67. * Defines the sound scene component responsible to manage any sounds
  68. * in a given scene.
  69. */
  70. export declare class AudioSceneComponent implements ISceneSerializableComponent {
  71. private static _CameraDirection;
  72. /**
  73. * The component name helpful to identify the component in the list of scene components.
  74. */
  75. readonly name = "Audio";
  76. /**
  77. * The scene the component belongs to.
  78. */
  79. scene: Scene;
  80. private _audioEnabled;
  81. /**
  82. * Gets whether audio is enabled or not.
  83. * Please use related enable/disable method to switch state.
  84. */
  85. get audioEnabled(): boolean;
  86. private _headphone;
  87. /**
  88. * Gets whether audio is outputting to headphone or not.
  89. * Please use the according Switch methods to change output.
  90. */
  91. get headphone(): boolean;
  92. /**
  93. * Gets or sets a refresh rate when using 3D audio positioning
  94. */
  95. audioPositioningRefreshRate: number;
  96. /**
  97. * Gets or Sets a custom listener position for all sounds in the scene
  98. * By default, this is the position of the first active camera
  99. */
  100. audioListenerPositionProvider: Nullable<() => Vector3>;
  101. /**
  102. * Gets or Sets a custom listener rotation for all sounds in the scene
  103. * By default, this is the rotation of the first active camera
  104. */
  105. audioListenerRotationProvider: Nullable<() => Vector3>;
  106. /**
  107. * Creates a new instance of the component for the given scene
  108. * @param scene Defines the scene to register the component in
  109. */
  110. constructor(scene?: Nullable<Scene>);
  111. /**
  112. * Registers the component in a given scene
  113. */
  114. register(): void;
  115. /**
  116. * Rebuilds the elements related to this component in case of
  117. * context lost for instance.
  118. */
  119. rebuild(): void;
  120. /**
  121. * Serializes the component data to the specified json object
  122. * @param serializationObject The object to serialize to
  123. */
  124. serialize(serializationObject: any): void;
  125. /**
  126. * Adds all the elements from the container to the scene
  127. * @param container the container holding the elements
  128. */
  129. addFromContainer(container: AbstractScene): void;
  130. /**
  131. * Removes all the elements in the container from the scene
  132. * @param container contains the elements to remove
  133. * @param dispose if the removed element should be disposed (default: false)
  134. */
  135. removeFromContainer(container: AbstractScene, dispose?: boolean): void;
  136. /**
  137. * Disposes the component and the associated resources.
  138. */
  139. dispose(): void;
  140. /**
  141. * Disables audio in the associated scene.
  142. */
  143. disableAudio(): void;
  144. /**
  145. * Enables audio in the associated scene.
  146. */
  147. enableAudio(): void;
  148. /**
  149. * Switch audio to headphone output.
  150. */
  151. switchAudioModeForHeadphones(): void;
  152. /**
  153. * Switch audio to normal speakers.
  154. */
  155. switchAudioModeForNormalSpeakers(): void;
  156. private _cachedCameraDirection;
  157. private _cachedCameraPosition;
  158. private _lastCheck;
  159. private _invertMatrixTemp;
  160. private _cameraDirectionTemp;
  161. private _afterRender;
  162. }