소스 검색

Camera behaviors fix
Behaviors can now be configured and are a part of the default configuration.

Raanan Weber 7 년 전
부모
커밋
d529c5d541
2개의 변경된 파일34개의 추가작업 그리고 13개의 파일을 삭제
  1. 12 3
      Viewer/src/configuration/configuration.ts
  2. 22 10
      Viewer/src/viewer/defaultViewer.ts

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

@@ -49,7 +49,7 @@ export interface ViewerConfiguration {
         minZ?: number;
         maxZ?: number;
         behaviors?: Array<number | {
-            type?: number;
+            type: number;
             [propName: string]: any;
         }>
     },
@@ -91,11 +91,20 @@ export let defaultConfiguration: ViewerConfiguration = {
             }
         }
     },
+    camera: {
+        behaviors: [
+            0,
+            {
+                type: 2,
+                zoomOnBoundingInfo: true
+            }
+        ]
+    },
     engine: {
         antialiasing: true
     },
     scene: {
-        autoRotate: true,
-        rotationSpeed: 0.1
+        //autoRotate: true,
+        //rotationSpeed: 0.1
     }
 }

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

@@ -187,7 +187,7 @@ export class DefaultViewer extends AbstractViewer {
 
         if (cameraConfig.behaviors) {
             cameraConfig.behaviors.forEach((behaviorConfig) => {
-
+                this.setCameraBehavior(behaviorConfig, focusMeshes);
             });
         };
 
@@ -196,16 +196,17 @@ export class DefaultViewer extends AbstractViewer {
         }
     }
 
-    private setCameraBehavior(behaviorConfig: {
+    private setCameraBehavior(behaviorConfig: number | {
         type: number;
         [propName: string]: any;
     }, payload: any) {
 
-
-
         let behavior: Behavior<ArcRotateCamera>;
         let type = (typeof behaviorConfig !== "object") ? behaviorConfig : behaviorConfig.type;
 
+        let config: { [propName: string]: any } = (typeof behaviorConfig === "object") ? behaviorConfig : {};
+
+        // constructing behavior
         switch (type) {
             case CameraBehavior.AUTOROTATION:
                 behavior = new AutoRotationBehavior();
@@ -215,12 +216,6 @@ export class DefaultViewer extends AbstractViewer {
                 break;
             case CameraBehavior.FRAMING:
                 behavior = new FramingBehavior();
-                if (behaviorConfig.zoomOnBoundingInfo) {
-                    //payload is an array of meshes
-                    let meshes = <Array<AbstractMesh>>payload;
-                    let bounding = meshes[0].getHierarchyBoundingVectors();
-                    (<FramingBehavior>behavior).zoomOnBoundingInfo(bounding.min, bounding.max);
-                }
                 break;
         }
 
@@ -230,6 +225,23 @@ export class DefaultViewer extends AbstractViewer {
             }
             this.camera.addBehavior(behavior);
         }
+
+        // post attach configuration
+        switch (type) {
+            case CameraBehavior.AUTOROTATION:
+                break;
+            case CameraBehavior.BOUNCING:
+                break;
+            case CameraBehavior.FRAMING:
+                if (config.zoomOnBoundingInfo) {
+                    //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;
+        }
     }
 
     private extendClassWithConfig(object: any, config: any) {