videoTexture.d.ts 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. import { Observable } from "../../Misc/observable";
  2. import type { Nullable } from "../../types";
  3. import type { Scene } from "../../scene";
  4. import { Texture } from "../../Materials/Textures/texture";
  5. import type { ExternalTexture } from "./externalTexture";
  6. import "../../Engines/Extensions/engine.videoTexture";
  7. import "../../Engines/Extensions/engine.dynamicTexture";
  8. /**
  9. * Settings for finer control over video usage
  10. */
  11. export interface VideoTextureSettings {
  12. /**
  13. * Applies `autoplay` to video, if specified
  14. */
  15. autoPlay?: boolean;
  16. /**
  17. * Applies `muted` to video, if specified
  18. */
  19. muted?: boolean;
  20. /**
  21. * Applies `loop` to video, if specified
  22. */
  23. loop?: boolean;
  24. /**
  25. * Automatically updates internal texture from video at every frame in the render loop
  26. */
  27. autoUpdateTexture: boolean;
  28. /**
  29. * Image src displayed during the video loading or until the user interacts with the video.
  30. */
  31. poster?: string;
  32. /**
  33. * Defines the associated texture format.
  34. */
  35. format?: number;
  36. /**
  37. * Notify babylon to not modify any video settings and not control the video's playback.
  38. * Set this to true if you are controlling the way the video is being played, stopped and paused.
  39. */
  40. independentVideoSource?: boolean;
  41. }
  42. /**
  43. * If you want to display a video in your scene, this is the special texture for that.
  44. * This special texture works similar to other textures, with the exception of a few parameters.
  45. * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/using/videoTexture
  46. */
  47. export declare class VideoTexture extends Texture {
  48. /**
  49. * Tells whether textures will be updated automatically or user is required to call `updateTexture` manually
  50. */
  51. readonly autoUpdateTexture: boolean;
  52. /**
  53. * The video instance used by the texture internally
  54. */
  55. readonly video: HTMLVideoElement;
  56. private _externalTexture;
  57. private _onUserActionRequestedObservable;
  58. /**
  59. * Event triggered when a dom action is required by the user to play the video.
  60. * This happens due to recent changes in browser policies preventing video to auto start.
  61. */
  62. get onUserActionRequestedObservable(): Observable<Texture>;
  63. private _generateMipMaps;
  64. private _stillImageCaptured;
  65. private _displayingPosterTexture;
  66. private _settings;
  67. private _createInternalTextureOnEvent;
  68. private _frameId;
  69. private _currentSrc;
  70. private _onError?;
  71. private _errorFound;
  72. /**
  73. * Serialize the flag to define this texture as a video texture
  74. */
  75. readonly isVideo = true;
  76. private _processError;
  77. private _handlePlay;
  78. /**
  79. * Creates a video texture.
  80. * If you want to display a video in your scene, this is the special texture for that.
  81. * This special texture works similar to other textures, with the exception of a few parameters.
  82. * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/using/videoTexture
  83. * @param name optional name, will detect from video source, if not defined
  84. * @param src can be used to provide an url, array of urls or an already setup HTML video element.
  85. * @param scene is obviously the current scene.
  86. * @param generateMipMaps can be used to turn on mipmaps (Can be expensive for videoTextures because they are often updated).
  87. * @param invertY is false by default but can be used to invert video on Y axis
  88. * @param samplingMode controls the sampling method and is set to TRILINEAR_SAMPLINGMODE by default
  89. * @param settings allows finer control over video usage
  90. * @param onError defines a callback triggered when an error occurred during the loading session
  91. * @param format defines the texture format to use (Engine.TEXTUREFORMAT_RGBA by default)
  92. */
  93. constructor(name: Nullable<string>, src: string | string[] | HTMLVideoElement, scene: Nullable<Scene>, generateMipMaps?: boolean, invertY?: boolean, samplingMode?: number, settings?: Partial<VideoTextureSettings>, onError?: Nullable<(message?: string, exception?: any) => void>, format?: number);
  94. /**
  95. * Get the current class name of the video texture useful for serialization or dynamic coding.
  96. * @returns "VideoTexture"
  97. */
  98. getClassName(): string;
  99. private _getName;
  100. private _getVideo;
  101. private _resizeInternalTexture;
  102. private _createInternalTexture;
  103. private _reset;
  104. /**
  105. * @internal Internal method to initiate `update`.
  106. */
  107. _rebuild(): void;
  108. /**
  109. * Update Texture in the `auto` mode. Does not do anything if `settings.autoUpdateTexture` is false.
  110. */
  111. update(): void;
  112. /**
  113. * Update Texture in `manual` mode. Does not do anything if not visible or paused.
  114. * @param isVisible Visibility state, detected by user using `scene.getActiveMeshes()` or otherwise.
  115. */
  116. updateTexture(isVisible: boolean): void;
  117. protected _updateInternalTexture: () => void;
  118. /**
  119. * Get the underlying external texture (if supported by the current engine, else null)
  120. */
  121. get externalTexture(): Nullable<ExternalTexture>;
  122. /**
  123. * Change video content. Changing video instance or setting multiple urls (as in constructor) is not supported.
  124. * @param url New url.
  125. */
  126. updateURL(url: string): void;
  127. /**
  128. * Clones the texture.
  129. * @returns the cloned texture
  130. */
  131. clone(): VideoTexture;
  132. /**
  133. * Dispose the texture and release its associated resources.
  134. */
  135. dispose(): void;
  136. /**
  137. * Creates a video texture straight from a stream.
  138. * @param scene Define the scene the texture should be created in
  139. * @param stream Define the stream the texture should be created from
  140. * @param constraints video constraints
  141. * @param invertY Defines if the video should be stored with invert Y set to true (true by default)
  142. * @returns The created video texture as a promise
  143. */
  144. static CreateFromStreamAsync(scene: Scene, stream: MediaStream, constraints: any, invertY?: boolean): Promise<VideoTexture>;
  145. /**
  146. * Creates a video texture straight from your WebCam video feed.
  147. * @param scene Define the scene the texture should be created in
  148. * @param constraints Define the constraints to use to create the web cam feed from WebRTC
  149. * @param audioConstaints Define the audio constraints to use to create the web cam feed from WebRTC
  150. * @param invertY Defines if the video should be stored with invert Y set to true (true by default)
  151. * @returns The created video texture as a promise
  152. */
  153. static CreateFromWebCamAsync(scene: Scene, constraints: {
  154. minWidth: number;
  155. maxWidth: number;
  156. minHeight: number;
  157. maxHeight: number;
  158. deviceId: string;
  159. } & MediaTrackConstraints, audioConstaints?: boolean | MediaTrackConstraints, invertY?: boolean): Promise<VideoTexture>;
  160. /**
  161. * Creates a video texture straight from your WebCam video feed.
  162. * @param scene Defines the scene the texture should be created in
  163. * @param onReady Defines a callback to triggered once the texture will be ready
  164. * @param constraints Defines the constraints to use to create the web cam feed from WebRTC
  165. * @param audioConstaints Defines the audio constraints to use to create the web cam feed from WebRTC
  166. * @param invertY Defines if the video should be stored with invert Y set to true (true by default)
  167. */
  168. static CreateFromWebCam(scene: Scene, onReady: (videoTexture: VideoTexture) => void, constraints: {
  169. minWidth: number;
  170. maxWidth: number;
  171. minHeight: number;
  172. maxHeight: number;
  173. deviceId: string;
  174. } & MediaTrackConstraints, audioConstaints?: boolean | MediaTrackConstraints, invertY?: boolean): void;
  175. }