浏览代码

cleaner object etending and further configuration values

Raanan Weber 7 年之前
父节点
当前提交
0d93973e08
共有 2 个文件被更改,包括 30 次插入16 次删除
  1. 20 1
      Viewer/src/configuration/configuration.ts
  2. 10 15
      Viewer/src/viewer/defaultViewer.ts

+ 20 - 1
Viewer/src/configuration/configuration.ts

@@ -40,6 +40,25 @@ export interface ViewerConfiguration {
         defaultCamera?: boolean;
         defaultLight?: boolean;
         clearColor?: { r: number, g: number, b: number, a: number };
+        imageProcessingConfiguration?: {
+            colorGradingEnabled?: boolean;
+            colorCurvesEnabled?: boolean;
+            colorGradingWithGreenDepth?: boolean;
+            colorGradingBGR?: boolean;
+            exposure?: number;
+            toneMappingEnabled?: boolean;
+            contrast?: number;
+            vignetteEnabled?: boolean;
+            vignetteStretch?: number;
+            vignetteCentreX?: number;
+            vignetteCentreY?: number;
+            vignetteWeight?: number;
+            vignetteColor?: { r: number, g: number, b: number, a: number };
+            vignetteCameraFov?: number;
+            vignetteBlendMode?: number;
+            applyByPostProcess?: boolean;
+
+        }
     },
     // at the moment, support only a single camera.
     camera?: {
@@ -130,7 +149,7 @@ export let defaultConfiguration: ViewerConfiguration = {
     lights: [
         {
             type: 1,
-            enableShadows: true,
+            shadowEnabled: true,
             direction: { x: -0.2, y: -1, z: 0 },
             position: { x: 0.017, y: 0.5, z: 0 },
             intensity: 4.5,

+ 10 - 15
Viewer/src/viewer/defaultViewer.ts

@@ -144,19 +144,11 @@ export class DefaultViewer extends AbstractViewer {
                     light.setEnabled(!lightConfig.disabled);
                 }
 
-                light.intensity = lightConfig.intensity || light.intensity;
+                this.extendClassWithConfig(light, lightConfig);
 
-                //position. Some lights don't have position!!
+                //position. Some lights don'T support shadows
                 if (light instanceof ShadowLight) {
-                    if (lightConfig.position && light.position) {
-                        this.extendClassWithConfig(light.position, lightConfig.position);
-                    }
-
-                    if (lightConfig.direction) {
-                        this.extendClassWithConfig(light.direction, lightConfig.direction);
-                    }
-
-                    if (lightConfig.enableShadows) {
+                    if (lightConfig.shadowEnabled) {
                         var shadowGenerator = new BABYLON.ShadowGenerator(512, light)
                         this.extendClassWithConfig(shadowGenerator, lightConfig.shadowConfig || {});
                         // add the focues meshes to the shadow list
@@ -166,8 +158,6 @@ export class DefaultViewer extends AbstractViewer {
                         console.log("shadows enabled");
                     }
                 }
-
-                console.log(light);
             });
         }
     }
@@ -242,7 +232,6 @@ export class DefaultViewer extends AbstractViewer {
                     //payload is an array of meshes
                     let meshes = <Array<AbstractMesh>>payload;
                     let bounding = meshes[0].getHierarchyBoundingVectors();
-                    console.log(bounding);
                     (<FramingBehavior>behavior).zoomOnBoundingInfo(bounding.min, bounding.max);
                 }
                 break;
@@ -252,7 +241,13 @@ export class DefaultViewer extends AbstractViewer {
     private extendClassWithConfig(object: any, config: any) {
         Object.keys(config).forEach(key => {
             if (key in object && typeof object[key] !== 'function') {
-                object[key] = config[key];
+                if (typeof object[key] === 'function') return;
+                // if it is an object, iterate internally until reaching basic types
+                if (typeof object[key] === 'object') {
+                    this.extendClassWithConfig(object[key], config[key]);
+                } else {
+                    object[key] = config[key];
+                }
             }
         });
     }