Jelajahi Sumber

moved CORS settings directly into VideoTexture, corrected VideoDome ctor for current VideoTexture ctor

David Gillen 7 tahun lalu
induk
melakukan
4e61ac55a4

+ 1 - 2
src/Helpers/babylon.videoDome.ts

@@ -44,7 +44,7 @@ module BABYLON {
          * @param options **loop=true** Automatically loop video on end.
          * @param options **size=1000** Physical radius to create the dome at, defaults to approximately half the far clip plane.
          */
-        constructor(name: string, urlsOrVideo: string[] | HTMLVideoElement, options: {
+        constructor(name: string, urlsOrVideo: string | string[] | HTMLVideoElement, options: {
             resolution?: number,
             clickToPlay?: boolean,
             autoPlay?: boolean,
@@ -75,7 +75,6 @@ module BABYLON {
             // configure material
             texture.coordinatesMode = BABYLON.Texture.FIXED_EQUIRECTANGULAR_MIRRORED_MODE; // matches orientation
             texture.wrapV = Texture.CLAMP_ADDRESSMODE; // always clamp the up/down
-            texture.video.crossOrigin = "anonymous";
             material.reflectionTexture = this._videoTexture;
             material.useEquirectangularFOV = true;
             material.fovMultiplier = 1.0;

+ 18 - 1
src/Materials/Textures/babylon.videoTexture.ts

@@ -84,6 +84,20 @@
             }
         }
 
+        private _setCORS(src: string, element: HTMLVideoElement): void {
+            if(Tools.CorsBehavior != null) {
+                if (typeof (Tools.CorsBehavior) === 'string') {
+                    element.crossOrigin = <string>Tools.CorsBehavior;
+                }
+                else {
+                    var result = Tools.CorsBehavior(src);
+                    if (result) {
+                        element.crossOrigin = result;
+                    }
+                }
+            }
+        }
+
         private _getName(src: string | string[] | HTMLVideoElement): string {
             if (src instanceof HTMLVideoElement) {
                 return src.currentSrc;
@@ -92,18 +106,21 @@
             if (typeof src === "object") {
                 return src.toString();
             }
-    
+
             return src;
         };
     
         private _getVideo(src: string | string[] | HTMLVideoElement): HTMLVideoElement {
             if (src instanceof HTMLVideoElement) {
+                this._setCORS(src.currentSrc, src);
                 return src;
             }
             const video: HTMLVideoElement = document.createElement("video");
             if (typeof src === "string") {
+                this._setCORS(src, video);
                 video.src = src;
             } else {
+                this._setCORS(src[0], video);
                 src.forEach(url => {
                     const source = document.createElement("source");
                     source.src = url;