Jelajahi Sumber

Adding a few convenient properties to cameras behaviors

David Catuhe 8 tahun lalu
induk
melakukan
93b67da716

File diff ditekan karena terlalu besar
+ 1610 - 1600
dist/preview release/babylon.d.ts


File diff ditekan karena terlalu besar
+ 24 - 24
dist/preview release/babylon.js


+ 45 - 17
dist/preview release/babylon.max.js

@@ -34314,16 +34314,25 @@ var BABYLON;
             this._onLostFocus = function () {
                 _this._keys = [];
             };
-            element.addEventListener("keydown", this._onKeyDown, false);
-            element.addEventListener("keyup", this._onKeyUp, false);
+            this._onFocus = function () {
+                element.addEventListener("keydown", _this._onKeyDown, false);
+                element.addEventListener("keyup", _this._onKeyUp, false);
+            };
+            this._onBlur = function () {
+                element.removeEventListener("keydown", _this._onKeyDown);
+                element.removeEventListener("keyup", _this._onKeyUp);
+            };
+            element.addEventListener("focus", this._onFocus);
+            element.addEventListener("blur", this._onBlur);
             BABYLON.Tools.RegisterTopRootEvents([
                 { name: "blur", handler: this._onLostFocus }
             ]);
         };
         ArcRotateCameraKeyboardMoveInput.prototype.detachControl = function (element) {
-            if (element) {
-                element.removeEventListener("keydown", this._onKeyDown);
-                element.removeEventListener("keyup", this._onKeyUp);
+            if (element && this._onBlur) {
+                this._onBlur();
+                element.removeEventListener("focus", this._onFocus);
+                element.removeEventListener("blur", this._onBlur);
             }
             BABYLON.Tools.UnregisterTopRootEvents([
                 { name: "blur", handler: this._onLostFocus }
@@ -34332,6 +34341,8 @@ var BABYLON;
             this._onKeyDown = null;
             this._onKeyUp = null;
             this._onLostFocus = null;
+            this._onBlur = null;
+            this._onFocus = null;
         };
         ArcRotateCameraKeyboardMoveInput.prototype.checkInputs = function () {
             if (this._onKeyDown) {
@@ -70189,7 +70200,7 @@ var BABYLON;
          *  Applies any current user interaction to the camera. Takes into account maximum alpha rotation.
          */
         FramingBehavior.prototype._applyUserInteraction = function () {
-            if (this._userIsMoving()) {
+            if (this.isUserIsMoving) {
                 this._lastInteractionTime = BABYLON.Tools.Now;
                 this.stopAllAnimations();
                 this._clearAnimationLocks();
@@ -70208,15 +70219,21 @@ var BABYLON;
                 this._animatables.shift();
             }
         };
-        // Tools
-        FramingBehavior.prototype._userIsMoving = function () {
-            return this._attachedCamera.inertialAlphaOffset !== 0 ||
-                this._attachedCamera.inertialBetaOffset !== 0 ||
-                this._attachedCamera.inertialRadiusOffset !== 0 ||
-                this._attachedCamera.inertialPanningX !== 0 ||
-                this._attachedCamera.inertialPanningY !== 0 ||
-                this._isPointerDown;
-        };
+        Object.defineProperty(FramingBehavior.prototype, "isUserIsMoving", {
+            /**
+             * Gets a value indicating if the user is moving the camera
+             */
+            get: function () {
+                return this._attachedCamera.inertialAlphaOffset !== 0 ||
+                    this._attachedCamera.inertialBetaOffset !== 0 ||
+                    this._attachedCamera.inertialRadiusOffset !== 0 ||
+                    this._attachedCamera.inertialPanningX !== 0 ||
+                    this._attachedCamera.inertialPanningY !== 0 ||
+                    this._isPointerDown;
+            },
+            enumerable: true,
+            configurable: true
+        });
         /**
          * The easing function used by animations
          */
@@ -70403,6 +70420,7 @@ var BABYLON;
             this._isPointerDown = false;
             this._lastFrameTime = null;
             this._lastInteractionTime = -Infinity;
+            this._cameraRotationSpeed = 0;
             this._lastFrameRadius = 0;
         }
         Object.defineProperty(AutoRotationBehavior.prototype, "name", {
@@ -70476,6 +70494,16 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+        Object.defineProperty(AutoRotationBehavior.prototype, "rotationInProgress", {
+            /**
+             * Gets a value indicating if the camera is currently rotating because of this behavior
+             */
+            get: function () {
+                return this._cameraRotationSpeed > 0;
+            },
+            enumerable: true,
+            configurable: true
+        });
         AutoRotationBehavior.prototype.attach = function (camera) {
             var _this = this;
             this._attachedCamera = camera;
@@ -70500,9 +70528,9 @@ var BABYLON;
                 _this._applyUserInteraction();
                 var timeToRotation = now - _this._lastInteractionTime - _this._idleRotationWaitTime;
                 var scale = Math.max(Math.min(timeToRotation / (_this._idleRotationSpinupTime), 1), 0);
-                var cameraRotationSpeed = _this._idleRotationSpeed * scale;
+                _this._cameraRotationSpeed = _this._idleRotationSpeed * scale;
                 // Step camera rotation by rotation speed
-                _this._attachedCamera.alpha -= cameraRotationSpeed * (dt / 1000);
+                _this._attachedCamera.alpha -= _this._cameraRotationSpeed * (dt / 1000);
             });
         };
         AutoRotationBehavior.prototype.detach = function (camera) {

File diff ditekan karena terlalu besar
+ 1610 - 1600
dist/preview release/babylon.module.d.ts


File diff ditekan karena terlalu besar
+ 24 - 24
dist/preview release/babylon.worker.js


File diff ditekan karena terlalu besar
+ 2559 - 2549
dist/preview release/customConfigurations/minimalGLTFViewer/babylon.d.ts


File diff ditekan karena terlalu besar
+ 9 - 9
dist/preview release/customConfigurations/minimalGLTFViewer/babylon.js


+ 45 - 17
dist/preview release/customConfigurations/minimalGLTFViewer/babylon.max.js

@@ -31406,16 +31406,25 @@ var BABYLON;
             this._onLostFocus = function () {
                 _this._keys = [];
             };
-            element.addEventListener("keydown", this._onKeyDown, false);
-            element.addEventListener("keyup", this._onKeyUp, false);
+            this._onFocus = function () {
+                element.addEventListener("keydown", _this._onKeyDown, false);
+                element.addEventListener("keyup", _this._onKeyUp, false);
+            };
+            this._onBlur = function () {
+                element.removeEventListener("keydown", _this._onKeyDown);
+                element.removeEventListener("keyup", _this._onKeyUp);
+            };
+            element.addEventListener("focus", this._onFocus);
+            element.addEventListener("blur", this._onBlur);
             BABYLON.Tools.RegisterTopRootEvents([
                 { name: "blur", handler: this._onLostFocus }
             ]);
         };
         ArcRotateCameraKeyboardMoveInput.prototype.detachControl = function (element) {
-            if (element) {
-                element.removeEventListener("keydown", this._onKeyDown);
-                element.removeEventListener("keyup", this._onKeyUp);
+            if (element && this._onBlur) {
+                this._onBlur();
+                element.removeEventListener("focus", this._onFocus);
+                element.removeEventListener("blur", this._onBlur);
             }
             BABYLON.Tools.UnregisterTopRootEvents([
                 { name: "blur", handler: this._onLostFocus }
@@ -31424,6 +31433,8 @@ var BABYLON;
             this._onKeyDown = null;
             this._onKeyUp = null;
             this._onLostFocus = null;
+            this._onBlur = null;
+            this._onFocus = null;
         };
         ArcRotateCameraKeyboardMoveInput.prototype.checkInputs = function () {
             if (this._onKeyDown) {
@@ -50162,7 +50173,7 @@ var BABYLON;
          *  Applies any current user interaction to the camera. Takes into account maximum alpha rotation.
          */
         FramingBehavior.prototype._applyUserInteraction = function () {
-            if (this._userIsMoving()) {
+            if (this.isUserIsMoving) {
                 this._lastInteractionTime = BABYLON.Tools.Now;
                 this.stopAllAnimations();
                 this._clearAnimationLocks();
@@ -50181,15 +50192,21 @@ var BABYLON;
                 this._animatables.shift();
             }
         };
-        // Tools
-        FramingBehavior.prototype._userIsMoving = function () {
-            return this._attachedCamera.inertialAlphaOffset !== 0 ||
-                this._attachedCamera.inertialBetaOffset !== 0 ||
-                this._attachedCamera.inertialRadiusOffset !== 0 ||
-                this._attachedCamera.inertialPanningX !== 0 ||
-                this._attachedCamera.inertialPanningY !== 0 ||
-                this._isPointerDown;
-        };
+        Object.defineProperty(FramingBehavior.prototype, "isUserIsMoving", {
+            /**
+             * Gets a value indicating if the user is moving the camera
+             */
+            get: function () {
+                return this._attachedCamera.inertialAlphaOffset !== 0 ||
+                    this._attachedCamera.inertialBetaOffset !== 0 ||
+                    this._attachedCamera.inertialRadiusOffset !== 0 ||
+                    this._attachedCamera.inertialPanningX !== 0 ||
+                    this._attachedCamera.inertialPanningY !== 0 ||
+                    this._isPointerDown;
+            },
+            enumerable: true,
+            configurable: true
+        });
         /**
          * The easing function used by animations
          */
@@ -50376,6 +50393,7 @@ var BABYLON;
             this._isPointerDown = false;
             this._lastFrameTime = null;
             this._lastInteractionTime = -Infinity;
+            this._cameraRotationSpeed = 0;
             this._lastFrameRadius = 0;
         }
         Object.defineProperty(AutoRotationBehavior.prototype, "name", {
@@ -50449,6 +50467,16 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+        Object.defineProperty(AutoRotationBehavior.prototype, "rotationInProgress", {
+            /**
+             * Gets a value indicating if the camera is currently rotating because of this behavior
+             */
+            get: function () {
+                return this._cameraRotationSpeed > 0;
+            },
+            enumerable: true,
+            configurable: true
+        });
         AutoRotationBehavior.prototype.attach = function (camera) {
             var _this = this;
             this._attachedCamera = camera;
@@ -50473,9 +50501,9 @@ var BABYLON;
                 _this._applyUserInteraction();
                 var timeToRotation = now - _this._lastInteractionTime - _this._idleRotationWaitTime;
                 var scale = Math.max(Math.min(timeToRotation / (_this._idleRotationSpinupTime), 1), 0);
-                var cameraRotationSpeed = _this._idleRotationSpeed * scale;
+                _this._cameraRotationSpeed = _this._idleRotationSpeed * scale;
                 // Step camera rotation by rotation speed
-                _this._attachedCamera.alpha -= cameraRotationSpeed * (dt / 1000);
+                _this._attachedCamera.alpha -= _this._cameraRotationSpeed * (dt / 1000);
             });
         };
         AutoRotationBehavior.prototype.detach = function (camera) {

File diff ditekan karena terlalu besar
+ 2559 - 2549
dist/preview release/customConfigurations/minimalGLTFViewer/babylon.module.d.ts


+ 11 - 3
src/Behaviors/Cameras/babylon.autoRotationBehavior.ts

@@ -64,6 +64,13 @@ module BABYLON {
 		public get idleRotationSpinupTime() {
 			return this._idleRotationSpinupTime;
 		}
+
+		/**
+		 * Gets a value indicating if the camera is currently rotating because of this behavior
+		 */
+		public get rotationInProgress(): boolean {
+			return this._cameraRotationSpeed > 0;
+		}
         
         // Default behavior functions
         private _onPrePointerObservableObserver: Observer<PointerInfoPre>;
@@ -71,7 +78,8 @@ module BABYLON {
         private _attachedCamera: ArcRotateCamera;
         private _isPointerDown = false;
         private _lastFrameTime: number = null;
-        private _lastInteractionTime = -Infinity;
+		private _lastInteractionTime = -Infinity;
+		private _cameraRotationSpeed: number = 0;
 
         public attach(camera: ArcRotateCamera): void {
             this._attachedCamera = camera;
@@ -101,10 +109,10 @@ module BABYLON {
     
                 let timeToRotation = now - this._lastInteractionTime - this._idleRotationWaitTime;
 				let scale = Math.max(Math.min(timeToRotation / (this._idleRotationSpinupTime), 1), 0);
-                let cameraRotationSpeed = this._idleRotationSpeed * scale;
+                this._cameraRotationSpeed = this._idleRotationSpeed * scale;
     
                 // Step camera rotation by rotation speed
-                this._attachedCamera.alpha -= cameraRotationSpeed * (dt / 1000);
+                this._attachedCamera.alpha -= this._cameraRotationSpeed * (dt / 1000);
             });
         }
              

+ 5 - 3
src/Behaviors/Cameras/babylon.framingBehavior.ts

@@ -349,7 +349,7 @@ module BABYLON {
 		 *  Applies any current user interaction to the camera. Takes into account maximum alpha rotation.
 		 */          
         private _applyUserInteraction(): void {
-			if (this._userIsMoving()) {
+			if (this.isUserIsMoving) {
                 this._lastInteractionTime = Tools.Now;
 				this.stopAllAnimations();				
 				this._clearAnimationLocks();
@@ -370,8 +370,10 @@ module BABYLON {
 			}
 		}        
 
-        // Tools
-        private _userIsMoving(): boolean {
+        /**
+		 * Gets a value indicating if the user is moving the camera
+		 */
+        public get isUserIsMoving(): boolean {
 			return this._attachedCamera.inertialAlphaOffset !== 0 ||
 				this._attachedCamera.inertialBetaOffset !== 0 ||
 				this._attachedCamera.inertialRadiusOffset !== 0 ||

+ 20 - 5
src/Cameras/Inputs/babylon.arcRotateCameraKeyboardMoveInput.ts

@@ -5,6 +5,8 @@ module BABYLON {
         private _onKeyDown: (e: KeyboardEvent) => any;
         private _onKeyUp: (e: KeyboardEvent) => any;
         private _onLostFocus: (e: FocusEvent) => any;
+        private _onFocus: () => void;
+        private _onBlur: () => void;
         
         @serialize()
         public keysUp = [38];
@@ -65,8 +67,18 @@ module BABYLON {
                 this._keys = [];
             };
 
-            element.addEventListener("keydown", this._onKeyDown, false);
-            element.addEventListener("keyup", this._onKeyUp, false);
+            this._onFocus = () => {
+                element.addEventListener("keydown", this._onKeyDown, false);
+                element.addEventListener("keyup", this._onKeyUp, false);   
+            }
+
+            this._onBlur = () => {
+                element.removeEventListener("keydown", this._onKeyDown);
+                element.removeEventListener("keyup", this._onKeyUp);
+            }
+
+            element.addEventListener("focus", this._onFocus);
+            element.addEventListener("blur", this._onBlur);
 
             Tools.RegisterTopRootEvents([
                 { name: "blur", handler: this._onLostFocus }
@@ -74,9 +86,10 @@ module BABYLON {
         }
 
         public detachControl(element: HTMLElement) {
-            if (element) {
-                element.removeEventListener("keydown", this._onKeyDown);
-                element.removeEventListener("keyup", this._onKeyUp);
+            if (element && this._onBlur) {
+                this._onBlur();
+                element.removeEventListener("focus", this._onFocus);
+                element.removeEventListener("blur", this._onBlur);
             }
 
             Tools.UnregisterTopRootEvents([
@@ -87,6 +100,8 @@ module BABYLON {
             this._onKeyDown = null;
             this._onKeyUp = null;
             this._onLostFocus = null;
+            this._onBlur = null;
+            this._onFocus = null;
         }
 
         public checkInputs() {