Browse Source

Merge pull request #7385 from sebavan/master

Support VideoTexture Cloning. Fix #7383
sebavan 5 years ago
parent
commit
7f2e3e943e
1 changed files with 19 additions and 0 deletions
  1. 19 0
      src/Materials/Textures/videoTexture.ts

+ 19 - 0
src/Materials/Textures/videoTexture.ts

@@ -69,6 +69,7 @@ export class VideoTexture extends Texture {
     private _settings: VideoTextureSettings;
     private _createInternalTextureOnEvent: string;
     private _frameId = -1;
+    private _currentSrc: Nullable<string | string[] | HTMLVideoElement> = null;
 
     /**
      * Creates a video texture.
@@ -103,6 +104,7 @@ export class VideoTexture extends Texture {
         this._initialSamplingMode = samplingMode;
         this.autoUpdateTexture = settings.autoUpdateTexture;
 
+        this._currentSrc = src;
         this.name = name || this._getName(src);
         this.video = this._getVideo(src);
         this._settings = settings;
@@ -317,6 +319,21 @@ export class VideoTexture extends Texture {
      */
     public updateURL(url: string): void {
         this.video.src = url;
+        this._currentSrc = url;
+    }
+
+    /**
+     * Clones the texture.
+     * @returns the cloned texture
+     */
+    public clone(): VideoTexture {
+        return new VideoTexture(this.name,
+            this._currentSrc!,
+            this.getScene(),
+            this._generateMipMaps,
+            this.invertY,
+            this.samplingMode,
+            this._settings);
     }
 
     /**
@@ -325,6 +342,8 @@ export class VideoTexture extends Texture {
     public dispose(): void {
         super.dispose();
 
+        this._currentSrc = null;
+
         if (this._onUserActionRequestedObservable) {
             this._onUserActionRequestedObservable.clear();
             this._onUserActionRequestedObservable = null;