Browse Source

Merge pull request #4905 from ltetzlaff/patch-2

Fix File Loading if hosted from `file:`-Protocol
David Catuhe 7 years ago
parent
commit
54901f7e8f
2 changed files with 10 additions and 1 deletions
  1. 1 0
      dist/preview release/what's new.md
  2. 9 1
      src/Tools/babylon.tools.ts

+ 1 - 0
dist/preview release/what's new.md

@@ -155,6 +155,7 @@
 - Fixed issue where VRExperienceHelper.onExitingVR observable was being fired twice ([atulyar](https://github.com/atulyar))
 - GizmoManager should hide existing gizmos if a non-attachable mesh is selected ([TrevorDev](https://github.com/TrevorDev))
 - Ignore isPickable = false for vr ray casting if the mesh's name matches the specified floorMeshName to maintain backwards compatability ([TrevorDev](https://github.com/TrevorDev))
+- Fix File Loading if hosted from `file:`-Protocol ([ltetzlaff](https://github.com/ltetzlaff))
 
 ### Core Engine
 

+ 9 - 1
src/Tools/babylon.tools.ts

@@ -753,7 +753,7 @@
                             // Some browsers have issues where onreadystatechange can be called multiple times with the same value.
                             request.removeEventListener("readystatechange", onReadyStateChange);
 
-                            if (request.status >= 200 && request.status < 300 || (!Tools.IsWindowObjectExist() && (request.status === 0))) {
+                            if ((request.status >= 200 && request.status < 300) || (request.status === 0 && (!Tools.IsWindowObjectExist() || Tools.IsFileURL()))) {
                                 onSuccess(!useArrayBuffer ? request.responseText : <ArrayBuffer>request.response, request.responseURL);
                                 return;
                             }
@@ -1505,6 +1505,14 @@
                 Tools.Error = Tools._ErrorDisabled;
             }
         }
+	
+	/** 
+         * Check if the loaded document was accessed via `file:`-Protocol.
+         * @returns boolean
+         */
+	public static IsFileURL(): boolean {
+	    return location.protocol === "file:";
+	}
 
         public static IsWindowObjectExist(): boolean {
             return (typeof window) !== "undefined";