Browse Source

set crosbehavior when image assetmanager load.

KK 9 years ago
parent
commit
3497520bd7
2 changed files with 20 additions and 14 deletions
  1. 2 0
      src/Tools/babylon.assetsManager.ts
  2. 18 14
      src/Tools/babylon.tools.ts

+ 2 - 0
src/Tools/babylon.assetsManager.ts

@@ -120,6 +120,8 @@
         public run(scene: Scene, onSuccess: () => void, onError: () => void) {
             var img = new Image();
 
+            Tools.SetCorsBehavior(this.url, img);
+
             img.onload = () => {
                 this.image = img;
                 this.isCompleted = true;

+ 18 - 14
src/Tools/babylon.tools.ts

@@ -288,6 +288,23 @@
             }
         }
 
+        public static SetCorsBehavior(url: string, img: HTMLImageElement): string {
+            if (Tools.CorsBehavior) {
+                switch (typeof (Tools.CorsBehavior)) {
+                    case "function":
+                        var result = Tools.CorsBehavior(url);
+                        if (result) {
+                            return result;
+                        }
+                        break;
+                    case "string":
+                    default:
+                        img.crossOrigin = Tools.CorsBehavior;
+                        break;
+                }
+            }
+        }
+
         // External files
         public static CleanUrl(url: string): string {
             url = url.replace(/#/mg, "%23");
@@ -304,20 +321,7 @@
             var img = new Image();
 
             if (url.substr(0, 5) !== "data:") {
-                if (Tools.CorsBehavior) {
-                    switch (typeof (Tools.CorsBehavior)) {
-                        case "function":
-                            var result = Tools.CorsBehavior(url);
-                            if (result) {
-                                img.crossOrigin = result;
-                            }
-                            break;
-                        case "string":
-                        default:
-                            img.crossOrigin = Tools.CorsBehavior;
-                            break;
-                    }
-                }
+                Tools.SetCorsBehavior(url, img);
             }
 
             img.onload = () => {