瀏覽代碼

Merge pull request #3015 from noalak/master

Load environment texture from .babylon
David Catuhe 7 年之前
父節點
當前提交
abcc3515d5
共有 3 個文件被更改,包括 32 次插入5 次删除
  1. 21 4
      sandbox/index.js
  2. 10 0
      src/Loading/Plugins/babylon.babylonFileLoader.ts
  3. 1 1
      src/babylon.scene.ts

+ 21 - 4
sandbox/index.js

@@ -19,6 +19,7 @@ if (BABYLON.Engine.isSupported()) {
     var currentSkybox;
     var enableDebugLayer = false;
     var currentPluginName;
+    var toExecuteAfterSceneCreation;
 
     canvas.addEventListener("contextmenu", function(evt) {
         evt.preventDefault();
@@ -128,6 +129,11 @@ if (BABYLON.Engine.isSupported()) {
                 currentScene.activeCamera.keysRight.push(68); // D
             }
         }
+
+        if (toExecuteAfterSceneCreation) {
+            toExecuteAfterSceneCreation();
+        }
+
     };
 
     var sceneError = function (sceneFile, babylonScene, message) {
@@ -150,11 +156,22 @@ if (BABYLON.Engine.isSupported()) {
     filesInput.onProcessFileCallback = (function (file, name, extension) {
         if (extension === "dds") {
             BABYLON.FilesInput.FilesToLoad[name] = file;
-            var newHdrTexture = BABYLON.CubeTexture.CreateFromPrefilteredData("file:" + file.correctName, currentScene);
-            if (currentSkybox) {
-                currentSkybox.dispose();
+            var loadTexture = () => {
+                if (currentPluginName === "gltf") { // currentPluginName is updated only once scene is loaded
+                    var newHdrTexture = BABYLON.CubeTexture.CreateFromPrefilteredData("file:" + file.correctName, currentScene);
+                    if (currentSkybox) {
+                        currentSkybox.dispose();
+                    }
+                    currentSkybox = currentScene.createDefaultSkybox(newHdrTexture, true, (currentScene.activeCamera.maxZ - currentScene.activeCamera.minZ) / 2, 0.3);
+                }
+            }
+            if (currentScene) {
+                loadTexture();
+            }
+            else {
+                // Postpone texture loading until scene is loaded
+                toExecuteAfterSceneCreation = loadTexture;
             }
-            currentSkybox = currentScene.createDefaultSkybox(newHdrTexture, true, (currentScene.activeCamera.maxZ - currentScene.activeCamera.minZ) / 2, 0.3);
             return false;
         }
         return true;

+ 10 - 0
src/Loading/Plugins/babylon.babylonFileLoader.ts

@@ -529,6 +529,16 @@
                     }
                 }
 
+                // Environment texture
+                if (parsedData.environmentTexture !== undefined && parsedData.environmentTexture !== null) {
+                    scene.environmentTexture = CubeTexture.CreateFromPrefilteredData(rootUrl + parsedData.environmentTexture, scene);
+                    if (parsedData.createDefaultSkybox === true) {
+                        var skyboxScale = (scene.activeCamera !== undefined && scene.activeCamera !== null) ? (scene.activeCamera.maxZ - scene.activeCamera.minZ) / 2 : 1000;
+                        var skyboxBlurLevel = parsedData.skyboxBlurLevel || 0;
+                        scene.createDefaultSkybox(undefined, true, skyboxScale, skyboxBlurLevel);
+                    }
+                }
+
                 // Lens flares
                 if (parsedData.lensFlareSystems !== undefined && parsedData.lensFlareSystems !== null) {
                     for (index = 0, cache = parsedData.lensFlareSystems.length; index < cache; index++) {

+ 1 - 1
src/babylon.scene.ts

@@ -3757,7 +3757,7 @@
             for (var index = 0; index < this.meshes.length; index++) {
                 var mesh = this.meshes[index];
 
-                if (!mesh.subMeshes || mesh.subMeshes.length === 0) {
+                if (!mesh.subMeshes || mesh.subMeshes.length === 0 || mesh.infiniteDistance) {
                     continue;
                 }