Browse Source

arc rotate camera => input manager

gleborgne 9 years ago
parent
commit
8885716c5c
41 changed files with 3096 additions and 2919 deletions
  1. 5 0
      Tools/Gulp/config.json
  2. 21 21
      dist/preview release/babylon.js
  3. 1113 1085
      dist/preview release/babylon.max.js
  4. 105 0
      src/Cameras/Inputs/babylon.arcrotatecamera.input.keyboard.js
  5. 104 0
      src/Cameras/Inputs/babylon.arcrotatecamera.input.keyboard.ts
  6. 52 0
      src/Cameras/Inputs/babylon.arcrotatecamera.input.mousewheel.js
  7. 49 0
      src/Cameras/Inputs/babylon.arcrotatecamera.input.mousewheel.ts
  8. 190 0
      src/Cameras/Inputs/babylon.arcrotatecamera.input.pointers.js
  9. 225 0
      src/Cameras/Inputs/babylon.arcrotatecamera.input.pointers.ts
  10. 62 65
      src/Cameras/Inputs/babylon.freecamera.input.deviceorientation.js
  11. 2 2
      src/Cameras/Inputs/babylon.freecamera.input.deviceorientation.ts
  12. 50 53
      src/Cameras/Inputs/babylon.freecamera.input.gamepad.js
  13. 2 2
      src/Cameras/Inputs/babylon.freecamera.input.gamepad.ts
  14. 92 95
      src/Cameras/Inputs/babylon.freecamera.input.keyboard.js
  15. 2 2
      src/Cameras/Inputs/babylon.freecamera.input.keyboard.ts
  16. 88 91
      src/Cameras/Inputs/babylon.freecamera.input.mouse.js
  17. 2 2
      src/Cameras/Inputs/babylon.freecamera.input.mouse.ts
  18. 121 124
      src/Cameras/Inputs/babylon.freecamera.input.touch.js
  19. 2 2
      src/Cameras/Inputs/babylon.freecamera.input.touch.ts
  20. 45 48
      src/Cameras/Inputs/babylon.freecamera.input.virtualjoystick.js
  21. 3 2
      src/Cameras/Inputs/babylon.freecamera.input.virtualjoystick.ts
  22. 1 27
      src/Cameras/VR/babylon.vrDeviceOrientationCamera.js
  23. 2 41
      src/Cameras/VR/babylon.vrDeviceOrientationCamera.ts
  24. 252 274
      src/Cameras/babylon.arcRotateCamera.js
  25. 307 292
      src/Cameras/babylon.arcRotateCamera.ts
  26. 28 0
      src/Cameras/babylon.arcRotateCameraInputsManager.js
  27. 22 0
      src/Cameras/babylon.arcRotateCameraInputsManager.ts
  28. 2 5
      src/Cameras/babylon.cameraInputsManager.js
  29. 2 4
      src/Cameras/babylon.cameraInputsManager.ts
  30. 0 70
      src/Cameras/babylon.deviceOrientationCamera.js
  31. 0 72
      src/Cameras/babylon.deviceOrientationCamera.ts
  32. 1 35
      src/Cameras/babylon.freeCamera.js
  33. 1 39
      src/Cameras/babylon.freeCamera.ts
  34. 46 0
      src/Cameras/babylon.freeCameraInputsManager.js
  35. 44 0
      src/Cameras/babylon.freeCameraInputsManager.ts
  36. 0 141
      src/Cameras/babylon.touchCamera.js
  37. 0 144
      src/Cameras/babylon.touchCamera.ts
  38. 0 52
      src/Cameras/babylon.universalCamera.js
  39. 0 53
      src/Cameras/babylon.universalCamera.ts
  40. 13 37
      src/Cameras/babylon.virtualJoysticksCamera.js
  41. 40 39
      src/Cameras/babylon.virtualJoysticksCamera.ts

+ 5 - 0
Tools/Gulp/config.json

@@ -50,11 +50,16 @@
       "../../src/cameras/inputs/babylon.freecamera.input.deviceorientation.js",
       "../../src/cameras/inputs/babylon.freecamera.input.gamepad.js",
       "../../src/cameras/inputs/babylon.freecamera.input.virtualjoystick.js",
+      "../../src/cameras/inputs/babylon.arcrotatecamera.input.keyboard.js",
+      "../../src/cameras/inputs/babylon.arcrotatecamera.input.mousewheel.js",
+      "../../src/cameras/inputs/babylon.arcrotatecamera.input.pointers.js",
       "../../src/Cameras/babylon.targetCamera.js",
       "../../src/Cameras/babylon.freeCamera.js",
+      "../../src/Cameras/babylon.freeCameraInputsManager.js",
       "../../src/Cameras/babylon.followCamera.js",
       "../../src/Cameras/babylon.touchCamera.js",
       "../../src/Cameras/babylon.arcRotateCamera.js",
+      "../../src/Cameras/babylon.arcRotateCameraInputsManager.js",
       "../../src/Rendering/babylon.renderingManager.js",
       "../../src/Rendering/babylon.renderingGroup.js",
       "../../src/babylon.scene.js",

File diff suppressed because it is too large
+ 21 - 21
dist/preview release/babylon.js


File diff suppressed because it is too large
+ 1113 - 1085
dist/preview release/babylon.max.js


+ 105 - 0
src/Cameras/Inputs/babylon.arcrotatecamera.input.keyboard.js

@@ -0,0 +1,105 @@
+var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
+    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
+    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
+    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
+    return c > 3 && r && Object.defineProperty(target, key, r), r;
+};
+var BABYLON;
+(function (BABYLON) {
+    var ArcRotateCameraKeyboardMoveInput = (function () {
+        function ArcRotateCameraKeyboardMoveInput() {
+            this._keys = [];
+            this.keysUp = [38];
+            this.keysDown = [40];
+            this.keysLeft = [37];
+            this.keysRight = [39];
+        }
+        ArcRotateCameraKeyboardMoveInput.prototype.attachCamera = function (camera) {
+            var _this = this;
+            this.camera = camera;
+            this._onKeyDown = function (evt) {
+                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) {
+                    var index = _this._keys.indexOf(evt.keyCode);
+                    if (index === -1) {
+                        _this._keys.push(evt.keyCode);
+                    }
+                    if (evt.preventDefault) {
+                        if (!camera._noPreventDefault) {
+                            evt.preventDefault();
+                        }
+                    }
+                }
+            };
+            this._onKeyUp = function (evt) {
+                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) {
+                    var index = _this._keys.indexOf(evt.keyCode);
+                    if (index >= 0) {
+                        _this._keys.splice(index, 1);
+                    }
+                    if (evt.preventDefault) {
+                        if (!camera._noPreventDefault) {
+                            evt.preventDefault();
+                        }
+                    }
+                }
+            };
+            this._onLostFocus = function () {
+                _this._keys = [];
+            };
+            BABYLON.Tools.RegisterTopRootEvents([
+                { name: "keydown", handler: this._onKeyDown },
+                { name: "keyup", handler: this._onKeyUp },
+                { name: "blur", handler: this._onLostFocus }
+            ]);
+        };
+        ArcRotateCameraKeyboardMoveInput.prototype.detach = function () {
+            BABYLON.Tools.UnregisterTopRootEvents([
+                { name: "keydown", handler: this._onKeyDown },
+                { name: "keyup", handler: this._onKeyUp },
+                { name: "blur", handler: this._onLostFocus }
+            ]);
+        };
+        ArcRotateCameraKeyboardMoveInput.prototype.checkInputs = function () {
+            var camera = this.camera;
+            for (var index = 0; index < this._keys.length; index++) {
+                var keyCode = this._keys[index];
+                if (this.keysLeft.indexOf(keyCode) !== -1) {
+                    camera.inertialAlphaOffset -= 0.01;
+                }
+                else if (this.keysUp.indexOf(keyCode) !== -1) {
+                    camera.inertialBetaOffset -= 0.01;
+                }
+                else if (this.keysRight.indexOf(keyCode) !== -1) {
+                    camera.inertialAlphaOffset += 0.01;
+                }
+                else if (this.keysDown.indexOf(keyCode) !== -1) {
+                    camera.inertialBetaOffset += 0.01;
+                }
+            }
+        };
+        ArcRotateCameraKeyboardMoveInput.prototype.getTypeName = function () {
+            return "arcrotate.keyboard";
+        };
+        __decorate([
+            BABYLON.serialize()
+        ], ArcRotateCameraKeyboardMoveInput.prototype, "keysUp", void 0);
+        __decorate([
+            BABYLON.serialize()
+        ], ArcRotateCameraKeyboardMoveInput.prototype, "keysDown", void 0);
+        __decorate([
+            BABYLON.serialize()
+        ], ArcRotateCameraKeyboardMoveInput.prototype, "keysLeft", void 0);
+        __decorate([
+            BABYLON.serialize()
+        ], ArcRotateCameraKeyboardMoveInput.prototype, "keysRight", void 0);
+        return ArcRotateCameraKeyboardMoveInput;
+    }());
+    BABYLON.ArcRotateCameraKeyboardMoveInput = ArcRotateCameraKeyboardMoveInput;
+    BABYLON.CameraInputTypes["arcrotate.keyboard"] = ArcRotateCameraKeyboardMoveInput;
+})(BABYLON || (BABYLON = {}));

+ 104 - 0
src/Cameras/Inputs/babylon.arcrotatecamera.input.keyboard.ts

@@ -0,0 +1,104 @@
+module BABYLON {
+    export class ArcRotateCameraKeyboardMoveInput implements ICameraInput<ArcRotateCamera> {
+        camera: ArcRotateCamera;
+        private _keys = [];
+        private _onKeyDown: (e: KeyboardEvent) => any;
+        private _onKeyUp: (e: KeyboardEvent) => any;
+        private _onLostFocus: (e: FocusEvent) => any;
+        
+        @serialize()
+        public keysUp = [38];
+
+        @serialize()
+        public keysDown = [40];
+
+        @serialize()
+        public keysLeft = [37];
+
+        @serialize()
+        public keysRight = [39];
+
+        public attachCamera(camera: ArcRotateCamera) {
+            this.camera = camera;
+
+            this._onKeyDown = evt => {
+                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) {
+                    var index = this._keys.indexOf(evt.keyCode);
+
+                    if (index === -1) {
+                        this._keys.push(evt.keyCode);
+                    }
+
+                    if (evt.preventDefault) {
+                        if (!camera._noPreventDefault) {
+                            evt.preventDefault();
+                        }
+                    }
+                }
+            };
+
+            this._onKeyUp = evt => {
+                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) {
+                    var index = this._keys.indexOf(evt.keyCode);
+
+                    if (index >= 0) {
+                        this._keys.splice(index, 1);
+                    }
+
+                    if (evt.preventDefault) {
+                        if (!camera._noPreventDefault) {
+                            evt.preventDefault();
+                        }
+                    }
+                }
+            };
+
+            this._onLostFocus = () => {
+                this._keys = [];
+            };
+
+            Tools.RegisterTopRootEvents([
+                { name: "keydown", handler: this._onKeyDown },
+                { name: "keyup", handler: this._onKeyUp },
+                { name: "blur", handler: this._onLostFocus }
+            ]);
+        }
+
+        public detach() {
+            Tools.UnregisterTopRootEvents([
+                { name: "keydown", handler: this._onKeyDown },
+                { name: "keyup", handler: this._onKeyUp },
+                { name: "blur", handler: this._onLostFocus }
+            ]);
+        }
+
+        public checkInputs() {
+            var camera = this.camera;
+
+            for (var index = 0; index < this._keys.length; index++) {
+                var keyCode = this._keys[index];
+                if (this.keysLeft.indexOf(keyCode) !== -1) {
+                    camera.inertialAlphaOffset -= 0.01;
+                } else if (this.keysUp.indexOf(keyCode) !== -1) {
+                    camera.inertialBetaOffset -= 0.01;
+                } else if (this.keysRight.indexOf(keyCode) !== -1) {
+                    camera.inertialAlphaOffset += 0.01;
+                } else if (this.keysDown.indexOf(keyCode) !== -1) {
+                    camera.inertialBetaOffset += 0.01;
+                }
+            }
+        }
+
+        getTypeName(): string {
+            return "arcrotate.keyboard";
+        }
+    }
+    
+    CameraInputTypes["arcrotate.keyboard"] = ArcRotateCameraKeyboardMoveInput;
+}

+ 52 - 0
src/Cameras/Inputs/babylon.arcrotatecamera.input.mousewheel.js

@@ -0,0 +1,52 @@
+var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
+    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
+    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
+    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
+    return c > 3 && r && Object.defineProperty(target, key, r), r;
+};
+var BABYLON;
+(function (BABYLON) {
+    var ArcRotateCameraMouseWheelInput = (function () {
+        function ArcRotateCameraMouseWheelInput() {
+            this.wheelPrecision = 3.0;
+        }
+        ArcRotateCameraMouseWheelInput.prototype.attachCamera = function (camera) {
+            this.camera = camera;
+        };
+        ArcRotateCameraMouseWheelInput.prototype.attachElement = function (element) {
+            var _this = this;
+            this.attachedElement = element;
+            this._wheel = function (event) {
+                var delta = 0;
+                if (event.wheelDelta) {
+                    delta = event.wheelDelta / (_this.wheelPrecision * 40);
+                }
+                else if (event.detail) {
+                    delta = -event.detail / _this.wheelPrecision;
+                }
+                if (delta)
+                    _this.camera.inertialRadiusOffset += delta;
+                if (event.preventDefault) {
+                    if (!_this.camera._noPreventDefault) {
+                        event.preventDefault();
+                    }
+                }
+            };
+            element.addEventListener('mousewheel', this._wheel, false);
+            element.addEventListener('DOMMouseScroll', this._wheel, false);
+        };
+        ArcRotateCameraMouseWheelInput.prototype.detach = function () {
+            this.attachedElement.removeEventListener('mousewheel', this._wheel);
+            this.attachedElement.removeEventListener('DOMMouseScroll', this._wheel);
+        };
+        ArcRotateCameraMouseWheelInput.prototype.getTypeName = function () {
+            return "arcrotate.mousewheel";
+        };
+        __decorate([
+            BABYLON.serialize()
+        ], ArcRotateCameraMouseWheelInput.prototype, "wheelPrecision", void 0);
+        return ArcRotateCameraMouseWheelInput;
+    }());
+    BABYLON.ArcRotateCameraMouseWheelInput = ArcRotateCameraMouseWheelInput;
+    BABYLON.CameraInputTypes["arcrotate.mousewheel"] = ArcRotateCameraMouseWheelInput;
+})(BABYLON || (BABYLON = {}));

+ 49 - 0
src/Cameras/Inputs/babylon.arcrotatecamera.input.mousewheel.ts

@@ -0,0 +1,49 @@
+module BABYLON {
+    export class ArcRotateCameraMouseWheelInput implements ICameraInput<ArcRotateCamera> {
+        camera: ArcRotateCamera;
+        attachedElement: HTMLElement;
+
+        private _wheel: (e: MouseWheelEvent) => void;
+
+        @serialize()
+        public wheelPrecision = 3.0;
+
+        public attachCamera(camera: ArcRotateCamera) {
+            this.camera = camera;
+        }
+
+        public attachElement(element: HTMLElement) {
+            this.attachedElement = element;
+            this._wheel = event => {
+                var delta = 0;
+                if (event.wheelDelta) {
+                    delta = event.wheelDelta / (this.wheelPrecision * 40);
+                } else if (event.detail) {
+                    delta = -event.detail / this.wheelPrecision;
+                }
+
+                if (delta)
+                    this.camera.inertialRadiusOffset += delta;
+
+                if (event.preventDefault) {
+                    if (!this.camera._noPreventDefault) {
+                        event.preventDefault();
+                    }
+                }
+            };
+            element.addEventListener('mousewheel', this._wheel, false);
+            element.addEventListener('DOMMouseScroll', this._wheel, false);
+        }
+
+        public detach() {
+            this.attachedElement.removeEventListener('mousewheel', this._wheel);
+            this.attachedElement.removeEventListener('DOMMouseScroll', this._wheel);
+        }
+
+        getTypeName(): string {
+            return "arcrotate.mousewheel";
+        }
+    }
+    
+    CameraInputTypes["arcrotate.mousewheel"] = ArcRotateCameraMouseWheelInput;
+}

+ 190 - 0
src/Cameras/Inputs/babylon.arcrotatecamera.input.pointers.js

@@ -0,0 +1,190 @@
+var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
+    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
+    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
+    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
+    return c > 3 && r && Object.defineProperty(target, key, r), r;
+};
+var BABYLON;
+(function (BABYLON) {
+    var eventPrefix = BABYLON.Tools.GetPointerPrefix();
+    var ArcRotateCameraPointersInput = (function () {
+        function ArcRotateCameraPointersInput() {
+            this._isRightClick = false;
+            this._isCtrlPushed = false;
+            this.pinchInwards = true;
+            this.angularSensibilityX = 1000.0;
+            this.angularSensibilityY = 1000.0;
+            this.pinchPrecision = 6.0;
+            this.panningSensibility = 50.0;
+        }
+        ArcRotateCameraPointersInput.prototype.attachCamera = function (camera) {
+            this.camera = camera;
+        };
+        ArcRotateCameraPointersInput.prototype.attachElement = function (element, noPreventDefault) {
+            var _this = this;
+            this.attachedElement = element;
+            var engine = this.camera.getEngine();
+            var cacheSoloPointer; // cache pointer object for better perf on camera rotation
+            var pointers = new BABYLON.SmartCollection();
+            var previousPinchDistance = 0;
+            if (this._onPointerDown === undefined) {
+                if (!this.camera._useCtrlForPanning) {
+                    element.addEventListener("contextmenu", this._onContextMenu, false);
+                }
+                this._onLostFocus = function () {
+                    //this._keys = [];
+                    pointers.empty();
+                    previousPinchDistance = 0;
+                    cacheSoloPointer = null;
+                };
+                this._onKeyDown = function (evt) {
+                    _this._isCtrlPushed = evt.ctrlKey;
+                };
+                this._onKeyUp = function (evt) {
+                    _this._isCtrlPushed = evt.ctrlKey;
+                };
+                this._onPointerDown = function (evt) {
+                    // Manage panning with right click
+                    _this._isRightClick = evt.button === 2;
+                    // manage pointers
+                    pointers.add(evt.pointerId, { x: evt.clientX, y: evt.clientY, type: evt.pointerType });
+                    cacheSoloPointer = pointers.item(evt.pointerId);
+                    if (!noPreventDefault) {
+                        evt.preventDefault();
+                    }
+                };
+                this._onPointerUp = function (evt) {
+                    cacheSoloPointer = null;
+                    previousPinchDistance = 0;
+                    //would be better to use pointers.remove(evt.pointerId) for multitouch gestures, 
+                    //but emptying completly pointers collection is required to fix a bug on iPhone : 
+                    //when changing orientation while pinching camera, one pointer stay pressed forever if we don't release all pointers  
+                    //will be ok to put back pointers.remove(evt.pointerId); when iPhone bug corrected
+                    pointers.empty();
+                    if (!noPreventDefault) {
+                        evt.preventDefault();
+                    }
+                };
+                this._onContextMenu = function (evt) {
+                    evt.preventDefault();
+                };
+                this._onPointerMove = function (evt) {
+                    if (!noPreventDefault) {
+                        evt.preventDefault();
+                    }
+                    switch (pointers.count) {
+                        case 1:
+                            if (_this.panningSensibility !== 0 && ((_this._isCtrlPushed && _this.camera._useCtrlForPanning) || (!_this.camera._useCtrlForPanning && _this._isRightClick))) {
+                                _this.camera.inertialPanningX += -(evt.clientX - cacheSoloPointer.x) / _this.panningSensibility;
+                                _this.camera.inertialPanningY += (evt.clientY - cacheSoloPointer.y) / _this.panningSensibility;
+                            }
+                            else {
+                                var offsetX = evt.clientX - cacheSoloPointer.x;
+                                var offsetY = evt.clientY - cacheSoloPointer.y;
+                                _this.camera.inertialAlphaOffset -= offsetX / _this.angularSensibilityX;
+                                _this.camera.inertialBetaOffset -= offsetY / _this.angularSensibilityY;
+                            }
+                            cacheSoloPointer.x = evt.clientX;
+                            cacheSoloPointer.y = evt.clientY;
+                            break;
+                        case 2:
+                            //if (noPreventDefault) { evt.preventDefault(); } //if pinch gesture, could be usefull to force preventDefault to avoid html page scroll/zoom in some mobile browsers
+                            pointers.item(evt.pointerId).x = evt.clientX;
+                            pointers.item(evt.pointerId).y = evt.clientY;
+                            var direction = _this.pinchInwards ? 1 : -1;
+                            var distX = pointers.getItemByIndex(0).x - pointers.getItemByIndex(1).x;
+                            var distY = pointers.getItemByIndex(0).y - pointers.getItemByIndex(1).y;
+                            var pinchSquaredDistance = (distX * distX) + (distY * distY);
+                            if (previousPinchDistance === 0) {
+                                previousPinchDistance = pinchSquaredDistance;
+                                return;
+                            }
+                            if (pinchSquaredDistance !== previousPinchDistance) {
+                                _this.camera.inertialRadiusOffset += (pinchSquaredDistance - previousPinchDistance) / (_this.pinchPrecision * ((_this.angularSensibilityX + _this.angularSensibilityY) / 2) * direction);
+                                previousPinchDistance = pinchSquaredDistance;
+                            }
+                            break;
+                        default:
+                            if (pointers.item(evt.pointerId)) {
+                                pointers.item(evt.pointerId).x = evt.clientX;
+                                pointers.item(evt.pointerId).y = evt.clientY;
+                            }
+                    }
+                };
+                this._onMouseMove = function (evt) {
+                    if (!engine.isPointerLock) {
+                        return;
+                    }
+                    var offsetX = evt.movementX || evt.mozMovementX || evt.webkitMovementX || evt.msMovementX || 0;
+                    var offsetY = evt.movementY || evt.mozMovementY || evt.webkitMovementY || evt.msMovementY || 0;
+                    _this.camera.inertialAlphaOffset -= offsetX / _this.angularSensibilityX;
+                    _this.camera.inertialBetaOffset -= offsetY / _this.angularSensibilityY;
+                    if (!noPreventDefault) {
+                        evt.preventDefault();
+                    }
+                };
+                this._onGestureStart = function (e) {
+                    if (window.MSGesture === undefined) {
+                        return;
+                    }
+                    if (!_this._MSGestureHandler) {
+                        _this._MSGestureHandler = new MSGesture();
+                        _this._MSGestureHandler.target = element;
+                    }
+                    _this._MSGestureHandler.addPointer(e.pointerId);
+                };
+                this._onGesture = function (e) {
+                    _this.camera.radius *= e.scale;
+                    if (e.preventDefault) {
+                        if (!noPreventDefault) {
+                            e.stopPropagation();
+                            e.preventDefault();
+                        }
+                    }
+                };
+            }
+            this.attachedElement.addEventListener(eventPrefix + "down", this._onPointerDown, false);
+            this.attachedElement.addEventListener(eventPrefix + "up", this._onPointerUp, false);
+            this.attachedElement.addEventListener(eventPrefix + "out", this._onPointerUp, false);
+            this.attachedElement.addEventListener(eventPrefix + "move", this._onPointerMove, false);
+            this.attachedElement.addEventListener("mousemove", this._onMouseMove, false);
+            this.attachedElement.addEventListener("MSPointerDown", this._onGestureStart, false);
+            this.attachedElement.addEventListener("MSGestureChange", this._onGesture, false);
+            BABYLON.Tools.RegisterTopRootEvents([
+                { name: "blur", handler: this._onLostFocus }
+            ]);
+        };
+        ArcRotateCameraPointersInput.prototype.detach = function () {
+            this._MSGestureHandler = null;
+            this.attachedElement.removeEventListener("contextmenu", this._onContextMenu);
+            this.attachedElement.removeEventListener(eventPrefix + "down", this._onPointerDown);
+            this.attachedElement.removeEventListener(eventPrefix + "up", this._onPointerUp);
+            this.attachedElement.removeEventListener(eventPrefix + "out", this._onPointerUp);
+            this.attachedElement.removeEventListener(eventPrefix + "move", this._onPointerMove);
+            this.attachedElement.removeEventListener("mousemove", this._onMouseMove);
+            this.attachedElement.removeEventListener("MSPointerDown", this._onGestureStart);
+            this.attachedElement.removeEventListener("MSGestureChange", this._onGesture);
+            BABYLON.Tools.UnregisterTopRootEvents([
+                { name: "blur", handler: this._onLostFocus }
+            ]);
+        };
+        ArcRotateCameraPointersInput.prototype.getTypeName = function () {
+            return "arcrotate.pointers";
+        };
+        __decorate([
+            BABYLON.serialize()
+        ], ArcRotateCameraPointersInput.prototype, "angularSensibilityX", void 0);
+        __decorate([
+            BABYLON.serialize()
+        ], ArcRotateCameraPointersInput.prototype, "angularSensibilityY", void 0);
+        __decorate([
+            BABYLON.serialize()
+        ], ArcRotateCameraPointersInput.prototype, "pinchPrecision", void 0);
+        __decorate([
+            BABYLON.serialize()
+        ], ArcRotateCameraPointersInput.prototype, "panningSensibility", void 0);
+        return ArcRotateCameraPointersInput;
+    }());
+    BABYLON.ArcRotateCameraPointersInput = ArcRotateCameraPointersInput;
+    BABYLON.CameraInputTypes["arcrotate.pointers"] = ArcRotateCameraPointersInput;
+})(BABYLON || (BABYLON = {}));

+ 225 - 0
src/Cameras/Inputs/babylon.arcrotatecamera.input.pointers.ts

@@ -0,0 +1,225 @@
+module BABYLON {
+    var eventPrefix = Tools.GetPointerPrefix();
+
+    export class ArcRotateCameraPointersInput implements ICameraInput<ArcRotateCamera> {
+        camera: ArcRotateCamera;
+        attachedElement: HTMLElement;
+        private _isRightClick: boolean = false;
+        private _isCtrlPushed: boolean = false;
+        public pinchInwards = true;
+        
+        @serialize()
+        public angularSensibilityX = 1000.0;
+
+        @serialize()
+        public angularSensibilityY = 1000.0;
+
+        @serialize()
+        public pinchPrecision = 6.0;
+
+        @serialize()
+        public panningSensibility: number = 50.0;       
+
+        private _onKeyDown: (e: KeyboardEvent) => any;
+        private _onKeyUp: (e: KeyboardEvent) => any;
+        private _onPointerDown: (e: PointerEvent) => void;
+        private _onPointerUp: (e: PointerEvent) => void;
+        private _onPointerMove: (e: PointerEvent) => void;
+        private _onMouseMove: (e: MouseEvent) => any;
+        private _onGestureStart: (e: PointerEvent) => void;
+        private _onGesture: (e: MSGestureEvent) => void;
+        private _MSGestureHandler: MSGesture;
+        private _onLostFocus: (e: FocusEvent) => any;
+        private _onContextMenu: (e: PointerEvent) => void;
+        
+        public attachCamera(camera: ArcRotateCamera) {
+            this.camera = camera;
+
+        }
+
+        public attachElement(element: HTMLElement, noPreventDefault?: boolean) {
+            this.attachedElement = element;
+
+            var engine = this.camera.getEngine();
+            var cacheSoloPointer; // cache pointer object for better perf on camera rotation
+            var pointers = new SmartCollection();
+            var previousPinchDistance = 0;
+
+            if (this._onPointerDown === undefined) {
+                if (!this.camera._useCtrlForPanning) {
+                    element.addEventListener("contextmenu", this._onContextMenu, false);
+                }
+                
+                this._onLostFocus = () => {
+                    //this._keys = [];
+                    pointers.empty();
+                    previousPinchDistance = 0;
+                    cacheSoloPointer = null;
+                };
+
+                this._onKeyDown = evt => {
+                    this._isCtrlPushed = evt.ctrlKey;
+                };
+
+                this._onKeyUp = evt => {
+                    this._isCtrlPushed = evt.ctrlKey;
+                };
+
+                this._onPointerDown = evt => {
+                    // Manage panning with right click
+                    this._isRightClick = evt.button === 2;
+
+                    // manage pointers
+                    pointers.add(evt.pointerId, { x: evt.clientX, y: evt.clientY, type: evt.pointerType });
+                    cacheSoloPointer = pointers.item(evt.pointerId);
+                    if (!noPreventDefault) {
+                        evt.preventDefault();
+                    }
+                };
+
+                this._onPointerUp = evt => {
+                    cacheSoloPointer = null;
+                    previousPinchDistance = 0;
+
+                    //would be better to use pointers.remove(evt.pointerId) for multitouch gestures, 
+                    //but emptying completly pointers collection is required to fix a bug on iPhone : 
+                    //when changing orientation while pinching camera, one pointer stay pressed forever if we don't release all pointers  
+                    //will be ok to put back pointers.remove(evt.pointerId); when iPhone bug corrected
+                    pointers.empty();
+
+                    if (!noPreventDefault) {
+                        evt.preventDefault();
+                    }
+                };
+
+                this._onContextMenu = evt => {
+                    evt.preventDefault();
+                };
+
+                this._onPointerMove = evt => {
+                    if (!noPreventDefault) {
+                        evt.preventDefault();
+                    }
+
+                    switch (pointers.count) {
+
+                        case 1: //normal camera rotation
+                            if (this.panningSensibility !== 0 && ((this._isCtrlPushed && this.camera._useCtrlForPanning) || (!this.camera._useCtrlForPanning && this._isRightClick))) {
+                                this.camera.inertialPanningX += -(evt.clientX - cacheSoloPointer.x) / this.panningSensibility;
+                                this.camera.inertialPanningY += (evt.clientY - cacheSoloPointer.y) / this.panningSensibility;
+                            } else {
+                                var offsetX = evt.clientX - cacheSoloPointer.x;
+                                var offsetY = evt.clientY - cacheSoloPointer.y;
+                                this.camera.inertialAlphaOffset -= offsetX / this.angularSensibilityX;
+                                this.camera.inertialBetaOffset -= offsetY / this.angularSensibilityY;
+                            }
+                            cacheSoloPointer.x = evt.clientX;
+                            cacheSoloPointer.y = evt.clientY;
+                            break;
+
+                        case 2: //pinch
+                            //if (noPreventDefault) { evt.preventDefault(); } //if pinch gesture, could be usefull to force preventDefault to avoid html page scroll/zoom in some mobile browsers
+                            pointers.item(evt.pointerId).x = evt.clientX;
+                            pointers.item(evt.pointerId).y = evt.clientY;
+                            var direction = this.pinchInwards ? 1 : -1;
+                            var distX = pointers.getItemByIndex(0).x - pointers.getItemByIndex(1).x;
+                            var distY = pointers.getItemByIndex(0).y - pointers.getItemByIndex(1).y;
+                            var pinchSquaredDistance = (distX * distX) + (distY * distY);
+                            if (previousPinchDistance === 0) {
+                                previousPinchDistance = pinchSquaredDistance;
+                                return;
+                            }
+
+                            if (pinchSquaredDistance !== previousPinchDistance) {
+                                this.camera.inertialRadiusOffset += (pinchSquaredDistance - previousPinchDistance) / (this.pinchPrecision * ((this.angularSensibilityX + this.angularSensibilityY) / 2) * direction);
+                                previousPinchDistance = pinchSquaredDistance;
+                            }
+                            break;
+
+                        default:
+                            if (pointers.item(evt.pointerId)) {
+                                pointers.item(evt.pointerId).x = evt.clientX;
+                                pointers.item(evt.pointerId).y = evt.clientY;
+                            }
+                    }
+                };
+
+                this._onMouseMove = evt => {
+                    if (!engine.isPointerLock) {
+                        return;
+                    }
+
+                    var offsetX = evt.movementX || evt.mozMovementX || evt.webkitMovementX || evt.msMovementX || 0;
+                    var offsetY = evt.movementY || evt.mozMovementY || evt.webkitMovementY || evt.msMovementY || 0;
+
+                    this.camera.inertialAlphaOffset -= offsetX / this.angularSensibilityX;
+                    this.camera.inertialBetaOffset -= offsetY / this.angularSensibilityY;
+
+                    if (!noPreventDefault) {
+                        evt.preventDefault();
+                    }
+                };
+
+                this._onGestureStart = e => {
+                    if (window.MSGesture === undefined) {
+                        return;
+                    }
+
+                    if (!this._MSGestureHandler) {
+                        this._MSGestureHandler = new MSGesture();
+                        this._MSGestureHandler.target = element;
+                    }
+
+                    this._MSGestureHandler.addPointer(e.pointerId);
+                };
+
+                this._onGesture = e => {
+                    this.camera.radius *= e.scale;
+
+
+                    if (e.preventDefault) {
+                        if (!noPreventDefault) {
+                            e.stopPropagation();
+                            e.preventDefault();
+                        }
+                    }
+                };
+            }
+
+            this.attachedElement.addEventListener(eventPrefix + "down", this._onPointerDown, false);
+            this.attachedElement.addEventListener(eventPrefix + "up", this._onPointerUp, false);
+            this.attachedElement.addEventListener(eventPrefix + "out", this._onPointerUp, false);
+            this.attachedElement.addEventListener(eventPrefix + "move", this._onPointerMove, false);
+            this.attachedElement.addEventListener("mousemove", this._onMouseMove, false);
+            this.attachedElement.addEventListener("MSPointerDown", this._onGestureStart, false);
+            this.attachedElement.addEventListener("MSGestureChange", this._onGesture, false);
+
+            Tools.RegisterTopRootEvents([
+                { name: "blur", handler: this._onLostFocus }
+            ]);
+        }
+
+        public detach() {
+            this._MSGestureHandler = null;
+
+            this.attachedElement.removeEventListener("contextmenu", this._onContextMenu);
+            this.attachedElement.removeEventListener(eventPrefix + "down", this._onPointerDown);
+            this.attachedElement.removeEventListener(eventPrefix + "up", this._onPointerUp);
+            this.attachedElement.removeEventListener(eventPrefix + "out", this._onPointerUp);
+            this.attachedElement.removeEventListener(eventPrefix + "move", this._onPointerMove);
+            this.attachedElement.removeEventListener("mousemove", this._onMouseMove);
+            this.attachedElement.removeEventListener("MSPointerDown", this._onGestureStart);
+            this.attachedElement.removeEventListener("MSGestureChange", this._onGesture);
+
+            Tools.UnregisterTopRootEvents([
+                { name: "blur", handler: this._onLostFocus }
+            ]);
+        }        
+
+        getTypeName(): string {
+            return "arcrotate.pointers";
+        }
+    }
+    
+    CameraInputTypes["arcrotate.pointers"] = ArcRotateCameraPointersInput;
+}

+ 62 - 65
src/Cameras/Inputs/babylon.freecamera.input.deviceorientation.js

@@ -6,70 +6,67 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
 };
 var BABYLON;
 (function (BABYLON) {
-    var CameraInputs;
-    (function (CameraInputs) {
-        var FreeCameraDeviceOrientationInput = (function () {
-            function FreeCameraDeviceOrientationInput() {
-                this._offsetX = null;
-                this._offsetY = null;
-                this._orientationGamma = 0;
-                this._orientationBeta = 0;
-                this._initialOrientationGamma = 0;
-                this._initialOrientationBeta = 0;
-                this.angularSensibility = 10000.0;
-                this.moveSensibility = 50.0;
-                this._resetOrientationGamma = this.resetOrientationGamma.bind(this);
-                this._orientationChanged = this.orientationChanged.bind(this);
+    var FreeCameraDeviceOrientationInput = (function () {
+        function FreeCameraDeviceOrientationInput() {
+            this._offsetX = null;
+            this._offsetY = null;
+            this._orientationGamma = 0;
+            this._orientationBeta = 0;
+            this._initialOrientationGamma = 0;
+            this._initialOrientationBeta = 0;
+            this.angularSensibility = 10000.0;
+            this.moveSensibility = 50.0;
+            this._resetOrientationGamma = this.resetOrientationGamma.bind(this);
+            this._orientationChanged = this.orientationChanged.bind(this);
+        }
+        FreeCameraDeviceOrientationInput.prototype.attachCamera = function (camera) {
+            this.camera = camera;
+            window.addEventListener("resize", this._resetOrientationGamma, false);
+            window.addEventListener("deviceorientation", this._orientationChanged);
+        };
+        FreeCameraDeviceOrientationInput.prototype.resetOrientationGamma = function () {
+            this._initialOrientationGamma = null;
+        };
+        FreeCameraDeviceOrientationInput.prototype.orientationChanged = function (evt) {
+            if (!this._initialOrientationGamma) {
+                this._initialOrientationGamma = evt.gamma;
+                this._initialOrientationBeta = evt.beta;
             }
-            FreeCameraDeviceOrientationInput.prototype.attachCamera = function (camera) {
-                this.camera = camera;
-                window.addEventListener("resize", this._resetOrientationGamma, false);
-                window.addEventListener("deviceorientation", this._orientationChanged);
-            };
-            FreeCameraDeviceOrientationInput.prototype.resetOrientationGamma = function () {
-                this._initialOrientationGamma = null;
-            };
-            FreeCameraDeviceOrientationInput.prototype.orientationChanged = function (evt) {
-                if (!this._initialOrientationGamma) {
-                    this._initialOrientationGamma = evt.gamma;
-                    this._initialOrientationBeta = evt.beta;
-                }
-                this._orientationGamma = evt.gamma;
-                this._orientationBeta = evt.beta;
-                this._offsetY = (this._initialOrientationBeta - this._orientationBeta);
-                this._offsetX = (this._initialOrientationGamma - this._orientationGamma);
-            };
-            FreeCameraDeviceOrientationInput.prototype.detach = function () {
-                window.removeEventListener("resize", this._resetOrientationGamma);
-                window.removeEventListener("deviceorientation", this._orientationChanged);
-                this._orientationGamma = 0;
-                this._orientationBeta = 0;
-                this._initialOrientationGamma = 0;
-                this._initialOrientationBeta = 0;
-            };
-            FreeCameraDeviceOrientationInput.prototype.checkInputs = function () {
-                if (!this._offsetX) {
-                    return;
-                }
-                var camera = this.camera;
-                camera.cameraRotation.y -= this._offsetX / this.angularSensibility;
-                var speed = camera._computeLocalCameraSpeed();
-                var direction = new BABYLON.Vector3(0, 0, speed * this._offsetY / this.moveSensibility);
-                BABYLON.Matrix.RotationYawPitchRollToRef(camera.rotation.y, camera.rotation.x, 0, camera._cameraRotationMatrix);
-                camera.cameraDirection.addInPlace(BABYLON.Vector3.TransformCoordinates(direction, camera._cameraRotationMatrix));
-            };
-            FreeCameraDeviceOrientationInput.prototype.getTypeName = function () {
-                return "freecamera.deviceorientation";
-            };
-            __decorate([
-                BABYLON.serialize()
-            ], FreeCameraDeviceOrientationInput.prototype, "angularSensibility", void 0);
-            __decorate([
-                BABYLON.serialize()
-            ], FreeCameraDeviceOrientationInput.prototype, "moveSensibility", void 0);
-            return FreeCameraDeviceOrientationInput;
-        }());
-        CameraInputs.FreeCameraDeviceOrientationInput = FreeCameraDeviceOrientationInput;
-        CameraInputs.InputTypes["freecamera.deviceorientation"] = FreeCameraDeviceOrientationInput;
-    })(CameraInputs = BABYLON.CameraInputs || (BABYLON.CameraInputs = {}));
+            this._orientationGamma = evt.gamma;
+            this._orientationBeta = evt.beta;
+            this._offsetY = (this._initialOrientationBeta - this._orientationBeta);
+            this._offsetX = (this._initialOrientationGamma - this._orientationGamma);
+        };
+        FreeCameraDeviceOrientationInput.prototype.detach = function () {
+            window.removeEventListener("resize", this._resetOrientationGamma);
+            window.removeEventListener("deviceorientation", this._orientationChanged);
+            this._orientationGamma = 0;
+            this._orientationBeta = 0;
+            this._initialOrientationGamma = 0;
+            this._initialOrientationBeta = 0;
+        };
+        FreeCameraDeviceOrientationInput.prototype.checkInputs = function () {
+            if (!this._offsetX) {
+                return;
+            }
+            var camera = this.camera;
+            camera.cameraRotation.y -= this._offsetX / this.angularSensibility;
+            var speed = camera._computeLocalCameraSpeed();
+            var direction = new BABYLON.Vector3(0, 0, speed * this._offsetY / this.moveSensibility);
+            BABYLON.Matrix.RotationYawPitchRollToRef(camera.rotation.y, camera.rotation.x, 0, camera._cameraRotationMatrix);
+            camera.cameraDirection.addInPlace(BABYLON.Vector3.TransformCoordinates(direction, camera._cameraRotationMatrix));
+        };
+        FreeCameraDeviceOrientationInput.prototype.getTypeName = function () {
+            return "freecamera.deviceorientation";
+        };
+        __decorate([
+            BABYLON.serialize()
+        ], FreeCameraDeviceOrientationInput.prototype, "angularSensibility", void 0);
+        __decorate([
+            BABYLON.serialize()
+        ], FreeCameraDeviceOrientationInput.prototype, "moveSensibility", void 0);
+        return FreeCameraDeviceOrientationInput;
+    }());
+    BABYLON.FreeCameraDeviceOrientationInput = FreeCameraDeviceOrientationInput;
+    BABYLON.CameraInputTypes["freecamera.deviceorientation"] = FreeCameraDeviceOrientationInput;
 })(BABYLON || (BABYLON = {}));

+ 2 - 2
src/Cameras/Inputs/babylon.freecamera.input.deviceorientation.ts

@@ -1,4 +1,4 @@
-module BABYLON.CameraInputs {
+module BABYLON {
     export class FreeCameraDeviceOrientationInput implements ICameraInput<FreeCamera> {
         camera: FreeCamera;
 
@@ -76,5 +76,5 @@ module BABYLON.CameraInputs {
         }
     }
     
-    InputTypes["freecamera.deviceorientation"] = FreeCameraDeviceOrientationInput;
+    CameraInputTypes["freecamera.deviceorientation"] = FreeCameraDeviceOrientationInput;
 }

+ 50 - 53
src/Cameras/Inputs/babylon.freecamera.input.gamepad.js

@@ -6,58 +6,55 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
 };
 var BABYLON;
 (function (BABYLON) {
-    var CameraInputs;
-    (function (CameraInputs) {
-        var FreeCameraGamepadInput = (function () {
-            function FreeCameraGamepadInput() {
-                var _this = this;
-                this.gamepadAngularSensibility = 200;
-                this.gamepadMoveSensibility = 40;
-                this._gamepads = new BABYLON.Gamepads(function (gamepad) { _this._onNewGameConnected(gamepad); });
+    var FreeCameraGamepadInput = (function () {
+        function FreeCameraGamepadInput() {
+            var _this = this;
+            this.gamepadAngularSensibility = 200;
+            this.gamepadMoveSensibility = 40;
+            this._gamepads = new BABYLON.Gamepads(function (gamepad) { _this._onNewGameConnected(gamepad); });
+        }
+        FreeCameraGamepadInput.prototype.attachCamera = function (camera) {
+            this.camera = camera;
+        };
+        FreeCameraGamepadInput.prototype.detach = function () {
+        };
+        FreeCameraGamepadInput.prototype.checkInputs = function () {
+            if (this.gamepad) {
+                var camera = this.camera;
+                var LSValues = this.gamepad.leftStick;
+                var normalizedLX = LSValues.x / this.gamepadMoveSensibility;
+                var normalizedLY = LSValues.y / this.gamepadMoveSensibility;
+                LSValues.x = Math.abs(normalizedLX) > 0.005 ? 0 + normalizedLX : 0;
+                LSValues.y = Math.abs(normalizedLY) > 0.005 ? 0 + normalizedLY : 0;
+                var RSValues = this.gamepad.rightStick;
+                var normalizedRX = RSValues.x / this.gamepadAngularSensibility;
+                var normalizedRY = RSValues.y / this.gamepadAngularSensibility;
+                RSValues.x = Math.abs(normalizedRX) > 0.001 ? 0 + normalizedRX : 0;
+                RSValues.y = Math.abs(normalizedRY) > 0.001 ? 0 + normalizedRY : 0;
+                var cameraTransform = BABYLON.Matrix.RotationYawPitchRoll(camera.rotation.y, camera.rotation.x, 0);
+                var speed = camera._computeLocalCameraSpeed() * 50.0;
+                var deltaTransform = BABYLON.Vector3.TransformCoordinates(new BABYLON.Vector3(LSValues.x * speed, 0, -LSValues.y * speed), cameraTransform);
+                camera.cameraDirection = camera.cameraDirection.add(deltaTransform);
+                camera.cameraRotation = camera.cameraRotation.add(new BABYLON.Vector2(RSValues.y, RSValues.x));
             }
-            FreeCameraGamepadInput.prototype.attachCamera = function (camera) {
-                this.camera = camera;
-            };
-            FreeCameraGamepadInput.prototype.detach = function () {
-            };
-            FreeCameraGamepadInput.prototype.checkInputs = function () {
-                if (this.gamepad) {
-                    var camera = this.camera;
-                    var LSValues = this.gamepad.leftStick;
-                    var normalizedLX = LSValues.x / this.gamepadMoveSensibility;
-                    var normalizedLY = LSValues.y / this.gamepadMoveSensibility;
-                    LSValues.x = Math.abs(normalizedLX) > 0.005 ? 0 + normalizedLX : 0;
-                    LSValues.y = Math.abs(normalizedLY) > 0.005 ? 0 + normalizedLY : 0;
-                    var RSValues = this.gamepad.rightStick;
-                    var normalizedRX = RSValues.x / this.gamepadAngularSensibility;
-                    var normalizedRY = RSValues.y / this.gamepadAngularSensibility;
-                    RSValues.x = Math.abs(normalizedRX) > 0.001 ? 0 + normalizedRX : 0;
-                    RSValues.y = Math.abs(normalizedRY) > 0.001 ? 0 + normalizedRY : 0;
-                    var cameraTransform = BABYLON.Matrix.RotationYawPitchRoll(camera.rotation.y, camera.rotation.x, 0);
-                    var speed = camera._computeLocalCameraSpeed() * 50.0;
-                    var deltaTransform = BABYLON.Vector3.TransformCoordinates(new BABYLON.Vector3(LSValues.x * speed, 0, -LSValues.y * speed), cameraTransform);
-                    camera.cameraDirection = camera.cameraDirection.add(deltaTransform);
-                    camera.cameraRotation = camera.cameraRotation.add(new BABYLON.Vector2(RSValues.y, RSValues.x));
-                }
-            };
-            FreeCameraGamepadInput.prototype._onNewGameConnected = function (gamepad) {
-                // Only the first gamepad can control the camera
-                if (gamepad.index === 0) {
-                    this.gamepad = gamepad;
-                }
-            };
-            FreeCameraGamepadInput.prototype.getTypeName = function () {
-                return "freecamera.gamepad";
-            };
-            __decorate([
-                BABYLON.serialize()
-            ], FreeCameraGamepadInput.prototype, "gamepadAngularSensibility", void 0);
-            __decorate([
-                BABYLON.serialize()
-            ], FreeCameraGamepadInput.prototype, "gamepadMoveSensibility", void 0);
-            return FreeCameraGamepadInput;
-        }());
-        CameraInputs.FreeCameraGamepadInput = FreeCameraGamepadInput;
-        CameraInputs.InputTypes["freecamera.gamepad"] = FreeCameraGamepadInput;
-    })(CameraInputs = BABYLON.CameraInputs || (BABYLON.CameraInputs = {}));
+        };
+        FreeCameraGamepadInput.prototype._onNewGameConnected = function (gamepad) {
+            // Only the first gamepad can control the camera
+            if (gamepad.index === 0) {
+                this.gamepad = gamepad;
+            }
+        };
+        FreeCameraGamepadInput.prototype.getTypeName = function () {
+            return "freecamera.gamepad";
+        };
+        __decorate([
+            BABYLON.serialize()
+        ], FreeCameraGamepadInput.prototype, "gamepadAngularSensibility", void 0);
+        __decorate([
+            BABYLON.serialize()
+        ], FreeCameraGamepadInput.prototype, "gamepadMoveSensibility", void 0);
+        return FreeCameraGamepadInput;
+    }());
+    BABYLON.FreeCameraGamepadInput = FreeCameraGamepadInput;
+    BABYLON.CameraInputTypes["freecamera.gamepad"] = FreeCameraGamepadInput;
 })(BABYLON || (BABYLON = {}));

+ 2 - 2
src/Cameras/Inputs/babylon.freecamera.input.gamepad.ts

@@ -1,4 +1,4 @@
-module BABYLON.CameraInputs {       
+module BABYLON {       
     export class FreeCameraGamepadInput implements ICameraInput<FreeCamera> {
         camera : FreeCamera;
         
@@ -59,5 +59,5 @@ module BABYLON.CameraInputs {
         }
     }
     
-    InputTypes["freecamera.gamepad"] = FreeCameraGamepadInput;
+    CameraInputTypes["freecamera.gamepad"] = FreeCameraGamepadInput;
 }

+ 92 - 95
src/Cameras/Inputs/babylon.freecamera.input.keyboard.js

@@ -6,106 +6,103 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
 };
 var BABYLON;
 (function (BABYLON) {
-    var CameraInputs;
-    (function (CameraInputs) {
-        var FreeCameraKeyboardMoveInput = (function () {
-            function FreeCameraKeyboardMoveInput() {
-                this._keys = [];
-                this.keysUp = [38];
-                this.keysDown = [40];
-                this.keysLeft = [37];
-                this.keysRight = [39];
-            }
-            FreeCameraKeyboardMoveInput.prototype.attachCamera = function (camera) {
-                var _this = this;
-                this.camera = camera;
-                if (this._onKeyDown === undefined) {
-                    this._onKeyDown = function (evt) {
-                        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) {
-                            var index = _this._keys.indexOf(evt.keyCode);
-                            if (index === -1) {
-                                _this._keys.push(evt.keyCode);
-                            }
-                            if (!camera._noPreventDefault) {
-                                evt.preventDefault();
-                            }
+    var FreeCameraKeyboardMoveInput = (function () {
+        function FreeCameraKeyboardMoveInput() {
+            this._keys = [];
+            this.keysUp = [38];
+            this.keysDown = [40];
+            this.keysLeft = [37];
+            this.keysRight = [39];
+        }
+        FreeCameraKeyboardMoveInput.prototype.attachCamera = function (camera) {
+            var _this = this;
+            this.camera = camera;
+            if (this._onKeyDown === undefined) {
+                this._onKeyDown = function (evt) {
+                    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) {
+                        var index = _this._keys.indexOf(evt.keyCode);
+                        if (index === -1) {
+                            _this._keys.push(evt.keyCode);
                         }
-                    };
-                    this._onKeyUp = function (evt) {
-                        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) {
-                            var index = _this._keys.indexOf(evt.keyCode);
-                            if (index >= 0) {
-                                _this._keys.splice(index, 1);
-                            }
-                            if (!camera._noPreventDefault) {
-                                evt.preventDefault();
-                            }
+                        if (!camera._noPreventDefault) {
+                            evt.preventDefault();
                         }
-                    };
-                    BABYLON.Tools.RegisterTopRootEvents([
-                        { name: "keydown", handler: this._onKeyDown },
-                        { name: "keyup", handler: this._onKeyUp },
-                        { name: "blur", handler: this._onLostFocus }
-                    ]);
-                }
-            };
-            FreeCameraKeyboardMoveInput.prototype.detach = function () {
-                BABYLON.Tools.UnregisterTopRootEvents([
+                    }
+                };
+                this._onKeyUp = function (evt) {
+                    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) {
+                        var index = _this._keys.indexOf(evt.keyCode);
+                        if (index >= 0) {
+                            _this._keys.splice(index, 1);
+                        }
+                        if (!camera._noPreventDefault) {
+                            evt.preventDefault();
+                        }
+                    }
+                };
+                BABYLON.Tools.RegisterTopRootEvents([
                     { name: "keydown", handler: this._onKeyDown },
                     { name: "keyup", handler: this._onKeyUp },
                     { name: "blur", handler: this._onLostFocus }
                 ]);
-            };
-            FreeCameraKeyboardMoveInput.prototype.checkInputs = function () {
-                var camera = this.camera;
-                // Keyboard
-                for (var index = 0; index < this._keys.length; index++) {
-                    var keyCode = this._keys[index];
-                    var speed = camera._computeLocalCameraSpeed();
-                    if (this.keysLeft.indexOf(keyCode) !== -1) {
-                        camera._localDirection.copyFromFloats(-speed, 0, 0);
-                    }
-                    else if (this.keysUp.indexOf(keyCode) !== -1) {
-                        camera._localDirection.copyFromFloats(0, 0, speed);
-                    }
-                    else if (this.keysRight.indexOf(keyCode) !== -1) {
-                        camera._localDirection.copyFromFloats(speed, 0, 0);
-                    }
-                    else if (this.keysDown.indexOf(keyCode) !== -1) {
-                        camera._localDirection.copyFromFloats(0, 0, -speed);
-                    }
-                    camera.getViewMatrix().invertToRef(camera._cameraTransformMatrix);
-                    BABYLON.Vector3.TransformNormalToRef(camera._localDirection, camera._cameraTransformMatrix, camera._transformedDirection);
-                    camera.cameraDirection.addInPlace(camera._transformedDirection);
+            }
+        };
+        FreeCameraKeyboardMoveInput.prototype.detach = function () {
+            BABYLON.Tools.UnregisterTopRootEvents([
+                { name: "keydown", handler: this._onKeyDown },
+                { name: "keyup", handler: this._onKeyUp },
+                { name: "blur", handler: this._onLostFocus }
+            ]);
+        };
+        FreeCameraKeyboardMoveInput.prototype.checkInputs = function () {
+            var camera = this.camera;
+            // Keyboard
+            for (var index = 0; index < this._keys.length; index++) {
+                var keyCode = this._keys[index];
+                var speed = camera._computeLocalCameraSpeed();
+                if (this.keysLeft.indexOf(keyCode) !== -1) {
+                    camera._localDirection.copyFromFloats(-speed, 0, 0);
+                }
+                else if (this.keysUp.indexOf(keyCode) !== -1) {
+                    camera._localDirection.copyFromFloats(0, 0, speed);
                 }
-            };
-            FreeCameraKeyboardMoveInput.prototype.getTypeName = function () {
-                return "freecamera.keyboardmove";
-            };
-            FreeCameraKeyboardMoveInput.prototype._onLostFocus = function (e) {
-                this._keys = [];
-            };
-            __decorate([
-                BABYLON.serialize()
-            ], FreeCameraKeyboardMoveInput.prototype, "keysUp", void 0);
-            __decorate([
-                BABYLON.serialize()
-            ], FreeCameraKeyboardMoveInput.prototype, "keysDown", void 0);
-            __decorate([
-                BABYLON.serialize()
-            ], FreeCameraKeyboardMoveInput.prototype, "keysLeft", void 0);
-            __decorate([
-                BABYLON.serialize()
-            ], FreeCameraKeyboardMoveInput.prototype, "keysRight", void 0);
-            return FreeCameraKeyboardMoveInput;
-        }());
-        CameraInputs.FreeCameraKeyboardMoveInput = FreeCameraKeyboardMoveInput;
-        CameraInputs.InputTypes["freecamera.keyboardmove"] = FreeCameraKeyboardMoveInput;
-    })(CameraInputs = BABYLON.CameraInputs || (BABYLON.CameraInputs = {}));
+                else if (this.keysRight.indexOf(keyCode) !== -1) {
+                    camera._localDirection.copyFromFloats(speed, 0, 0);
+                }
+                else if (this.keysDown.indexOf(keyCode) !== -1) {
+                    camera._localDirection.copyFromFloats(0, 0, -speed);
+                }
+                camera.getViewMatrix().invertToRef(camera._cameraTransformMatrix);
+                BABYLON.Vector3.TransformNormalToRef(camera._localDirection, camera._cameraTransformMatrix, camera._transformedDirection);
+                camera.cameraDirection.addInPlace(camera._transformedDirection);
+            }
+        };
+        FreeCameraKeyboardMoveInput.prototype.getTypeName = function () {
+            return "freecamera.keyboardmove";
+        };
+        FreeCameraKeyboardMoveInput.prototype._onLostFocus = function (e) {
+            this._keys = [];
+        };
+        __decorate([
+            BABYLON.serialize()
+        ], FreeCameraKeyboardMoveInput.prototype, "keysUp", void 0);
+        __decorate([
+            BABYLON.serialize()
+        ], FreeCameraKeyboardMoveInput.prototype, "keysDown", void 0);
+        __decorate([
+            BABYLON.serialize()
+        ], FreeCameraKeyboardMoveInput.prototype, "keysLeft", void 0);
+        __decorate([
+            BABYLON.serialize()
+        ], FreeCameraKeyboardMoveInput.prototype, "keysRight", void 0);
+        return FreeCameraKeyboardMoveInput;
+    }());
+    BABYLON.FreeCameraKeyboardMoveInput = FreeCameraKeyboardMoveInput;
+    BABYLON.CameraInputTypes["freecamera.keyboardmove"] = FreeCameraKeyboardMoveInput;
 })(BABYLON || (BABYLON = {}));

+ 2 - 2
src/Cameras/Inputs/babylon.freecamera.input.keyboard.ts

@@ -1,4 +1,4 @@
-module BABYLON.CameraInputs {
+module BABYLON {
     export class FreeCameraKeyboardMoveInput implements ICameraInput<FreeCamera> {
         camera: FreeCamera;
         private _keys = [];
@@ -102,5 +102,5 @@ module BABYLON.CameraInputs {
         }
     }
     
-    InputTypes["freecamera.keyboardmove"] = FreeCameraKeyboardMoveInput;
+    CameraInputTypes["freecamera.keyboardmove"] = FreeCameraKeyboardMoveInput;
 }

+ 88 - 91
src/Cameras/Inputs/babylon.freecamera.input.mouse.js

@@ -6,97 +6,94 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
 };
 var BABYLON;
 (function (BABYLON) {
-    var CameraInputs;
-    (function (CameraInputs) {
-        var FreeCameraMouseInput = (function () {
-            function FreeCameraMouseInput() {
-                this.angularSensibility = 2000.0;
-            }
-            FreeCameraMouseInput.prototype.attachCamera = function (camera) {
-                this.camera = camera;
-            };
-            FreeCameraMouseInput.prototype.attachElement = function (element, noPreventDefault) {
-                var _this = this;
-                var previousPosition;
-                this.attachedElement = element;
-                if (this._onMouseDown === undefined) {
-                    var camera = this.camera;
-                    var engine = this.camera.getEngine();
-                    this._onMouseDown = function (evt) {
-                        previousPosition = {
-                            x: evt.clientX,
-                            y: evt.clientY
-                        };
-                        if (!noPreventDefault) {
-                            evt.preventDefault();
-                        }
-                    };
-                    this._onMouseUp = function (evt) {
-                        previousPosition = null;
-                        if (!noPreventDefault) {
-                            evt.preventDefault();
-                        }
-                    };
-                    this._onMouseOut = function (evt) {
-                        previousPosition = null;
-                        if (!noPreventDefault) {
-                            evt.preventDefault();
-                        }
+    var FreeCameraMouseInput = (function () {
+        function FreeCameraMouseInput() {
+            this.angularSensibility = 2000.0;
+        }
+        FreeCameraMouseInput.prototype.attachCamera = function (camera) {
+            this.camera = camera;
+        };
+        FreeCameraMouseInput.prototype.attachElement = function (element, noPreventDefault) {
+            var _this = this;
+            var previousPosition;
+            this.attachedElement = element;
+            if (this._onMouseDown === undefined) {
+                var camera = this.camera;
+                var engine = this.camera.getEngine();
+                this._onMouseDown = function (evt) {
+                    previousPosition = {
+                        x: evt.clientX,
+                        y: evt.clientY
                     };
-                    this._onMouseMove = function (evt) {
-                        if (!previousPosition && !engine.isPointerLock) {
-                            return;
-                        }
-                        var offsetX;
-                        var offsetY;
-                        if (!engine.isPointerLock) {
-                            offsetX = evt.clientX - previousPosition.x;
-                            offsetY = evt.clientY - previousPosition.y;
-                        }
-                        else {
-                            offsetX = evt.movementX || evt.mozMovementX || evt.webkitMovementX || evt.msMovementX || 0;
-                            offsetY = evt.movementY || evt.mozMovementY || evt.webkitMovementY || evt.msMovementY || 0;
-                        }
-                        camera.cameraRotation.y += offsetX / _this.angularSensibility;
-                        camera.cameraRotation.x += offsetY / _this.angularSensibility;
-                        previousPosition = {
-                            x: evt.clientX,
-                            y: evt.clientY
-                        };
-                        if (!noPreventDefault) {
-                            evt.preventDefault();
-                        }
+                    if (!noPreventDefault) {
+                        evt.preventDefault();
+                    }
+                };
+                this._onMouseUp = function (evt) {
+                    previousPosition = null;
+                    if (!noPreventDefault) {
+                        evt.preventDefault();
+                    }
+                };
+                this._onMouseOut = function (evt) {
+                    previousPosition = null;
+                    if (!noPreventDefault) {
+                        evt.preventDefault();
+                    }
+                };
+                this._onMouseMove = function (evt) {
+                    if (!previousPosition && !engine.isPointerLock) {
+                        return;
+                    }
+                    var offsetX;
+                    var offsetY;
+                    if (!engine.isPointerLock) {
+                        offsetX = evt.clientX - previousPosition.x;
+                        offsetY = evt.clientY - previousPosition.y;
+                    }
+                    else {
+                        offsetX = evt.movementX || evt.mozMovementX || evt.webkitMovementX || evt.msMovementX || 0;
+                        offsetY = evt.movementY || evt.mozMovementY || evt.webkitMovementY || evt.msMovementY || 0;
+                    }
+                    camera.cameraRotation.y += offsetX / _this.angularSensibility;
+                    camera.cameraRotation.x += offsetY / _this.angularSensibility;
+                    previousPosition = {
+                        x: evt.clientX,
+                        y: evt.clientY
                     };
-                }
-                element.addEventListener("mousedown", this._onMouseDown, false);
-                element.addEventListener("mouseup", this._onMouseUp, false);
-                element.addEventListener("mouseout", this._onMouseOut, false);
-                element.addEventListener("mousemove", this._onMouseMove, false);
-            };
-            FreeCameraMouseInput.prototype.detachElement = function (element) {
-                if (this.attachedElement !== element) {
-                    return;
-                }
-                element.removeEventListener("mousedown", this._onMouseDown);
-                element.removeEventListener("mouseup", this._onMouseUp);
-                element.removeEventListener("mouseout", this._onMouseOut);
-                element.removeEventListener("mousemove", this._onMouseMove);
-                this.attachedElement = null;
-            };
-            FreeCameraMouseInput.prototype.detach = function () {
-                if (this.attachedElement) {
-                    this.detachElement(this.attachedElement);
-                }
-            };
-            FreeCameraMouseInput.prototype.getTypeName = function () {
-                return "freecamera.mouse";
-            };
-            __decorate([
-                BABYLON.serialize()
-            ], FreeCameraMouseInput.prototype, "angularSensibility", void 0);
-            return FreeCameraMouseInput;
-        }());
-        CameraInputs.FreeCameraMouseInput = FreeCameraMouseInput;
-        CameraInputs.InputTypes["freecamera.mouse"] = FreeCameraMouseInput;
-    })(CameraInputs = BABYLON.CameraInputs || (BABYLON.CameraInputs = {}));
+                    if (!noPreventDefault) {
+                        evt.preventDefault();
+                    }
+                };
+            }
+            element.addEventListener("mousedown", this._onMouseDown, false);
+            element.addEventListener("mouseup", this._onMouseUp, false);
+            element.addEventListener("mouseout", this._onMouseOut, false);
+            element.addEventListener("mousemove", this._onMouseMove, false);
+        };
+        FreeCameraMouseInput.prototype.detachElement = function (element) {
+            if (this.attachedElement !== element) {
+                return;
+            }
+            element.removeEventListener("mousedown", this._onMouseDown);
+            element.removeEventListener("mouseup", this._onMouseUp);
+            element.removeEventListener("mouseout", this._onMouseOut);
+            element.removeEventListener("mousemove", this._onMouseMove);
+            this.attachedElement = null;
+        };
+        FreeCameraMouseInput.prototype.detach = function () {
+            if (this.attachedElement) {
+                this.detachElement(this.attachedElement);
+            }
+        };
+        FreeCameraMouseInput.prototype.getTypeName = function () {
+            return "freecamera.mouse";
+        };
+        __decorate([
+            BABYLON.serialize()
+        ], FreeCameraMouseInput.prototype, "angularSensibility", void 0);
+        return FreeCameraMouseInput;
+    }());
+    BABYLON.FreeCameraMouseInput = FreeCameraMouseInput;
+    BABYLON.CameraInputTypes["freecamera.mouse"] = FreeCameraMouseInput;
 })(BABYLON || (BABYLON = {}));

+ 2 - 2
src/Cameras/Inputs/babylon.freecamera.input.mouse.ts

@@ -1,4 +1,4 @@
-module BABYLON.CameraInputs {       
+module BABYLON {       
     export class FreeCameraMouseInput implements ICameraInput<FreeCamera> {
         camera : FreeCamera;
         attachedElement : HTMLElement;
@@ -109,5 +109,5 @@ module BABYLON.CameraInputs {
         }
     }
     
-    InputTypes["freecamera.mouse"] = FreeCameraMouseInput;
+    CameraInputTypes["freecamera.mouse"] = FreeCameraMouseInput;
 }

+ 121 - 124
src/Cameras/Inputs/babylon.freecamera.input.touch.js

@@ -6,134 +6,131 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
 };
 var BABYLON;
 (function (BABYLON) {
-    var CameraInputs;
-    (function (CameraInputs) {
-        var FreeCameraTouchInput = (function () {
-            function FreeCameraTouchInput() {
-                this._offsetX = null;
-                this._offsetY = null;
-                this._pointerCount = 0;
-                this._pointerPressed = [];
-                this.touchAngularSensibility = 200000.0;
-                this.touchMoveSensibility = 250.0;
+    var FreeCameraTouchInput = (function () {
+        function FreeCameraTouchInput() {
+            this._offsetX = null;
+            this._offsetY = null;
+            this._pointerCount = 0;
+            this._pointerPressed = [];
+            this.touchAngularSensibility = 200000.0;
+            this.touchMoveSensibility = 250.0;
+        }
+        FreeCameraTouchInput.prototype.attachCamera = function (camera) {
+            this.camera = camera;
+        };
+        FreeCameraTouchInput.prototype.attachElement = function (element, noPreventDefault) {
+            var _this = this;
+            var previousPosition;
+            if (this._attachedElement) {
+                return;
             }
-            FreeCameraTouchInput.prototype.attachCamera = function (camera) {
-                this.camera = camera;
-            };
-            FreeCameraTouchInput.prototype.attachElement = function (element, noPreventDefault) {
-                var _this = this;
-                var previousPosition;
-                if (this._attachedElement) {
-                    return;
-                }
-                this._attachedElement = element;
-                if (this._onPointerDown === undefined) {
-                    this._onLostFocus = function (evt) {
-                        _this._offsetX = null;
-                        _this._offsetY = null;
-                    };
-                    this._onPointerDown = function (evt) {
-                        if (evt.pointerType === "mouse") {
-                            return;
-                        }
-                        if (!noPreventDefault) {
-                            evt.preventDefault();
-                        }
-                        _this._pointerPressed.push(evt.pointerId);
-                        if (_this._pointerPressed.length !== 1) {
-                            return;
-                        }
-                        previousPosition = {
-                            x: evt.clientX,
-                            y: evt.clientY
-                        };
-                    };
-                    this._onPointerUp = function (evt) {
-                        if (evt.pointerType === "mouse") {
-                            return;
-                        }
-                        if (!noPreventDefault) {
-                            evt.preventDefault();
-                        }
-                        var index = _this._pointerPressed.indexOf(evt.pointerId);
-                        if (index === -1) {
-                            return;
-                        }
-                        _this._pointerPressed.splice(index, 1);
-                        if (index != 0) {
-                            return;
-                        }
-                        previousPosition = null;
-                        _this._offsetX = null;
-                        _this._offsetY = null;
-                    };
-                    this._onPointerMove = function (evt) {
-                        if (evt.pointerType === "mouse") {
-                            return;
-                        }
-                        if (!noPreventDefault) {
-                            evt.preventDefault();
-                        }
-                        if (!previousPosition) {
-                            return;
-                        }
-                        var index = _this._pointerPressed.indexOf(evt.pointerId);
-                        if (index != 0) {
-                            return;
-                        }
-                        _this._offsetX = evt.clientX - previousPosition.x;
-                        _this._offsetY = -(evt.clientY - previousPosition.y);
+            this._attachedElement = element;
+            if (this._onPointerDown === undefined) {
+                this._onLostFocus = function (evt) {
+                    _this._offsetX = null;
+                    _this._offsetY = null;
+                };
+                this._onPointerDown = function (evt) {
+                    if (evt.pointerType === "mouse") {
+                        return;
+                    }
+                    if (!noPreventDefault) {
+                        evt.preventDefault();
+                    }
+                    _this._pointerPressed.push(evt.pointerId);
+                    if (_this._pointerPressed.length !== 1) {
+                        return;
+                    }
+                    previousPosition = {
+                        x: evt.clientX,
+                        y: evt.clientY
                     };
-                }
-                element.addEventListener("blur", this._onLostFocus);
-                element.addEventListener("pointerdown", this._onPointerDown);
-                element.addEventListener("pointerup", this._onPointerUp);
-                element.addEventListener("pointerout", this._onPointerUp);
-                element.addEventListener("pointermove", this._onPointerMove);
-            };
-            FreeCameraTouchInput.prototype.detachElement = function (element) {
-                if (this._attachedElement !== element) {
-                    return;
-                }
-                element.removeEventListener("blur", this._onLostFocus);
-                element.removeEventListener("pointerdown", this._onPointerDown);
-                element.removeEventListener("pointerup", this._onPointerUp);
-                element.removeEventListener("pointerout", this._onPointerUp);
-                element.removeEventListener("pointermove", this._onPointerMove);
-                this._attachedElement = null;
-            };
-            FreeCameraTouchInput.prototype.checkInputs = function () {
-                if (this._offsetX) {
-                    var camera = this.camera;
-                    camera.cameraRotation.y += this._offsetX / this.touchAngularSensibility;
-                    if (this._pointerPressed.length > 1) {
-                        camera.cameraRotation.x += -this._offsetY / this.touchAngularSensibility;
+                };
+                this._onPointerUp = function (evt) {
+                    if (evt.pointerType === "mouse") {
+                        return;
+                    }
+                    if (!noPreventDefault) {
+                        evt.preventDefault();
                     }
-                    else {
-                        var speed = camera._computeLocalCameraSpeed();
-                        var direction = new BABYLON.Vector3(0, 0, speed * this._offsetY / this.touchMoveSensibility);
-                        BABYLON.Matrix.RotationYawPitchRollToRef(camera.rotation.y, camera.rotation.x, 0, camera._cameraRotationMatrix);
-                        camera.cameraDirection.addInPlace(BABYLON.Vector3.TransformCoordinates(direction, camera._cameraRotationMatrix));
+                    var index = _this._pointerPressed.indexOf(evt.pointerId);
+                    if (index === -1) {
+                        return;
                     }
+                    _this._pointerPressed.splice(index, 1);
+                    if (index != 0) {
+                        return;
+                    }
+                    previousPosition = null;
+                    _this._offsetX = null;
+                    _this._offsetY = null;
+                };
+                this._onPointerMove = function (evt) {
+                    if (evt.pointerType === "mouse") {
+                        return;
+                    }
+                    if (!noPreventDefault) {
+                        evt.preventDefault();
+                    }
+                    if (!previousPosition) {
+                        return;
+                    }
+                    var index = _this._pointerPressed.indexOf(evt.pointerId);
+                    if (index != 0) {
+                        return;
+                    }
+                    _this._offsetX = evt.clientX - previousPosition.x;
+                    _this._offsetY = -(evt.clientY - previousPosition.y);
+                };
+            }
+            element.addEventListener("blur", this._onLostFocus);
+            element.addEventListener("pointerdown", this._onPointerDown);
+            element.addEventListener("pointerup", this._onPointerUp);
+            element.addEventListener("pointerout", this._onPointerUp);
+            element.addEventListener("pointermove", this._onPointerMove);
+        };
+        FreeCameraTouchInput.prototype.detachElement = function (element) {
+            if (this._attachedElement !== element) {
+                return;
+            }
+            element.removeEventListener("blur", this._onLostFocus);
+            element.removeEventListener("pointerdown", this._onPointerDown);
+            element.removeEventListener("pointerup", this._onPointerUp);
+            element.removeEventListener("pointerout", this._onPointerUp);
+            element.removeEventListener("pointermove", this._onPointerMove);
+            this._attachedElement = null;
+        };
+        FreeCameraTouchInput.prototype.checkInputs = function () {
+            if (this._offsetX) {
+                var camera = this.camera;
+                camera.cameraRotation.y += this._offsetX / this.touchAngularSensibility;
+                if (this._pointerPressed.length > 1) {
+                    camera.cameraRotation.x += -this._offsetY / this.touchAngularSensibility;
                 }
-            };
-            FreeCameraTouchInput.prototype.detach = function () {
-                if (this._attachedElement) {
-                    this.detachElement(this._attachedElement);
+                else {
+                    var speed = camera._computeLocalCameraSpeed();
+                    var direction = new BABYLON.Vector3(0, 0, speed * this._offsetY / this.touchMoveSensibility);
+                    BABYLON.Matrix.RotationYawPitchRollToRef(camera.rotation.y, camera.rotation.x, 0, camera._cameraRotationMatrix);
+                    camera.cameraDirection.addInPlace(BABYLON.Vector3.TransformCoordinates(direction, camera._cameraRotationMatrix));
                 }
-            };
-            FreeCameraTouchInput.prototype.getTypeName = function () {
-                return "freecamera.touch";
-            };
-            __decorate([
-                BABYLON.serialize()
-            ], FreeCameraTouchInput.prototype, "touchAngularSensibility", void 0);
-            __decorate([
-                BABYLON.serialize()
-            ], FreeCameraTouchInput.prototype, "touchMoveSensibility", void 0);
-            return FreeCameraTouchInput;
-        }());
-        CameraInputs.FreeCameraTouchInput = FreeCameraTouchInput;
-        CameraInputs.InputTypes["freecamera.touch"] = FreeCameraTouchInput;
-    })(CameraInputs = BABYLON.CameraInputs || (BABYLON.CameraInputs = {}));
+            }
+        };
+        FreeCameraTouchInput.prototype.detach = function () {
+            if (this._attachedElement) {
+                this.detachElement(this._attachedElement);
+            }
+        };
+        FreeCameraTouchInput.prototype.getTypeName = function () {
+            return "freecamera.touch";
+        };
+        __decorate([
+            BABYLON.serialize()
+        ], FreeCameraTouchInput.prototype, "touchAngularSensibility", void 0);
+        __decorate([
+            BABYLON.serialize()
+        ], FreeCameraTouchInput.prototype, "touchMoveSensibility", void 0);
+        return FreeCameraTouchInput;
+    }());
+    BABYLON.FreeCameraTouchInput = FreeCameraTouchInput;
+    BABYLON.CameraInputTypes["freecamera.touch"] = FreeCameraTouchInput;
 })(BABYLON || (BABYLON = {}));

+ 2 - 2
src/Cameras/Inputs/babylon.freecamera.input.touch.ts

@@ -1,4 +1,4 @@
-module BABYLON.CameraInputs {
+module BABYLON {
     export class FreeCameraTouchInput implements ICameraInput<FreeCamera> {
         camera: FreeCamera;
 
@@ -158,5 +158,5 @@ module BABYLON.CameraInputs {
         }
     }
     
-    InputTypes["freecamera.touch"] = FreeCameraTouchInput;
+    CameraInputTypes["freecamera.touch"] = FreeCameraTouchInput;
 }

+ 45 - 48
src/Cameras/Inputs/babylon.freecamera.input.virtualjoystick.js

@@ -1,52 +1,49 @@
 var BABYLON;
 (function (BABYLON) {
-    var CameraInputs;
-    (function (CameraInputs) {
-        var FreeCameraVirtualJoystickInput = (function () {
-            function FreeCameraVirtualJoystickInput() {
+    var FreeCameraVirtualJoystickInput = (function () {
+        function FreeCameraVirtualJoystickInput() {
+        }
+        FreeCameraVirtualJoystickInput.prototype.getLeftJoystick = function () {
+            return this._leftjoystick;
+        };
+        FreeCameraVirtualJoystickInput.prototype.getRightJoystick = function () {
+            return this._rightjoystick;
+        };
+        FreeCameraVirtualJoystickInput.prototype.checkInputs = function () {
+            var camera = this.camera;
+            var speed = camera._computeLocalCameraSpeed() * 50;
+            var cameraTransform = BABYLON.Matrix.RotationYawPitchRoll(camera.rotation.y, camera.rotation.x, 0);
+            var deltaTransform = BABYLON.Vector3.TransformCoordinates(new BABYLON.Vector3(this._leftjoystick.deltaPosition.x * speed, this._leftjoystick.deltaPosition.y * speed, this._leftjoystick.deltaPosition.z * speed), cameraTransform);
+            camera.cameraDirection = camera.cameraDirection.add(deltaTransform);
+            camera.cameraRotation = camera.cameraRotation.addVector3(this._rightjoystick.deltaPosition);
+            if (!this._leftjoystick.pressed) {
+                this._leftjoystick.deltaPosition = this._leftjoystick.deltaPosition.scale(0.9);
             }
-            FreeCameraVirtualJoystickInput.prototype.getLeftJoystick = function () {
-                return this._leftjoystick;
-            };
-            FreeCameraVirtualJoystickInput.prototype.getRightJoystick = function () {
-                return this._rightjoystick;
-            };
-            FreeCameraVirtualJoystickInput.prototype.checkInputs = function () {
-                var camera = this.camera;
-                var speed = camera._computeLocalCameraSpeed() * 50;
-                var cameraTransform = BABYLON.Matrix.RotationYawPitchRoll(camera.rotation.y, camera.rotation.x, 0);
-                var deltaTransform = BABYLON.Vector3.TransformCoordinates(new BABYLON.Vector3(this._leftjoystick.deltaPosition.x * speed, this._leftjoystick.deltaPosition.y * speed, this._leftjoystick.deltaPosition.z * speed), cameraTransform);
-                camera.cameraDirection = camera.cameraDirection.add(deltaTransform);
-                camera.cameraRotation = camera.cameraRotation.addVector3(this._rightjoystick.deltaPosition);
-                if (!this._leftjoystick.pressed) {
-                    this._leftjoystick.deltaPosition = this._leftjoystick.deltaPosition.scale(0.9);
-                }
-                if (!this._rightjoystick.pressed) {
-                    this._rightjoystick.deltaPosition = this._rightjoystick.deltaPosition.scale(0.9);
-                }
-            };
-            FreeCameraVirtualJoystickInput.prototype.attachCamera = function (camera) {
-                this.camera = camera;
-                this._leftjoystick = new BABYLON.VirtualJoystick(true);
-                this._leftjoystick.setAxisForUpDown(BABYLON.JoystickAxis.Z);
-                this._leftjoystick.setAxisForLeftRight(BABYLON.JoystickAxis.X);
-                this._leftjoystick.setJoystickSensibility(0.15);
-                this._rightjoystick = new BABYLON.VirtualJoystick(false);
-                this._rightjoystick.setAxisForUpDown(BABYLON.JoystickAxis.X);
-                this._rightjoystick.setAxisForLeftRight(BABYLON.JoystickAxis.Y);
-                this._rightjoystick.reverseUpDown = true;
-                this._rightjoystick.setJoystickSensibility(0.05);
-                this._rightjoystick.setJoystickColor("yellow");
-            };
-            FreeCameraVirtualJoystickInput.prototype.detach = function () {
-                this._leftjoystick.releaseCanvas();
-            };
-            FreeCameraVirtualJoystickInput.prototype.getTypeName = function () {
-                return "freecamera.virtualjoystick";
-            };
-            return FreeCameraVirtualJoystickInput;
-        }());
-        CameraInputs.FreeCameraVirtualJoystickInput = FreeCameraVirtualJoystickInput;
-        CameraInputs.InputTypes["freecamera.virtualjoystick"] = FreeCameraVirtualJoystickInput;
-    })(CameraInputs = BABYLON.CameraInputs || (BABYLON.CameraInputs = {}));
+            if (!this._rightjoystick.pressed) {
+                this._rightjoystick.deltaPosition = this._rightjoystick.deltaPosition.scale(0.9);
+            }
+        };
+        FreeCameraVirtualJoystickInput.prototype.attachCamera = function (camera) {
+            this.camera = camera;
+            this._leftjoystick = new BABYLON.VirtualJoystick(true);
+            this._leftjoystick.setAxisForUpDown(BABYLON.JoystickAxis.Z);
+            this._leftjoystick.setAxisForLeftRight(BABYLON.JoystickAxis.X);
+            this._leftjoystick.setJoystickSensibility(0.15);
+            this._rightjoystick = new BABYLON.VirtualJoystick(false);
+            this._rightjoystick.setAxisForUpDown(BABYLON.JoystickAxis.X);
+            this._rightjoystick.setAxisForLeftRight(BABYLON.JoystickAxis.Y);
+            this._rightjoystick.reverseUpDown = true;
+            this._rightjoystick.setJoystickSensibility(0.05);
+            this._rightjoystick.setJoystickColor("yellow");
+        };
+        FreeCameraVirtualJoystickInput.prototype.detach = function () {
+            this._leftjoystick.releaseCanvas();
+        };
+        FreeCameraVirtualJoystickInput.prototype.getTypeName = function () {
+            return "freecamera.virtualjoystick";
+        };
+        return FreeCameraVirtualJoystickInput;
+    }());
+    BABYLON.FreeCameraVirtualJoystickInput = FreeCameraVirtualJoystickInput;
+    BABYLON.CameraInputTypes["freecamera.virtualjoystick"] = FreeCameraVirtualJoystickInput;
 })(BABYLON || (BABYLON = {}));

+ 3 - 2
src/Cameras/Inputs/babylon.freecamera.input.virtualjoystick.ts

@@ -1,4 +1,4 @@
-module BABYLON.CameraInputs {
+module BABYLON {
     export class FreeCameraVirtualJoystickInput implements ICameraInput<FreeCamera> {
         camera: FreeCamera;
 
@@ -52,5 +52,6 @@ module BABYLON.CameraInputs {
             return "freecamera.virtualjoystick";
         }
     }
-    InputTypes["freecamera.virtualjoystick"] = FreeCameraVirtualJoystickInput;
+    
+    CameraInputTypes["freecamera.virtualjoystick"] = FreeCameraVirtualJoystickInput;
 }

+ 1 - 27
src/Cameras/VR/babylon.vrDeviceOrientationCamera.js

@@ -10,37 +10,11 @@ var BABYLON;
         function VRDeviceOrientationFreeCamera(name, position, scene, compensateDistortion) {
             if (compensateDistortion === void 0) { compensateDistortion = true; }
             _super.call(this, name, position, scene);
-            this._alpha = 0;
-            this._beta = 0;
-            this._gamma = 0;
+            this.inputs.addDeviceOrientation();
             var metrics = BABYLON.VRCameraMetrics.GetDefault();
             metrics.compensateDistortion = compensateDistortion;
             this.setCameraRigMode(BABYLON.Camera.RIG_MODE_VR, { vrCameraMetrics: metrics });
-            this._deviceOrientationHandler = this._onOrientationEvent.bind(this);
         }
-        VRDeviceOrientationFreeCamera.prototype._onOrientationEvent = function (evt) {
-            this._alpha = +evt.alpha | 0;
-            this._beta = +evt.beta | 0;
-            this._gamma = +evt.gamma | 0;
-            if (this._gamma < 0) {
-                this._gamma = 90 + this._gamma;
-            }
-            else {
-                // Incline it in the correct angle.
-                this._gamma = 270 - this._gamma;
-            }
-            this.rotation.x = this._gamma / 180.0 * Math.PI;
-            this.rotation.y = -this._alpha / 180.0 * Math.PI;
-            this.rotation.z = this._beta / 180.0 * Math.PI;
-        };
-        VRDeviceOrientationFreeCamera.prototype.attachControl = function (element, noPreventDefault) {
-            _super.prototype.attachControl.call(this, element, noPreventDefault);
-            window.addEventListener("deviceorientation", this._deviceOrientationHandler);
-        };
-        VRDeviceOrientationFreeCamera.prototype.detachControl = function (element) {
-            _super.prototype.detachControl.call(this, element);
-            window.removeEventListener("deviceorientation", this._deviceOrientationHandler);
-        };
         VRDeviceOrientationFreeCamera.prototype.getTypeName = function () {
             return "VRDeviceOrientationFreeCamera";
         };

+ 2 - 41
src/Cameras/VR/babylon.vrDeviceOrientationCamera.ts

@@ -1,50 +1,11 @@
 module BABYLON {
     export class VRDeviceOrientationFreeCamera extends FreeCamera {
-        public _alpha = 0;
-        public _beta = 0;
-        public _gamma = 0;
-    
-        private _offsetOrientation: { yaw: number; pitch: number; roll: number };
-        private _deviceOrientationHandler;
-
         constructor(name: string, position: Vector3, scene: Scene, compensateDistortion = true) {
             super(name, position, scene);
-
+            this.inputs.addDeviceOrientation();
             var metrics = VRCameraMetrics.GetDefault();
             metrics.compensateDistortion = compensateDistortion;
-            this.setCameraRigMode(Camera.RIG_MODE_VR, { vrCameraMetrics: metrics });
-
-            this._deviceOrientationHandler = this._onOrientationEvent.bind(this);
-        }
-
-        public _onOrientationEvent(evt: DeviceOrientationEvent): void {
-            this._alpha = +evt.alpha|0;
-            this._beta = +evt.beta|0;
-            this._gamma = +evt.gamma|0;
-
-            if (this._gamma < 0) {
-                this._gamma = 90 + this._gamma;
-            }
-            else {
-                // Incline it in the correct angle.
-                this._gamma = 270 - this._gamma;
-            }
-
-            this.rotation.x = this._gamma / 180.0 * Math.PI;   
-            this.rotation.y = -this._alpha / 180.0 * Math.PI;   
-            this.rotation.z = this._beta / 180.0 * Math.PI;     
-        }
-
-        public attachControl(element: HTMLElement, noPreventDefault?: boolean): void {
-            super.attachControl(element, noPreventDefault);
-
-            window.addEventListener("deviceorientation", this._deviceOrientationHandler);
-        }
-
-        public detachControl(element: HTMLElement): void {
-            super.detachControl(element);
-
-            window.removeEventListener("deviceorientation", this._deviceOrientationHandler);
+            this.setCameraRigMode(Camera.RIG_MODE_VR, { vrCameraMetrics: metrics });            
         }
 
         public getTypeName(): string {

+ 252 - 274
src/Cameras/babylon.arcRotateCamera.js

@@ -11,9 +11,20 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
 };
 var BABYLON;
 (function (BABYLON) {
-    var eventPrefix = BABYLON.Tools.GetPointerPrefix();
+    // var eventPrefix = Tools.GetPointerPrefix();
     var ArcRotateCamera = (function (_super) {
         __extends(ArcRotateCamera, _super);
+        //deprecated angularSensibility support
+        // public get angularSensibility() {
+        //     Tools.Warn("Warning: angularSensibility is deprecated, use angularSensibilityX and angularSensibilityY instead.");
+        //     return Math.max(this.angularSensibilityX, this.angularSensibilityY);
+        // }
+        // //deprecated angularSensibility support
+        // public set angularSensibility(value) {
+        //     Tools.Warn("Warning: angularSensibility is deprecated, use angularSensibilityX and angularSensibilityY instead.");
+        //     this.angularSensibilityX = value;
+        //     this.angularSensibilityY = value;
+        // }
         function ArcRotateCamera(name, alpha, beta, radius, target, scene) {
             var _this = this;
             _super.call(this, name, BABYLON.Vector3.Zero(), scene);
@@ -26,27 +37,34 @@ var BABYLON;
             this.upperBetaLimit = Math.PI;
             this.lowerRadiusLimit = null;
             this.upperRadiusLimit = null;
-            this.angularSensibilityX = 1000.0;
-            this.angularSensibilityY = 1000.0;
-            this.wheelPrecision = 3.0;
-            this.pinchPrecision = 2.0;
-            this.panningSensibility = 50.0;
+            // @serialize()
+            // public angularSensibilityX = 1000.0;
+            // @serialize()
+            // public angularSensibilityY = 1000.0;
+            // @serialize()
+            // public wheelPrecision = 3.0;
+            // @serialize()
+            // public pinchPrecision = 2.0;
+            // @serialize()
+            // public panningSensibility: number = 50.0;
             this.inertialPanningX = 0;
             this.inertialPanningY = 0;
-            this.keysUp = [38];
-            this.keysDown = [40];
-            this.keysLeft = [37];
-            this.keysRight = [39];
+            // @serialize()
+            // public keysUp = [38];
+            // @serialize()
+            // public keysDown = [40];
+            // @serialize()
+            // public keysLeft = [37];
+            // @serialize()
+            // public keysRight = [39];
             this.zoomOnFactor = 1;
             this.targetScreenOffset = BABYLON.Vector2.Zero();
-            this.pinchInwards = true;
+            // public pinchInwards = true;
             this.allowUpsideDown = true;
-            this._keys = [];
+            // private _keys = [];
             this._viewMatrix = new BABYLON.Matrix();
             // Panning
             this.panningAxis = new BABYLON.Vector3(1, 1, 0);
-            this._isRightClick = false;
-            this._isCtrlPushed = false;
             this.checkCollisions = false;
             this.collisionRadius = new BABYLON.Vector3(0.5, 0.5, 0.5);
             this._collider = new BABYLON.Collider();
@@ -98,22 +116,9 @@ var BABYLON;
             this.beta = beta;
             this.radius = radius;
             this.getViewMatrix();
+            this.inputs = new BABYLON.ArcRotateCameraInputsManager(this);
+            this.inputs.addKeyboard().addMouseWheel().addPointers();
         }
-        Object.defineProperty(ArcRotateCamera.prototype, "angularSensibility", {
-            //deprecated angularSensibility support
-            get: function () {
-                BABYLON.Tools.Warn("Warning: angularSensibility is deprecated, use angularSensibilityX and angularSensibilityY instead.");
-                return Math.max(this.angularSensibilityX, this.angularSensibilityY);
-            },
-            //deprecated angularSensibility support
-            set: function (value) {
-                BABYLON.Tools.Warn("Warning: angularSensibility is deprecated, use angularSensibilityX and angularSensibilityY instead.");
-                this.angularSensibilityX = value;
-                this.angularSensibilityY = value;
-            },
-            enumerable: true,
-            configurable: true
-        });
         // Cache
         ArcRotateCamera.prototype._initCache = function () {
             _super.prototype._initCache.call(this);
@@ -151,220 +156,222 @@ var BABYLON;
         };
         // Methods
         ArcRotateCamera.prototype.attachControl = function (element, noPreventDefault, useCtrlForPanning) {
+            // var cacheSoloPointer; // cache pointer object for better perf on camera rotation
+            // var previousPinchDistance = 0;
+            // // var pointers = new SmartCollection();
             var _this = this;
             if (useCtrlForPanning === void 0) { useCtrlForPanning = true; }
-            var cacheSoloPointer; // cache pointer object for better perf on camera rotation
-            var previousPinchDistance = 0;
-            var pointers = new BABYLON.SmartCollection();
             if (this._attachedElement) {
                 return;
             }
             this._attachedElement = element;
-            var engine = this.getEngine();
-            if (this._onPointerDown === undefined) {
-                this._onPointerDown = function (evt) {
-                    // Manage panning with right click
-                    _this._isRightClick = evt.button === 2;
-                    // manage pointers
-                    pointers.add(evt.pointerId, { x: evt.clientX, y: evt.clientY, type: evt.pointerType });
-                    cacheSoloPointer = pointers.item(evt.pointerId);
-                    if (!noPreventDefault) {
-                        evt.preventDefault();
-                    }
-                };
-                this._onPointerUp = function (evt) {
-                    cacheSoloPointer = null;
-                    previousPinchDistance = 0;
-                    //would be better to use pointers.remove(evt.pointerId) for multitouch gestures, 
-                    //but emptying completly pointers collection is required to fix a bug on iPhone : 
-                    //when changing orientation while pinching camera, one pointer stay pressed forever if we don't release all pointers  
-                    //will be ok to put back pointers.remove(evt.pointerId); when iPhone bug corrected
-                    pointers.empty();
-                    if (!noPreventDefault) {
-                        evt.preventDefault();
-                    }
-                };
-                this._onContextMenu = function (evt) {
-                    evt.preventDefault();
-                };
-                this._onPointerMove = function (evt) {
-                    if (!noPreventDefault) {
-                        evt.preventDefault();
-                    }
-                    switch (pointers.count) {
-                        case 1:
-                            if (_this.panningSensibility !== 0 && ((_this._isCtrlPushed && useCtrlForPanning) || (!useCtrlForPanning && _this._isRightClick))) {
-                                _this.inertialPanningX += -(evt.clientX - cacheSoloPointer.x) / _this.panningSensibility;
-                                _this.inertialPanningY += (evt.clientY - cacheSoloPointer.y) / _this.panningSensibility;
-                            }
-                            else {
-                                var offsetX = evt.clientX - cacheSoloPointer.x;
-                                var offsetY = evt.clientY - cacheSoloPointer.y;
-                                _this.inertialAlphaOffset -= offsetX / _this.angularSensibilityX;
-                                _this.inertialBetaOffset -= offsetY / _this.angularSensibilityY;
-                            }
-                            cacheSoloPointer.x = evt.clientX;
-                            cacheSoloPointer.y = evt.clientY;
-                            break;
-                        case 2:
-                            //if (noPreventDefault) { evt.preventDefault(); } //if pinch gesture, could be usefull to force preventDefault to avoid html page scroll/zoom in some mobile browsers
-                            pointers.item(evt.pointerId).x = evt.clientX;
-                            pointers.item(evt.pointerId).y = evt.clientY;
-                            var direction = _this.pinchInwards ? 1 : -1;
-                            var distX = pointers.getItemByIndex(0).x - pointers.getItemByIndex(1).x;
-                            var distY = pointers.getItemByIndex(0).y - pointers.getItemByIndex(1).y;
-                            var pinchSquaredDistance = (distX * distX) + (distY * distY);
-                            if (previousPinchDistance === 0) {
-                                previousPinchDistance = pinchSquaredDistance;
-                                return;
-                            }
-                            if (pinchSquaredDistance !== previousPinchDistance) {
-                                _this.inertialRadiusOffset += (pinchSquaredDistance - previousPinchDistance) / (_this.pinchPrecision * _this.wheelPrecision * ((_this.angularSensibilityX + _this.angularSensibilityY) / 2) * direction);
-                                previousPinchDistance = pinchSquaredDistance;
-                            }
-                            break;
-                        default:
-                            if (pointers.item(evt.pointerId)) {
-                                pointers.item(evt.pointerId).x = evt.clientX;
-                                pointers.item(evt.pointerId).y = evt.clientY;
-                            }
-                    }
-                };
-                this._onMouseMove = function (evt) {
-                    if (!engine.isPointerLock) {
-                        return;
-                    }
-                    var offsetX = evt.movementX || evt.mozMovementX || evt.webkitMovementX || evt.msMovementX || 0;
-                    var offsetY = evt.movementY || evt.mozMovementY || evt.webkitMovementY || evt.msMovementY || 0;
-                    _this.inertialAlphaOffset -= offsetX / _this.angularSensibilityX;
-                    _this.inertialBetaOffset -= offsetY / _this.angularSensibilityY;
-                    if (!noPreventDefault) {
-                        evt.preventDefault();
-                    }
-                };
-                this._wheel = function (event) {
-                    var delta = 0;
-                    if (event.wheelDelta) {
-                        delta = event.wheelDelta / (_this.wheelPrecision * 40);
-                    }
-                    else if (event.detail) {
-                        delta = -event.detail / _this.wheelPrecision;
-                    }
-                    if (delta)
-                        _this.inertialRadiusOffset += delta;
-                    if (event.preventDefault) {
-                        if (!noPreventDefault) {
-                            event.preventDefault();
-                        }
-                    }
-                };
-                this._onKeyDown = function (evt) {
-                    _this._isCtrlPushed = evt.ctrlKey;
-                    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) {
-                        var index = _this._keys.indexOf(evt.keyCode);
-                        if (index === -1) {
-                            _this._keys.push(evt.keyCode);
-                        }
-                        if (evt.preventDefault) {
-                            if (!noPreventDefault) {
-                                evt.preventDefault();
-                            }
-                        }
-                    }
-                };
-                this._onKeyUp = function (evt) {
-                    _this._isCtrlPushed = evt.ctrlKey;
-                    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) {
-                        var index = _this._keys.indexOf(evt.keyCode);
-                        if (index >= 0) {
-                            _this._keys.splice(index, 1);
-                        }
-                        if (evt.preventDefault) {
-                            if (!noPreventDefault) {
-                                evt.preventDefault();
-                            }
-                        }
-                    }
-                };
-                this._onLostFocus = function () {
-                    _this._keys = [];
-                    pointers.empty();
-                    previousPinchDistance = 0;
-                    cacheSoloPointer = null;
-                };
-                this._onGestureStart = function (e) {
-                    if (window.MSGesture === undefined) {
-                        return;
-                    }
-                    if (!_this._MSGestureHandler) {
-                        _this._MSGestureHandler = new MSGesture();
-                        _this._MSGestureHandler.target = element;
-                    }
-                    _this._MSGestureHandler.addPointer(e.pointerId);
-                };
-                this._onGesture = function (e) {
-                    _this.radius *= e.scale;
-                    if (e.preventDefault) {
-                        if (!noPreventDefault) {
-                            e.stopPropagation();
-                            e.preventDefault();
-                        }
-                    }
-                };
-                this._reset = function () {
-                    _this._keys = [];
-                    _this.inertialAlphaOffset = 0;
-                    _this.inertialBetaOffset = 0;
-                    _this.inertialRadiusOffset = 0;
-                    pointers.empty();
-                    previousPinchDistance = 0;
-                    cacheSoloPointer = null;
-                };
-            }
-            if (!useCtrlForPanning) {
-                element.addEventListener("contextmenu", this._onContextMenu, false);
-            }
-            element.addEventListener(eventPrefix + "down", this._onPointerDown, false);
-            element.addEventListener(eventPrefix + "up", this._onPointerUp, false);
-            element.addEventListener(eventPrefix + "out", this._onPointerUp, false);
-            element.addEventListener(eventPrefix + "move", this._onPointerMove, false);
-            element.addEventListener("mousemove", this._onMouseMove, false);
-            element.addEventListener("MSPointerDown", this._onGestureStart, false);
-            element.addEventListener("MSGestureChange", this._onGesture, false);
-            element.addEventListener('mousewheel', this._wheel, false);
-            element.addEventListener('DOMMouseScroll', this._wheel, false);
-            BABYLON.Tools.RegisterTopRootEvents([
-                { name: "keydown", handler: this._onKeyDown },
-                { name: "keyup", handler: this._onKeyUp },
-                { name: "blur", handler: this._onLostFocus }
-            ]);
+            this._noPreventDefault = noPreventDefault;
+            this._useCtrlForPanning = useCtrlForPanning;
+            this.inputs.attachElement(element, noPreventDefault);
+            // var engine = this.getEngine();
+            // if (this._wheel === undefined) {
+            //     this._onPointerDown = evt => {
+            //         // Manage panning with right click
+            //         this._isRightClick = evt.button === 2;
+            //         // manage pointers
+            //         pointers.add(evt.pointerId, { x: evt.clientX, y: evt.clientY, type: evt.pointerType });
+            //         cacheSoloPointer = pointers.item(evt.pointerId);
+            //         if (!noPreventDefault) {
+            //             evt.preventDefault();
+            //         }
+            //     };
+            //     this._onPointerUp = evt => {
+            //         cacheSoloPointer = null;
+            //         previousPinchDistance = 0;
+            //         //would be better to use pointers.remove(evt.pointerId) for multitouch gestures, 
+            //         //but emptying completly pointers collection is required to fix a bug on iPhone : 
+            //         //when changing orientation while pinching camera, one pointer stay pressed forever if we don't release all pointers  
+            //         //will be ok to put back pointers.remove(evt.pointerId); when iPhone bug corrected
+            //         pointers.empty();
+            //         if (!noPreventDefault) {
+            //             evt.preventDefault();
+            //         }
+            //     };
+            //     this._onContextMenu = evt => {
+            //         evt.preventDefault();
+            //     };
+            //     this._onPointerMove = evt => {
+            //         if (!noPreventDefault) {
+            //             evt.preventDefault();
+            //         }
+            //         switch (pointers.count) {
+            //             case 1: //normal camera rotation
+            //                 if (this.panningSensibility !== 0 && ((this._isCtrlPushed && useCtrlForPanning) || (!useCtrlForPanning && this._isRightClick))) {
+            //                     this.inertialPanningX += -(evt.clientX - cacheSoloPointer.x) / this.panningSensibility;
+            //                     this.inertialPanningY += (evt.clientY - cacheSoloPointer.y) / this.panningSensibility;
+            //                 } else {
+            //                     var offsetX = evt.clientX - cacheSoloPointer.x;
+            //                     var offsetY = evt.clientY - cacheSoloPointer.y;
+            //                     this.inertialAlphaOffset -= offsetX / this.angularSensibilityX;
+            //                     this.inertialBetaOffset -= offsetY / this.angularSensibilityY;
+            //                 }
+            //                 cacheSoloPointer.x = evt.clientX;
+            //                 cacheSoloPointer.y = evt.clientY;
+            //                 break;
+            //             case 2: //pinch
+            //                 //if (noPreventDefault) { evt.preventDefault(); } //if pinch gesture, could be usefull to force preventDefault to avoid html page scroll/zoom in some mobile browsers
+            //                 pointers.item(evt.pointerId).x = evt.clientX;
+            //                 pointers.item(evt.pointerId).y = evt.clientY;
+            //                 var direction = this.pinchInwards ? 1 : -1;
+            //                 var distX = pointers.getItemByIndex(0).x - pointers.getItemByIndex(1).x;
+            //                 var distY = pointers.getItemByIndex(0).y - pointers.getItemByIndex(1).y;
+            //                 var pinchSquaredDistance = (distX * distX) + (distY * distY);
+            //                 if (previousPinchDistance === 0) {
+            //                     previousPinchDistance = pinchSquaredDistance;
+            //                     return;
+            //                 }
+            //                 if (pinchSquaredDistance !== previousPinchDistance) {
+            //                     this.inertialRadiusOffset += (pinchSquaredDistance - previousPinchDistance) / (this.pinchPrecision * this.wheelPrecision * ((this.angularSensibilityX + this.angularSensibilityY) / 2) * direction);
+            //                     previousPinchDistance = pinchSquaredDistance;
+            //                 }
+            //                 break;
+            //             default:
+            //                 if (pointers.item(evt.pointerId)) {
+            //                     pointers.item(evt.pointerId).x = evt.clientX;
+            //                     pointers.item(evt.pointerId).y = evt.clientY;
+            //                 }
+            //         }
+            //     };
+            //     this._onMouseMove = evt => {
+            //         if (!engine.isPointerLock) {
+            //             return;
+            //         }
+            //         var offsetX = evt.movementX || evt.mozMovementX || evt.webkitMovementX || evt.msMovementX || 0;
+            //         var offsetY = evt.movementY || evt.mozMovementY || evt.webkitMovementY || evt.msMovementY || 0;
+            //         this.inertialAlphaOffset -= offsetX / this.angularSensibilityX;
+            //         this.inertialBetaOffset -= offsetY / this.angularSensibilityY;
+            //         if (!noPreventDefault) {
+            //             evt.preventDefault();
+            //         }
+            //     };
+            // this._wheel = event => {
+            //     var delta = 0;
+            //     if (event.wheelDelta) {
+            //         delta = event.wheelDelta / (this.wheelPrecision * 40);
+            //     } else if (event.detail) {
+            //         delta = -event.detail / this.wheelPrecision;
+            //     }
+            //     if (delta)
+            //         this.inertialRadiusOffset += delta;
+            //     if (event.preventDefault) {
+            //         if (!noPreventDefault) {
+            //             event.preventDefault();
+            //         }
+            //     }
+            // };
+            // this._onKeyDown = evt => {
+            //     this._isCtrlPushed = evt.ctrlKey;
+            //     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) {
+            //         var index = this._keys.indexOf(evt.keyCode);
+            //         if (index === -1) {
+            //             this._keys.push(evt.keyCode);
+            //         }
+            //         if (evt.preventDefault) {
+            //             if (!noPreventDefault) {
+            //                 evt.preventDefault();
+            //             }
+            //         }
+            //     }
+            // };
+            // this._onKeyUp = evt => {
+            //     this._isCtrlPushed = evt.ctrlKey;
+            //     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) {
+            //         var index = this._keys.indexOf(evt.keyCode);
+            //         if (index >= 0) {
+            //             this._keys.splice(index, 1);
+            //         }
+            //         if (evt.preventDefault) {
+            //             if (!noPreventDefault) {
+            //                 evt.preventDefault();
+            //             }
+            //         }
+            //     }
+            // };
+            // this._onLostFocus = () => {
+            //     //this._keys = [];
+            //     pointers.empty();
+            //     previousPinchDistance = 0;
+            //     cacheSoloPointer = null;
+            // };
+            // this._onGestureStart = e => {
+            //     if (window.MSGesture === undefined) {
+            //         return;
+            //     }
+            //     if (!this._MSGestureHandler) {
+            //         this._MSGestureHandler = new MSGesture();
+            //         this._MSGestureHandler.target = element;
+            //     }
+            //     this._MSGestureHandler.addPointer(e.pointerId);
+            // };
+            // this._onGesture = e => {
+            //     this.radius *= e.scale;
+            //     if (e.preventDefault) {
+            //         if (!noPreventDefault) {
+            //             e.stopPropagation();
+            //             e.preventDefault();
+            //         }
+            //     }
+            // };
+            this._reset = function () {
+                // this._keys = [];
+                _this.inertialAlphaOffset = 0;
+                _this.inertialBetaOffset = 0;
+                _this.inertialRadiusOffset = 0;
+                // pointers.empty();
+                // previousPinchDistance = 0;
+                // cacheSoloPointer = null;
+            };
+            // }
+            // if (!useCtrlForPanning) {
+            //     element.addEventListener("contextmenu", this._onContextMenu, false);
+            // }
+            //element.addEventListener(eventPrefix + "down", this._onPointerDown, false);
+            // element.addEventListener(eventPrefix + "up", this._onPointerUp, false);
+            // element.addEventListener(eventPrefix + "out", this._onPointerUp, false);
+            // element.addEventListener(eventPrefix + "move", this._onPointerMove, false);
+            // element.addEventListener("mousemove", this._onMouseMove, false);
+            // element.addEventListener("MSPointerDown", this._onGestureStart, false);
+            // element.addEventListener("MSGestureChange", this._onGesture, false);
+            // element.addEventListener('mousewheel', this._wheel, false);
+            // element.addEventListener('DOMMouseScroll', this._wheel, false);
+            // Tools.RegisterTopRootEvents([
+            //     // { name: "keydown", handler: this._onKeyDown },
+            //     // { name: "keyup", handler: this._onKeyUp },
+            //     { name: "blur", handler: this._onLostFocus }
+            // ]);
         };
         ArcRotateCamera.prototype.detachControl = function (element) {
             if (this._attachedElement !== element) {
                 return;
             }
-            element.removeEventListener("contextmenu", this._onContextMenu);
-            element.removeEventListener(eventPrefix + "down", this._onPointerDown);
-            element.removeEventListener(eventPrefix + "up", this._onPointerUp);
-            element.removeEventListener(eventPrefix + "out", this._onPointerUp);
-            element.removeEventListener(eventPrefix + "move", this._onPointerMove);
-            element.removeEventListener("mousemove", this._onMouseMove);
-            element.removeEventListener("MSPointerDown", this._onGestureStart);
-            element.removeEventListener("MSGestureChange", this._onGesture);
-            element.removeEventListener('mousewheel', this._wheel);
-            element.removeEventListener('DOMMouseScroll', this._wheel);
-            BABYLON.Tools.UnregisterTopRootEvents([
-                { name: "keydown", handler: this._onKeyDown },
-                { name: "keyup", handler: this._onKeyUp },
-                { name: "blur", handler: this._onLostFocus }
-            ]);
-            this._MSGestureHandler = null;
+            this.inputs.detachElement(this._attachedElement);
+            // element.removeEventListener("contextmenu", this._onContextMenu);
+            // element.removeEventListener(eventPrefix + "down", this._onPointerDown);
+            // element.removeEventListener(eventPrefix + "up", this._onPointerUp);
+            // element.removeEventListener(eventPrefix + "out", this._onPointerUp);
+            // element.removeEventListener(eventPrefix + "move", this._onPointerMove);
+            // element.removeEventListener("mousemove", this._onMouseMove);
+            // element.removeEventListener("MSPointerDown", this._onGestureStart);
+            // element.removeEventListener("MSGestureChange", this._onGesture);
+            // element.removeEventListener('mousewheel', this._wheel);
+            // element.removeEventListener('DOMMouseScroll', this._wheel);
+            // Tools.UnregisterTopRootEvents([
+            //     // { name: "keydown", handler: this._onKeyDown },
+            //     // { name: "keyup", handler: this._onKeyUp },
+            //     { name: "blur", handler: this._onLostFocus }
+            // ]);
+            // this._MSGestureHandler = null;
             this._attachedElement = null;
             if (this._reset) {
                 this._reset();
@@ -375,22 +382,20 @@ var BABYLON;
             if (this._collisionTriggered) {
                 return;
             }
+            this.inputs.checkInputs();
             // Keyboard
-            for (var index = 0; index < this._keys.length; index++) {
-                var keyCode = this._keys[index];
-                if (this.keysLeft.indexOf(keyCode) !== -1) {
-                    this.inertialAlphaOffset -= 0.01;
-                }
-                else if (this.keysUp.indexOf(keyCode) !== -1) {
-                    this.inertialBetaOffset -= 0.01;
-                }
-                else if (this.keysRight.indexOf(keyCode) !== -1) {
-                    this.inertialAlphaOffset += 0.01;
-                }
-                else if (this.keysDown.indexOf(keyCode) !== -1) {
-                    this.inertialBetaOffset += 0.01;
-                }
-            }
+            // for (var index = 0; index < this._keys.length; index++) {
+            //     var keyCode = this._keys[index];
+            //     if (this.keysLeft.indexOf(keyCode) !== -1) {
+            //         this.inertialAlphaOffset -= 0.01;
+            //     } else if (this.keysUp.indexOf(keyCode) !== -1) {
+            //         this.inertialBetaOffset -= 0.01;
+            //     } else if (this.keysRight.indexOf(keyCode) !== -1) {
+            //         this.inertialAlphaOffset += 0.01;
+            //     } else if (this.keysDown.indexOf(keyCode) !== -1) {
+            //         this.inertialBetaOffset += 0.01;
+            //     }
+            // }			
             // Inertia
             if (this.inertialAlphaOffset !== 0 || this.inertialBetaOffset !== 0 || this.inertialRadiusOffset !== 0) {
                 this.alpha += this.beta <= 0 ? -this.inertialAlphaOffset : this.inertialAlphaOffset;
@@ -629,39 +634,12 @@ var BABYLON;
         ], ArcRotateCamera.prototype, "upperRadiusLimit", void 0);
         __decorate([
             BABYLON.serialize()
-        ], ArcRotateCamera.prototype, "angularSensibilityX", void 0);
-        __decorate([
-            BABYLON.serialize()
-        ], ArcRotateCamera.prototype, "angularSensibilityY", void 0);
-        __decorate([
-            BABYLON.serialize()
-        ], ArcRotateCamera.prototype, "wheelPrecision", void 0);
-        __decorate([
-            BABYLON.serialize()
-        ], ArcRotateCamera.prototype, "pinchPrecision", void 0);
-        __decorate([
-            BABYLON.serialize()
-        ], ArcRotateCamera.prototype, "panningSensibility", void 0);
-        __decorate([
-            BABYLON.serialize()
         ], ArcRotateCamera.prototype, "inertialPanningX", void 0);
         __decorate([
             BABYLON.serialize()
         ], ArcRotateCamera.prototype, "inertialPanningY", void 0);
         __decorate([
             BABYLON.serialize()
-        ], ArcRotateCamera.prototype, "keysUp", void 0);
-        __decorate([
-            BABYLON.serialize()
-        ], ArcRotateCamera.prototype, "keysDown", void 0);
-        __decorate([
-            BABYLON.serialize()
-        ], ArcRotateCamera.prototype, "keysLeft", void 0);
-        __decorate([
-            BABYLON.serialize()
-        ], ArcRotateCamera.prototype, "keysRight", void 0);
-        __decorate([
-            BABYLON.serialize()
         ], ArcRotateCamera.prototype, "zoomOnFactor", void 0);
         __decorate([
             BABYLON.serialize()

+ 307 - 292
src/Cameras/babylon.arcRotateCamera.ts

@@ -1,5 +1,5 @@
 module BABYLON {
-    var eventPrefix = Tools.GetPointerPrefix();
+    // var eventPrefix = Tools.GetPointerPrefix();
 
     export class ArcRotateCamera extends TargetCamera {
         @serialize()
@@ -41,20 +41,20 @@
         @serialize()
         public upperRadiusLimit = null;
 
-        @serialize()
-        public angularSensibilityX = 1000.0;
+        // @serialize()
+        // public angularSensibilityX = 1000.0;
 
-        @serialize()
-        public angularSensibilityY = 1000.0;
+        // @serialize()
+        // public angularSensibilityY = 1000.0;
 
-        @serialize()
-        public wheelPrecision = 3.0;
+        // @serialize()
+        // public wheelPrecision = 3.0;
 
-        @serialize()
-        public pinchPrecision = 2.0;
+        // @serialize()
+        // public pinchPrecision = 2.0;
 
-        @serialize()
-        public panningSensibility: number = 50.0;
+        // @serialize()
+        // public panningSensibility: number = 50.0;
 
         @serialize()
         public inertialPanningX: number = 0;
@@ -62,51 +62,55 @@
         @serialize()
         public inertialPanningY: number = 0;
 
-        @serialize()
-        public keysUp = [38];
+        // @serialize()
+        // public keysUp = [38];
 
-        @serialize()
-        public keysDown = [40];
+        // @serialize()
+        // public keysDown = [40];
 
-        @serialize()
-        public keysLeft = [37];
+        // @serialize()
+        // public keysLeft = [37];
 
-        @serialize()
-        public keysRight = [39];
+        // @serialize()
+        // public keysRight = [39];
 
         @serialize()
         public zoomOnFactor = 1;
 
         public targetScreenOffset = Vector2.Zero();
-        public pinchInwards = true;
+        // public pinchInwards = true;
 
         @serialize()
         public allowUpsideDown = true;
 
-        private _keys = [];
+        // private _keys = [];
         public _viewMatrix = new Matrix();
-        private _attachedElement: HTMLElement;
-
-        private _onContextMenu: (e: PointerEvent) => void;
-        private _onPointerDown: (e: PointerEvent) => void;
-        private _onPointerUp: (e: PointerEvent) => void;
-        private _onPointerMove: (e: PointerEvent) => void;
-        private _wheel: (e: MouseWheelEvent) => void;
-        private _onMouseMove: (e: MouseEvent) => any;
-        private _onKeyDown: (e: KeyboardEvent) => any;
-        private _onKeyUp: (e: KeyboardEvent) => any;
-        private _onLostFocus: (e: FocusEvent) => any;
+        public _attachedElement: HTMLElement;
+        public _noPreventDefault : boolean;
+        public _useCtrlForPanning : boolean;
+        public inputs : ArcRotateCameraInputsManager;
+        
+        // private _onContextMenu: (e: PointerEvent) => void;
+        // private _onPointerDown: (e: PointerEvent) => void;
+        // private _onPointerUp: (e: PointerEvent) => void;
+        // private _onPointerMove: (e: PointerEvent) => void;
+        // private _onMouseMove: (e: MouseEvent) => any;
+        // private _onGestureStart: (e: PointerEvent) => void;
+        // private _onGesture: (e: MSGestureEvent) => void;
+        // private _MSGestureHandler: MSGesture;
+
+        // private _wheel: (e: MouseWheelEvent) => void;
+        // private _onKeyDown: (e: KeyboardEvent) => any;
+        // private _onKeyUp: (e: KeyboardEvent) => any;
+        // private _onLostFocus: (e: FocusEvent) => any;
         public _reset: () => void;
-        private _onGestureStart: (e: PointerEvent) => void;
-        private _onGesture: (e: MSGestureEvent) => void;
-        private _MSGestureHandler: MSGesture;
-
+        
         // Panning
         public panningAxis: Vector3 = new Vector3(1, 1, 0);
         private _localDirection: Vector3;
         private _transformedDirection: Vector3;
-        private _isRightClick: boolean = false;
-        private _isCtrlPushed: boolean = false;
+        // private _isRightClick: boolean = false;
+        // private _isCtrlPushed: boolean = false;
 
         // Collisions
         public onCollide: (collidedMesh: AbstractMesh) => void;
@@ -123,17 +127,17 @@
         private _collisionTriggered: boolean;
         
         //deprecated angularSensibility support
-        public get angularSensibility() {
-            Tools.Warn("Warning: angularSensibility is deprecated, use angularSensibilityX and angularSensibilityY instead.");
-            return Math.max(this.angularSensibilityX, this.angularSensibilityY);
-        }
+        // public get angularSensibility() {
+        //     Tools.Warn("Warning: angularSensibility is deprecated, use angularSensibilityX and angularSensibilityY instead.");
+        //     return Math.max(this.angularSensibilityX, this.angularSensibilityY);
+        // }
         
-        //deprecated angularSensibility support
-        public set angularSensibility(value) {
-            Tools.Warn("Warning: angularSensibility is deprecated, use angularSensibilityX and angularSensibilityY instead.");
-            this.angularSensibilityX = value;
-            this.angularSensibilityY = value;
-        }
+        // //deprecated angularSensibility support
+        // public set angularSensibility(value) {
+        //     Tools.Warn("Warning: angularSensibility is deprecated, use angularSensibilityX and angularSensibilityY instead.");
+        //     this.angularSensibilityX = value;
+        //     this.angularSensibilityY = value;
+        // }
 
         constructor(name: string, alpha: number, beta: number, radius: number, target: Vector3, scene: Scene) {
             super(name, Vector3.Zero(), scene);
@@ -149,6 +153,8 @@
             this.radius = radius;
 
             this.getViewMatrix();
+            this.inputs = new ArcRotateCameraInputsManager(this);
+            this.inputs.addKeyboard().addMouseWheel().addPointers();
         }
 
         // Cache
@@ -195,234 +201,238 @@
 
         // Methods
         public attachControl(element: HTMLElement, noPreventDefault?: boolean, useCtrlForPanning: boolean = true): void {
-            var cacheSoloPointer; // cache pointer object for better perf on camera rotation
-            var previousPinchDistance = 0;
-            var pointers = new SmartCollection();
+            // var cacheSoloPointer; // cache pointer object for better perf on camera rotation
+            // var previousPinchDistance = 0;
+            // // var pointers = new SmartCollection();
 
             if (this._attachedElement) {
                 return;
             }
             this._attachedElement = element;
-
-            var engine = this.getEngine();
-
-            if (this._onPointerDown === undefined) {
-                this._onPointerDown = evt => {
-                    // Manage panning with right click
-                    this._isRightClick = evt.button === 2;
-
-                    // manage pointers
-                    pointers.add(evt.pointerId, { x: evt.clientX, y: evt.clientY, type: evt.pointerType });
-                    cacheSoloPointer = pointers.item(evt.pointerId);
-                    if (!noPreventDefault) {
-                        evt.preventDefault();
-                    }
-                };
-
-                this._onPointerUp = evt => {
-                    cacheSoloPointer = null;
-                    previousPinchDistance = 0;
+            this._noPreventDefault = noPreventDefault;
+            this._useCtrlForPanning = useCtrlForPanning;
+
+            this.inputs.attachElement(element, noPreventDefault);
+            
+            // var engine = this.getEngine();
+
+            // if (this._wheel === undefined) {
+            //     this._onPointerDown = evt => {
+            //         // Manage panning with right click
+            //         this._isRightClick = evt.button === 2;
+
+            //         // manage pointers
+            //         pointers.add(evt.pointerId, { x: evt.clientX, y: evt.clientY, type: evt.pointerType });
+            //         cacheSoloPointer = pointers.item(evt.pointerId);
+            //         if (!noPreventDefault) {
+            //             evt.preventDefault();
+            //         }
+            //     };
+
+            //     this._onPointerUp = evt => {
+            //         cacheSoloPointer = null;
+            //         previousPinchDistance = 0;
                     
-                    //would be better to use pointers.remove(evt.pointerId) for multitouch gestures, 
-                    //but emptying completly pointers collection is required to fix a bug on iPhone : 
-                    //when changing orientation while pinching camera, one pointer stay pressed forever if we don't release all pointers  
-                    //will be ok to put back pointers.remove(evt.pointerId); when iPhone bug corrected
-                    pointers.empty();
-
-                    if (!noPreventDefault) {
-                        evt.preventDefault();
-                    }
-                };
-
-                this._onContextMenu = evt => {
-                    evt.preventDefault();
-                };
-
-                this._onPointerMove = evt => {
-                    if (!noPreventDefault) {
-                        evt.preventDefault();
-                    }
-
-                    switch (pointers.count) {
-
-                        case 1: //normal camera rotation
-                            if (this.panningSensibility !== 0 && ((this._isCtrlPushed && useCtrlForPanning) || (!useCtrlForPanning && this._isRightClick))) {
-                                this.inertialPanningX += -(evt.clientX - cacheSoloPointer.x) / this.panningSensibility;
-                                this.inertialPanningY += (evt.clientY - cacheSoloPointer.y) / this.panningSensibility;
-                            } else {
-                                var offsetX = evt.clientX - cacheSoloPointer.x;
-                                var offsetY = evt.clientY - cacheSoloPointer.y;
-                                this.inertialAlphaOffset -= offsetX / this.angularSensibilityX;
-                                this.inertialBetaOffset -= offsetY / this.angularSensibilityY;
-                            }
-                            cacheSoloPointer.x = evt.clientX;
-                            cacheSoloPointer.y = evt.clientY;
-                            break;
-
-                        case 2: //pinch
-                            //if (noPreventDefault) { evt.preventDefault(); } //if pinch gesture, could be usefull to force preventDefault to avoid html page scroll/zoom in some mobile browsers
-                            pointers.item(evt.pointerId).x = evt.clientX;
-                            pointers.item(evt.pointerId).y = evt.clientY;
-                            var direction = this.pinchInwards ? 1 : -1;
-                            var distX = pointers.getItemByIndex(0).x - pointers.getItemByIndex(1).x;
-                            var distY = pointers.getItemByIndex(0).y - pointers.getItemByIndex(1).y;
-                            var pinchSquaredDistance = (distX * distX) + (distY * distY);
-                            if (previousPinchDistance === 0) {
-                                previousPinchDistance = pinchSquaredDistance;
-                                return;
-                            }
-
-                            if (pinchSquaredDistance !== previousPinchDistance) {
-                                this.inertialRadiusOffset += (pinchSquaredDistance - previousPinchDistance) / (this.pinchPrecision * this.wheelPrecision * ((this.angularSensibilityX + this.angularSensibilityY) / 2) * direction);
-                                previousPinchDistance = pinchSquaredDistance;
-                            }
-                            break;
-
-                        default:
-                            if (pointers.item(evt.pointerId)) {
-                                pointers.item(evt.pointerId).x = evt.clientX;
-                                pointers.item(evt.pointerId).y = evt.clientY;
-                            }
-                    }
-                };
-
-                this._onMouseMove = evt => {
-                    if (!engine.isPointerLock) {
-                        return;
-                    }
-
-                    var offsetX = evt.movementX || evt.mozMovementX || evt.webkitMovementX || evt.msMovementX || 0;
-                    var offsetY = evt.movementY || evt.mozMovementY || evt.webkitMovementY || evt.msMovementY || 0;
-
-                    this.inertialAlphaOffset -= offsetX / this.angularSensibilityX;
-                    this.inertialBetaOffset -= offsetY / this.angularSensibilityY;
-
-                    if (!noPreventDefault) {
-                        evt.preventDefault();
-                    }
-                };
-
-                this._wheel = event => {
-                    var delta = 0;
-                    if (event.wheelDelta) {
-                        delta = event.wheelDelta / (this.wheelPrecision * 40);
-                    } else if (event.detail) {
-                        delta = -event.detail / this.wheelPrecision;
-                    }
-
-                    if (delta)
-                        this.inertialRadiusOffset += delta;
-
-                    if (event.preventDefault) {
-                        if (!noPreventDefault) {
-                            event.preventDefault();
-                        }
-                    }
-                };
-
-                this._onKeyDown = evt => {
-                    this._isCtrlPushed = evt.ctrlKey;
-                    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) {
-                        var index = this._keys.indexOf(evt.keyCode);
-
-                        if (index === -1) {
-                            this._keys.push(evt.keyCode);
-                        }
-
-                        if (evt.preventDefault) {
-                            if (!noPreventDefault) {
-                                evt.preventDefault();
-                            }
-                        }
-                    }
-                };
-
-                this._onKeyUp = evt => {
-                    this._isCtrlPushed = evt.ctrlKey;
-                    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) {
-                        var index = this._keys.indexOf(evt.keyCode);
-
-                        if (index >= 0) {
-                            this._keys.splice(index, 1);
-                        }
-
-                        if (evt.preventDefault) {
-                            if (!noPreventDefault) {
-                                evt.preventDefault();
-                            }
-                        }
-                    }
-                };
-
-                this._onLostFocus = () => {
-                    this._keys = [];
-                    pointers.empty();
-                    previousPinchDistance = 0;
-                    cacheSoloPointer = null;
-                };
-
-                this._onGestureStart = e => {
-                    if (window.MSGesture === undefined) {
-                        return;
-                    }
-
-                    if (!this._MSGestureHandler) {
-                        this._MSGestureHandler = new MSGesture();
-                        this._MSGestureHandler.target = element;
-                    }
-
-                    this._MSGestureHandler.addPointer(e.pointerId);
-                };
-
-                this._onGesture = e => {
-                    this.radius *= e.scale;
-
-
-                    if (e.preventDefault) {
-                        if (!noPreventDefault) {
-                            e.stopPropagation();
-                            e.preventDefault();
-                        }
-                    }
-                };
+            //         //would be better to use pointers.remove(evt.pointerId) for multitouch gestures, 
+            //         //but emptying completly pointers collection is required to fix a bug on iPhone : 
+            //         //when changing orientation while pinching camera, one pointer stay pressed forever if we don't release all pointers  
+            //         //will be ok to put back pointers.remove(evt.pointerId); when iPhone bug corrected
+            //         pointers.empty();
+
+            //         if (!noPreventDefault) {
+            //             evt.preventDefault();
+            //         }
+            //     };
+
+            //     this._onContextMenu = evt => {
+            //         evt.preventDefault();
+            //     };
+
+            //     this._onPointerMove = evt => {
+            //         if (!noPreventDefault) {
+            //             evt.preventDefault();
+            //         }
+
+            //         switch (pointers.count) {
+
+            //             case 1: //normal camera rotation
+            //                 if (this.panningSensibility !== 0 && ((this._isCtrlPushed && useCtrlForPanning) || (!useCtrlForPanning && this._isRightClick))) {
+            //                     this.inertialPanningX += -(evt.clientX - cacheSoloPointer.x) / this.panningSensibility;
+            //                     this.inertialPanningY += (evt.clientY - cacheSoloPointer.y) / this.panningSensibility;
+            //                 } else {
+            //                     var offsetX = evt.clientX - cacheSoloPointer.x;
+            //                     var offsetY = evt.clientY - cacheSoloPointer.y;
+            //                     this.inertialAlphaOffset -= offsetX / this.angularSensibilityX;
+            //                     this.inertialBetaOffset -= offsetY / this.angularSensibilityY;
+            //                 }
+            //                 cacheSoloPointer.x = evt.clientX;
+            //                 cacheSoloPointer.y = evt.clientY;
+            //                 break;
+
+            //             case 2: //pinch
+            //                 //if (noPreventDefault) { evt.preventDefault(); } //if pinch gesture, could be usefull to force preventDefault to avoid html page scroll/zoom in some mobile browsers
+            //                 pointers.item(evt.pointerId).x = evt.clientX;
+            //                 pointers.item(evt.pointerId).y = evt.clientY;
+            //                 var direction = this.pinchInwards ? 1 : -1;
+            //                 var distX = pointers.getItemByIndex(0).x - pointers.getItemByIndex(1).x;
+            //                 var distY = pointers.getItemByIndex(0).y - pointers.getItemByIndex(1).y;
+            //                 var pinchSquaredDistance = (distX * distX) + (distY * distY);
+            //                 if (previousPinchDistance === 0) {
+            //                     previousPinchDistance = pinchSquaredDistance;
+            //                     return;
+            //                 }
+
+            //                 if (pinchSquaredDistance !== previousPinchDistance) {
+            //                     this.inertialRadiusOffset += (pinchSquaredDistance - previousPinchDistance) / (this.pinchPrecision * this.wheelPrecision * ((this.angularSensibilityX + this.angularSensibilityY) / 2) * direction);
+            //                     previousPinchDistance = pinchSquaredDistance;
+            //                 }
+            //                 break;
+
+            //             default:
+            //                 if (pointers.item(evt.pointerId)) {
+            //                     pointers.item(evt.pointerId).x = evt.clientX;
+            //                     pointers.item(evt.pointerId).y = evt.clientY;
+            //                 }
+            //         }
+            //     };
+
+            //     this._onMouseMove = evt => {
+            //         if (!engine.isPointerLock) {
+            //             return;
+            //         }
+
+            //         var offsetX = evt.movementX || evt.mozMovementX || evt.webkitMovementX || evt.msMovementX || 0;
+            //         var offsetY = evt.movementY || evt.mozMovementY || evt.webkitMovementY || evt.msMovementY || 0;
+
+            //         this.inertialAlphaOffset -= offsetX / this.angularSensibilityX;
+            //         this.inertialBetaOffset -= offsetY / this.angularSensibilityY;
+
+            //         if (!noPreventDefault) {
+            //             evt.preventDefault();
+            //         }
+            //     };
+
+                // this._wheel = event => {
+                //     var delta = 0;
+                //     if (event.wheelDelta) {
+                //         delta = event.wheelDelta / (this.wheelPrecision * 40);
+                //     } else if (event.detail) {
+                //         delta = -event.detail / this.wheelPrecision;
+                //     }
+
+                //     if (delta)
+                //         this.inertialRadiusOffset += delta;
+
+                //     if (event.preventDefault) {
+                //         if (!noPreventDefault) {
+                //             event.preventDefault();
+                //         }
+                //     }
+                // };
+
+                // this._onKeyDown = evt => {
+                //     this._isCtrlPushed = evt.ctrlKey;
+                //     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) {
+                //         var index = this._keys.indexOf(evt.keyCode);
+
+                //         if (index === -1) {
+                //             this._keys.push(evt.keyCode);
+                //         }
+
+                //         if (evt.preventDefault) {
+                //             if (!noPreventDefault) {
+                //                 evt.preventDefault();
+                //             }
+                //         }
+                //     }
+                // };
+
+                // this._onKeyUp = evt => {
+                //     this._isCtrlPushed = evt.ctrlKey;
+                //     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) {
+                //         var index = this._keys.indexOf(evt.keyCode);
+
+                //         if (index >= 0) {
+                //             this._keys.splice(index, 1);
+                //         }
+
+                //         if (evt.preventDefault) {
+                //             if (!noPreventDefault) {
+                //                 evt.preventDefault();
+                //             }
+                //         }
+                //     }
+                // };
+
+                // this._onLostFocus = () => {
+                //     //this._keys = [];
+                //     pointers.empty();
+                //     previousPinchDistance = 0;
+                //     cacheSoloPointer = null;
+                // };
+
+                // this._onGestureStart = e => {
+                //     if (window.MSGesture === undefined) {
+                //         return;
+                //     }
+
+                //     if (!this._MSGestureHandler) {
+                //         this._MSGestureHandler = new MSGesture();
+                //         this._MSGestureHandler.target = element;
+                //     }
+
+                //     this._MSGestureHandler.addPointer(e.pointerId);
+                // };
+
+                // this._onGesture = e => {
+                //     this.radius *= e.scale;
+
+
+                //     if (e.preventDefault) {
+                //         if (!noPreventDefault) {
+                //             e.stopPropagation();
+                //             e.preventDefault();
+                //         }
+                //     }
+                // };
 
                 this._reset = () => {
-                    this._keys = [];
+                    // this._keys = [];
                     this.inertialAlphaOffset = 0;
                     this.inertialBetaOffset = 0;
                     this.inertialRadiusOffset = 0;
-                    pointers.empty();
-                    previousPinchDistance = 0;
-                    cacheSoloPointer = null;
+                    // pointers.empty();
+                    // previousPinchDistance = 0;
+                    // cacheSoloPointer = null;
                 };
 
 
-            }
-
-            if (!useCtrlForPanning) {
-                element.addEventListener("contextmenu", this._onContextMenu, false);
-            }
-            element.addEventListener(eventPrefix + "down", this._onPointerDown, false);
-            element.addEventListener(eventPrefix + "up", this._onPointerUp, false);
-            element.addEventListener(eventPrefix + "out", this._onPointerUp, false);
-            element.addEventListener(eventPrefix + "move", this._onPointerMove, false);
-            element.addEventListener("mousemove", this._onMouseMove, false);
-            element.addEventListener("MSPointerDown", this._onGestureStart, false);
-            element.addEventListener("MSGestureChange", this._onGesture, false);
-            element.addEventListener('mousewheel', this._wheel, false);
-            element.addEventListener('DOMMouseScroll', this._wheel, false);
-
-            Tools.RegisterTopRootEvents([
-                { name: "keydown", handler: this._onKeyDown },
-                { name: "keyup", handler: this._onKeyUp },
-                { name: "blur", handler: this._onLostFocus }
-            ]);
+            // }
+
+            // if (!useCtrlForPanning) {
+            //     element.addEventListener("contextmenu", this._onContextMenu, false);
+            // }
+            //element.addEventListener(eventPrefix + "down", this._onPointerDown, false);
+            // element.addEventListener(eventPrefix + "up", this._onPointerUp, false);
+            // element.addEventListener(eventPrefix + "out", this._onPointerUp, false);
+            // element.addEventListener(eventPrefix + "move", this._onPointerMove, false);
+            // element.addEventListener("mousemove", this._onMouseMove, false);
+            // element.addEventListener("MSPointerDown", this._onGestureStart, false);
+            // element.addEventListener("MSGestureChange", this._onGesture, false);
+            // element.addEventListener('mousewheel', this._wheel, false);
+            // element.addEventListener('DOMMouseScroll', this._wheel, false);
+
+            // Tools.RegisterTopRootEvents([
+            //     // { name: "keydown", handler: this._onKeyDown },
+            //     // { name: "keyup", handler: this._onKeyUp },
+            //     { name: "blur", handler: this._onLostFocus }
+            // ]);
         }
 
         public detachControl(element: HTMLElement): void {
@@ -430,24 +440,26 @@
                 return;
             }
 
-            element.removeEventListener("contextmenu", this._onContextMenu);
-            element.removeEventListener(eventPrefix + "down", this._onPointerDown);
-            element.removeEventListener(eventPrefix + "up", this._onPointerUp);
-            element.removeEventListener(eventPrefix + "out", this._onPointerUp);
-            element.removeEventListener(eventPrefix + "move", this._onPointerMove);
-            element.removeEventListener("mousemove", this._onMouseMove);
-            element.removeEventListener("MSPointerDown", this._onGestureStart);
-            element.removeEventListener("MSGestureChange", this._onGesture);
-            element.removeEventListener('mousewheel', this._wheel);
-            element.removeEventListener('DOMMouseScroll', this._wheel);
-
-            Tools.UnregisterTopRootEvents([
-                { name: "keydown", handler: this._onKeyDown },
-                { name: "keyup", handler: this._onKeyUp },
-                { name: "blur", handler: this._onLostFocus }
-            ]);
-
-            this._MSGestureHandler = null;
+            this.inputs.detachElement(this._attachedElement);
+            
+            // element.removeEventListener("contextmenu", this._onContextMenu);
+            // element.removeEventListener(eventPrefix + "down", this._onPointerDown);
+            // element.removeEventListener(eventPrefix + "up", this._onPointerUp);
+            // element.removeEventListener(eventPrefix + "out", this._onPointerUp);
+            // element.removeEventListener(eventPrefix + "move", this._onPointerMove);
+            // element.removeEventListener("mousemove", this._onMouseMove);
+            // element.removeEventListener("MSPointerDown", this._onGestureStart);
+            // element.removeEventListener("MSGestureChange", this._onGesture);
+            // element.removeEventListener('mousewheel', this._wheel);
+            // element.removeEventListener('DOMMouseScroll', this._wheel);
+
+            // Tools.UnregisterTopRootEvents([
+            //     // { name: "keydown", handler: this._onKeyDown },
+            //     // { name: "keyup", handler: this._onKeyUp },
+            //     { name: "blur", handler: this._onLostFocus }
+            // ]);
+
+            // this._MSGestureHandler = null;
             this._attachedElement = null;
 
             if (this._reset) {
@@ -460,19 +472,22 @@
             if (this._collisionTriggered) {
                 return;
             }
+            
+            this.inputs.checkInputs();
+            
             // Keyboard
-            for (var index = 0; index < this._keys.length; index++) {
-                var keyCode = this._keys[index];
-                if (this.keysLeft.indexOf(keyCode) !== -1) {
-                    this.inertialAlphaOffset -= 0.01;
-                } else if (this.keysUp.indexOf(keyCode) !== -1) {
-                    this.inertialBetaOffset -= 0.01;
-                } else if (this.keysRight.indexOf(keyCode) !== -1) {
-                    this.inertialAlphaOffset += 0.01;
-                } else if (this.keysDown.indexOf(keyCode) !== -1) {
-                    this.inertialBetaOffset += 0.01;
-                }
-            }			
+            // for (var index = 0; index < this._keys.length; index++) {
+            //     var keyCode = this._keys[index];
+            //     if (this.keysLeft.indexOf(keyCode) !== -1) {
+            //         this.inertialAlphaOffset -= 0.01;
+            //     } else if (this.keysUp.indexOf(keyCode) !== -1) {
+            //         this.inertialBetaOffset -= 0.01;
+            //     } else if (this.keysRight.indexOf(keyCode) !== -1) {
+            //         this.inertialAlphaOffset += 0.01;
+            //     } else if (this.keysDown.indexOf(keyCode) !== -1) {
+            //         this.inertialBetaOffset += 0.01;
+            //     }
+            // }			
 			
             // Inertia
             if (this.inertialAlphaOffset !== 0 || this.inertialBetaOffset !== 0 || this.inertialRadiusOffset !== 0) {

+ 28 - 0
src/Cameras/babylon.arcRotateCameraInputsManager.js

@@ -0,0 +1,28 @@
+var __extends = (this && this.__extends) || function (d, b) {
+    for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
+    function __() { this.constructor = d; }
+    d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
+};
+var BABYLON;
+(function (BABYLON) {
+    var ArcRotateCameraInputsManager = (function (_super) {
+        __extends(ArcRotateCameraInputsManager, _super);
+        function ArcRotateCameraInputsManager(camera) {
+            _super.call(this, camera);
+        }
+        ArcRotateCameraInputsManager.prototype.addMouseWheel = function () {
+            this.add(new BABYLON.ArcRotateCameraMouseWheelInput());
+            return this;
+        };
+        ArcRotateCameraInputsManager.prototype.addPointers = function () {
+            this.add(new BABYLON.ArcRotateCameraPointersInput());
+            return this;
+        };
+        ArcRotateCameraInputsManager.prototype.addKeyboard = function () {
+            this.add(new BABYLON.ArcRotateCameraKeyboardMoveInput());
+            return this;
+        };
+        return ArcRotateCameraInputsManager;
+    }(BABYLON.CameraInputsManager));
+    BABYLON.ArcRotateCameraInputsManager = ArcRotateCameraInputsManager;
+})(BABYLON || (BABYLON = {}));

+ 22 - 0
src/Cameras/babylon.arcRotateCameraInputsManager.ts

@@ -0,0 +1,22 @@
+module BABYLON {
+    export class ArcRotateCameraInputsManager extends CameraInputsManager<ArcRotateCamera> {
+        constructor(camera : ArcRotateCamera){
+            super(camera);    
+        }
+        
+        public addMouseWheel(){
+            this.add(new ArcRotateCameraMouseWheelInput());
+            return this;
+        }
+        
+        public addPointers(){
+            this.add(new ArcRotateCameraPointersInput());
+            return this;
+        }
+        
+        public addKeyboard(){
+            this.add(new ArcRotateCameraKeyboardMoveInput());
+            return this;
+        }
+    }
+}

+ 2 - 5
src/Cameras/babylon.cameraInputsManager.js

@@ -1,9 +1,6 @@
 var BABYLON;
 (function (BABYLON) {
-    var CameraInputs;
-    (function (CameraInputs) {
-        CameraInputs.InputTypes = {};
-    })(CameraInputs = BABYLON.CameraInputs || (BABYLON.CameraInputs = {}));
+    BABYLON.CameraInputTypes = {};
     var CameraInputsManager = (function () {
         function CameraInputsManager(camera) {
             this.inputs = {};
@@ -74,7 +71,7 @@ var BABYLON;
             if (parsedInputs) {
                 this.clear();
                 for (var n in parsedInputs) {
-                    var construct = CameraInputs.InputTypes[n];
+                    var construct = BABYLON.CameraInputTypes[n];
                     if (construct) {
                         var parsedinput = parsedInputs[n];
                         var input = BABYLON.SerializationHelper.Parse(function () { return new construct(); }, parsedinput, null);

+ 2 - 4
src/Cameras/babylon.cameraInputsManager.ts

@@ -1,7 +1,5 @@
 module BABYLON {
-    export module CameraInputs{
-        export var InputTypes = {};
-    }
+    export var CameraInputTypes = {};
     
     export interface ICameraInput<TCamera extends BABYLON.Camera> {
         camera: TCamera;
@@ -109,7 +107,7 @@ module BABYLON {
                 this.clear();
                 
                 for (var n in parsedInputs) {
-                    var construct = CameraInputs.InputTypes[n];
+                    var construct = CameraInputTypes[n];
                     if (construct){
                         var parsedinput = parsedInputs[n];
                         var input = SerializationHelper.Parse(() => { return new construct() }, parsedinput, null);

+ 0 - 70
src/Cameras/babylon.deviceOrientationCamera.js

@@ -8,80 +8,10 @@ var BABYLON;
     // We're mainly based on the logic defined into the FreeCamera code
     var DeviceOrientationCamera = (function (_super) {
         __extends(DeviceOrientationCamera, _super);
-        //         private _offsetX: number = null;
-        //         private _offsetY: number = null;
-        //         private _orientationGamma: number = 0;
-        //         private _orientationBeta: number = 0;
-        //         private _initialOrientationGamma: number = 0;
-        //         private _initialOrientationBeta: number = 0;
-        //         private _attachedCanvas: HTMLCanvasElement;
-        //         private _orientationChanged: (e: DeviceOrientationEvent) => any;
-        // 
-        //         @serialize()
-        //         public angularSensibility: number = 10000.0;
-        // 
-        //         @serialize()
-        //         public moveSensibility: number = 50.0;
         function DeviceOrientationCamera(name, position, scene) {
             _super.call(this, name, position, scene);
             this.inputs.addDeviceOrientation();
-            // window.addEventListener("resize", () => {
-            //     this._initialOrientationGamma = null;
-            // }, false);
         }
-        //         public attachControl(canvas: HTMLCanvasElement, noPreventDefault: boolean): void {
-        //             if (this._attachedCanvas) {
-        //                 return;
-        //             }
-        //             this._attachedCanvas = canvas;
-        // 
-        //             if (!this._orientationChanged) {
-        //                 this._orientationChanged = (evt) => {
-        // 
-        //                     if (!this._initialOrientationGamma) {
-        //                             this._initialOrientationGamma = evt.gamma;
-        //                             this._initialOrientationBeta = evt.beta;
-        //                     }
-        // 
-        //                     this._orientationGamma = evt.gamma;
-        //                     this._orientationBeta = evt.beta;
-        //  
-        //                     this._offsetY = (this._initialOrientationBeta - this._orientationBeta);
-        //                     this._offsetX = (this._initialOrientationGamma - this._orientationGamma);
-        //                 };
-        //             }
-        // 
-        //             window.addEventListener("deviceorientation", this._orientationChanged);
-        //         }
-        // 
-        //         public detachControl(canvas: HTMLCanvasElement): void {
-        //             if (this._attachedCanvas !== canvas) {
-        //                 return;
-        //             }
-        // 
-        //             window.removeEventListener("deviceorientation", this._orientationChanged);
-        // 
-        //             this._attachedCanvas = null;
-        //             this._orientationGamma = 0;
-        //             this._orientationBeta = 0;
-        //             this._initialOrientationGamma = 0;
-        //             this._initialOrientationBeta = 0;
-        //         }
-        // 
-        //         public _checkInputs(): void {
-        //             if (!this._offsetX) {
-        //                 return;
-        //             }
-        //             this.cameraRotation.y -= this._offsetX / this.angularSensibility;
-        // 
-        //             var speed = this._computeLocalCameraSpeed();
-        //             var direction = new Vector3(0, 0, speed * this._offsetY / this.moveSensibility);
-        // 
-        //             Matrix.RotationYawPitchRollToRef(this.rotation.y, this.rotation.x, 0, this._cameraRotationMatrix);
-        //             this.cameraDirection.addInPlace(Vector3.TransformCoordinates(direction, this._cameraRotationMatrix));
-        // 
-        //             super._checkInputs();
-        //         }
         DeviceOrientationCamera.prototype.getTypeName = function () {
             return "DeviceOrientationCamera";
         };

+ 0 - 72
src/Cameras/babylon.deviceOrientationCamera.ts

@@ -1,83 +1,11 @@
 module BABYLON {
     // We're mainly based on the logic defined into the FreeCamera code
     export class DeviceOrientationCamera extends FreeCamera {
-//         private _offsetX: number = null;
-//         private _offsetY: number = null;
-//         private _orientationGamma: number = 0;
-//         private _orientationBeta: number = 0;
-//         private _initialOrientationGamma: number = 0;
-//         private _initialOrientationBeta: number = 0;
-//         private _attachedCanvas: HTMLCanvasElement;
-//         private _orientationChanged: (e: DeviceOrientationEvent) => any;
-// 
-//         @serialize()
-//         public angularSensibility: number = 10000.0;
-// 
-//         @serialize()
-//         public moveSensibility: number = 50.0;
-
         constructor(name: string, position: Vector3, scene: Scene) {
             super(name, position, scene);
             this.inputs.addDeviceOrientation();
-            // window.addEventListener("resize", () => {
-            //     this._initialOrientationGamma = null;
-            // }, false);
         }
 
-//         public attachControl(canvas: HTMLCanvasElement, noPreventDefault: boolean): void {
-//             if (this._attachedCanvas) {
-//                 return;
-//             }
-//             this._attachedCanvas = canvas;
-// 
-//             if (!this._orientationChanged) {
-//                 this._orientationChanged = (evt) => {
-// 
-//                     if (!this._initialOrientationGamma) {
-//                             this._initialOrientationGamma = evt.gamma;
-//                             this._initialOrientationBeta = evt.beta;
-//                     }
-// 
-//                     this._orientationGamma = evt.gamma;
-//                     this._orientationBeta = evt.beta;
-//  
-//                     this._offsetY = (this._initialOrientationBeta - this._orientationBeta);
-//                     this._offsetX = (this._initialOrientationGamma - this._orientationGamma);
-//                 };
-//             }
-// 
-//             window.addEventListener("deviceorientation", this._orientationChanged);
-//         }
-// 
-//         public detachControl(canvas: HTMLCanvasElement): void {
-//             if (this._attachedCanvas !== canvas) {
-//                 return;
-//             }
-// 
-//             window.removeEventListener("deviceorientation", this._orientationChanged);
-// 
-//             this._attachedCanvas = null;
-//             this._orientationGamma = 0;
-//             this._orientationBeta = 0;
-//             this._initialOrientationGamma = 0;
-//             this._initialOrientationBeta = 0;
-//         }
-// 
-//         public _checkInputs(): void {
-//             if (!this._offsetX) {
-//                 return;
-//             }
-//             this.cameraRotation.y -= this._offsetX / this.angularSensibility;
-// 
-//             var speed = this._computeLocalCameraSpeed();
-//             var direction = new Vector3(0, 0, speed * this._offsetY / this.moveSensibility);
-// 
-//             Matrix.RotationYawPitchRollToRef(this.rotation.y, this.rotation.x, 0, this._cameraRotationMatrix);
-//             this.cameraDirection.addInPlace(Vector3.TransformCoordinates(direction, this._cameraRotationMatrix));
-// 
-//             super._checkInputs();
-//         }
-
         public getTypeName(): string {
             return "DeviceOrientationCamera";
         }

+ 1 - 35
src/Cameras/babylon.freeCamera.js

@@ -42,7 +42,7 @@ var BABYLON;
                 };
                 updatePosition(newPosition);
             };
-            this.inputs = new FreeCameraInputsManager(this);
+            this.inputs = new BABYLON.FreeCameraInputsManager(this);
             this.inputs.addKeyboard().addMouse();
         }
         // Controls
@@ -120,38 +120,4 @@ var BABYLON;
         return FreeCamera;
     }(BABYLON.TargetCamera));
     BABYLON.FreeCamera = FreeCamera;
-    var FreeCameraInputsManager = (function (_super) {
-        __extends(FreeCameraInputsManager, _super);
-        function FreeCameraInputsManager(camera) {
-            _super.call(this, camera);
-        }
-        FreeCameraInputsManager.prototype.add = function (input) {
-            _super.prototype.add.call(this, input);
-            if (this.camera._attachedElement && input.attachElement) {
-                input.attachElement(this.camera._attachedElement, this.camera._noPreventDefault);
-            }
-        };
-        FreeCameraInputsManager.prototype.addKeyboard = function () {
-            this.add(new BABYLON.CameraInputs.FreeCameraKeyboardMoveInput());
-            return this;
-        };
-        FreeCameraInputsManager.prototype.addMouse = function () {
-            this.add(new BABYLON.CameraInputs.FreeCameraMouseInput());
-            return this;
-        };
-        FreeCameraInputsManager.prototype.addGamepad = function () {
-            this.add(new BABYLON.CameraInputs.FreeCameraGamepadInput());
-            return this;
-        };
-        FreeCameraInputsManager.prototype.addDeviceOrientation = function () {
-            this.add(new BABYLON.CameraInputs.FreeCameraDeviceOrientationInput());
-            return this;
-        };
-        FreeCameraInputsManager.prototype.addTouch = function () {
-            this.add(new BABYLON.CameraInputs.FreeCameraTouchInput());
-            return this;
-        };
-        return FreeCameraInputsManager;
-    }(BABYLON.CameraInputsManager));
-    BABYLON.FreeCameraInputsManager = FreeCameraInputsManager;
 })(BABYLON || (BABYLON = {}));

+ 1 - 39
src/Cameras/babylon.freeCamera.ts

@@ -131,43 +131,5 @@
         public getTypeName(): string {
             return "FreeCamera";
         }
-    }
-    
-    export class FreeCameraInputsManager extends CameraInputsManager<FreeCamera> {
-        constructor(camera : FreeCamera){
-            super(camera);    
-        }
-        
-        add(input: ICameraInput<FreeCamera>){
-            super.add(input);
-            if (this.camera._attachedElement && input.attachElement) {
-                input.attachElement(this.camera._attachedElement, this.camera._noPreventDefault);
-            }
-        }
-        
-        addKeyboard(){
-            this.add(new CameraInputs.FreeCameraKeyboardMoveInput());
-            return this;
-        }
-        
-        addMouse(){
-            this.add(new CameraInputs.FreeCameraMouseInput());
-            return this;
-        }
-        
-        addGamepad(){
-            this.add(new CameraInputs.FreeCameraGamepadInput());
-            return this;
-        }
-        
-        addDeviceOrientation(){
-            this.add(new CameraInputs.FreeCameraDeviceOrientationInput());
-            return this;
-        }
-        
-        addTouch(){
-            this.add(new CameraInputs.FreeCameraTouchInput());
-            return this;
-        }
-    }
+    }    
 } 

+ 46 - 0
src/Cameras/babylon.freeCameraInputsManager.js

@@ -0,0 +1,46 @@
+var __extends = (this && this.__extends) || function (d, b) {
+    for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
+    function __() { this.constructor = d; }
+    d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
+};
+var BABYLON;
+(function (BABYLON) {
+    var FreeCameraInputsManager = (function (_super) {
+        __extends(FreeCameraInputsManager, _super);
+        function FreeCameraInputsManager(camera) {
+            _super.call(this, camera);
+        }
+        FreeCameraInputsManager.prototype.add = function (input) {
+            _super.prototype.add.call(this, input);
+            if (this.camera._attachedElement && input.attachElement) {
+                input.attachElement(this.camera._attachedElement, this.camera._noPreventDefault);
+            }
+        };
+        FreeCameraInputsManager.prototype.addKeyboard = function () {
+            this.add(new BABYLON.FreeCameraKeyboardMoveInput());
+            return this;
+        };
+        FreeCameraInputsManager.prototype.addMouse = function () {
+            this.add(new BABYLON.FreeCameraMouseInput());
+            return this;
+        };
+        FreeCameraInputsManager.prototype.addGamepad = function () {
+            this.add(new BABYLON.FreeCameraGamepadInput());
+            return this;
+        };
+        FreeCameraInputsManager.prototype.addDeviceOrientation = function () {
+            this.add(new BABYLON.FreeCameraDeviceOrientationInput());
+            return this;
+        };
+        FreeCameraInputsManager.prototype.addTouch = function () {
+            this.add(new BABYLON.FreeCameraTouchInput());
+            return this;
+        };
+        FreeCameraInputsManager.prototype.addVirtualJoystick = function () {
+            this.add(new BABYLON.FreeCameraVirtualJoystickInput());
+            return this;
+        };
+        return FreeCameraInputsManager;
+    }(BABYLON.CameraInputsManager));
+    BABYLON.FreeCameraInputsManager = FreeCameraInputsManager;
+})(BABYLON || (BABYLON = {}));

+ 44 - 0
src/Cameras/babylon.freeCameraInputsManager.ts

@@ -0,0 +1,44 @@
+module BABYLON {
+    export class FreeCameraInputsManager extends CameraInputsManager<FreeCamera> {
+        constructor(camera : FreeCamera){
+            super(camera);    
+        }
+        
+        add(input: ICameraInput<FreeCamera>){
+            super.add(input);
+            if (this.camera._attachedElement && input.attachElement) {
+                input.attachElement(this.camera._attachedElement, this.camera._noPreventDefault);
+            }
+        }
+        
+        addKeyboard(){
+            this.add(new FreeCameraKeyboardMoveInput());
+            return this;
+        }
+        
+        addMouse(){
+            this.add(new FreeCameraMouseInput());
+            return this;
+        }
+        
+        addGamepad(){
+            this.add(new FreeCameraGamepadInput());
+            return this;
+        }
+        
+        addDeviceOrientation(){
+            this.add(new FreeCameraDeviceOrientationInput());
+            return this;
+        }
+        
+        addTouch(){
+            this.add(new FreeCameraTouchInput());
+            return this;
+        }
+        
+        addVirtualJoystick(){
+            this.add(new FreeCameraVirtualJoystickInput());
+            return this;
+        }
+    }
+}

+ 0 - 141
src/Cameras/babylon.touchCamera.js

@@ -8,151 +8,10 @@ var BABYLON;
     // We're mainly based on the logic defined into the FreeCamera code
     var TouchCamera = (function (_super) {
         __extends(TouchCamera, _super);
-        //         private _offsetX: number = null;
-        //         private _offsetY: number = null;
-        //         private _pointerCount:number = 0;
-        //         private _pointerPressed = [];
-        //         private _attachedCanvas: HTMLCanvasElement;
-        //         private _onPointerDown: (e: PointerEvent) => any;
-        //         private _onPointerUp: (e: PointerEvent) => any;
-        //         private _onPointerMove: (e: PointerEvent) => any;
-        // 
-        //         @serialize()
-        //         public touchAngularSensibility: number = 200000.0;
-        // 
-        //         @serialize()
-        //         public touchMoveSensibility: number = 250.0;
         function TouchCamera(name, position, scene) {
             _super.call(this, name, position, scene);
             this.inputs.addTouch();
         }
-        // public _onLostFocus(e: FocusEvent): void {
-        //     this._offsetX = null;
-        //     this._offsetY = null;
-        //     super._onLostFocus(e);
-        // }
-        //         public attachControl(canvas: HTMLCanvasElement, noPreventDefault: boolean): void {
-        //             var previousPosition;
-        // 
-        //             if (this._attachedCanvas) {
-        //                 return;
-        //             }
-        // 
-        //             if (this._onPointerDown === undefined) {
-        // 
-        //                 this._onPointerDown = (evt) => {
-        // 
-        //                     if (evt.pointerType === "mouse") {
-        //                         return;
-        //                     }
-        // 
-        //                     if (!noPreventDefault) {
-        //                         evt.preventDefault();
-        //                     }
-        // 
-        //                     this._pointerPressed.push(evt.pointerId);
-        // 
-        //                     if (this._pointerPressed.length !== 1) {
-        //                         return;
-        //                     }
-        // 
-        //                     previousPosition = {
-        //                         x: evt.clientX,
-        //                         y: evt.clientY
-        //                     };
-        //                 };
-        // 
-        //                 this._onPointerUp = (evt) => {
-        // 
-        //                     if (evt.pointerType === "mouse") {
-        //                         return;
-        //                     }
-        // 
-        //                     if (!noPreventDefault) {
-        //                         evt.preventDefault();
-        //                     }
-        // 
-        //                     var index: number = this._pointerPressed.indexOf(evt.pointerId);
-        // 
-        //                     if (index === -1) {
-        //                         return;
-        //                     }
-        //                     this._pointerPressed.splice(index, 1);
-        // 
-        //                     if (index != 0) {
-        //                         return;
-        //                     }
-        //                     previousPosition = null;
-        //                     this._offsetX = null;
-        //                     this._offsetY = null;
-        //                 };
-        // 
-        //                 this._onPointerMove = (evt) => {
-        // 
-        //                     if (evt.pointerType === "mouse") {
-        //                         return;
-        //                     }
-        // 
-        //                     if (!noPreventDefault) {
-        //                         evt.preventDefault();
-        //                     }
-        // 
-        //                     if (!previousPosition) {
-        //                         return;
-        //                     }
-        // 
-        //                     var index: number = this._pointerPressed.indexOf(evt.pointerId);
-        // 
-        //                     if (index != 0) {
-        //                         return;
-        //                     }
-        // 
-        //                     this._offsetX = evt.clientX - previousPosition.x;
-        //                     this._offsetY = -(evt.clientY - previousPosition.y);
-        //                 };
-        // 
-        //                 
-        //             }
-        // 
-        //             canvas.addEventListener("pointerdown", this._onPointerDown);
-        //             canvas.addEventListener("pointerup", this._onPointerUp);
-        //             canvas.addEventListener("pointerout", this._onPointerUp);
-        //             canvas.addEventListener("pointermove", this._onPointerMove);
-        // 
-        //             super.attachControl(canvas);
-        //         }
-        // 
-        //         public detachControl(canvas: HTMLCanvasElement): void {
-        //             if (this._attachedCanvas !== canvas) {
-        //                 return;
-        //             }
-        // 
-        //             canvas.removeEventListener("pointerdown", this._onPointerDown);
-        //             canvas.removeEventListener("pointerup", this._onPointerUp);
-        //             canvas.removeEventListener("pointerout", this._onPointerUp);
-        //             canvas.removeEventListener("pointermove", this._onPointerMove);
-        //             
-        //             super.detachControl(canvas);
-        //         }
-        // 
-        //         public _checkInputs(): void {
-        //             if (this._offsetX) {
-        // 
-        //                 this.cameraRotation.y += this._offsetX / this.touchAngularSensibility;
-        // 
-        //                 if (this._pointerPressed.length > 1) {
-        //                     this.cameraRotation.x += -this._offsetY / this.touchAngularSensibility;
-        //                 } else {
-        //                     var speed = this._computeLocalCameraSpeed();
-        //                     var direction = new Vector3(0, 0, speed * this._offsetY / this.touchMoveSensibility);
-        // 
-        //                     Matrix.RotationYawPitchRollToRef(this.rotation.y, this.rotation.x, 0, this._cameraRotationMatrix);
-        //                     this.cameraDirection.addInPlace(Vector3.TransformCoordinates(direction, this._cameraRotationMatrix));
-        //                 }
-        //             }
-        // 
-        //             super._checkInputs();
-        //         }
         TouchCamera.prototype.getTypeName = function () {
             return "TouchCamera";
         };

+ 0 - 144
src/Cameras/babylon.touchCamera.ts

@@ -1,155 +1,11 @@
 module BABYLON {
     // We're mainly based on the logic defined into the FreeCamera code
     export class TouchCamera extends FreeCamera {
-//         private _offsetX: number = null;
-//         private _offsetY: number = null;
-//         private _pointerCount:number = 0;
-//         private _pointerPressed = [];
-//         private _attachedCanvas: HTMLCanvasElement;
-//         private _onPointerDown: (e: PointerEvent) => any;
-//         private _onPointerUp: (e: PointerEvent) => any;
-//         private _onPointerMove: (e: PointerEvent) => any;
-// 
-//         @serialize()
-//         public touchAngularSensibility: number = 200000.0;
-// 
-//         @serialize()
-//         public touchMoveSensibility: number = 250.0;
-
         constructor(name: string, position: Vector3, scene: Scene) {
             super(name, position, scene);
             this.inputs.addTouch();
         }
 
-        // public _onLostFocus(e: FocusEvent): void {
-        //     this._offsetX = null;
-        //     this._offsetY = null;
-        //     super._onLostFocus(e);
-        // }
-
-//         public attachControl(canvas: HTMLCanvasElement, noPreventDefault: boolean): void {
-//             var previousPosition;
-// 
-//             if (this._attachedCanvas) {
-//                 return;
-//             }
-// 
-//             if (this._onPointerDown === undefined) {
-// 
-//                 this._onPointerDown = (evt) => {
-// 
-//                     if (evt.pointerType === "mouse") {
-//                         return;
-//                     }
-// 
-//                     if (!noPreventDefault) {
-//                         evt.preventDefault();
-//                     }
-// 
-//                     this._pointerPressed.push(evt.pointerId);
-// 
-//                     if (this._pointerPressed.length !== 1) {
-//                         return;
-//                     }
-// 
-//                     previousPosition = {
-//                         x: evt.clientX,
-//                         y: evt.clientY
-//                     };
-//                 };
-// 
-//                 this._onPointerUp = (evt) => {
-// 
-//                     if (evt.pointerType === "mouse") {
-//                         return;
-//                     }
-// 
-//                     if (!noPreventDefault) {
-//                         evt.preventDefault();
-//                     }
-// 
-//                     var index: number = this._pointerPressed.indexOf(evt.pointerId);
-// 
-//                     if (index === -1) {
-//                         return;
-//                     }
-//                     this._pointerPressed.splice(index, 1);
-// 
-//                     if (index != 0) {
-//                         return;
-//                     }
-//                     previousPosition = null;
-//                     this._offsetX = null;
-//                     this._offsetY = null;
-//                 };
-// 
-//                 this._onPointerMove = (evt) => {
-// 
-//                     if (evt.pointerType === "mouse") {
-//                         return;
-//                     }
-// 
-//                     if (!noPreventDefault) {
-//                         evt.preventDefault();
-//                     }
-// 
-//                     if (!previousPosition) {
-//                         return;
-//                     }
-// 
-//                     var index: number = this._pointerPressed.indexOf(evt.pointerId);
-// 
-//                     if (index != 0) {
-//                         return;
-//                     }
-// 
-//                     this._offsetX = evt.clientX - previousPosition.x;
-//                     this._offsetY = -(evt.clientY - previousPosition.y);
-//                 };
-// 
-//                 
-//             }
-// 
-//             canvas.addEventListener("pointerdown", this._onPointerDown);
-//             canvas.addEventListener("pointerup", this._onPointerUp);
-//             canvas.addEventListener("pointerout", this._onPointerUp);
-//             canvas.addEventListener("pointermove", this._onPointerMove);
-// 
-//             super.attachControl(canvas);
-//         }
-// 
-//         public detachControl(canvas: HTMLCanvasElement): void {
-//             if (this._attachedCanvas !== canvas) {
-//                 return;
-//             }
-// 
-//             canvas.removeEventListener("pointerdown", this._onPointerDown);
-//             canvas.removeEventListener("pointerup", this._onPointerUp);
-//             canvas.removeEventListener("pointerout", this._onPointerUp);
-//             canvas.removeEventListener("pointermove", this._onPointerMove);
-//             
-//             super.detachControl(canvas);
-//         }
-// 
-//         public _checkInputs(): void {
-//             if (this._offsetX) {
-// 
-//                 this.cameraRotation.y += this._offsetX / this.touchAngularSensibility;
-// 
-//                 if (this._pointerPressed.length > 1) {
-//                     this.cameraRotation.x += -this._offsetY / this.touchAngularSensibility;
-//                 } else {
-//                     var speed = this._computeLocalCameraSpeed();
-//                     var direction = new Vector3(0, 0, speed * this._offsetY / this.touchMoveSensibility);
-// 
-//                     Matrix.RotationYawPitchRollToRef(this.rotation.y, this.rotation.x, 0, this._cameraRotationMatrix);
-//                     this.cameraDirection.addInPlace(Vector3.TransformCoordinates(direction, this._cameraRotationMatrix));
-//                 }
-//             }
-// 
-//             super._checkInputs();
-//         }
-
         public getTypeName(): string {
             return "TouchCamera";
         }

+ 0 - 52
src/Cameras/babylon.universalCamera.js

@@ -8,62 +8,10 @@ var BABYLON;
     // We're mainly based on the logic defined into the FreeCamera code
     var UniversalCamera = (function (_super) {
         __extends(UniversalCamera, _super);
-        //         public gamepad: Gamepad;
-        //         private _gamepads: Gamepads;
-        // 
-        //         @serialize()
-        //         public gamepadAngularSensibility = 200;
-        // 
-        //         @serialize()
-        //         public gamepadMoveSensibility = 40;
         function UniversalCamera(name, position, scene) {
             _super.call(this, name, position, scene);
             this.inputs.addGamepad();
-            // this._gamepads = new Gamepads((gamepad: Gamepad) => { this._onNewGameConnected(gamepad); });
         }
-        //         private _onNewGameConnected(gamepad: Gamepad) {
-        //             // Only the first gamepad can control the camera
-        //             if (gamepad.index === 0) {
-        //                 this.gamepad = gamepad;
-        //             }
-        //         }
-        // 
-        //         public attachControl(canvas: HTMLCanvasElement, noPreventDefault: boolean): void {
-        //             super.attachControl(canvas, false);
-        //         }
-        // 
-        //         public detachControl(canvas: HTMLCanvasElement): void {
-        //             super.detachControl(canvas);
-        //         }
-        // 
-        //         public _checkInputs(): void {
-        //             if (this.gamepad) {
-        //                 var LSValues = this.gamepad.leftStick;
-        //                 var normalizedLX = LSValues.x / this.gamepadMoveSensibility;
-        //                 var normalizedLY = LSValues.y / this.gamepadMoveSensibility;
-        //                 LSValues.x = Math.abs(normalizedLX) > 0.005 ? 0 + normalizedLX : 0;
-        //                 LSValues.y = Math.abs(normalizedLY) > 0.005 ? 0 + normalizedLY : 0;
-        // 
-        //                 var RSValues = this.gamepad.rightStick;
-        //                 var normalizedRX = RSValues.x / this.gamepadAngularSensibility;
-        //                 var normalizedRY = RSValues.y / this.gamepadAngularSensibility;
-        //                 RSValues.x = Math.abs(normalizedRX) > 0.001 ? 0 + normalizedRX : 0;
-        //                 RSValues.y = Math.abs(normalizedRY) > 0.001 ? 0 + normalizedRY : 0;
-        // 
-        //                 var cameraTransform = Matrix.RotationYawPitchRoll(this.rotation.y, this.rotation.x, 0);
-        // 
-        //                 var speed = this._computeLocalCameraSpeed() * 50.0;
-        //                 var deltaTransform = Vector3.TransformCoordinates(new Vector3(LSValues.x * speed, 0, -LSValues.y * speed), cameraTransform);
-        //                 this.cameraDirection = this.cameraDirection.add(deltaTransform);
-        //                 this.cameraRotation = this.cameraRotation.add(new Vector2(RSValues.y, RSValues.x));
-        //             }
-        //             super._checkInputs();
-        //         }
-        // 
-        //         public dispose(): void {
-        //             this._gamepads.dispose();
-        //             super.dispose();
-        //         }
         UniversalCamera.prototype.getTypeName = function () {
             return "UniversalCamera";
         };

+ 0 - 53
src/Cameras/babylon.universalCamera.ts

@@ -1,65 +1,12 @@
 module BABYLON {
     // We're mainly based on the logic defined into the FreeCamera code
     export class UniversalCamera extends TouchCamera {
-//         public gamepad: Gamepad;
-//         private _gamepads: Gamepads;
-// 
-//         @serialize()
-//         public gamepadAngularSensibility = 200;
-// 
-//         @serialize()
-//         public gamepadMoveSensibility = 40;
 
         constructor(name: string, position: Vector3, scene: Scene) {
             super(name, position, scene);
             this.inputs.addGamepad();
-            // this._gamepads = new Gamepads((gamepad: Gamepad) => { this._onNewGameConnected(gamepad); });
         }
 
-//         private _onNewGameConnected(gamepad: Gamepad) {
-//             // Only the first gamepad can control the camera
-//             if (gamepad.index === 0) {
-//                 this.gamepad = gamepad;
-//             }
-//         }
-// 
-//         public attachControl(canvas: HTMLCanvasElement, noPreventDefault: boolean): void {
-//             super.attachControl(canvas, false);
-//         }
-// 
-//         public detachControl(canvas: HTMLCanvasElement): void {
-//             super.detachControl(canvas);
-//         }
-// 
-//         public _checkInputs(): void {
-//             if (this.gamepad) {
-//                 var LSValues = this.gamepad.leftStick;
-//                 var normalizedLX = LSValues.x / this.gamepadMoveSensibility;
-//                 var normalizedLY = LSValues.y / this.gamepadMoveSensibility;
-//                 LSValues.x = Math.abs(normalizedLX) > 0.005 ? 0 + normalizedLX : 0;
-//                 LSValues.y = Math.abs(normalizedLY) > 0.005 ? 0 + normalizedLY : 0;
-// 
-//                 var RSValues = this.gamepad.rightStick;
-//                 var normalizedRX = RSValues.x / this.gamepadAngularSensibility;
-//                 var normalizedRY = RSValues.y / this.gamepadAngularSensibility;
-//                 RSValues.x = Math.abs(normalizedRX) > 0.001 ? 0 + normalizedRX : 0;
-//                 RSValues.y = Math.abs(normalizedRY) > 0.001 ? 0 + normalizedRY : 0;
-// 
-//                 var cameraTransform = Matrix.RotationYawPitchRoll(this.rotation.y, this.rotation.x, 0);
-// 
-//                 var speed = this._computeLocalCameraSpeed() * 50.0;
-//                 var deltaTransform = Vector3.TransformCoordinates(new Vector3(LSValues.x * speed, 0, -LSValues.y * speed), cameraTransform);
-//                 this.cameraDirection = this.cameraDirection.add(deltaTransform);
-//                 this.cameraRotation = this.cameraRotation.add(new Vector2(RSValues.y, RSValues.x));
-//             }
-//             super._checkInputs();
-//         }
-// 
-//         public dispose(): void {
-//             this._gamepads.dispose();
-//             super.dispose();
-//         }
-
         public getTypeName(): string {
             return "UniversalCamera";
         }

+ 13 - 37
src/Cameras/babylon.virtualJoysticksCamera.js

@@ -8,46 +8,22 @@ var BABYLON;
     // We're mainly based on the logic defined into the FreeCamera code
     var VirtualJoysticksCamera = (function (_super) {
         __extends(VirtualJoysticksCamera, _super);
+        // private _leftjoystick: VirtualJoystick;
+        // private _rightjoystick: VirtualJoystick;
         function VirtualJoysticksCamera(name, position, scene) {
             _super.call(this, name, position, scene);
-            this._leftjoystick = new BABYLON.VirtualJoystick(true);
-            this._leftjoystick.setAxisForUpDown(BABYLON.JoystickAxis.Z);
-            this._leftjoystick.setAxisForLeftRight(BABYLON.JoystickAxis.X);
-            this._leftjoystick.setJoystickSensibility(0.15);
-            this._rightjoystick = new BABYLON.VirtualJoystick(false);
-            this._rightjoystick.setAxisForUpDown(BABYLON.JoystickAxis.X);
-            this._rightjoystick.setAxisForLeftRight(BABYLON.JoystickAxis.Y);
-            this._rightjoystick.reverseUpDown = true;
-            this._rightjoystick.setJoystickSensibility(0.05);
-            this._rightjoystick.setJoystickColor("yellow");
+            this.inputs.addVirtualJoystick();
+            // this._leftjoystick = new VirtualJoystick(true);
+            // this._leftjoystick.setAxisForUpDown(JoystickAxis.Z);
+            // this._leftjoystick.setAxisForLeftRight(JoystickAxis.X);
+            // this._leftjoystick.setJoystickSensibility(0.15);
+            // this._rightjoystick = new VirtualJoystick(false);
+            // this._rightjoystick.setAxisForUpDown(JoystickAxis.X);
+            // this._rightjoystick.setAxisForLeftRight(JoystickAxis.Y);
+            // this._rightjoystick.reverseUpDown = true;
+            // this._rightjoystick.setJoystickSensibility(0.05);
+            // this._rightjoystick.setJoystickColor("yellow");
         }
-        VirtualJoysticksCamera.prototype.getLeftJoystick = function () {
-            return this._leftjoystick;
-        };
-        VirtualJoysticksCamera.prototype.getRightJoystick = function () {
-            return this._rightjoystick;
-        };
-        VirtualJoysticksCamera.prototype._checkInputs = function () {
-            var speed = this._computeLocalCameraSpeed() * 50;
-            var cameraTransform = BABYLON.Matrix.RotationYawPitchRoll(this.rotation.y, this.rotation.x, 0);
-            var deltaTransform = BABYLON.Vector3.TransformCoordinates(new BABYLON.Vector3(this._leftjoystick.deltaPosition.x * speed, this._leftjoystick.deltaPosition.y * speed, this._leftjoystick.deltaPosition.z * speed), cameraTransform);
-            this.cameraDirection = this.cameraDirection.add(deltaTransform);
-            this.cameraRotation = this.cameraRotation.addVector3(this._rightjoystick.deltaPosition);
-            if (!this._leftjoystick.pressed) {
-                this._leftjoystick.deltaPosition = this._leftjoystick.deltaPosition.scale(0.9);
-            }
-            if (!this._rightjoystick.pressed) {
-                this._rightjoystick.deltaPosition = this._rightjoystick.deltaPosition.scale(0.9);
-            }
-            _super.prototype._checkInputs.call(this);
-        };
-        VirtualJoysticksCamera.prototype.dispose = function () {
-            this._leftjoystick.releaseCanvas();
-            _super.prototype.dispose.call(this);
-        };
-        VirtualJoysticksCamera.prototype.getTypeName = function () {
-            return "VirtualJoysticksCamera";
-        };
         return VirtualJoysticksCamera;
     }(BABYLON.FreeCamera));
     BABYLON.VirtualJoysticksCamera = VirtualJoysticksCamera;

+ 40 - 39
src/Cameras/babylon.virtualJoysticksCamera.ts

@@ -1,54 +1,55 @@
 module BABYLON {
     // We're mainly based on the logic defined into the FreeCamera code
     export class VirtualJoysticksCamera extends FreeCamera {
-        private _leftjoystick: VirtualJoystick;
-        private _rightjoystick: VirtualJoystick;
+        // private _leftjoystick: VirtualJoystick;
+        // private _rightjoystick: VirtualJoystick;
 
         constructor(name: string, position: Vector3, scene: Scene) {
             super(name, position, scene);
-            this._leftjoystick = new VirtualJoystick(true);
-            this._leftjoystick.setAxisForUpDown(JoystickAxis.Z);
-            this._leftjoystick.setAxisForLeftRight(JoystickAxis.X);
-            this._leftjoystick.setJoystickSensibility(0.15);
-            this._rightjoystick = new VirtualJoystick(false);
-            this._rightjoystick.setAxisForUpDown(JoystickAxis.X);
-            this._rightjoystick.setAxisForLeftRight(JoystickAxis.Y);
-            this._rightjoystick.reverseUpDown = true;
-            this._rightjoystick.setJoystickSensibility(0.05);
-            this._rightjoystick.setJoystickColor("yellow");
+            this.inputs.addVirtualJoystick();
+            // this._leftjoystick = new VirtualJoystick(true);
+            // this._leftjoystick.setAxisForUpDown(JoystickAxis.Z);
+            // this._leftjoystick.setAxisForLeftRight(JoystickAxis.X);
+            // this._leftjoystick.setJoystickSensibility(0.15);
+            // this._rightjoystick = new VirtualJoystick(false);
+            // this._rightjoystick.setAxisForUpDown(JoystickAxis.X);
+            // this._rightjoystick.setAxisForLeftRight(JoystickAxis.Y);
+            // this._rightjoystick.reverseUpDown = true;
+            // this._rightjoystick.setJoystickSensibility(0.05);
+            // this._rightjoystick.setJoystickColor("yellow");
         }
 
-        public getLeftJoystick(): VirtualJoystick {
-            return this._leftjoystick;
-        }
+        // public getLeftJoystick(): VirtualJoystick {
+        //     return this._leftjoystick;
+        // }
 
-        public getRightJoystick(): VirtualJoystick {
-            return this._rightjoystick;
-        }
+        // public getRightJoystick(): VirtualJoystick {
+        //     return this._rightjoystick;
+        // }
 
-        public _checkInputs(): void {
-            var speed = this._computeLocalCameraSpeed() * 50;
-            var cameraTransform = Matrix.RotationYawPitchRoll(this.rotation.y, this.rotation.x, 0);
-            var deltaTransform = Vector3.TransformCoordinates(new Vector3(this._leftjoystick.deltaPosition.x * speed, this._leftjoystick.deltaPosition.y * speed, this._leftjoystick.deltaPosition.z * speed), cameraTransform);
-            this.cameraDirection = this.cameraDirection.add(deltaTransform);
-            this.cameraRotation = this.cameraRotation.addVector3(this._rightjoystick.deltaPosition);
-            if (!this._leftjoystick.pressed) {
-                this._leftjoystick.deltaPosition = this._leftjoystick.deltaPosition.scale(0.9);
-            }
-            if (!this._rightjoystick.pressed) {
-                this._rightjoystick.deltaPosition = this._rightjoystick.deltaPosition.scale(0.9);
-            }
+        // public _checkInputs(): void {
+        //     var speed = this._computeLocalCameraSpeed() * 50;
+        //     var cameraTransform = Matrix.RotationYawPitchRoll(this.rotation.y, this.rotation.x, 0);
+        //     var deltaTransform = Vector3.TransformCoordinates(new Vector3(this._leftjoystick.deltaPosition.x * speed, this._leftjoystick.deltaPosition.y * speed, this._leftjoystick.deltaPosition.z * speed), cameraTransform);
+        //     this.cameraDirection = this.cameraDirection.add(deltaTransform);
+        //     this.cameraRotation = this.cameraRotation.addVector3(this._rightjoystick.deltaPosition);
+        //     if (!this._leftjoystick.pressed) {
+        //         this._leftjoystick.deltaPosition = this._leftjoystick.deltaPosition.scale(0.9);
+        //     }
+        //     if (!this._rightjoystick.pressed) {
+        //         this._rightjoystick.deltaPosition = this._rightjoystick.deltaPosition.scale(0.9);
+        //     }
 
-            super._checkInputs();
-        }
+        //     super._checkInputs();
+        // }
 
-        public dispose(): void {
-            this._leftjoystick.releaseCanvas();
-            super.dispose();
-        }
+        // public dispose(): void {
+        //     this._leftjoystick.releaseCanvas();
+        //     super.dispose();
+        // }
 
-        public getTypeName(): string {
-            return "VirtualJoysticksCamera";
-        }
+        // public getTypeName(): string {
+        //     return "VirtualJoysticksCamera";
+        // }
     }
 }