ソースを参照

Camera behaviro can now be disabled
Fixing - https://github.com/BabylonJS/Babylon.js/issues/4348

Raanan Weber 7 年 前
コミット
547c759c63

+ 6 - 4
Viewer/src/configuration/configuration.ts

@@ -438,10 +438,7 @@ export interface ICameraConfiguration {
     exposure?: number;
     pinchPrecision?: number;
     behaviors?: {
-        [name: string]: number | {
-            type: number;
-            [propName: string]: any;
-        };
+        [name: string]: boolean | number | ICameraBehaviorConfiguration;
     };
     disableCameraControl?: boolean;
     disableCtrlForPanning?: boolean;
@@ -450,6 +447,11 @@ export interface ICameraConfiguration {
     [propName: string]: any;
 }
 
+export interface ICameraBehaviorConfiguration {
+    type: number;
+    [propName: string]: any;
+}
+
 export interface ILightConfiguration {
     type: number;
     name?: string;

+ 25 - 7
Viewer/src/viewer/sceneManager.ts

@@ -768,8 +768,8 @@ export class SceneManager {
 
         if (cameraConfig.behaviors) {
             for (let name in cameraConfig.behaviors) {
-                if (cameraConfig.behaviors[name]) {
-                    this._setCameraBehavior(cameraConfig.behaviors[name]);
+                if (cameraConfig.behaviors[name] !== undefined) {
+                    this._setCameraBehavior(name, cameraConfig.behaviors[name]);
                 }
             }
         };
@@ -1290,28 +1290,44 @@ export class SceneManager {
         }
     }
 
-    private _setCameraBehavior(behaviorConfig: number | {
+    private _cameraBehaviorMapping: { [name: string]: number } = {};
+
+    private _setCameraBehavior(name: string, behaviorConfig: boolean | number | {
         type: number;
         [propName: string]: any;
     }, payload?: any) {
 
         let behavior: Behavior<ArcRotateCamera> | null;
-        let type = (typeof behaviorConfig !== "object") ? behaviorConfig : behaviorConfig.type;
+        let type: number;
+        if (typeof behaviorConfig === 'object') {
+            type = behaviorConfig.type
+        } else if (typeof behaviorConfig === 'number') {
+            type = behaviorConfig;
+        } else {
+            type = this._cameraBehaviorMapping[name];
+        }
+
+        if (type === undefined) return;
 
         let config: { [propName: string]: any } = (typeof behaviorConfig === "object") ? behaviorConfig : {};
 
+        let enabled = true;
+        if (typeof behaviorConfig === 'boolean') {
+            enabled = behaviorConfig;
+        }
+
         // constructing behavior
         switch (type) {
             case CameraBehavior.AUTOROTATION:
-                this.camera.useAutoRotationBehavior = true;
+                this.camera.useAutoRotationBehavior = enabled;
                 behavior = this.camera.autoRotationBehavior;
                 break;
             case CameraBehavior.BOUNCING:
-                this.camera.useBouncingBehavior = true;
+                this.camera.useBouncingBehavior = enabled;
                 behavior = this.camera.bouncingBehavior;
                 break;
             case CameraBehavior.FRAMING:
-                this.camera.useFramingBehavior = true;
+                this.camera.useFramingBehavior = enabled;
                 behavior = this.camera.framingBehavior;
                 break;
             default:
@@ -1320,6 +1336,8 @@ export class SceneManager {
         }
 
         if (behavior) {
+            this._cameraBehaviorMapping[name] = type;
+
             if (typeof behaviorConfig === "object") {
                 extendClassWithConfig(behavior, behaviorConfig);
             }