Bladeren bron

Merge remote-tracking branch 'upstream/master'

sebavan 6 jaren geleden
bovenliggende
commit
811cfaf92f

+ 2 - 1
dist/preview release/what's new.md

@@ -89,6 +89,7 @@
 - Added per mesh culling strategy ([jerome](https://github.com/jbousquie))
 - Added InputsManager and keyboard bindings for FollowCamera. ([mrdunk](https://github.com))
 - Fix typo in FollowCamera InputsManager when limiting rotation to 360 degrees. ([mrdunk](https://github.com))
+- In FollowCamera InputsManager, allow choice of modifier key (Alt, Ctrl and/or Shift) for each camera movement axis. ([mrdunk](https://github.com))
 - Added MouseWheel bindings for FollowCamera. ([mrdunk](https://github.com))
 - Added maximum and minimum limits for FollowCamera parameters. ([mrdunk](https://github.com))
 - Added per solid particle culling possibility : `solidParticle.isInFrustum()`  ([jerome](https://github.com/jbousquie))
@@ -149,7 +150,7 @@
 - Fix more case sensitive paths ([mrdunk](https://github.com))
 - Attaching a BoundingBoxGizmo on a child should not remove its parent ([TrevorDev](https://github.com/TrevorDev)))
 - AmmoJS fix include issue caused after modules update and use world contact point to be consistent with oimo and cannon ([TrevorDev](https://github.com/TrevorDev)))
-- Oimo disable motor maxForce, cannonJS support no impostor, cannonJS cylinder axis ([TrevorDev](https://github.com/TrevorDev)))
+- Oimo disable motor maxForce, cannonJS support no impostor, cannonJS cylinder axis, ammoJS wake up impostor when apply force/impulse ([TrevorDev](https://github.com/TrevorDev)))
 - Utility layer should render on last active camera ([TrevorDev](https://github.com/TrevorDev))
 
 ### Core Engine

+ 137 - 51
src/Cameras/Inputs/followCameraKeyboardMoveInput.ts

@@ -8,7 +8,7 @@ import { KeyboardInfo, KeyboardEventTypes } from "../../Events/keyboardEvents";
 import { Scene } from "../../scene";
 
 /**
- * Manage the keyboard inputs to control the movement of an arc rotate camera.
+ * Manage the keyboard inputs to control the movement of a follow camera.
  * @see http://doc.babylonjs.com/how_to/customizing_camera_inputs
  */
 export class FollowCameraKeyboardMoveInput implements ICameraInput<FollowCamera> {
@@ -21,59 +21,114 @@ export class FollowCameraKeyboardMoveInput implements ICameraInput<FollowCamera>
      * Defines the list of key codes associated with the up action (increase heightOffset)
      */
     @serialize()
-    public keysUp = [38];
+    public keysHeightOffsetIncr = [38];
 
     /**
      * Defines the list of key codes associated with the down action (decrease heightOffset)
      */
     @serialize()
-    public keysDown = [40];
+    public keysHeightOffsetDecr = [40];
 
     /**
-     * Defines the list of key codes associated with the left action (increase rotation)
+     * Defines whether the Alt modifier key is required to move up/down (alter heightOffset)
      */
     @serialize()
-    public keysLeft = [37];
+    public keysHeightOffsetModifierAlt: boolean = false;
 
     /**
-     * Defines the list of key codes associated with the right action (decrease rotation)
+     * Defines whether the Ctrl modifier key is required to move up/down (alter heightOffset)
      */
     @serialize()
-    public keysRight = [39];
+    public keysHeightOffsetModifierCtrl: boolean = false;
 
     /**
-     * Defines the rate of change of heightOffset.
+     * Defines whether the Shift modifier key is required to move up/down (alter heightOffset)
      */
     @serialize()
-    public heightSensibility: number = 1;
+    public keysHeightOffsetModifierShift: boolean = false;
 
     /**
-     * Defines the rate of change of rotationOffset.
+     * Defines the list of key codes associated with the left action (increase rotationOffset)
      */
     @serialize()
-    public rotationSensibility: number = 1;
+    public keysRotationOffsetIncr = [37];
 
     /**
-     * Defines the rate of change of radius.
+     * Defines the list of key codes associated with the right action (decrease rotationOffset)
      */
     @serialize()
-    public radiusSensibility: number = 1;
+    public keysRotationOffsetDecr = [39];
+
+    /**
+     * Defines whether the Alt modifier key is required to move left/right (alter rotationOffset)
+     */
+    @serialize()
+    public keysRotationOffsetModifierAlt: boolean = false;
+
+    /**
+     * Defines whether the Ctrl modifier key is required to move left/right (alter rotationOffset)
+     */
+    @serialize()
+    public keysRotationOffsetModifierCtrl: boolean = false;
+
+    /**
+     * Defines whether the Shift modifier key is required to move left/right (alter rotationOffset)
+     */
+    @serialize()
+    public keysRotationOffsetModifierShift: boolean = false;
+
+    /**
+     * Defines the list of key codes associated with the zoom-in action (decrease radius)
+     */
+    @serialize()
+    public keysRadiusIncr = [40];
+
+    /**
+     * Defines the list of key codes associated with the zoom-out action (increase radius)
+     */
+    @serialize()
+    public keysRadiusDecr = [38];
+
+    /**
+     * Defines whether the Alt modifier key is required to zoom in/out (alter radius value)
+     */
+    @serialize()
+    public keysRadiusModifierAlt: boolean = true;
+
+    /**
+     * Defines whether the Ctrl modifier key is required to zoom in/out (alter radius value)
+     */
+    @serialize()
+    public keysRadiusModifierCtrl: boolean = false;
+
+    /**
+     * Defines whether the Shift modifier key is required to zoom in/out (alter radius value)
+     */
+    @serialize()
+    public keysRadiusModifierShift: boolean = false;
+
+    /**
+     * Defines the rate of change of heightOffset.
+     */
+    @serialize()
+    public heightSensibility: number = 1;
 
     /**
-     * Defines the minimum heightOffset value.
+     * Defines the rate of change of rotationOffset.
      */
     @serialize()
-    public minHeightOffset: number = 0;
+    public rotationSensibility: number = 1;
 
     /**
-     * Defines the minimum radius value.
+     * Defines the rate of change of radius.
      */
     @serialize()
-    public minRadius: number = 0;
+    public radiusSensibility: number = 1;
 
     private _keys = new Array<number>();
-    // private _ctrlPressed: boolean;
+    private _ctrlPressed: boolean;
     private _altPressed: boolean;
+    private _shiftPressed: boolean;
     private _onCanvasBlurObserver: Nullable<Observer<Engine>>;
     private _onKeyboardObserver: Nullable<Observer<KeyboardInfo>>;
     private _engine: Engine;
@@ -100,13 +155,16 @@ export class FollowCameraKeyboardMoveInput implements ICameraInput<FollowCamera>
             let evt = info.event;
             if (!evt.metaKey) {
                 if (info.type === KeyboardEventTypes.KEYDOWN) {
-                    // this._ctrlPressed = evt.ctrlKey;
+                    this._ctrlPressed = evt.ctrlKey;
                     this._altPressed = evt.altKey;
+                    this._shiftPressed = evt.shiftKey;
 
-                    if (this.keysUp.indexOf(evt.keyCode) !== -1 ||
-                        this.keysDown.indexOf(evt.keyCode) !== -1 ||
-                        this.keysLeft.indexOf(evt.keyCode) !== -1 ||
-                        this.keysRight.indexOf(evt.keyCode) !== -1) {
+                    if (this.keysHeightOffsetIncr.indexOf(evt.keyCode) !== -1 ||
+                        this.keysHeightOffsetDecr.indexOf(evt.keyCode) !== -1 ||
+                        this.keysRotationOffsetIncr.indexOf(evt.keyCode) !== -1 ||
+                        this.keysRotationOffsetDecr.indexOf(evt.keyCode) !== -1 ||
+                        this.keysRadiusIncr.indexOf(evt.keyCode) !== -1 ||
+                        this.keysRadiusDecr.indexOf(evt.keyCode) !== -1) {
                         var index = this._keys.indexOf(evt.keyCode);
 
                         if (index === -1) {
@@ -119,12 +177,13 @@ export class FollowCameraKeyboardMoveInput implements ICameraInput<FollowCamera>
                             }
                         }
                     }
-                }
-                else {
-                    if (this.keysUp.indexOf(evt.keyCode) !== -1 ||
-                        this.keysDown.indexOf(evt.keyCode) !== -1 ||
-                        this.keysLeft.indexOf(evt.keyCode) !== -1 ||
-                        this.keysRight.indexOf(evt.keyCode) !== -1) {
+                } else {
+                    if (this.keysHeightOffsetIncr.indexOf(evt.keyCode) !== -1 ||
+                        this.keysHeightOffsetDecr.indexOf(evt.keyCode) !== -1 ||
+                        this.keysRotationOffsetIncr.indexOf(evt.keyCode) !== -1 ||
+                        this.keysRotationOffsetDecr.indexOf(evt.keyCode) !== -1 ||
+                        this.keysRadiusIncr.indexOf(evt.keyCode) !== -1 ||
+                        this.keysRadiusDecr.indexOf(evt.keyCode) !== -1) {
                         var index = this._keys.indexOf(evt.keyCode);
 
                         if (index >= 0) {
@@ -167,37 +226,34 @@ export class FollowCameraKeyboardMoveInput implements ICameraInput<FollowCamera>
      */
     public checkInputs(): void {
         if (this._onKeyboardObserver) {
-            for (var index = 0; index < this._keys.length; index++) {
-                var keyCode = this._keys[index];
-                if (this.keysLeft.indexOf(keyCode) !== -1) {
+            this._keys.forEach((keyCode) => {
+                if (this.keysHeightOffsetIncr.indexOf(keyCode) !== -1 &&
+                           this._modifierHeightOffset()) {
+                    this.camera.heightOffset += this.heightSensibility;
+                } else if (this.keysHeightOffsetDecr.indexOf(keyCode) !== -1 &&
+                           this._modifierHeightOffset()) {
+                    this.camera.heightOffset -= this.heightSensibility;
+                } else if (this.keysRotationOffsetIncr.indexOf(keyCode) !== -1 &&
+                           this._modifierRotationOffset()) {
                     this.camera.rotationOffset += this.rotationSensibility;
                     this.camera.rotationOffset %= 360;
-                } else if (this.keysUp.indexOf(keyCode) !== -1) {
-                    if (this._altPressed) {
-                        this.camera.radius += this.radiusSensibility;
-                    } else {
-                        this.camera.heightOffset += this.heightSensibility;
-                    }
-                } else if (this.keysRight.indexOf(keyCode) !== -1) {
+                } else if (this.keysRotationOffsetDecr.indexOf(keyCode) !== -1 &&
+                           this._modifierRotationOffset()) {
                     this.camera.rotationOffset -= this.rotationSensibility;
                     this.camera.rotationOffset %= 360;
-                } else if (this.keysDown.indexOf(keyCode) !== -1) {
-                    if (this._altPressed) {
-                        this.camera.radius -= this.radiusSensibility;
-                        this.camera.radius =
-                            Math.max(this.minRadius, this.camera.radius);
-                    } else {
-                        this.camera.heightOffset -= this.heightSensibility;
-                        this.camera.heightOffset =
-                            Math.max(this.minHeightOffset, this.camera.heightOffset);
-                    }
+                } else if (this.keysRadiusIncr.indexOf(keyCode) !== -1 &&
+                           this._modifierRadius()) {
+                    this.camera.radius += this.radiusSensibility;
+                } else if (this.keysRadiusDecr.indexOf(keyCode) !== -1 &&
+                           this._modifierRadius()) {
+                    this.camera.radius -= this.radiusSensibility;
                 }
-            }
+            });
         }
     }
 
     /**
-     * Gets the class name of the current intput.
+     * Gets the class name of the current input.
      * @returns the class name
      */
     public getClassName(): string {
@@ -211,6 +267,36 @@ export class FollowCameraKeyboardMoveInput implements ICameraInput<FollowCamera>
     public getSimpleName(): string {
         return "keyboard";
     }
+
+    /**
+     * Check if the pressed modifier keys (Alt/Ctrl/Shift) match those configured to
+     * allow modification of the heightOffset value.
+     */
+    private _modifierHeightOffset(): boolean {
+        return (this.keysHeightOffsetModifierAlt === this._altPressed &&
+                this.keysHeightOffsetModifierCtrl === this._ctrlPressed &&
+                this.keysHeightOffsetModifierShift === this._shiftPressed);
+    }
+
+    /**
+     * Check if the pressed modifier keys (Alt/Ctrl/Shift) match those configured to
+     * allow modification of the rotationOffset value.
+     */
+    private _modifierRotationOffset(): boolean {
+        return (this.keysRotationOffsetModifierAlt === this._altPressed &&
+                this.keysRotationOffsetModifierCtrl === this._ctrlPressed &&
+                this.keysRotationOffsetModifierShift === this._shiftPressed);
+    }
+
+    /**
+     * Check if the pressed modifier keys (Alt/Ctrl/Shift) match those configured to
+     * allow modification of the radius value.
+     */
+    private _modifierRadius(): boolean {
+        return (this.keysRadiusModifierAlt === this._altPressed &&
+                this.keysRadiusModifierCtrl === this._ctrlPressed &&
+                this.keysRadiusModifierShift === this._shiftPressed);
+    }
 }
 
 (<any>CameraInputTypes)["FollowCameraKeyboardMoveInput"] = FollowCameraKeyboardMoveInput;

+ 2 - 0
src/Physics/Plugins/ammoJSPlugin.ts

@@ -208,6 +208,7 @@ export class AmmoJSPlugin implements IPhysicsEnginePlugin {
      * @param contactPoint the location to apply the impulse on the imposter
      */
     public applyImpulse(impostor: PhysicsImpostor, force: Vector3, contactPoint: Vector3) {
+        impostor.physicsBody.activate();
         var worldPoint = this._tmpAmmoVectorA;
         var impulse = this._tmpAmmoVectorB;
 
@@ -231,6 +232,7 @@ export class AmmoJSPlugin implements IPhysicsEnginePlugin {
      * @param contactPoint the location to apply the force on the imposter
      */
     public applyForce(impostor: PhysicsImpostor, force: Vector3, contactPoint: Vector3) {
+        impostor.physicsBody.activate();
         var worldPoint = this._tmpAmmoVectorA;
         var impulse = this._tmpAmmoVectorB;