Kaynağa Gözat

Merge pull request #3843 from sebavan/master

Sandbox Environment Swap
sebavan 7 yıl önce
ebeveyn
işleme
01b5d265f0
2 değiştirilmiş dosya ile 11 ekleme ve 1 silme
  1. 1 0
      dist/preview release/what's new.md
  2. 10 1
      sandbox/index.js

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

@@ -83,6 +83,7 @@
 - NPM package now has a dependency system, updated during build. ([RaananW](https://github.com/RaananW))
 - WebVRExperienceHelper will create an empty controller model so that controller interactions can be used while the actual model is still loading ([trevordev](https://github.com/trevordev))
 - Default fragment shader will clamp negative values to avoid underflow, webVR post processing will render to eye texture size ([trevordev](https://github.com/trevordev))
+- Supports Environment Drag and Drop in Sandbox ([sebavan](https://github.com/sebavan))
 
 ## Bug fixes
 

+ 10 - 1
sandbox/index.js

@@ -20,6 +20,7 @@ if (BABYLON.Engine.isSupported()) {
     var currentSkybox;
     var enableDebugLayer = false;
     var currentPluginName;
+    var skyboxPath = "Assets/environment.dds";
 
     canvas.addEventListener("contextmenu", function (evt) {
         evt.preventDefault();
@@ -98,7 +99,7 @@ if (BABYLON.Engine.isSupported()) {
 
         // Environment
         if (currentPluginName === "gltf") {
-            var hdrTexture = BABYLON.CubeTexture.CreateFromPrefilteredData("Assets/environment.dds", currentScene);
+            var hdrTexture = BABYLON.CubeTexture.CreateFromPrefilteredData(skyboxPath, currentScene);
             currentSkybox = currentScene.createDefaultSkybox(hdrTexture, true, (currentScene.activeCamera.maxZ - currentScene.activeCamera.minZ) / 2, 0.3);
 
             // glTF assets use a +Z forward convention while the default camera faces +Z. Rotate the camera to look at the front of the asset.
@@ -147,6 +148,14 @@ if (BABYLON.Engine.isSupported()) {
     };
 
     filesInput = new BABYLON.FilesInput(engine, null, sceneLoaded, null, null, null, function () { BABYLON.Tools.ClearLogCache() }, null, sceneError);
+    filesInput.onProcessFileCallback = (function (file, name, extension) {
+        if (filesInput._filesToLoad && filesInput._filesToLoad.length === 1 && extension && extension.toLowerCase() === "dds") {
+            BABYLON.FilesInput.FilesToLoad[name] = file;
+            skyboxPath = "file:" + file.correctName;
+            return false;
+        }
+        return true;
+    }).bind(this);
     filesInput.monitorElementForDragNDrop(canvas);
 
     window.addEventListener("keydown", function (evt) {