Browse Source

Merge pull request #7303 from BabylonJS/master

Deploy
sebavan 5 years ago
parent
commit
84d96d8d20
3 changed files with 15 additions and 10 deletions
  1. 10 9
      Playground/js/main.js
  2. 1 0
      dist/preview release/what's new.md
  3. 4 1
      src/Misc/fileTools.ts

+ 10 - 9
Playground/js/main.js

@@ -68,7 +68,8 @@ compileAndRun = function(parent, fpsLabel) {
                 return new BABYLON.Engine(canvas, true, { preserveDrawingBuffer: true, stencil: true });
             }
 
-            var defaultEngineZip = "new BABYLON.Engine(canvas, true, { preserveDrawingBuffer: true, stencil: true })";
+            var zipVariables = "var engine = null;\r\nvar scene = null;\r\n";
+            var defaultEngineZip = "var createDefaultEngine = function() { return new BABYLON.Engine(canvas, true, { preserveDrawingBuffer: true, stencil: true }); }";
 
             if (code.indexOf("createEngine") !== -1) {
                 createEngineFunction = "createEngine";
@@ -94,13 +95,13 @@ compileAndRun = function(parent, fpsLabel) {
                 fastEval("runScript = function(scene, canvas) {" + code + "}");
                 runScript(scene, canvas);
 
-                parent.zipTool.ZipCode = "var engine = " + defaultEngineZip + ";\r\nvar scene = new BABYLON.Scene(engine);\r\n\r\n" + code;
+                parent.zipTool.ZipCode = zipVariables + defaultEngineZip + "var engine = createDefaultEngine();" + ";\r\nvar scene = new BABYLON.Scene(engine);\r\n\r\n" + code;
             } else {
-                code += "\n engine = " + createEngineFunction + "();";
-                code += "\n if (!engine) throw 'engine should not be null.';";
+                code += "\r\n\r\nengine = " + createEngineFunction + "();";
+                code += "\r\nif (!engine) throw 'engine should not be null.';";
 
                 if (parent.settingsPG.ScriptLanguage == "JS") {
-                    code += "\n" + "scene = " + createSceneFunction + "();";
+                    code += "\r\n" + "scene = " + createSceneFunction + "();";
                 }
                 else {
                     var startCar = code.search('var ' + createSceneFunction);
@@ -128,12 +129,12 @@ compileAndRun = function(parent, fpsLabel) {
                 }
 
                 var createEngineZip = (createEngineFunction === "createEngine")
-                    ? "createEngine()"
-                    : defaultEngineZip;
+                    ? zipVariables
+                    : zipVariables + defaultEngineZip;
 
                 parent.zipTool.zipCode =
-                    "var engine = " + createEngineZip + ";\r\n" +
-                    code + "\r\n\r\n";
+                    createEngineZip + ";\r\n" +
+                    code;
             }
 
             engine = engine;

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

@@ -259,6 +259,7 @@
 - Fixed an issue with pose input in webxr ([RaananW](https://github.com/RaananW/))
 - Fixed bug when parsing animation group without 'to' value ([noalak](https://github.com/noalak/))
 - isRightCamer and isLeftCamera were not set in WebXR ([RaananW](https://github.com/RaananW/))
+- Sandbox will now load assets relatively path-ed to same folder([Kyle Belfort](https://github.com/belfortk))
 
 ## Breaking changes
 

+ 4 - 1
src/Misc/fileTools.ts

@@ -301,7 +301,10 @@ export class FileTools {
     public static LoadFile(url: string, onSuccess: (data: string | ArrayBuffer, responseURL?: string) => void, onProgress?: (ev: ProgressEvent) => void, offlineProvider?: IOfflineProvider, useArrayBuffer?: boolean, onError?: (request?: WebRequest, exception?: LoadFileError) => void): IFileRequest {
         // If file and file input are set
         if (url.indexOf("file:") !== -1) {
-            const fileName = decodeURIComponent(url.substring(5).toLowerCase());
+            let fileName = decodeURIComponent(url.substring(5).toLowerCase());
+            if (fileName.indexOf('./') === 0) {
+                fileName = fileName.substring(2);
+            }
             const file = FilesInputStore.FilesToLoad[fileName];
             if (file) {
                 return this.ReadFile(file, onSuccess, onProgress, useArrayBuffer, onError ? (error) => onError(undefined, new LoadFileError(error.message, error.file)) : undefined);