浏览代码

ground configuration and default mplementation

Raanan Weber 7 年之前
父节点
当前提交
23076a6009
共有 2 个文件被更改,包括 34 次插入13 次删除
  1. 12 2
      Viewer/src/configuration/configuration.ts
  2. 22 11
      Viewer/src/viewer/defaultViewer.ts

+ 12 - 2
Viewer/src/configuration/configuration.ts

@@ -72,7 +72,16 @@ export interface ViewerConfiguration {
         };
         infiniteDIstance?: boolean;
 
-    },
+    };
+
+    ground?: boolean | {
+        size?: number;
+        receiveShadows?: boolean;
+        shadowOnly?: boolean;
+        material?: {
+            [propName: string]: any;
+        }
+    };
     lights?: Array<{
         type: number;
         name?: string;
@@ -200,7 +209,7 @@ export let defaultConfiguration: ViewerConfiguration = {
     skybox: {
         cubeTexture: {
             url: 'http://localhost:9000/environment.dds',
-
+            gammaSpace: false
         },
         pbr: true,
         blur: 0.7,
@@ -224,6 +233,7 @@ export let defaultConfiguration: ViewerConfiguration = {
             }
         }
     },
+    ground: true,
     engine: {
         antialiasing: true
     },

+ 22 - 11
Viewer/src/viewer/defaultViewer.ts

@@ -60,12 +60,6 @@ export class DefaultViewer extends AbstractViewer {
         this.setupCamera(meshes);
         this.setupLights(meshes);
 
-        var ground = Mesh.CreatePlane('ground', 100, this.scene)
-        ground.rotation.x = Math.PI / 2
-        ground.receiveShadows = true;
-        ground.material = new ShadowOnlyMaterial('shadow-only-mat', this.scene)
-        ground.material.alpha = 0.4;
-
         return this.initEnvironment();
     }
 
@@ -82,12 +76,11 @@ export class DefaultViewer extends AbstractViewer {
                 }
             }
             if (texture) {
-
                 this.extendClassWithConfig(texture, this.configuration.skybox.cubeTexture);
 
-                console.log((this.scene.activeCamera.maxZ - this.scene.activeCamera.minZ) / 2);
+                let scale = this.configuration.skybox.scale || (this.scene.activeCamera.maxZ - this.scene.activeCamera.minZ) / 2;
 
-                let box = this.scene.createDefaultSkybox(texture, this.configuration.skybox.pbr, this.configuration.skybox.scale, this.configuration.skybox.blur);
+                let box = this.scene.createDefaultSkybox(texture, this.configuration.skybox.pbr, scale, this.configuration.skybox.blur);
 
                 // before extending, set the material's imageprocessing configuration object, if needed:
                 if (this.configuration.skybox.material && this.configuration.skybox.material.imageProcessingConfiguration) {
@@ -98,6 +91,25 @@ export class DefaultViewer extends AbstractViewer {
             }
         }
 
+        if (this.configuration.ground) {
+            let groundConfig = (typeof this.configuration.ground === 'boolean') ? {} : this.configuration.ground;
+
+            var ground = Mesh.CreateGround('ground', groundConfig.size || 100, groundConfig.size || 100, 8, this.scene);
+            if (this.configuration.ground === true || groundConfig.shadowOnly) {
+                ground.material = new BABYLON.ShadowOnlyMaterial('groundmat', this.scene);
+            } else {
+                ground.material = new StandardMaterial('groundmat', this.scene);
+            }
+            //default configuration
+            if (this.configuration.ground === true) {
+                ground.receiveShadows = true;
+                ground.material.alpha = 0.4;
+            }
+
+
+            this.extendClassWithConfig(ground, groundConfig);
+        }
+
         return Promise.resolve(this.scene);
     }
 
@@ -148,7 +160,7 @@ export class DefaultViewer extends AbstractViewer {
 
                 this.extendClassWithConfig(light, lightConfig);
 
-                //position. Some lights don'T support shadows
+                //position. Some lights don't support shadows
                 if (light instanceof ShadowLight) {
                     if (lightConfig.shadowEnabled) {
                         var shadowGenerator = new BABYLON.ShadowGenerator(512, light)
@@ -157,7 +169,6 @@ export class DefaultViewer extends AbstractViewer {
                         for (var index = 0; index < focusMeshes.length; index++) {
                             shadowGenerator.getShadowMap().renderList.push(focusMeshes[index]);
                         }
-                        console.log("shadows enabled");
                     }
                 }
             });