فهرست منبع

Add environment texture parsing
Update sandbox to read .dds files only for gltf
Fix sandbox .dds files reading to wait for scene to be loaded
Update world extends to ignore meshes at infinite distance like default skybox

noalak 7 سال پیش
والد
کامیت
ea9c4087d6
3فایلهای تغییر یافته به همراه33 افزوده شده و 6 حذف شده
  1. 22 5
      sandbox/index.js
  2. 10 0
      src/Loading/Plugins/babylon.babylonFileLoader.ts
  3. 1 1
      src/babylon.scene.ts

+ 22 - 5
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) {
@@ -149,12 +155,23 @@ 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 (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
+                    BABYLON.FilesInput.FilesToLoad[name] = file;
+                    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

@@ -528,6 +528,16 @@
                     }
                 }
 
+                // Environment texture
+                if (parsedData.environmentTexture !== undefined && parsedData.environmentTexture !== null) {
+                    scene.environmentTexture = Texture.Parse(parsedData.environmentTexture, scene, rootUrl);
+                    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

@@ -3680,7 +3680,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;
                 }