Bläddra i källkod

FlyCamera Checks Passed

Fixes checks for Pull Request 5286.
James Koss 6 år sedan
förälder
incheckning
89b5ff2da2

+ 1 - 1
src/Cameras/Inputs/babylon.flyCameraKeyboardInput.ts

@@ -68,7 +68,7 @@ module BABYLON {
                 this._keys = [];
             });
 
-            this._onKeyboardObserver = this._scene.onKeyboardObservable.add(info => {
+            this._onKeyboardObserver = this._scene.onKeyboardObservable.add((info) => {
                 let evt = info.event;
 
                 if (info.type === KeyboardEventTypes.KEYDOWN) {

+ 34 - 19
src/Cameras/Inputs/babylon.flyCameraMouseInput.ts

@@ -10,16 +10,29 @@ module BABYLON {
         public camera: FlyCamera;
 
         /**
+         * Defines if touch is enabled. (Default is true.)
+         */
+        public touchEnabled: boolean;
+
+        /**
          * Defines the buttons associated with the input to handle camera rotation.
          */
         @serialize()
         public buttons = [0, 1, 2];
 
         /**
-         * Assign buttons for rotation control.
+         * Assign buttons for Yaw control.
          */
         public buttonsYaw: number[]    = [-1, 0, 1];
+
+        /**
+        * Assign buttons for Pitch control.
+        */
         public buttonsPitch: number[]  = [-1, 0, 1];
+
+        /**
+        * Assign buttons for Roll control.
+        */
         public buttonsRoll: number[]   = [2];
 
         /**
@@ -42,15 +55,15 @@ module BABYLON {
         private _observer: Nullable<Observer<PointerInfo>>;
         private _rollObserver: Nullable<Observer<Scene>>;
         private previousPosition: Nullable<{ x: number, y: number }> = null;
-        private noPreventDefault: boolean|undefined;
+        private noPreventDefault: boolean | undefined;
         private element: HTMLElement;
 
         /**
          * Listen to mouse events to control the camera.
-         * @see http://doc.babylonjs.com/how_to/customizing_camera_inputs
          * @param touchEnabled Define if touch is enabled. (Default is true.)
+         * @see http://doc.babylonjs.com/how_to/customizing_camera_inputs
          */
-        constructor(public touchEnabled = true) {
+        constructor(touchEnabled = true) {
         }
 
         /**
@@ -59,29 +72,29 @@ module BABYLON {
          * @param noPreventDefault Defines whether events caught by the controls should call preventdefault().
          */
         public attachControl(element: HTMLElement, noPreventDefault?: boolean): void {
-            var _this = this;
-
             this.element = element;
             this.noPreventDefault = noPreventDefault;
 
             this._observer = this.camera.getScene().onPointerObservable.add(
-                (p: any, s: any) => { _this._pointerInput(p, s); },
+                (p: any, s: any) => {
+                    this._pointerInput(p, s);
+                },
                 PointerEventTypes.POINTERDOWN | PointerEventTypes.POINTERUP | PointerEventTypes.POINTERMOVE
             );
 
             // Correct Roll by rate, if enabled.
             this._rollObserver = this.camera.getScene().onBeforeRenderObservable.add(
                 () => {
-                    if (_this.camera.rollCorrect) {
-                        _this.camera.restoreRoll(_this.camera.rollCorrect);
+                    if (this.camera.rollCorrect) {
+                        this.camera.restoreRoll(this.camera.rollCorrect);
                     }
                 }
             );
 
             // Helper function to keep 'this'.
-            this._mousemoveCallback = function (e: any) {
-                _this._onMouseMove(e);
-            }
+            this._mousemoveCallback = (e: any) => {
+                this._onMouseMove(e);
+            };
             element.addEventListener("mousemove", this._mousemoveCallback, false);
         }
 
@@ -188,7 +201,7 @@ module BABYLON {
                 var offsetX = e.clientX - this.previousPosition.x;
                 var offsetY = e.clientY - this.previousPosition.y;
 
-                this.rotateCamera(offsetX, offsetY)
+                this.rotateCamera(offsetX, offsetY);
 
                 this.previousPosition = {
                     x: e.clientX,
@@ -213,7 +226,7 @@ module BABYLON {
             var offsetX = e.movementX || e.mozMovementX || e.webkitMovementX || e.msMovementX || 0;
             var offsetY = e.movementY || e.mozMovementY || e.webkitMovementY || e.msMovementY || 0;
 
-            this.rotateCamera(offsetX, offsetY)
+            this.rotateCamera(offsetX, offsetY);
 
             this.previousPosition = null;
 
@@ -229,11 +242,13 @@ module BABYLON {
             let camera = this.camera;
             let scene = this.camera.getScene();
 
-            if (scene.useRightHandedSystem)
+            if (scene.useRightHandedSystem) {
               offsetX *= -1;
+            }
 
-            if (camera.parent && camera.parent._getWorldMatrixDeterminant() < 0)
+            if (camera.parent && camera.parent._getWorldMatrixDeterminant() < 0) {
                 offsetX *= -1;
+            }
 
             var x = offsetX / this.angularSensibility;
             var y = offsetY / this.angularSensibility;
@@ -247,7 +262,7 @@ module BABYLON {
             var rotationChange: BABYLON.Quaternion;
 
             // Pitch.
-            if (this.buttonsPitch.some((v) => { return v === this.activeButton })) {
+            if (this.buttonsPitch.some((v) => { return v === this.activeButton; })) {
                 // Apply change in Radians to vector Angle.
                 rotationChange = BABYLON.Quaternion.RotationAxis(BABYLON.Axis.X, y);
                 // Apply Pitch to quaternion.
@@ -255,7 +270,7 @@ module BABYLON {
             }
 
             // Yaw.
-            if (this.buttonsYaw.some((v) => { return v === this.activeButton })) {
+            if (this.buttonsYaw.some((v) => { return v === this.activeButton; })) {
                 // Apply change in Radians to vector Angle.
                 rotationChange = BABYLON.Quaternion.RotationAxis(BABYLON.Axis.Y, x);
                 // Apply Yaw to quaternion.
@@ -273,7 +288,7 @@ module BABYLON {
             }
 
             // Roll.
-            if (this.buttonsRoll.some((v) => { return v === this.activeButton })) {
+            if (this.buttonsRoll.some((v) => { return v === this.activeButton; })) {
                 // Apply change in Radians to vector Angle.
                 rotationChange = BABYLON.Quaternion.RotationAxis(BABYLON.Axis.Z, -x);
                 // Track Rolling.

+ 38 - 18
src/Cameras/babylon.flyCamera.ts

@@ -59,10 +59,15 @@
          */
         public bankedTurn: boolean = false;
 
-        // Limit in radians for how much Roll banking will add. (Default: 90°)
+        /**
+         * Limit in radians for how much Roll banking will add. (Default: 90°)
+         */
         public bankedTurnLimit: number = Math.PI / 4;
 
-        // 0 disables the banked Roll. 1 is equal to the Yaw angle in radians.
+        /**
+         * Value of 0 disables the banked Roll.
+         * Value of 1 is equal to the Yaw angle in radians.
+         */
         public bankedTurnMultiplier: number = 1;
 
         /**
@@ -76,8 +81,9 @@
          */
         public get angularSensibility(): number {
             var mouse = <FlyCameraMouseInput>this.inputs.attached["mouse"];
-            if (mouse)
+            if (mouse) {
                 return mouse.angularSensibility;
+            }
 
             return 0;
         }
@@ -88,8 +94,9 @@
          */
         public set angularSensibility(value: number) {
             var mouse = <FlyCameraMouseInput>this.inputs.attached["mouse"];
-            if (mouse)
+            if (mouse) {
                 mouse.angularSensibility = value;
+            }
         }
 
         /**
@@ -97,8 +104,9 @@
          */
         public get keysForward(): number[] {
             var keyboard = <FlyCameraKeyboardInput>this.inputs.attached["keyboard"];
-            if (keyboard)
+            if (keyboard) {
                 return keyboard.keysForward;
+            }
 
             return [];
         }
@@ -108,8 +116,9 @@
         */
         public set keysForward(value: number[]) {
             var keyboard = <FlyCameraKeyboardInput>this.inputs.attached["keyboard"];
-            if (keyboard)
+            if (keyboard) {
                 keyboard.keysForward = value;
+            }
         }
 
         /**
@@ -117,16 +126,18 @@
          */
         public get keysBackward(): number[] {
             var keyboard = <FlyCameraKeyboardInput>this.inputs.attached["keyboard"];
-            if (keyboard)
+            if (keyboard) {
                 return keyboard.keysBackward;
+            }
 
             return [];
         }
 
         public set keysBackward(value: number[]) {
             var keyboard = <FlyCameraKeyboardInput>this.inputs.attached["keyboard"];
-            if (keyboard)
+            if (keyboard) {
                 keyboard.keysBackward = value;
+            }
         }
 
         /**
@@ -134,8 +145,9 @@
          */
         public get keysUp(): number[] {
             var keyboard = <FlyCameraKeyboardInput>this.inputs.attached["keyboard"];
-            if (keyboard)
+            if (keyboard) {
                 return keyboard.keysUp;
+            }
 
             return [];
         }
@@ -145,8 +157,9 @@
         */
         public set keysUp(value: number[]) {
             var keyboard = <FlyCameraKeyboardInput>this.inputs.attached["keyboard"];
-            if (keyboard)
+            if (keyboard) {
                 keyboard.keysUp = value;
+            }
         }
 
         /**
@@ -154,8 +167,9 @@
          */
         public get keysDown(): number[] {
             var keyboard = <FlyCameraKeyboardInput>this.inputs.attached["keyboard"];
-            if (keyboard)
+            if (keyboard) {
                 return keyboard.keysDown;
+            }
 
             return [];
         }
@@ -165,8 +179,9 @@
         */
         public set keysDown(value: number[]) {
             var keyboard = <FlyCameraKeyboardInput>this.inputs.attached["keyboard"];
-            if (keyboard)
+            if (keyboard) {
                 keyboard.keysDown = value;
+            }
         }
 
         /**
@@ -174,8 +189,9 @@
          */
         public get keysLeft(): number[] {
             var keyboard = <FlyCameraKeyboardInput>this.inputs.attached["keyboard"];
-            if (keyboard)
+            if (keyboard) {
                 return keyboard.keysLeft;
+            }
 
             return [];
         }
@@ -185,8 +201,9 @@
         */
         public set keysLeft(value: number[]) {
             var keyboard = <FlyCameraKeyboardInput>this.inputs.attached["keyboard"];
-            if (keyboard)
+            if (keyboard) {
                 keyboard.keysLeft = value;
+            }
         }
 
         /**
@@ -194,8 +211,9 @@
          */
         public get keysRight(): number[] {
             var keyboard = <FlyCameraKeyboardInput>this.inputs.attached["keyboard"];
-            if (keyboard)
+            if (keyboard) {
                 return keyboard.keysRight;
+            }
 
             return [];
         }
@@ -205,8 +223,9 @@
         */
         public set keysRight(value: number[]) {
             var keyboard = <FlyCameraKeyboardInput>this.inputs.attached["keyboard"];
-            if (keyboard)
+            if (keyboard) {
                 keyboard.keysRight = value;
+            }
         }
 
         /**
@@ -312,8 +331,9 @@
         /** @hidden */
         private _onCollisionPositionChange = (collisionId: number, newPosition: Vector3, collidedMesh: Nullable<AbstractMesh> = null) => {
             // TODO Move this to the collision coordinator!
-            if (this.getScene().workerCollisions)
+            if (this.getScene().workerCollisions) {
                 newPosition.multiplyInPlace(this._collider._radius);
+            }
 
             var updatePosition = (newPos: Vector3) => {
                 this._newPosition.copyFrom(newPos);
@@ -326,7 +346,7 @@
                         this.onCollide(collidedMesh);
                     }
                 }
-            }
+            };
 
             updatePosition(newPosition);
         }

+ 1 - 0
what's new.md

@@ -133,6 +133,7 @@
 - Added optional alphaFilter parameter to ```CreateGroundFromHeightMap``` to allow for heightmaps to be created that ignore any transparent data ([Postman-nz](https://github.com/Postman-nz))
 - Fixed renormalization of mesh weights to in cleanMatrixWeights function. ([Bolloxim](https://github.com/Bolloxim))
 - Added a validationSkin function to report out any errors on skinned meshes. ([Bolloxim](https://github.com/Bolloxim))
+- Added FlyCamera for free navigation in 3D space, with a limited set of settings.
 
 
 ### glTF Loader