Pārlūkot izejas kodu

Sandbox PBR Update

sebavan 6 gadi atpakaļ
vecāks
revīzija
fe2db9bea3
2 mainītis faili ar 35 papildinājumiem un 2 dzēšanām
  1. 19 1
      sandbox/environment.js
  2. 16 1
      sandbox/index.js

+ 19 - 1
sandbox/environment.js

@@ -52,7 +52,25 @@ addEnvironmentLoader = function(index) {
         }
         defaultSkyboxIndex = index;
         skyboxPath = skyboxes[defaultSkyboxIndex];
-        filesInput.reload();
+        if (filesInput) {
+            filesInput.reload();
+        }
+        else {
+            var currentScene = BABYLON.Engine.LastCreatedScene;
+            currentScene.environmentTexture = BABYLON.CubeTexture.CreateFromPrefilteredData(skyboxPath, currentScene);
+            for (var i = 0; i < currentScene.materials.length; i++) {
+                var material = currentScene.materials[i];
+                if (material.name === "skyBox") {
+                    var reflectionTexture = material.reflectionTexture;
+                    if (reflectionTexture && reflectionTexture.coordinatesMode === BABYLON.Texture.SKYBOX_MODE) {
+                        material.reflectionTexture = currentScene.environmentTexture.clone();
+                        if (material.reflectionTexture) {
+                            material.reflectionTexture.coordinatesMode = BABYLON.Texture.SKYBOX_MODE;
+                        }
+                    }
+                }
+            }
+        }
     });
 
     return env;

+ 16 - 1
sandbox/index.js

@@ -174,7 +174,22 @@ if (BABYLON.Engine.isSupported()) {
             currentSkybox = currentScene.createDefaultSkybox(currentScene.environmentTexture, true, (currentScene.activeCamera.maxZ - currentScene.activeCamera.minZ) / 2, 0.3, false);
         }
         else {
-            currentScene.createDefaultLight();
+            var pbrPresent = false;
+            for (var i = 0; i < currentScene.materials.length; i++) {
+                if (currentScene.materials[i]._transparencyMode !== undefined) {
+                    pbrPresent = true;
+                    break;
+                }
+            }
+
+            if (pbrPresent) {
+                if (!currentScene.environmentTexture) {
+                    currentScene.environmentTexture = BABYLON.CubeTexture.CreateFromPrefilteredData(skyboxPath, currentScene);
+                }
+            }
+            else {
+                currentScene.createDefaultLight();
+            }
         }
 
         // In case of error during loading, meshes will be empty and clearColor is set to red