Explorar o código

Fixing camera.setSubCameraMode - Implied a LOT of refactoring.. Need testing

David Catuhe %!s(int64=10) %!d(string=hai) anos
pai
achega
34cc16a946
Modificáronse 39 ficheiros con 1223 adicións e 1194 borrados
  1. 0 118
      Babylon/Cameras/VR/babylon.vrCamera.js
  2. 0 144
      Babylon/Cameras/VR/babylon.vrCamera.ts
  3. 17 7
      Babylon/Cameras/VR/babylon.vrDeviceOrientationCamera.js
  4. 23 4
      Babylon/Cameras/VR/babylon.vrDeviceOrientationCamera.ts
  5. 12 11
      Babylon/Cameras/VR/babylon.webVRCamera.js
  6. 8 5
      Babylon/Cameras/VR/babylon.webVRCamera.ts
  7. 10 64
      Babylon/Cameras/babylon.anaglyphCamera.js
  8. 6 95
      Babylon/Cameras/babylon.anaglyphCamera.ts
  9. 23 1
      Babylon/Cameras/babylon.arcRotateCamera.js
  10. 8 6
      Babylon/Cameras/babylon.arcRotateCamera.ts
  11. 222 2
      Babylon/Cameras/babylon.camera.js
  12. 175 123
      Babylon/Cameras/babylon.camera.ts
  13. 1 0
      Babylon/Cameras/babylon.deviceOrientationCamera.js
  14. 2 0
      Babylon/Cameras/babylon.deviceOrientationCamera.ts
  15. 2 2
      Babylon/Cameras/babylon.followCamera.js
  16. 1 4
      Babylon/Cameras/babylon.freeCamera.js
  17. 2 0
      Babylon/Cameras/babylon.freeCamera.ts
  18. 18 18
      Babylon/Cameras/babylon.gamepadCamera.js
  19. 20 20
      Babylon/Cameras/babylon.gamepadCamera.ts
  20. 0 175
      Babylon/Cameras/babylon.oculusGamepadCamera.js
  21. 55 1
      Babylon/Cameras/babylon.targetCamera.js
  22. 18 16
      Babylon/Cameras/babylon.targetCamera.ts
  23. 1 0
      Babylon/Cameras/babylon.touchCamera.js
  24. 2 0
      Babylon/Cameras/babylon.touchCamera.ts
  25. 1 0
      Babylon/Cameras/babylon.virtualJoysticksCamera.js
  26. 2 0
      Babylon/Cameras/babylon.virtualJoysticksCamera.ts
  27. 2 2
      Babylon/Loading/Plugins/babylon.babylonFileLoader.js
  28. 2 2
      Babylon/Loading/Plugins/babylon.babylonFileLoader.ts
  29. 1 0
      Babylon/PostProcess/babylon.stereogramInterlacePostProcess.js
  30. 5 5
      Babylon/PostProcess/babylon.vrDistortionCorrectionPostProcess.js
  31. 5 5
      Babylon/PostProcess/babylon.vrDistortionCorrectionPostProcess.ts
  32. 2 2
      Babylon/Tools/babylon.sceneSerializer.js
  33. 2 2
      Babylon/Tools/babylon.sceneSerializer.ts
  34. 1 2
      Tools/Gulp/config.json
  35. 406 239
      babylon.2.1-beta.debug.js
  36. 27 22
      babylon.2.1-beta.js
  37. 28 23
      babylon.2.1-beta.noworker.js
  38. 110 73
      babylon.2.1.d.ts
  39. 3 1
      what's new - 2.1 - proposal.md

+ 0 - 118
Babylon/Cameras/VR/babylon.vrCamera.js

@@ -1,118 +0,0 @@
-var __extends = this.__extends || function (d, b) {
-    for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
-    function __() { this.constructor = d; }
-    __.prototype = b.prototype;
-    d.prototype = new __();
-};
-var BABYLON;
-(function (BABYLON) {
-    var DefaultVRConstants = {
-        HResolution: 1280,
-        VResolution: 800,
-        HScreenSize: 0.149759993,
-        VScreenSize: 0.0935999975,
-        VScreenCenter: 0.0467999987,
-        EyeToScreenDistance: 0.0410000011,
-        LensSeparationDistance: 0.0635000020,
-        InterpupillaryDistance: 0.0640000030,
-        DistortionK: [1.0, 0.219999999, 0.239999995, 0.0],
-        ChromaAbCorrection: [0.995999992, -0.00400000019, 1.01400006, 0.0],
-        PostProcessScaleFactor: 1.714605507808412,
-        LensCenterOffset: 0.151976421
-    };
-    var _VRInnerCamera = (function (_super) {
-        __extends(_VRInnerCamera, _super);
-        function _VRInnerCamera(name, position, scene, isLeftEye, compensateDistorsion) {
-            _super.call(this, name, position, scene);
-            this._workMatrix = new BABYLON.Matrix();
-            this._actualUp = new BABYLON.Vector3(0, 0, 0);
-            // Constants
-            this._aspectRatioAspectRatio = DefaultVRConstants.HResolution / (2 * DefaultVRConstants.VResolution);
-            this._aspectRatioFov = (2 * Math.atan((DefaultVRConstants.PostProcessScaleFactor * DefaultVRConstants.VScreenSize) / (2 * DefaultVRConstants.EyeToScreenDistance)));
-            var hMeters = (DefaultVRConstants.HScreenSize / 4) - (DefaultVRConstants.LensSeparationDistance / 2);
-            var h = (4 * hMeters) / DefaultVRConstants.HScreenSize;
-            this._hMatrix = BABYLON.Matrix.Translation(isLeftEye ? h : -h, 0, 0);
-            this.viewport = new BABYLON.Viewport(isLeftEye ? 0 : 0.5, 0, 0.5, 1.0);
-            this._preViewMatrix = BABYLON.Matrix.Translation(isLeftEye ? .5 * DefaultVRConstants.InterpupillaryDistance : -.5 * DefaultVRConstants.InterpupillaryDistance, 0, 0);
-            if (compensateDistorsion) {
-                // Postprocess
-                var postProcess = new BABYLON.VRDistortionCorrectionPostProcess("VR Distortion", this, !isLeftEye, DefaultVRConstants);
-            }
-        }
-        _VRInnerCamera.prototype.getProjectionMatrix = function () {
-            BABYLON.Matrix.PerspectiveFovLHToRef(this._aspectRatioFov, this._aspectRatioAspectRatio, this.minZ, this.maxZ, this._workMatrix);
-            this._workMatrix.multiplyToRef(this._hMatrix, this._projectionMatrix);
-            return this._projectionMatrix;
-        };
-        _VRInnerCamera.prototype._getViewMatrix = function () {
-            BABYLON.Matrix.RotationYawPitchRollToRef(this.rotation.y, this.rotation.x, this.rotation.z, this._cameraRotationMatrix);
-            BABYLON.Vector3.TransformCoordinatesToRef(this._referencePoint, this._cameraRotationMatrix, this._transformedReferencePoint);
-            BABYLON.Vector3.TransformNormalToRef(this.upVector, this._cameraRotationMatrix, this._actualUp);
-            // Computing target and final matrix
-            this.position.addToRef(this._transformedReferencePoint, this._currentTarget);
-            BABYLON.Matrix.LookAtLHToRef(this.position, this._currentTarget, this._actualUp, this._workMatrix);
-            this._workMatrix.multiplyToRef(this._preViewMatrix, this._viewMatrix);
-            return this._viewMatrix;
-        };
-        return _VRInnerCamera;
-    })(BABYLON.FreeCamera);
-    var VRCamera = (function (_super) {
-        __extends(VRCamera, _super);
-        function VRCamera(name, position, scene, compensateDistorsion) {
-            if (compensateDistorsion === void 0) { compensateDistorsion = true; }
-            _super.call(this, name, position, scene);
-            this._leftCamera = new _VRInnerCamera(name + "_left", position.clone(), scene, true, compensateDistorsion);
-            this._rightCamera = new _VRInnerCamera(name + "_right", position.clone(), scene, false, compensateDistorsion);
-            this.subCameras.push(this._leftCamera);
-            this.subCameras.push(this._rightCamera);
-            this._deviceOrientationHandler = this._onOrientationEvent.bind(this);
-        }
-        VRCamera.prototype._update = function () {
-            this._leftCamera.position.copyFrom(this.position);
-            this._rightCamera.position.copyFrom(this.position);
-            this._updateCamera(this._leftCamera);
-            this._updateCamera(this._rightCamera);
-            _super.prototype._update.call(this);
-        };
-        VRCamera.prototype._updateCamera = function (camera) {
-            camera.minZ = this.minZ;
-            camera.maxZ = this.maxZ;
-            camera.rotation.x = this.rotation.x;
-            camera.rotation.y = this.rotation.y;
-            camera.rotation.z = this.rotation.z;
-        };
-        // Orientation events
-        VRCamera.prototype._onOrientationEvent = function (evt) {
-            var yaw = evt.alpha / 180 * Math.PI;
-            var pitch = evt.beta / 180 * Math.PI;
-            var roll = evt.gamma / 180 * Math.PI;
-            if (!this._offsetOrientation) {
-                this._offsetOrientation = {
-                    yaw: yaw,
-                    pitch: pitch,
-                    roll: roll
-                };
-                return;
-            }
-            else {
-                this.rotation.y += yaw - this._offsetOrientation.yaw;
-                this.rotation.x += pitch - this._offsetOrientation.pitch;
-                this.rotation.z += this._offsetOrientation.roll - roll;
-                this._offsetOrientation.yaw = yaw;
-                this._offsetOrientation.pitch = pitch;
-                this._offsetOrientation.roll = roll;
-            }
-        };
-        VRCamera.prototype.attachControl = function (element, noPreventDefault) {
-            _super.prototype.attachControl.call(this, element, noPreventDefault);
-            window.addEventListener("deviceorientation", this._deviceOrientationHandler);
-        };
-        VRCamera.prototype.detachControl = function (element) {
-            _super.prototype.detachControl.call(this, element);
-            window.removeEventListener("deviceorientation", this._deviceOrientationHandler);
-        };
-        return VRCamera;
-    })(BABYLON.FreeCamera);
-    BABYLON.VRCamera = VRCamera;
-})(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.vrCamera.js.map

+ 0 - 144
Babylon/Cameras/VR/babylon.vrCamera.ts

@@ -1,144 +0,0 @@
-module BABYLON {
-
-    var DefaultVRConstants = {
-        HResolution: 1280,
-        VResolution: 800,
-        HScreenSize: 0.149759993,
-        VScreenSize: 0.0935999975,
-        VScreenCenter: 0.0467999987,
-        EyeToScreenDistance: 0.0410000011,
-        LensSeparationDistance: 0.0635000020,
-        InterpupillaryDistance: 0.0640000030,
-        DistortionK: [1.0, 0.219999999, 0.239999995, 0.0],
-        ChromaAbCorrection: [0.995999992, -0.00400000019, 1.01400006, 0.0],
-        PostProcessScaleFactor: 1.714605507808412,
-        LensCenterOffset: 0.151976421
-    };
-
-    class _VRInnerCamera extends FreeCamera {
-        private _aspectRatioAspectRatio: number;
-        private _aspectRatioFov: number;
-        private _hMatrix: Matrix;
-        private _workMatrix = new BABYLON.Matrix();
-        private _preViewMatrix: Matrix;
-        private _actualUp = new BABYLON.Vector3(0, 0, 0);
-
-        constructor(name: string, position: Vector3, scene: Scene, isLeftEye: boolean, compensateDistorsion: boolean) {
-            super(name, position, scene);
-
-            // Constants
-            this._aspectRatioAspectRatio = DefaultVRConstants.HResolution / (2 * DefaultVRConstants.VResolution);
-            this._aspectRatioFov = (2 * Math.atan((DefaultVRConstants.PostProcessScaleFactor * DefaultVRConstants.VScreenSize) / (2 * DefaultVRConstants.EyeToScreenDistance)));
-
-            var hMeters = (DefaultVRConstants.HScreenSize / 4) - (DefaultVRConstants.LensSeparationDistance / 2);
-            var h = (4 * hMeters) / DefaultVRConstants.HScreenSize;
-
-            this._hMatrix = BABYLON.Matrix.Translation(isLeftEye ? h : -h, 0, 0);
-
-            this.viewport = new BABYLON.Viewport(isLeftEye ? 0 : 0.5, 0, 0.5, 1.0);
-
-            this._preViewMatrix = BABYLON.Matrix.Translation(isLeftEye ? .5 * DefaultVRConstants.InterpupillaryDistance : -.5 * DefaultVRConstants.InterpupillaryDistance, 0, 0);
-
-            if (compensateDistorsion) {
-                // Postprocess
-                var postProcess = new BABYLON.VRDistortionCorrectionPostProcess("VR Distortion", this, !isLeftEye, DefaultVRConstants);
-            }
-        }
-
-        public getProjectionMatrix(): Matrix {
-            BABYLON.Matrix.PerspectiveFovLHToRef(this._aspectRatioFov, this._aspectRatioAspectRatio, this.minZ, this.maxZ, this._workMatrix);
-            this._workMatrix.multiplyToRef(this._hMatrix, this._projectionMatrix);
-            return this._projectionMatrix;
-        }
-
-        public _getViewMatrix(): Matrix {
-            BABYLON.Matrix.RotationYawPitchRollToRef(this.rotation.y, this.rotation.x, this.rotation.z, this._cameraRotationMatrix);
-
-            BABYLON.Vector3.TransformCoordinatesToRef(this._referencePoint, this._cameraRotationMatrix, this._transformedReferencePoint);
-            BABYLON.Vector3.TransformNormalToRef(this.upVector, this._cameraRotationMatrix, this._actualUp);
-
-            // Computing target and final matrix
-            this.position.addToRef(this._transformedReferencePoint, this._currentTarget);
-
-            BABYLON.Matrix.LookAtLHToRef(this.position, this._currentTarget, this._actualUp, this._workMatrix);
-
-            this._workMatrix.multiplyToRef(this._preViewMatrix, this._viewMatrix);
-            return this._viewMatrix;
-        }
-    }
-
-    export class VRCamera extends FreeCamera {
-        private _leftCamera: _VRInnerCamera;
-        private _rightCamera: _VRInnerCamera;
-        private _offsetOrientation: { yaw: number; pitch: number; roll: number };
-        private _deviceOrientationHandler;
-
-        constructor(name: string, position: Vector3, scene: Scene, compensateDistorsion = true) {
-            super(name, position, scene);
-
-            this._leftCamera = new _VRInnerCamera(name + "_left", position.clone(), scene, true, compensateDistorsion);
-            this._rightCamera = new _VRInnerCamera(name + "_right", position.clone(), scene, false, compensateDistorsion);
-
-            this.subCameras.push(this._leftCamera);
-            this.subCameras.push(this._rightCamera);
-
-            this._deviceOrientationHandler = this._onOrientationEvent.bind(this);
-        }
-
-        public _update(): void {
-            this._leftCamera.position.copyFrom(this.position);
-            this._rightCamera.position.copyFrom(this.position);
-
-            this._updateCamera(this._leftCamera);
-            this._updateCamera(this._rightCamera);
-
-            super._update();
-        }
-
-        public _updateCamera(camera: FreeCamera): void {
-            camera.minZ = this.minZ;
-            camera.maxZ = this.maxZ;
-
-            camera.rotation.x = this.rotation.x;
-            camera.rotation.y = this.rotation.y;
-            camera.rotation.z = this.rotation.z;
-        }
-
-        // Orientation events
-        public _onOrientationEvent(evt: DeviceOrientationEvent): void {
-            var yaw = evt.alpha / 180 * Math.PI;
-            var pitch = evt.beta / 180 * Math.PI;
-            var roll = evt.gamma / 180 * Math.PI;
-
-            if (!this._offsetOrientation) {
-                this._offsetOrientation = {
-                    yaw: yaw,
-                    pitch: pitch,
-                    roll: roll
-                };
-                return;
-            }
-            else {
-                this.rotation.y += yaw - this._offsetOrientation.yaw;
-                this.rotation.x += pitch - this._offsetOrientation.pitch;
-                this.rotation.z += this._offsetOrientation.roll - roll;
-
-                this._offsetOrientation.yaw = yaw;
-                this._offsetOrientation.pitch = pitch;
-                this._offsetOrientation.roll = roll;
-            }
-        }
-
-        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);
-        }
-    }
-} 

+ 17 - 7
Babylon/Cameras/VR/babylon.vrDeviceOrientationCamera.js

@@ -6,15 +6,17 @@ var __extends = this.__extends || function (d, b) {
 };
 var BABYLON;
 (function (BABYLON) {
-    var VRDeviceOrientationCamera = (function (_super) {
-        __extends(VRDeviceOrientationCamera, _super);
-        function VRDeviceOrientationCamera(name, position, scene) {
+    var VRDeviceOrientationFreeCamera = (function (_super) {
+        __extends(VRDeviceOrientationFreeCamera, _super);
+        function VRDeviceOrientationFreeCamera(name, position, scene) {
             _super.call(this, name, position, scene);
             this._alpha = 0;
             this._beta = 0;
             this._gamma = 0;
+            this.setSubCameraMode(BABYLON.Camera.SUB_CAMERA_MODE_VR);
+            this._deviceOrientationHandler = this._onOrientationEvent.bind(this);
         }
-        VRDeviceOrientationCamera.prototype._onOrientationEvent = function (evt) {
+        VRDeviceOrientationFreeCamera.prototype._onOrientationEvent = function (evt) {
             this._alpha = +evt.alpha | 0;
             this._beta = +evt.beta | 0;
             this._gamma = +evt.gamma | 0;
@@ -29,8 +31,16 @@ var BABYLON;
             this.rotation.y = -this._alpha / 180.0 * Math.PI;
             this.rotation.z = this._beta / 180.0 * Math.PI;
         };
-        return VRDeviceOrientationCamera;
-    })(BABYLON.VRCamera);
-    BABYLON.VRDeviceOrientationCamera = VRDeviceOrientationCamera;
+        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);
+        };
+        return VRDeviceOrientationFreeCamera;
+    })(BABYLON.FreeCamera);
+    BABYLON.VRDeviceOrientationFreeCamera = VRDeviceOrientationFreeCamera;
 })(BABYLON || (BABYLON = {}));
 //# sourceMappingURL=babylon.vrDeviceOrientationCamera.js.map

+ 23 - 4
Babylon/Cameras/VR/babylon.vrDeviceOrientationCamera.ts

@@ -1,12 +1,19 @@
 module BABYLON {
-    export class VRDeviceOrientationCamera extends BABYLON.VRCamera {
+    export class VRDeviceOrientationFreeCamera extends BABYLON.FreeCamera {
 		public _alpha = 0;
 		public _beta = 0;
 		public _gamma = 0;
 	
-		constructor(name: string, position: Vector3, scene: Scene) {
-			super(name, position, scene);
-		}
+        private _offsetOrientation: { yaw: number; pitch: number; roll: number };
+        private _deviceOrientationHandler;
+
+        constructor(name: string, position: Vector3, scene: Scene) {
+            super(name, position, scene);
+
+            this.setSubCameraMode(Camera.SUB_CAMERA_MODE_VR);
+
+            this._deviceOrientationHandler = this._onOrientationEvent.bind(this);
+        }
 
         public _onOrientationEvent(evt: DeviceOrientationEvent): void {
             this._alpha = +evt.alpha|0;
@@ -25,5 +32,17 @@ module BABYLON {
 			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);
+        }
 	}
 }

+ 12 - 11
Babylon/Cameras/VR/babylon.webVRCamera.js

@@ -6,9 +6,9 @@ var __extends = this.__extends || function (d, b) {
 };
 var BABYLON;
 (function (BABYLON) {
-    var WebVRCamera = (function (_super) {
-        __extends(WebVRCamera, _super);
-        function WebVRCamera(name, position, scene) {
+    var WebVRFreeCamera = (function (_super) {
+        __extends(WebVRFreeCamera, _super);
+        function WebVRFreeCamera(name, position, scene) {
             _super.call(this, name, position, scene);
             this._hmdDevice = null;
             this._sensorDevice = null;
@@ -16,9 +16,10 @@ var BABYLON;
             this._cacheQuaternion = new BABYLON.Quaternion();
             this._cacheRotation = BABYLON.Vector3.Zero();
             this._vrEnabled = false;
+            this.setSubCameraMode(BABYLON.Camera.SUB_CAMERA_MODE_VR);
             this._getWebVRDevices = this._getWebVRDevices.bind(this);
         }
-        WebVRCamera.prototype._getWebVRDevices = function (devices) {
+        WebVRFreeCamera.prototype._getWebVRDevices = function (devices) {
             var size = devices.length;
             var i = 0;
             // Reset devices.
@@ -39,7 +40,7 @@ var BABYLON;
             }
             this._vrEnabled = this._sensorDevice && this._hmdDevice ? true : false;
         };
-        WebVRCamera.prototype._update = function () {
+        WebVRFreeCamera.prototype._checkInputs = function () {
             if (this._vrEnabled) {
                 this._cacheState = this._sensorDevice.getState();
                 this._cacheQuaternion.copyFromFloats(this._cacheState.orientation.x, this._cacheState.orientation.y, this._cacheState.orientation.z, this._cacheState.orientation.w);
@@ -48,9 +49,9 @@ var BABYLON;
                 this.rotation.y = -this._cacheRotation.y;
                 this.rotation.z = this._cacheRotation.x;
             }
-            _super.prototype._update.call(this);
+            _super.prototype._checkInputs.call(this);
         };
-        WebVRCamera.prototype.attachControl = function (element, noPreventDefault) {
+        WebVRFreeCamera.prototype.attachControl = function (element, noPreventDefault) {
             _super.prototype.attachControl.call(this, element, noPreventDefault);
             if (navigator.getVRDevices) {
                 navigator.getVRDevices().then(this._getWebVRDevices);
@@ -59,12 +60,12 @@ var BABYLON;
                 navigator.mozGetVRDevices(this._getWebVRDevices);
             }
         };
-        WebVRCamera.prototype.detachControl = function (element) {
+        WebVRFreeCamera.prototype.detachControl = function (element) {
             _super.prototype.detachControl.call(this, element);
             this._vrEnabled = false;
         };
-        return WebVRCamera;
-    })(BABYLON.VRCamera);
-    BABYLON.WebVRCamera = WebVRCamera;
+        return WebVRFreeCamera;
+    })(BABYLON.FreeCamera);
+    BABYLON.WebVRFreeCamera = WebVRFreeCamera;
 })(BABYLON || (BABYLON = {}));
 //# sourceMappingURL=babylon.webVRCamera.js.map

+ 8 - 5
Babylon/Cameras/VR/babylon.webVRCamera.ts

@@ -2,16 +2,19 @@ declare var HMDVRDevice;
 declare var PositionSensorVRDevice;
 
 module BABYLON {
-    export class WebVRCamera extends BABYLON.VRCamera {
+    export class WebVRFreeCamera extends FreeCamera {
         public _hmdDevice = null;
         public _sensorDevice = null;
         public _cacheState = null;
-        public _cacheQuaternion = new BABYLON.Quaternion();
-        public _cacheRotation = BABYLON.Vector3.Zero();
+        public _cacheQuaternion = new Quaternion();
+        public _cacheRotation = Vector3.Zero();
         public _vrEnabled = false;
 
         constructor(name: string, position: Vector3, scene: Scene) {
             super(name, position, scene);
+
+            this.setSubCameraMode(Camera.SUB_CAMERA_MODE_VR);
+
             this._getWebVRDevices = this._getWebVRDevices.bind(this);
         }
 
@@ -43,7 +46,7 @@ module BABYLON {
             this._vrEnabled = this._sensorDevice && this._hmdDevice ? true : false;
         }
 
-        public _update(): void {
+        public _checkInputs(): void {
             if (this._vrEnabled) {
                 this._cacheState = this._sensorDevice.getState();
                 this._cacheQuaternion.copyFromFloats(this._cacheState.orientation.x, this._cacheState.orientation.y, this._cacheState.orientation.z, this._cacheState.orientation.w);
@@ -54,7 +57,7 @@ module BABYLON {
                 this.rotation.z = this._cacheRotation.x;
             }
 
-            super._update();
+            super._checkInputs();
         }
 
         public attachControl(element: HTMLElement, noPreventDefault?: boolean): void {

+ 10 - 64
Babylon/Cameras/babylon.anaglyphCamera.js

@@ -6,77 +6,23 @@ var __extends = this.__extends || function (d, b) {
 };
 var BABYLON;
 (function (BABYLON) {
-    var buildCamera = function (that, name) {
-        that._leftCamera.isIntermediate = true;
-        that.subCameras.push(that._leftCamera);
-        that.subCameras.push(that._rightCamera);
-        that._leftTexture = new BABYLON.PassPostProcess(name + "_leftTexture", 1.0, that._leftCamera);
-        that._anaglyphPostProcess = new BABYLON.AnaglyphPostProcess(name + "_anaglyph", 1.0, that._rightCamera);
-        that._anaglyphPostProcess.onApply = function (effect) {
-            effect.setTextureFromPostProcess("leftSampler", that._leftTexture);
-        };
-        that._update();
-    };
-    var AnaglyphArcRotateCamera = (function (_super) {
-        __extends(AnaglyphArcRotateCamera, _super);
-        // ANY
-        function AnaglyphArcRotateCamera(name, alpha, beta, radius, target, eyeSpace, scene) {
-            _super.call(this, name, alpha, beta, radius, target, scene);
-            this._eyeSpace = BABYLON.Tools.ToRadians(eyeSpace);
-            this._leftCamera = new BABYLON.ArcRotateCamera(name + "_left", alpha - this._eyeSpace, beta, radius, target, scene);
-            this._rightCamera = new BABYLON.ArcRotateCamera(name + "_right", alpha + this._eyeSpace, beta, radius, target, scene);
-            buildCamera(this, name);
-        }
-        AnaglyphArcRotateCamera.prototype._update = function () {
-            this._updateCamera(this._leftCamera);
-            this._updateCamera(this._rightCamera);
-            this._leftCamera.alpha = this.alpha - this._eyeSpace;
-            this._rightCamera.alpha = this.alpha + this._eyeSpace;
-            _super.prototype._update.call(this);
-        };
-        AnaglyphArcRotateCamera.prototype._updateCamera = function (camera) {
-            camera.beta = this.beta;
-            camera.radius = this.radius;
-            camera.minZ = this.minZ;
-            camera.maxZ = this.maxZ;
-            camera.fov = this.fov;
-            camera.target = this.target;
-        };
-        return AnaglyphArcRotateCamera;
-    })(BABYLON.ArcRotateCamera);
-    BABYLON.AnaglyphArcRotateCamera = AnaglyphArcRotateCamera;
     var AnaglyphFreeCamera = (function (_super) {
         __extends(AnaglyphFreeCamera, _super);
         function AnaglyphFreeCamera(name, position, eyeSpace, scene) {
             _super.call(this, name, position, scene);
-            this._eyeSpace = BABYLON.Tools.ToRadians(eyeSpace);
-            this._transformMatrix = new BABYLON.Matrix();
-            this._leftCamera = new BABYLON.FreeCamera(name + "_left", position.clone(), scene);
-            this._rightCamera = new BABYLON.FreeCamera(name + "_right", position.clone(), scene);
-            buildCamera(this, name);
+            this.setSubCameraMode(BABYLON.Camera.SUB_CAMERA_MODE_ANAGLYPH, eyeSpace);
         }
-        AnaglyphFreeCamera.prototype._getSubCameraPosition = function (eyeSpace, result) {
-            var target = this.getTarget();
-            BABYLON.Matrix.Translation(-target.x, -target.y, -target.z).multiplyToRef(BABYLON.Matrix.RotationY(eyeSpace), this._transformMatrix);
-            this._transformMatrix = this._transformMatrix.multiply(BABYLON.Matrix.Translation(target.x, target.y, target.z));
-            BABYLON.Vector3.TransformCoordinatesToRef(this.position, this._transformMatrix, result);
-        };
-        AnaglyphFreeCamera.prototype._update = function () {
-            this._getSubCameraPosition(-this._eyeSpace, this._leftCamera.position);
-            this._getSubCameraPosition(this._eyeSpace, this._rightCamera.position);
-            this._updateCamera(this._leftCamera);
-            this._updateCamera(this._rightCamera);
-            _super.prototype._update.call(this);
-        };
-        AnaglyphFreeCamera.prototype._updateCamera = function (camera) {
-            camera.minZ = this.minZ;
-            camera.maxZ = this.maxZ;
-            camera.fov = this.fov;
-            camera.viewport = this.viewport;
-            camera.setTarget(this.getTarget());
-        };
         return AnaglyphFreeCamera;
     })(BABYLON.FreeCamera);
     BABYLON.AnaglyphFreeCamera = AnaglyphFreeCamera;
+    var AnaglyphArcRotateCamera = (function (_super) {
+        __extends(AnaglyphArcRotateCamera, _super);
+        function AnaglyphArcRotateCamera(name, alpha, beta, radius, target, eyeSpace, scene) {
+            _super.call(this, name, alpha, beta, radius, target, scene);
+            this.setSubCameraMode(BABYLON.Camera.SUB_CAMERA_MODE_ANAGLYPH, eyeSpace);
+        }
+        return AnaglyphArcRotateCamera;
+    })(BABYLON.ArcRotateCamera);
+    BABYLON.AnaglyphArcRotateCamera = AnaglyphArcRotateCamera;
 })(BABYLON || (BABYLON = {}));
 //# sourceMappingURL=babylon.anaglyphCamera.js.map

+ 6 - 95
Babylon/Cameras/babylon.anaglyphCamera.ts

@@ -1,106 +1,17 @@
 module BABYLON {
-    var buildCamera = (that, name) => {
-        that._leftCamera.isIntermediate = true;
-
-        that.subCameras.push(that._leftCamera);
-        that.subCameras.push(that._rightCamera);
-
-        that._leftTexture = new BABYLON.PassPostProcess(name + "_leftTexture", 1.0, that._leftCamera);
-        that._anaglyphPostProcess = new BABYLON.AnaglyphPostProcess(name + "_anaglyph", 1.0, that._rightCamera);
-
-        that._anaglyphPostProcess.onApply = effect => {
-            effect.setTextureFromPostProcess("leftSampler", that._leftTexture);
-        };
-
-        that._update();
-    };
-
-    export class AnaglyphArcRotateCamera extends ArcRotateCamera {
-        private _eyeSpace: number;
-        private _leftCamera: ArcRotateCamera;
-        private _rightCamera: ArcRotateCamera;
-
-        // ANY
-        constructor(name: string, alpha: number, beta: number, radius: number, target, eyeSpace: number, scene) {
-            super(name, alpha, beta, radius, target, scene);
-
-            this._eyeSpace = BABYLON.Tools.ToRadians(eyeSpace);
-
-            this._leftCamera = new BABYLON.ArcRotateCamera(name + "_left", alpha - this._eyeSpace, beta, radius, target, scene);
-            this._rightCamera = new BABYLON.ArcRotateCamera(name + "_right", alpha + this._eyeSpace, beta, radius, target, scene);
-
-            buildCamera(this, name);
-        }
-
-        public _update(): void {
-            this._updateCamera(this._leftCamera);
-            this._updateCamera(this._rightCamera);
-
-            this._leftCamera.alpha = this.alpha - this._eyeSpace;
-            this._rightCamera.alpha = this.alpha + this._eyeSpace;
-
-            super._update();
-        }
-
-        public _updateCamera(camera: ArcRotateCamera) {
-            camera.beta = this.beta;
-            camera.radius = this.radius;
-
-            camera.minZ = this.minZ;
-            camera.maxZ = this.maxZ;
-
-            camera.fov = this.fov;
-
-            camera.target = this.target;
-        }
-    }
-
     export class AnaglyphFreeCamera extends FreeCamera {
-        private _eyeSpace: number;
-        private _leftCamera: FreeCamera;
-        private _rightCamera: FreeCamera;
-        private _transformMatrix: Matrix;
 
         constructor(name: string, position: Vector3, eyeSpace: number, scene: Scene) {
             super(name, position, scene);
-
-            this._eyeSpace = BABYLON.Tools.ToRadians(eyeSpace);
-            this._transformMatrix = new BABYLON.Matrix();
-
-            this._leftCamera = new BABYLON.FreeCamera(name + "_left", position.clone(), scene);
-            this._rightCamera = new BABYLON.FreeCamera(name + "_right", position.clone(), scene);
-
-            buildCamera(this, name);
-        }
-
-        public _getSubCameraPosition(eyeSpace, result) {
-            var target = this.getTarget();
-            BABYLON.Matrix.Translation(-target.x, -target.y, -target.z).multiplyToRef(BABYLON.Matrix.RotationY(eyeSpace), this._transformMatrix);
-
-            this._transformMatrix = this._transformMatrix.multiply(BABYLON.Matrix.Translation(target.x, target.y, target.z));
-
-            BABYLON.Vector3.TransformCoordinatesToRef(this.position, this._transformMatrix, result);
+            this.setSubCameraMode(Camera.SUB_CAMERA_MODE_ANAGLYPH, eyeSpace);
         }
+    }
 
-        public _update(): void {
-            this._getSubCameraPosition(-this._eyeSpace, this._leftCamera.position);
-            this._getSubCameraPosition(this._eyeSpace, this._rightCamera.position);
-
-            this._updateCamera(this._leftCamera);
-            this._updateCamera(this._rightCamera);
-
-            super._update();
-        }
-
-        public _updateCamera(camera: FreeCamera): void {
-            camera.minZ = this.minZ;
-            camera.maxZ = this.maxZ;
-
-            camera.fov = this.fov;
-
-            camera.viewport = this.viewport;
+    export class AnaglyphArcRotateCamera extends ArcRotateCamera {
 
-            camera.setTarget(this.getTarget());
+        constructor(name: string, alpha: number, beta: number, radius: number, target, eyeSpace: number, scene) {
+            super(name, alpha, beta, radius, target, scene);
+            this.setSubCameraMode(Camera.SUB_CAMERA_MODE_ANAGLYPH, eyeSpace);
         }
     }
 } 

+ 23 - 1
Babylon/Cameras/babylon.arcRotateCamera.js

@@ -287,7 +287,7 @@ var BABYLON;
                 this._reset();
             }
         };
-        ArcRotateCamera.prototype._update = function () {
+        ArcRotateCamera.prototype._checkInputs = function () {
             //if (async) collision inspection was triggered, don't update the camera's position - until the collision callback was called.
             if (this._collisionTriggered) {
                 return;
@@ -341,6 +341,7 @@ var BABYLON;
             if (this.upperRadiusLimit && this.radius > this.upperRadiusLimit) {
                 this.radius = this.upperRadiusLimit;
             }
+            _super.prototype._checkInputs.call(this);
         };
         ArcRotateCamera.prototype.setPosition = function (position) {
             var radiusv3 = position.subtract(this._getTargetPosition());
@@ -398,6 +399,27 @@ var BABYLON;
             this.target = BABYLON.Mesh.Center(meshesOrMinMaxVector);
             this.maxZ = distance * 2;
         };
+        /**
+         * @override
+         * needs to be overridden, so sub has required properties to be copied
+         */
+        ArcRotateCamera.prototype.getSubCamera = function (name, isA) {
+            var alphaSpace = this._subCamHalfSpace * (isA ? -1 : 1);
+            return new BABYLON.ArcRotateCamera(name, this.alpha + alphaSpace, this.beta, this.radius, this.target, this.getScene());
+        };
+        /**
+         * @override
+         * needs to be overridden, adding copy of alpha, beta & radius
+         */
+        ArcRotateCamera.prototype._updateSubCameras = function () {
+            var camA = this.subCameras[BABYLON.Camera.SUB_CAMERAID_A];
+            var camB = this.subCameras[BABYLON.Camera.SUB_CAMERAID_B];
+            camA.alpha = this.alpha - this._subCamHalfSpace;
+            camB.alpha = this.alpha + this._subCamHalfSpace;
+            camA.beta = camB.beta = this.beta;
+            camA.radius = camB.radius = this.radius;
+            _super.prototype._updateSubCameras.call(this);
+        };
         return ArcRotateCamera;
     })(BABYLON.Camera);
     BABYLON.ArcRotateCamera = ArcRotateCamera;

+ 8 - 6
Babylon/Cameras/babylon.arcRotateCamera.ts

@@ -405,6 +405,8 @@
             if (this.upperRadiusLimit && this.radius > this.upperRadiusLimit) {
                 this.radius = this.upperRadiusLimit;
             }
+
+            super._checkInputs();
         }
 
         public setPosition(position: Vector3): void {
@@ -507,8 +509,8 @@
          * @override
          * needs to be overridden, so sub has required properties to be copied
          */
-        public GetSubCamera(name : string, isA : boolean) : Camera{
-            var alphaSpace = this._subCamHalfSapce * (isA? -1 : 1);
+        public getSubCamera(name : string, isA : boolean) : Camera{
+            var alphaSpace = this._subCamHalfSpace * (isA? -1 : 1);
             return new BABYLON.ArcRotateCamera(name, this.alpha + alphaSpace, this.beta, this.radius, this.target, this.getScene());
         }
         
@@ -517,11 +519,11 @@
          * needs to be overridden, adding copy of alpha, beta & radius
          */
         public _updateSubCameras(){
-            var camA = <ArcRotateCamera> this.subCameras[Camera.SUB_CAM_A];
-            var camB = <ArcRotateCamera> this.subCameras[Camera.SUB_CAM_B];
+            var camA = <ArcRotateCamera> this.subCameras[Camera.SUB_CAMERAID_A];
+            var camB = <ArcRotateCamera> this.subCameras[Camera.SUB_CAMERAID_B];
             
-            camA.alpha = this.alpha - this._subCamHalfSapce;
-            camB.alpha = this.alpha + this._subCamHalfSapce;
+            camA.alpha = this.alpha - this._subCamHalfSpace;
+            camB.alpha = this.alpha + this._subCamHalfSpace;
             
             camA.beta   = camB.beta   = this.beta;
             camA.radius = camB.radius = this.radius;

+ 222 - 2
Babylon/Cameras/babylon.camera.js

@@ -6,6 +6,74 @@ var __extends = this.__extends || function (d, b) {
 };
 var BABYLON;
 (function (BABYLON) {
+    var VRCameraMetrics = (function () {
+        function VRCameraMetrics() {
+            this.compensateDistorsion = true;
+        }
+        Object.defineProperty(VRCameraMetrics.prototype, "aspectRatio", {
+            get: function () {
+                return this.hResolution / (2 * this.vResolution);
+            },
+            enumerable: true,
+            configurable: true
+        });
+        Object.defineProperty(VRCameraMetrics.prototype, "aspectRatioFov", {
+            get: function () {
+                return (2 * Math.atan((this.postProcessScaleFactor * this.vScreenSize) / (2 * this.eyeToScreenDistance)));
+            },
+            enumerable: true,
+            configurable: true
+        });
+        Object.defineProperty(VRCameraMetrics.prototype, "leftHMatrix", {
+            get: function () {
+                var meters = (this.hScreenSize / 4) - (this.lensSeparationDistance / 2);
+                var h = (4 * meters) / this.hScreenSize;
+                return BABYLON.Matrix.Translation(h, 0, 0);
+            },
+            enumerable: true,
+            configurable: true
+        });
+        Object.defineProperty(VRCameraMetrics.prototype, "rightHMatrix", {
+            get: function () {
+                var meters = (this.hScreenSize / 4) - (this.lensSeparationDistance / 2);
+                var h = (4 * meters) / this.hScreenSize;
+                return BABYLON.Matrix.Translation(-h, 0, 0);
+            },
+            enumerable: true,
+            configurable: true
+        });
+        Object.defineProperty(VRCameraMetrics.prototype, "leftPreViewMatrix", {
+            get: function () {
+                return BABYLON.Matrix.Translation(0.5 * this.interpupillaryDistance, 0, 0);
+            },
+            enumerable: true,
+            configurable: true
+        });
+        Object.defineProperty(VRCameraMetrics.prototype, "rightPreViewMatrix", {
+            get: function () {
+                return BABYLON.Matrix.Translation(-0.5 * this.interpupillaryDistance, 0, 0);
+            },
+            enumerable: true,
+            configurable: true
+        });
+        VRCameraMetrics.GetDefault = function () {
+            var result = new VRCameraMetrics();
+            result.hResolution = 1280;
+            result.vResolution = 800;
+            result.hScreenSize = 0.149759993;
+            result.vScreenSize = 0.0935999975;
+            result.vScreenCenter = 0.0467999987, result.eyeToScreenDistance = 0.0410000011;
+            result.lensSeparationDistance = 0.0635000020;
+            result.interpupillaryDistance = 0.0640000030;
+            result.distortionK = [1.0, 0.219999999, 0.239999995, 0.0];
+            result.chromaAbCorrection = [0.995999992, -0.00400000019, 1.01400006, 0.0];
+            result.postProcessScaleFactor = 1.714605507808412;
+            result.lensCenterOffset = 0.151976421;
+            return result;
+        };
+        return VRCameraMetrics;
+    })();
+    BABYLON.VRCameraMetrics = VRCameraMetrics;
     var Camera = (function (_super) {
         __extends(Camera, _super);
         function Camera(name, position, scene) {
@@ -24,9 +92,12 @@ var BABYLON;
             this.mode = Camera.PERSPECTIVE_CAMERA;
             this.isIntermediate = false;
             this.viewport = new BABYLON.Viewport(0, 0, 1.0, 1.0);
-            this.subCameras = [];
-            this.layerMask = 0xFFFFFFFF;
+            this.layerMask = 0x0FFFFFFF;
             this.fovMode = Camera.FOVMODE_VERTICAL_FIXED;
+            // Subcamera members
+            this.subCameras = new Array();
+            this._subCameraMode = Camera.SUB_CAMERA_MODE_NONE;
+            // Cache
             this._computedViewMatrix = BABYLON.Matrix.Identity();
             this._projectionMatrix = new BABYLON.Matrix();
             this._postProcesses = new Array();
@@ -66,6 +137,55 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+        Object.defineProperty(Camera, "SUB_CAMERA_MODE_NONE", {
+            get: function () {
+                return Camera._SUB_CAMERA_MODE_NONE;
+            },
+            enumerable: true,
+            configurable: true
+        });
+        Object.defineProperty(Camera, "SUB_CAMERA_MODE_ANAGLYPH", {
+            get: function () {
+                return Camera._SUB_CAMERA_MODE_ANAGLYPH;
+            },
+            enumerable: true,
+            configurable: true
+        });
+        Object.defineProperty(Camera, "SUB_CAMERA_MODE_HORIZONTAL_STEREOGRAM", {
+            get: function () {
+                return Camera._SUB_CAMERA_MODE_HORIZONTAL_STEREOGRAM;
+            },
+            enumerable: true,
+            configurable: true
+        });
+        Object.defineProperty(Camera, "SUB_CAMERA_MODE_VERTICAL_STEREOGRAM", {
+            get: function () {
+                return Camera._SUB_CAMERA_MODE_VERTICAL_STEREOGRAM;
+            },
+            enumerable: true,
+            configurable: true
+        });
+        Object.defineProperty(Camera, "SUB_CAMERA_MODE_VR", {
+            get: function () {
+                return Camera._SUB_CAMERA_MODE_VR;
+            },
+            enumerable: true,
+            configurable: true
+        });
+        Object.defineProperty(Camera, "SUB_CAMERAID_A", {
+            get: function () {
+                return Camera._SUB_CAMERAID_A;
+            },
+            enumerable: true,
+            configurable: true
+        });
+        Object.defineProperty(Camera, "SUB_CAMERAID_B", {
+            get: function () {
+                return Camera._SUB_CAMERAID_B;
+            },
+            enumerable: true,
+            configurable: true
+        });
         Object.defineProperty(Camera.prototype, "globalPosition", {
             get: function () {
                 return this._globalPosition;
@@ -148,6 +268,12 @@ var BABYLON;
         Camera.prototype.detachControl = function (element) {
         };
         Camera.prototype._update = function () {
+            this._checkInputs();
+            if (this._subCameraMode !== Camera.SUB_CAMERA_MODE_NONE) {
+                this._updateSubCameras();
+            }
+        };
+        Camera.prototype._checkInputs = function () {
         };
         Camera.prototype.attachPostProcess = function (postProcess, insertAt) {
             if (insertAt === void 0) { insertAt = null; }
@@ -275,15 +401,109 @@ var BABYLON;
         Camera.prototype.dispose = function () {
             // Remove from scene
             this.getScene().removeCamera(this);
+            while (this.subCameras.length > 0) {
+                this.subCameras.pop().dispose();
+            }
             for (var i = 0; i < this._postProcessesTakenIndices.length; ++i) {
                 this._postProcesses[this._postProcessesTakenIndices[i]].dispose(this);
             }
         };
+        // ---- 3D cameras section ----
+        Camera.prototype.setSubCameraMode = function (mode, halfSpace, metrics) {
+            if (halfSpace === void 0) { halfSpace = 0; }
+            while (this.subCameras.length > 0) {
+                this.subCameras.pop().dispose();
+            }
+            this._subCameraMode = mode;
+            this._subCamHalfSpace = BABYLON.Tools.ToRadians(halfSpace);
+            var camA = this.getSubCamera(this.name + "_A", true);
+            var camB = this.getSubCamera(this.name + "_B", false);
+            var postProcessA;
+            var postProcessB;
+            switch (this._subCameraMode) {
+                case Camera.SUB_CAMERA_MODE_ANAGLYPH:
+                    postProcessA = new BABYLON.PassPostProcess(this.name + "_leftTexture", 1.0, camA);
+                    camA.isIntermediate = true;
+                    postProcessB = new BABYLON.AnaglyphPostProcess(this.name + "_anaglyph", 1.0, camB);
+                    postProcessB.onApply = function (effect) {
+                        effect.setTextureFromPostProcess("leftSampler", postProcessA);
+                    };
+                    break;
+                case Camera.SUB_CAMERA_MODE_HORIZONTAL_STEREOGRAM:
+                case Camera.SUB_CAMERA_MODE_VERTICAL_STEREOGRAM:
+                    var isStereogramHoriz = this._subCameraMode === Camera.SUB_CAMERA_MODE_HORIZONTAL_STEREOGRAM;
+                    postProcessA = new BABYLON.PassPostProcess("passthru", 1.0, camA);
+                    camA.isIntermediate = true;
+                    postProcessB = new BABYLON.StereogramInterlacePostProcess("st_interlace", camB, postProcessA, isStereogramHoriz);
+                    break;
+                case Camera.SUB_CAMERA_MODE_VR:
+                    metrics = metrics || VRCameraMetrics.GetDefault();
+                    ;
+                    camA._vrMetrics = metrics;
+                    camA.viewport = new BABYLON.Viewport(0, 0, 0.5, 1.0);
+                    camA._vrWorkMatrix = new BABYLON.Matrix();
+                    camA._vrHMatrix = metrics.leftHMatrix;
+                    camA._vrPreViewMatrix = metrics.leftPreViewMatrix;
+                    camA.getProjectionMatrix = camA._getVRProjectionMatrix;
+                    if (metrics.compensateDistorsion) {
+                        postProcessA = new BABYLON.VRDistortionCorrectionPostProcess("Distortion Compensation Left", camA, false, metrics);
+                    }
+                    camB._vrMetrics = camA._vrMetrics;
+                    camB.viewport = new BABYLON.Viewport(0.5, 0, 0.5, 1.0);
+                    camB._vrWorkMatrix = new BABYLON.Matrix();
+                    camB._vrHMatrix = metrics.rightHMatrix;
+                    camB._vrPreViewMatrix = metrics.rightPreViewMatrix;
+                    camB.getProjectionMatrix = camB._getVRProjectionMatrix;
+                    if (metrics.compensateDistorsion) {
+                        postProcessB = new BABYLON.VRDistortionCorrectionPostProcess("Distortion Compensation Right", camB, true, metrics);
+                    }
+            }
+            if (this._subCameraMode !== Camera.SUB_CAMERA_MODE_NONE) {
+                this.subCameras.push(camA);
+                this.subCameras.push(camB);
+            }
+            this._update();
+        };
+        Camera.prototype._getVRProjectionMatrix = function () {
+            BABYLON.Matrix.PerspectiveFovLHToRef(this._vrMetrics.aspectRatioFov, this._vrMetrics.aspectRatio, this.minZ, this.maxZ, this._vrWorkMatrix);
+            this._vrWorkMatrix.multiplyToRef(this._vrHMatrix, this._projectionMatrix);
+            return this._projectionMatrix;
+        };
+        Camera.prototype.setSubCamHalfSapce = function (halfSapce) {
+            this._subCamHalfSpace = BABYLON.Tools.ToRadians(halfSapce);
+        };
+        /**
+         * May needs to be overridden by children so sub has required properties to be copied
+         */
+        Camera.prototype.getSubCamera = function (name, isA) {
+            return null;
+        };
+        /**
+         * May needs to be overridden by children
+         */
+        Camera.prototype._updateSubCameras = function () {
+            var camA = this.subCameras[Camera.SUB_CAMERAID_A];
+            var camB = this.subCameras[Camera.SUB_CAMERAID_B];
+            camA.minZ = camB.minZ = this.minZ;
+            camA.maxZ = camB.maxZ = this.maxZ;
+            camA.fov = camB.fov = this.fov;
+            // only update viewport, when ANAGLYPH
+            if (this._subCameraMode === Camera.SUB_CAMERA_MODE_ANAGLYPH) {
+                camA.viewport = camB.viewport = this.viewport;
+            }
+        };
         // Statics
         Camera._PERSPECTIVE_CAMERA = 0;
         Camera._ORTHOGRAPHIC_CAMERA = 1;
         Camera._FOVMODE_VERTICAL_FIXED = 0;
         Camera._FOVMODE_HORIZONTAL_FIXED = 1;
+        Camera._SUB_CAMERA_MODE_NONE = 0;
+        Camera._SUB_CAMERA_MODE_ANAGLYPH = 1;
+        Camera._SUB_CAMERA_MODE_HORIZONTAL_STEREOGRAM = 2;
+        Camera._SUB_CAMERA_MODE_VERTICAL_STEREOGRAM = 3;
+        Camera._SUB_CAMERA_MODE_VR = 4;
+        Camera._SUB_CAMERAID_A = 0;
+        Camera._SUB_CAMERAID_B = 1;
         return Camera;
     })(BABYLON.Node);
     BABYLON.Camera = Camera;

+ 175 - 123
Babylon/Cameras/babylon.camera.ts

@@ -1,27 +1,69 @@
 module BABYLON {
-    // Oculus source & derived constants
-    var OculusRiftDevKit2013_Metric = {
-        HResolution: 1280,
-        VResolution: 800,
-        HScreenSize: 0.149759993,
-        VScreenSize: 0.0935999975,
-        VScreenCenter: 0.0467999987,
-        EyeToScreenDistance: 0.0410000011,
-        LensSeparationDistance: 0.0635000020,
-        InterpupillaryDistance: 0.0640000030,
-        DistortionK: [1.0, 0.219999999, 0.239999995, 0.0],
-        ChromaAbCorrection: [0.995999992, -0.00400000019, 1.01400006, 0.0],
-        PostProcessScaleFactor: 1.714605507808412,
-        LensCenterOffset: 0.151976421
-    };
-    var OculusAspectRatio = OculusRiftDevKit2013_Metric.HResolution / (2 * OculusRiftDevKit2013_Metric.VResolution);
-    var OculusAspectRatioFov = (2 * Math.atan((OculusRiftDevKit2013_Metric.PostProcessScaleFactor * OculusRiftDevKit2013_Metric.VScreenSize) / (2 * OculusRiftDevKit2013_Metric.EyeToScreenDistance)));
-    var OculusHMeters = (OculusRiftDevKit2013_Metric.HScreenSize / 4) - (OculusRiftDevKit2013_Metric.LensSeparationDistance / 2);
-    var OculusH = (4 * OculusHMeters) / OculusRiftDevKit2013_Metric.HScreenSize;
-    var OculusLeftHMatrix  = Matrix.Translation( OculusH , 0, 0);
-    var OculusRightHMatrix = Matrix.Translation(-OculusH , 0, 0);
-    var OculusLeftPreViewMatrix  = Matrix.Translation( .5 * OculusRiftDevKit2013_Metric.InterpupillaryDistance, 0, 0);
-    var OculusRightPreViewMatrix = Matrix.Translation(-.5 * OculusRiftDevKit2013_Metric.InterpupillaryDistance, 0, 0);
+
+    export class VRCameraMetrics {
+        public hResolution: number;
+        public vResolution: number;
+        public hScreenSize: number;
+        public vScreenSize: number;
+        public vScreenCenter: number;
+        public eyeToScreenDistance: number;
+        public lensSeparationDistance: number;
+        public interpupillaryDistance: number;
+        public distortionK: number[];
+        public chromaAbCorrection: number[];
+        public postProcessScaleFactor: number;
+        public lensCenterOffset: number;
+        public compensateDistorsion = true;
+
+        public get aspectRatio(): number {
+            return this.hResolution / (2 * this.vResolution);
+        }
+
+        public get aspectRatioFov(): number {
+            return (2 * Math.atan((this.postProcessScaleFactor * this.vScreenSize) / (2 * this.eyeToScreenDistance)));
+        }
+
+        public get leftHMatrix(): Matrix {
+            var meters = (this.hScreenSize / 4) - (this.lensSeparationDistance / 2);
+            var h = (4 * meters) / this.hScreenSize;
+
+            return Matrix.Translation(h, 0, 0);
+        }
+
+        public get rightHMatrix(): Matrix {
+            var meters = (this.hScreenSize / 4) - (this.lensSeparationDistance / 2);
+            var h = (4 * meters) / this.hScreenSize;
+
+            return Matrix.Translation(-h, 0, 0);
+        }
+
+        public get leftPreViewMatrix(): Matrix {
+            return Matrix.Translation(0.5 * this.interpupillaryDistance, 0, 0);
+        }
+
+        public get rightPreViewMatrix(): Matrix {
+            return Matrix.Translation(-0.5 * this.interpupillaryDistance, 0, 0);
+        }
+
+        public static GetDefault(): VRCameraMetrics {
+            var result = new VRCameraMetrics();
+
+            result.hResolution = 1280;
+            result.vResolution = 800;
+            result.hScreenSize = 0.149759993;
+            result.vScreenSize = 0.0935999975;
+            result.vScreenCenter = 0.0467999987,
+            result.eyeToScreenDistance = 0.0410000011;
+            result.lensSeparationDistance = 0.0635000020;
+            result.interpupillaryDistance = 0.0640000030;
+            result.distortionK = [1.0, 0.219999999, 0.239999995, 0.0];
+            result.chromaAbCorrection = [0.995999992, -0.00400000019, 1.01400006, 0.0];
+            result.postProcessScaleFactor = 1.714605507808412;
+            result.lensCenterOffset = 0.151976421;
+
+            return result;
+        }
+    }
 
     export class Camera extends Node {
         // Statics
@@ -31,14 +73,15 @@
         private static _FOVMODE_VERTICAL_FIXED = 0;
         private static _FOVMODE_HORIZONTAL_FIXED = 1;
 
-        private static _SUB_CAMS_NONE = 0;
-        private static _SUB_CAMS_ANAGLYPH = 1;
-        private static _SUB_CAMS_HORIZ_STEREOGRAM = 2;
-        private static _SUB_CAMS_VERT_STEREOGRAM = 3;
-        private static _SUB_CAMS_OCULUS = 4;
-        private static _SUB_CAM_A = 0;
-        private static _SUB_CAM_B = 1;
-        
+        private static _SUB_CAMERA_MODE_NONE = 0;
+        private static _SUB_CAMERA_MODE_ANAGLYPH = 1;
+        private static _SUB_CAMERA_MODE_HORIZONTAL_STEREOGRAM = 2;
+        private static _SUB_CAMERA_MODE_VERTICAL_STEREOGRAM = 3;
+        private static _SUB_CAMERA_MODE_VR = 4;
+
+        private static _SUB_CAMERAID_A = 0;
+        private static _SUB_CAMERAID_B = 1;
+
         public static get PERSPECTIVE_CAMERA(): number {
             return Camera._PERSPECTIVE_CAMERA;
         }
@@ -54,35 +97,33 @@
         public static get FOVMODE_HORIZONTAL_FIXED(): number {
             return Camera._FOVMODE_HORIZONTAL_FIXED;
         }
-        
-        public static get SUB_CAMS_NONE(): number {
-            return Camera._SUB_CAMS_NONE;
+
+        public static get SUB_CAMERA_MODE_NONE(): number {
+            return Camera._SUB_CAMERA_MODE_NONE;
         }
-        
-        public static get SUB_CAMS_ANAGLYPH(): number {
-            return Camera._SUB_CAMS_ANAGLYPH;
+
+        public static get SUB_CAMERA_MODE_ANAGLYPH(): number {
+            return Camera._SUB_CAMERA_MODE_ANAGLYPH;
         }
-        
-        public static get SUB_CAMS_HORIZ_STEREOGRAM(): number {
-            return Camera._SUB_CAMS_HORIZ_STEREOGRAM;
+
+        public static get SUB_CAMERA_MODE_HORIZONTAL_STEREOGRAM(): number {
+            return Camera._SUB_CAMERA_MODE_HORIZONTAL_STEREOGRAM;
         }
-        
-        public static get SUB_CAMS_VERT_STEREOGRAM(): number {
-            return Camera._SUB_CAMS_VERT_STEREOGRAM;
+
+        public static get SUB_CAMERA_MODE_VERTICAL_STEREOGRAM(): number {
+            return Camera._SUB_CAMERA_MODE_VERTICAL_STEREOGRAM;
         }
-        
-        public static get SUB_CAMS_OCULUS(): number {
-            return Camera._SUB_CAMS_OCULUS;
+
+        public static get SUB_CAMERA_MODE_VR(): number {
+            return Camera._SUB_CAMERA_MODE_VR;
         }
-        
-        public static SUB_CAMS_UI_ENGLISH = ['None', 'Anaglyph', 'Stereogram Horizontal', 'Stereogram Vertical', 'Oculus Rift'];
-        
-        public static get SUB_CAM_A(): number {
-            return Camera._SUB_CAM_A;
+
+        public static get SUB_CAMERAID_A(): number {
+            return Camera._SUB_CAMERAID_A;
         }
-        
-        public static get SUB_CAM_B(): number {
-            return Camera._SUB_CAM_B;
+
+        public static get SUB_CAMERAID_B(): number {
+            return Camera._SUB_CAMERAID_B;
         }
         
         // Members
@@ -103,13 +144,17 @@
    
         // Subcamera members
         public subCameras = new Array<Camera>();
-        public _subCameraMode = Camera._SUB_CAMS_NONE;
-        public _subCamHalfSapce: number;
-        private _OculusHMatrix : Matrix;
-        public _OculusPreViewMatrix : Matrix;
-        public _OculusWorkMatrix : Matrix;
-        public _OculusActualUp : Vector3;
+        public _subCameraMode = Camera.SUB_CAMERA_MODE_NONE;
+        public _subCamHalfSpace: number;
+
+        // VR related
+        private _vrMetrics: VRCameraMetrics;
+        private _vrHMatrix: Matrix;
+        public _vrPreViewMatrix: Matrix;
+        public _vrWorkMatrix: Matrix;
+        public _vrActualUp: Vector3;
 
+        // Cache
         private _computedViewMatrix = Matrix.Identity();
         public _projectionMatrix = new Matrix();
         private _worldMatrix: Matrix;
@@ -244,14 +289,14 @@
 
         public _update(): void {
             this._checkInputs();
-            if (this._subCameraMode !== Camera._SUB_CAMS_NONE){
+            if (this._subCameraMode !== Camera.SUB_CAMERA_MODE_NONE) {
                 this._updateSubCameras();
             }
         }
 
-        public _checkInputs(): void {            
+        public _checkInputs(): void {
         }
-        
+
         public attachPostProcess(postProcess: PostProcess, insertAt: number = null): number {
             if (!postProcess.isReusable() && this._postProcesses.indexOf(postProcess) > -1) {
                 Tools.Error("You're trying to reuse a post process not defined as reusable.");
@@ -422,7 +467,7 @@
         public dispose(): void {
             // Remove from scene
             this.getScene().removeCamera(this);
-            while (this.subCameras.length > 0){
+            while (this.subCameras.length > 0) {
                 this.subCameras.pop().dispose();
             }                    
 
@@ -433,95 +478,102 @@
         }
         
         // ---- 3D cameras section ----
-        public setSubCameraMode(mode : number, halfSapce : number) : void{
-            // not likely in production that any prior sub cams, but in dev maybe
-            while (this.subCameras.length > 0){
+        public setSubCameraMode(mode: number, halfSpace = 0, metrics?: VRCameraMetrics): void {
+            while (this.subCameras.length > 0) {
                 this.subCameras.pop().dispose();
-            }                        
-            this._subCameraMode = mode;   
-            this._subCamHalfSapce = Tools.ToRadians(halfSapce);
-            
-            var camA = this.GetSubCamera(this.name + "_A", true );
-            var camB = this.GetSubCamera(this.name + "_B", false);
-            var postProcessA : PostProcess;
-            var postProcessB : PostProcess;
-            
-            switch (this._subCameraMode){
-                case Camera._SUB_CAMS_ANAGLYPH:
+            }
+            this._subCameraMode = mode;
+            this._subCamHalfSpace = Tools.ToRadians(halfSpace);
+
+            var camA = this.getSubCamera(this.name + "_A", true);
+            var camB = this.getSubCamera(this.name + "_B", false);
+            var postProcessA: PostProcess;
+            var postProcessB: PostProcess;
+
+            switch (this._subCameraMode) {
+                case Camera.SUB_CAMERA_MODE_ANAGLYPH:
                     postProcessA = new PassPostProcess(this.name + "_leftTexture", 1.0, camA);
                     camA.isIntermediate = true;
-                    
+
                     postProcessB = new AnaglyphPostProcess(this.name + "_anaglyph", 1.0, camB);
                     postProcessB.onApply = effect => {
                         effect.setTextureFromPostProcess("leftSampler", postProcessA);
                     };
                     break;
-                    
-                case Camera._SUB_CAMS_HORIZ_STEREOGRAM:
-                case Camera._SUB_CAMS_VERT_STEREOGRAM:
-                    var isStereogramHoriz = this._subCameraMode === Camera._SUB_CAMS_HORIZ_STEREOGRAM;
-                    postProcessA = new PassPostProcess("passthru", 1.0, camA);  
+
+                case Camera.SUB_CAMERA_MODE_HORIZONTAL_STEREOGRAM:
+                case Camera.SUB_CAMERA_MODE_VERTICAL_STEREOGRAM:
+                    var isStereogramHoriz = this._subCameraMode === Camera.SUB_CAMERA_MODE_HORIZONTAL_STEREOGRAM;
+                    postProcessA = new PassPostProcess("passthru", 1.0, camA);
                     camA.isIntermediate = true;
-                    
-                    postProcessB = new StereogramInterlacePostProcess("st_interlace" , camB, postProcessA, isStereogramHoriz);  
+
+                    postProcessB = new StereogramInterlacePostProcess("st_interlace", camB, postProcessA, isStereogramHoriz);
                     break;
-                    
-                case Camera._SUB_CAMS_OCULUS:
-                    camA.viewport = new Viewport(  0,   0, 0.5, 1.0);
-                    camA._OculusWorkMatrix = new Matrix();
-                    
-                    camA._OculusHMatrix = OculusLeftHMatrix;
-                    camA._OculusPreViewMatrix = OculusLeftPreViewMatrix;                    
-                    camA.getProjectionMatrix = camA.getOculusProjectionMatrix;
-                    postProcessA = new OculusDistortionCorrectionPostProcess("Oculus Distortion Left", camA, false, OculusRiftDevKit2013_Metric);
-                    
-                    camB.viewport = new Viewport(0.5,   0, 0.5, 1.0);
-                    camB._OculusWorkMatrix = new Matrix();
-                    camB._OculusHMatrix = OculusRightHMatrix;
-                    camB._OculusPreViewMatrix = OculusRightPreViewMatrix;
-                    
-                    camB.getProjectionMatrix = camB.getOculusProjectionMatrix;
-                    postProcessB = new OculusDistortionCorrectionPostProcess("Oculus Distortion Right", camB, true , OculusRiftDevKit2013_Metric);
+
+                case Camera.SUB_CAMERA_MODE_VR:
+                    metrics = metrics || VRCameraMetrics.GetDefault();;
+                    camA._vrMetrics = metrics;
+                    camA.viewport = new Viewport(0, 0, 0.5, 1.0);
+                    camA._vrWorkMatrix = new Matrix();
+
+                    camA._vrHMatrix = metrics.leftHMatrix;
+                    camA._vrPreViewMatrix = metrics.leftPreViewMatrix;
+                    camA.getProjectionMatrix = camA._getVRProjectionMatrix;
+
+                    if (metrics.compensateDistorsion) {
+                        postProcessA = new VRDistortionCorrectionPostProcess("Distortion Compensation Left", camA, false, metrics);
+                    }
+
+                    camB._vrMetrics = camA._vrMetrics;
+                    camB.viewport = new Viewport(0.5, 0, 0.5, 1.0);
+                    camB._vrWorkMatrix = new Matrix();
+                    camB._vrHMatrix = metrics.rightHMatrix;
+                    camB._vrPreViewMatrix = metrics.rightPreViewMatrix;
+
+                    camB.getProjectionMatrix = camB._getVRProjectionMatrix;
+
+                    if (metrics.compensateDistorsion) {
+                        postProcessB = new VRDistortionCorrectionPostProcess("Distortion Compensation Right", camB, true, metrics);
+                    }
             }
-            if (this._subCameraMode !== Camera._SUB_CAMS_NONE){
+            if (this._subCameraMode !== Camera.SUB_CAMERA_MODE_NONE) {
                 this.subCameras.push(camA);
                 this.subCameras.push(camB);
             }
             this._update();
         }
-        
-        private getOculusProjectionMatrix(): Matrix {
-            Matrix.PerspectiveFovLHToRef(OculusAspectRatioFov, OculusAspectRatio, this.minZ, this.maxZ, this._OculusWorkMatrix);
-            this._OculusWorkMatrix.multiplyToRef(this._OculusHMatrix, this._projectionMatrix);
+
+        private _getVRProjectionMatrix(): Matrix {
+            Matrix.PerspectiveFovLHToRef(this._vrMetrics.aspectRatioFov, this._vrMetrics.aspectRatio, this.minZ, this.maxZ, this._vrWorkMatrix);
+            this._vrWorkMatrix.multiplyToRef(this._vrHMatrix, this._projectionMatrix);
             return this._projectionMatrix;
         }
-        
-        public setSubCamHalfSapce( halfSapce : number){
-            this._subCamHalfSapce = Tools.ToRadians(halfSapce);
+
+        public setSubCamHalfSapce(halfSapce: number) {
+            this._subCamHalfSpace = Tools.ToRadians(halfSapce);
         }
         
         /**
-         * needs to be overridden in ArcRotateCamera & TargetCamera, so sub has required properties to be copied
+         * May needs to be overridden by children so sub has required properties to be copied
          */
-        public GetSubCamera(name : string, isA : boolean) : Camera{ 
-            return null;  
+        public getSubCamera(name: string, isA: boolean): Camera {
+            return null;
         }
         
         /**
-         * needs to be overridden in ArcRotateCamera, adding copy of alpha, beta & radius
-         * needs to be overridden in TargetCamera, adding copy of position, and rotation for Oculus, or target for rest
+         * May needs to be overridden by children
          */
-        public _updateSubCameras(){
-            var camA = this.subCameras[Camera.SUB_CAM_A];
-            var camB = this.subCameras[Camera.SUB_CAM_B];
+        public _updateSubCameras() {
+            var camA = this.subCameras[Camera.SUB_CAMERAID_A];
+            var camB = this.subCameras[Camera.SUB_CAMERAID_B];
             camA.minZ = camB.minZ = this.minZ;
             camA.maxZ = camB.maxZ = this.maxZ;
-            camA.fov  = camB.fov  = this.fov; // original Oculus did not do this
+            camA.fov = camB.fov = this.fov;
             
             // only update viewport, when ANAGLYPH
-            if (this._subCameraMode === Camera.SUB_CAMS_ANAGLYPH){
-                camA.viewport = camB.viewport = this.viewport;                
+            if (this._subCameraMode === Camera.SUB_CAMERA_MODE_ANAGLYPH) {
+                camA.viewport = camB.viewport = this.viewport;
             }
-        }        
+        }
     }
 }

+ 1 - 0
Babylon/Cameras/babylon.deviceOrientationCamera.js

@@ -64,6 +64,7 @@ var BABYLON;
             var direction = new BABYLON.Vector3(0, 0, speed * this._offsetY / this.moveSensibility);
             BABYLON.Matrix.RotationYawPitchRollToRef(this.rotation.y, this.rotation.x, 0, this._cameraRotationMatrix);
             this.cameraDirection.addInPlace(BABYLON.Vector3.TransformCoordinates(direction, this._cameraRotationMatrix));
+            _super.prototype._checkInputs.call(this);
         };
         return DeviceOrientationCamera;
     })(BABYLON.FreeCamera);

+ 2 - 0
Babylon/Cameras/babylon.deviceOrientationCamera.ts

@@ -71,6 +71,8 @@ module BABYLON {
 
             BABYLON.Matrix.RotationYawPitchRollToRef(this.rotation.y, this.rotation.x, 0, this._cameraRotationMatrix);
             this.cameraDirection.addInPlace(BABYLON.Vector3.TransformCoordinates(direction, this._cameraRotationMatrix));
+
+            super._checkInputs();
         }
     }
 }

+ 2 - 2
Babylon/Cameras/babylon.followCamera.js

@@ -52,8 +52,8 @@ var BABYLON;
             this.position = new BABYLON.Vector3(this.position.x + vx, this.position.y + vy, this.position.z + vz);
             this.setTarget(cameraTarget.position);
         };
-        FollowCamera.prototype._update = function () {
-            _super.prototype._update.call(this);
+        FollowCamera.prototype._checkInputs = function () {
+            _super.prototype._checkInputs.call(this);
             this.follow(this.target);
         };
         return FollowCamera;

+ 1 - 4
Babylon/Cameras/babylon.freeCamera.js

@@ -200,6 +200,7 @@ var BABYLON;
                 BABYLON.Vector3.TransformNormalToRef(this._localDirection, this._cameraTransformMatrix, this._transformedDirection);
                 this.cameraDirection.addInPlace(this._transformedDirection);
             }
+            _super.prototype._checkInputs.call(this);
         };
         FreeCamera.prototype._decideIfNeedsToMove = function () {
             return this._needMoveForGravity || Math.abs(this.cameraDirection.x) > 0 || Math.abs(this.cameraDirection.y) > 0 || Math.abs(this.cameraDirection.z) > 0;
@@ -212,10 +213,6 @@ var BABYLON;
                 this.position.addInPlace(this.cameraDirection);
             }
         };
-        FreeCamera.prototype._update = function () {
-            this._checkInputs();
-            _super.prototype._update.call(this);
-        };
         return FreeCamera;
     })(BABYLON.TargetCamera);
     BABYLON.FreeCamera = FreeCamera;

+ 2 - 0
Babylon/Cameras/babylon.freeCamera.ts

@@ -245,6 +245,8 @@
                 BABYLON.Vector3.TransformNormalToRef(this._localDirection, this._cameraTransformMatrix, this._transformedDirection);
                 this.cameraDirection.addInPlace(this._transformedDirection);
             }
+
+            super._checkInputs();
         }
 
         public _decideIfNeedsToMove(): boolean {

+ 18 - 18
Babylon/Cameras/babylon.gamepadCamera.js

@@ -25,25 +25,25 @@ var BABYLON;
             }
         };
         GamepadCamera.prototype._checkInputs = function () {
-            if (!this._gamepad) {
-                return;
+            if (this._gamepad) {
+                var LSValues = this._gamepad.leftStick;
+                var normalizedLX = LSValues.x / this.moveSensibility;
+                var normalizedLY = LSValues.y / this.moveSensibility;
+                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.angularSensibility;
+                var normalizedRY = RSValues.y / this.angularSensibility;
+                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(this.rotation.y, this.rotation.x, 0);
+                var speed = this._computeLocalCameraSpeed() * 50.0;
+                var deltaTransform = BABYLON.Vector3.TransformCoordinates(new BABYLON.Vector3(LSValues.x * speed, 0, -LSValues.y * speed), cameraTransform);
+                this.cameraDirection = this.cameraDirection.add(deltaTransform);
+                this.cameraRotation = this.cameraRotation.add(new BABYLON.Vector2(RSValues.y, RSValues.x));
             }
-            var LSValues = this._gamepad.leftStick;
-            var normalizedLX = LSValues.x / this.moveSensibility;
-            var normalizedLY = LSValues.y / this.moveSensibility;
-            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.angularSensibility;
-            var normalizedRY = RSValues.y / this.angularSensibility;
-            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(this.rotation.y, this.rotation.x, 0);
-            var speed = this._computeLocalCameraSpeed() * 50.0;
-            var deltaTransform = BABYLON.Vector3.TransformCoordinates(new BABYLON.Vector3(LSValues.x * speed, 0, -LSValues.y * speed), cameraTransform);
-            this.cameraDirection = this.cameraDirection.add(deltaTransform);
-            this.cameraRotation = this.cameraRotation.add(new BABYLON.Vector2(RSValues.y, RSValues.x));
+            _super.prototype._checkInputs.call(this);
         };
         GamepadCamera.prototype.dispose = function () {
             this._gamepads.dispose();

+ 20 - 20
Babylon/Cameras/babylon.gamepadCamera.ts

@@ -19,28 +19,28 @@ module BABYLON {
         }
 
         public _checkInputs(): void {
-            if (!this._gamepad) {
-                return;
+            if (this._gamepad) {
+                var LSValues = this._gamepad.leftStick;
+                var normalizedLX = LSValues.x / this.moveSensibility;
+                var normalizedLY = LSValues.y / this.moveSensibility;
+                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.angularSensibility;
+                var normalizedRY = RSValues.y / this.angularSensibility;
+                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(this.rotation.y, this.rotation.x, 0);
+
+                var speed = this._computeLocalCameraSpeed() * 50.0;
+                var deltaTransform = BABYLON.Vector3.TransformCoordinates(new BABYLON.Vector3(LSValues.x * speed, 0, -LSValues.y * speed), cameraTransform);
+                this.cameraDirection = this.cameraDirection.add(deltaTransform);
+                this.cameraRotation = this.cameraRotation.add(new BABYLON.Vector2(RSValues.y, RSValues.x));
             }
 
-            var LSValues = this._gamepad.leftStick;
-            var normalizedLX = LSValues.x / this.moveSensibility;
-            var normalizedLY = LSValues.y / this.moveSensibility;
-            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.angularSensibility;
-            var normalizedRY = RSValues.y / this.angularSensibility;
-            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(this.rotation.y, this.rotation.x, 0);
-
-            var speed = this._computeLocalCameraSpeed() * 50.0;
-            var deltaTransform = BABYLON.Vector3.TransformCoordinates(new BABYLON.Vector3(LSValues.x * speed, 0, -LSValues.y * speed), cameraTransform);
-            this.cameraDirection = this.cameraDirection.add(deltaTransform);
-            this.cameraRotation = this.cameraRotation.add(new BABYLON.Vector2(RSValues.y, RSValues.x));
+            super._checkInputs();
         }
 
         public dispose(): void {

+ 0 - 175
Babylon/Cameras/babylon.oculusGamepadCamera.js

@@ -1,175 +0,0 @@
-var __extends = this.__extends || function (d, b) {
-    for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
-    function __() { this.constructor = d; }
-    __.prototype = b.prototype;
-    d.prototype = new __();
-};
-var BABYLON;
-(function (BABYLON) {
-    var OculusRiftDevKit2013_Metric = {
-        HResolution: 1280,
-        VResolution: 800,
-        HScreenSize: 0.149759993,
-        VScreenSize: 0.0935999975,
-        VScreenCenter: 0.0467999987,
-        EyeToScreenDistance: 0.0410000011,
-        LensSeparationDistance: 0.0635000020,
-        InterpupillaryDistance: 0.0640000030,
-        DistortionK: [1.0, 0.219999999, 0.239999995, 0.0],
-        ChromaAbCorrection: [0.995999992, -0.00400000019, 1.01400006, 0.0],
-        PostProcessScaleFactor: 1.714605507808412,
-        LensCenterOffset: 0.151976421
-    };
-
-    var _OculusInnerGamepadCamera = (function (_super) {
-        __extends(_OculusInnerGamepadCamera, _super);
-        function _OculusInnerGamepadCamera(name, position, scene, isLeftEye) {
-            _super.call(this, name, position, scene);
-            this._workMatrix = new BABYLON.Matrix();
-            this._actualUp = new BABYLON.Vector3(0, 0, 0);
-
-            // Constants
-            this._aspectRatioAspectRatio = OculusRiftDevKit2013_Metric.HResolution / (2 * OculusRiftDevKit2013_Metric.VResolution);
-            this._aspectRatioFov = (2 * Math.atan((OculusRiftDevKit2013_Metric.PostProcessScaleFactor * OculusRiftDevKit2013_Metric.VScreenSize) / (2 * OculusRiftDevKit2013_Metric.EyeToScreenDistance)));
-
-            var hMeters = (OculusRiftDevKit2013_Metric.HScreenSize / 4) - (OculusRiftDevKit2013_Metric.LensSeparationDistance / 2);
-            var h = (4 * hMeters) / OculusRiftDevKit2013_Metric.HScreenSize;
-
-            this._hMatrix = BABYLON.Matrix.Translation(isLeftEye ? h : -h, 0, 0);
-
-            this.viewport = new BABYLON.Viewport(isLeftEye ? 0 : 0.5, 0, 0.5, 1.0);
-
-            this._preViewMatrix = BABYLON.Matrix.Translation(isLeftEye ? .5 * OculusRiftDevKit2013_Metric.InterpupillaryDistance : -.5 * OculusRiftDevKit2013_Metric.InterpupillaryDistance, 0, 0);
-
-            // Postprocess
-            var postProcess = new BABYLON.OculusDistortionCorrectionPostProcess("Oculus Distortion", this, !isLeftEye, OculusRiftDevKit2013_Metric);
-        }
-        _OculusInnerGamepadCamera.prototype.getProjectionMatrix = function () {
-            BABYLON.Matrix.PerspectiveFovLHToRef(this._aspectRatioFov, this._aspectRatioAspectRatio, this.minZ, this.maxZ, this._workMatrix);
-            this._workMatrix.multiplyToRef(this._hMatrix, this._projectionMatrix);
-            return this._projectionMatrix;
-        };
-
-        _OculusInnerGamepadCamera.prototype._getViewMatrix = function () {
-            BABYLON.Matrix.RotationYawPitchRollToRef(this.rotation.y, this.rotation.x, this.rotation.z, this._cameraRotationMatrix);
-
-            BABYLON.Vector3.TransformCoordinatesToRef(this._referencePoint, this._cameraRotationMatrix, this._transformedReferencePoint);
-            BABYLON.Vector3.TransformNormalToRef(this.upVector, this._cameraRotationMatrix, this._actualUp);
-
-            // Computing target and final matrix
-            this.position.addToRef(this._transformedReferencePoint, this._currentTarget);
-
-            BABYLON.Matrix.LookAtLHToRef(this.position, this._currentTarget, this._actualUp, this._workMatrix);
-
-            this._workMatrix.multiplyToRef(this._preViewMatrix, this._viewMatrix);
-            return this._viewMatrix;
-        };
-        return _OculusInnerGamepadCamera;
-    })(BABYLON.FreeCamera);
-
-    var OculusGamepadCamera = (function (_super) {
-        __extends(OculusGamepadCamera, _super);
-        function OculusGamepadCamera(name, position, scene) {
-            var _this = this;
-            _super.call(this, name, position, scene);
-            this.angularSensibility = 200;
-            this.moveSensibility = 75;
-
-            this._leftCamera = new _OculusInnerGamepadCamera(name + "_left", position.clone(), scene, true);
-            this._rightCamera = new _OculusInnerGamepadCamera(name + "_right", position.clone(), scene, false);
-
-            this.subCameras.push(this._leftCamera);
-            this.subCameras.push(this._rightCamera);
-
-            this._deviceOrientationHandler = this._onOrientationEvent.bind(this);
-            this._gamepads = new BABYLON.Gamepads(function (gamepad) {
-                _this._onNewGameConnected(gamepad);
-            });
-        }
-        OculusGamepadCamera.prototype._onNewGameConnected = function (gamepad) {
-            // Only the first gamepad can control the camera
-            if (gamepad.index === 0) {
-                this._gamepad = gamepad;
-            }
-        };
-
-        OculusGamepadCamera.prototype._update = function () {
-            this._leftCamera.position.copyFrom(this.position);
-            this._rightCamera.position.copyFrom(this.position);
-
-            this._updateCamera(this._leftCamera);
-            this._updateCamera(this._rightCamera);
-
-            _super.prototype._update.call(this);
-        };
-
-        OculusGamepadCamera.prototype._checkInputs = function () {
-            if (!this._gamepad) {
-                return;
-            }
-
-            var LSValues = this._gamepad.leftStick;
-            var normalizedLX = LSValues.x / this.moveSensibility;
-            var normalizedLY = LSValues.y / this.moveSensibility;
-            LSValues.x = Math.abs(normalizedLX) > 0.005 ? 0 + normalizedLX : 0;
-            LSValues.y = Math.abs(normalizedLY) > 0.005 ? 0 + normalizedLY : 0;
-
-            var cameraTransform = BABYLON.Matrix.RotationYawPitchRoll(this.rotation.y, this.rotation.x, 0);
-            var deltaTransform = BABYLON.Vector3.TransformCoordinates(new BABYLON.Vector3(LSValues.x, 0, -LSValues.y), cameraTransform);
-            this.cameraDirection = this.cameraDirection.add(deltaTransform);
-        };
-
-        OculusGamepadCamera.prototype._updateCamera = function (camera) {
-            camera.minZ = this.minZ;
-            camera.maxZ = this.maxZ;
-
-            camera.rotation.x = this.rotation.x;
-            camera.rotation.y = this.rotation.y;
-            camera.rotation.z = this.rotation.z;
-        };
-
-        // Oculus events
-        OculusGamepadCamera.prototype._onOrientationEvent = function (evt) {
-            var yaw = evt.alpha / 180 * Math.PI;
-            var pitch = evt.beta / 180 * Math.PI;
-            var roll = evt.gamma / 180 * Math.PI;
-
-            if (!this._offsetOrientation) {
-                this._offsetOrientation = {
-                    yaw: yaw,
-                    pitch: pitch,
-                    roll: roll
-                };
-                return;
-            } else {
-                this.rotation.y += yaw - this._offsetOrientation.yaw;
-                this.rotation.x += pitch - this._offsetOrientation.pitch;
-                this.rotation.z += this._offsetOrientation.roll - roll;
-
-                this._offsetOrientation.yaw = yaw;
-                this._offsetOrientation.pitch = pitch;
-                this._offsetOrientation.roll = roll;
-            }
-        };
-
-        OculusGamepadCamera.prototype.attachControl = function (element, noPreventDefault) {
-            _super.prototype.attachControl.call(this, element, noPreventDefault);
-
-            window.addEventListener("deviceorientation", this._deviceOrientationHandler);
-        };
-
-        OculusGamepadCamera.prototype.detachControl = function (element) {
-            _super.prototype.detachControl.call(this, element);
-
-            window.removeEventListener("deviceorientation", this._deviceOrientationHandler);
-        };
-
-        OculusGamepadCamera.prototype.dispose = function () {
-            this._gamepads.dispose();
-            _super.prototype.dispose.call(this);
-        };
-        return OculusGamepadCamera;
-    })(BABYLON.FreeCamera);
-    BABYLON.OculusGamepadCamera = OculusGamepadCamera;
-})(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.oculusGamepadCamera.js.map

+ 55 - 1
Babylon/Cameras/babylon.targetCamera.js

@@ -102,7 +102,7 @@ var BABYLON;
         TargetCamera.prototype._updatePosition = function () {
             this.position.addInPlace(this.cameraDirection);
         };
-        TargetCamera.prototype._update = function () {
+        TargetCamera.prototype._checkInputs = function () {
             var needToMove = this._decideIfNeedsToMove();
             var needToRotate = Math.abs(this.cameraRotation.x) > 0 || Math.abs(this.cameraRotation.y) > 0;
             // Move
@@ -143,6 +143,7 @@ var BABYLON;
                 }
                 this.cameraRotation.scaleInPlace(this.inertia);
             }
+            _super.prototype._checkInputs.call(this);
         };
         TargetCamera.prototype._getViewMatrix = function () {
             if (!this.lockedTarget) {
@@ -167,6 +168,59 @@ var BABYLON;
             BABYLON.Matrix.LookAtLHToRef(this.position, this._currentTarget, this.upVector, this._viewMatrix);
             return this._viewMatrix;
         };
+        TargetCamera.prototype._getVRViewMatrix = function () {
+            BABYLON.Matrix.RotationYawPitchRollToRef(this.rotation.y, this.rotation.x, this.rotation.z, this._cameraRotationMatrix);
+            BABYLON.Vector3.TransformCoordinatesToRef(this._referencePoint, this._cameraRotationMatrix, this._transformedReferencePoint);
+            BABYLON.Vector3.TransformNormalToRef(this.upVector, this._cameraRotationMatrix, this._vrActualUp);
+            // Computing target and final matrix
+            this.position.addToRef(this._transformedReferencePoint, this._currentTarget);
+            BABYLON.Matrix.LookAtLHToRef(this.position, this._currentTarget, this._vrActualUp, this._vrWorkMatrix);
+            this._vrWorkMatrix.multiplyToRef(this._vrPreViewMatrix, this._viewMatrix);
+            return this._viewMatrix;
+        };
+        /**
+         * @override
+         * needs to be overridden, so sub has required properties to be copied
+         */
+        TargetCamera.prototype.getSubCamera = function (name, isA) {
+            var subCamera = new BABYLON.TargetCamera(name, this.position.clone(), this.getScene());
+            if (this._subCameraMode === BABYLON.Camera.SUB_CAMERA_MODE_VR) {
+                subCamera._vrActualUp = new BABYLON.Vector3(0, 0, 0);
+                subCamera._getViewMatrix = subCamera._getVRViewMatrix;
+            }
+            return subCamera;
+        };
+        /**
+         * @override
+         * needs to be overridden, adding copy of position, and rotation for VR, or target for rest
+         */
+        TargetCamera.prototype._updateSubCameras = function () {
+            var camA = this.subCameras[BABYLON.Camera.SUB_CAMERAID_A];
+            var camB = this.subCameras[BABYLON.Camera.SUB_CAMERAID_B];
+            if (this._subCameraMode === BABYLON.Camera.SUB_CAMERA_MODE_VR) {
+                camA.rotation.x = camB.rotation.x = this.rotation.x;
+                camA.rotation.y = camB.rotation.y = this.rotation.y;
+                camA.rotation.z = camB.rotation.z = this.rotation.z;
+                camA.position.copyFrom(this.position);
+                camB.position.copyFrom(this.position);
+            }
+            else {
+                camA.setTarget(this.getTarget());
+                camB.setTarget(this.getTarget());
+                this._getSubCamPosition(-this._subCamHalfSpace, camA.position);
+                this._getSubCamPosition(this._subCamHalfSpace, camB.position);
+            }
+            _super.prototype._updateSubCameras.call(this);
+        };
+        TargetCamera.prototype._getSubCamPosition = function (halfSpace, result) {
+            if (!this._subCamTransformMatrix) {
+                this._subCamTransformMatrix = new BABYLON.Matrix();
+            }
+            var target = this.getTarget();
+            BABYLON.Matrix.Translation(-target.x, -target.y, -target.z).multiplyToRef(BABYLON.Matrix.RotationY(halfSpace), this._subCamTransformMatrix);
+            this._subCamTransformMatrix = this._subCamTransformMatrix.multiply(BABYLON.Matrix.Translation(target.x, target.y, target.z));
+            BABYLON.Vector3.TransformCoordinatesToRef(this.position, this._subCamTransformMatrix, result);
+        };
         return TargetCamera;
     })(BABYLON.Camera);
     BABYLON.TargetCamera = TargetCamera;

+ 18 - 16
Babylon/Cameras/babylon.targetCamera.ts

@@ -179,6 +179,8 @@
                 }
                 this.cameraRotation.scaleInPlace(this.inertia);
             }
+
+            super._checkInputs();
         }
 
 
@@ -209,18 +211,18 @@
             return this._viewMatrix;
         }
         
-        public _getOculusViewMatrix(): Matrix {
+        public _getVRViewMatrix(): Matrix {
             BABYLON.Matrix.RotationYawPitchRollToRef(this.rotation.y, this.rotation.x, this.rotation.z, this._cameraRotationMatrix);
 
             BABYLON.Vector3.TransformCoordinatesToRef(this._referencePoint, this._cameraRotationMatrix, this._transformedReferencePoint);
-            BABYLON.Vector3.TransformNormalToRef(this.upVector, this._cameraRotationMatrix, this._OculusActualUp);
+            BABYLON.Vector3.TransformNormalToRef(this.upVector, this._cameraRotationMatrix, this._vrActualUp);
 
             // Computing target and final matrix
             this.position.addToRef(this._transformedReferencePoint, this._currentTarget);
 
-            BABYLON.Matrix.LookAtLHToRef(this.position, this._currentTarget, this._OculusActualUp, this._OculusWorkMatrix);
+            BABYLON.Matrix.LookAtLHToRef(this.position, this._currentTarget, this._vrActualUp, this._vrWorkMatrix);
 
-            this._OculusWorkMatrix.multiplyToRef(this._OculusPreViewMatrix, this._viewMatrix);
+            this._vrWorkMatrix.multiplyToRef(this._vrPreViewMatrix, this._viewMatrix);
             return this._viewMatrix;
         }
         
@@ -228,24 +230,24 @@
          * @override
          * needs to be overridden, so sub has required properties to be copied
          */
-        public GetSubCamera(name : string, isA : boolean) : Camera{
+        public getSubCamera(name : string, isA : boolean) : Camera{
             var subCamera = new BABYLON.TargetCamera(name, this.position.clone(), this.getScene());
-            if (this._subCameraMode === Camera.SUB_CAMS_OCULUS){
-                subCamera._OculusActualUp = new Vector3(0, 0, 0);
-                subCamera._getViewMatrix = subCamera._getOculusViewMatrix;
+            if (this._subCameraMode === Camera.SUB_CAMERA_MODE_VR){
+                subCamera._vrActualUp = new Vector3(0, 0, 0);
+                subCamera._getViewMatrix = subCamera._getVRViewMatrix;
             }
             return subCamera;
         }
         
         /**
          * @override
-         * needs to be overridden, adding copy of position, and rotation for Oculus, or target for rest
+         * needs to be overridden, adding copy of position, and rotation for VR, or target for rest
          */
         public _updateSubCameras(){
-            var camA = <TargetCamera> this.subCameras[Camera.SUB_CAM_A];
-            var camB = <TargetCamera> this.subCameras[Camera.SUB_CAM_B];
+            var camA = <TargetCamera> this.subCameras[Camera.SUB_CAMERAID_A];
+            var camB = <TargetCamera> this.subCameras[Camera.SUB_CAMERAID_B];
 
-            if (this._subCameraMode === Camera.SUB_CAMS_OCULUS){
+            if (this._subCameraMode === Camera.SUB_CAMERA_MODE_VR){
                 camA.rotation.x = camB.rotation.x = this.rotation.x;
                 camA.rotation.y = camB.rotation.y = this.rotation.y;
                 camA.rotation.z = camB.rotation.z = this.rotation.z;
@@ -257,18 +259,18 @@
                 camA.setTarget(this.getTarget());
                 camB.setTarget(this.getTarget());
                 
-                this._getSubCamPosition(-this._subCamHalfSapce, camA.position);
-                this._getSubCamPosition( this._subCamHalfSapce, camB.position);
+                this._getSubCamPosition(-this._subCamHalfSpace, camA.position);
+                this._getSubCamPosition( this._subCamHalfSpace, camB.position);
             }
             super._updateSubCameras();
         }
         
-        private _getSubCamPosition(halfSapce, result) {
+        private _getSubCamPosition(halfSpace: number, result: Vector3) {
             if (!this._subCamTransformMatrix){
                 this._subCamTransformMatrix = new BABYLON.Matrix();
             }
             var target = this.getTarget();
-            BABYLON.Matrix.Translation(-target.x, -target.y, -target.z).multiplyToRef(BABYLON.Matrix.RotationY(halfSapce), this._subCamTransformMatrix);
+            BABYLON.Matrix.Translation(-target.x, -target.y, -target.z).multiplyToRef(BABYLON.Matrix.RotationY(halfSpace), this._subCamTransformMatrix);
 
             this._subCamTransformMatrix = this._subCamTransformMatrix.multiply(BABYLON.Matrix.Translation(target.x, target.y, target.z));
 

+ 1 - 0
Babylon/Cameras/babylon.touchCamera.js

@@ -109,6 +109,7 @@ var BABYLON;
                 BABYLON.Matrix.RotationYawPitchRollToRef(this.rotation.y, this.rotation.x, 0, this._cameraRotationMatrix);
                 this.cameraDirection.addInPlace(BABYLON.Vector3.TransformCoordinates(direction, this._cameraRotationMatrix));
             }
+            _super.prototype._checkInputs.call(this);
         };
         return TouchCamera;
     })(BABYLON.FreeCamera);

+ 2 - 0
Babylon/Cameras/babylon.touchCamera.ts

@@ -132,6 +132,8 @@ module BABYLON {
                 BABYLON.Matrix.RotationYawPitchRollToRef(this.rotation.y, this.rotation.x, 0, this._cameraRotationMatrix);
                 this.cameraDirection.addInPlace(BABYLON.Vector3.TransformCoordinates(direction, this._cameraRotationMatrix));
             }
+
+            super._checkInputs();
         }
     }
 }

+ 1 - 0
Babylon/Cameras/babylon.virtualJoysticksCamera.js

@@ -33,6 +33,7 @@ var BABYLON;
             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();

+ 2 - 0
Babylon/Cameras/babylon.virtualJoysticksCamera.ts

@@ -29,6 +29,8 @@
             if (!this._rightjoystick.pressed) {
                 this._rightjoystick.deltaPosition = this._rightjoystick.deltaPosition.scale(0.9);
             }
+
+            super._checkInputs();
         }
 
         public dispose(): void {

+ 2 - 2
Babylon/Loading/Plugins/babylon.babylonFileLoader.js

@@ -352,10 +352,10 @@ var BABYLON;
                 camera = new BABYLON.VirtualJoysticksCamera(parsedCamera.name, position, scene);
             }
             else if (parsedCamera.type === "WebVRCamera") {
-                camera = new BABYLON.WebVRCamera(parsedCamera.name, position, scene);
+                camera = new BABYLON.WebVRFreeCamera(parsedCamera.name, position, scene);
             }
             else if (parsedCamera.type === "VRDeviceOrientationCamera") {
-                camera = new BABYLON.VRDeviceOrientationCamera(parsedCamera.name, position, scene);
+                camera = new BABYLON.VRDeviceOrientationFreeCamera(parsedCamera.name, position, scene);
             }
             else {
                 // Free Camera is the default value

+ 2 - 2
Babylon/Loading/Plugins/babylon.babylonFileLoader.ts

@@ -430,10 +430,10 @@
             camera = new VirtualJoysticksCamera(parsedCamera.name, position, scene);
 
         } else if (parsedCamera.type === "WebVRCamera") {
-            camera = new WebVRCamera(parsedCamera.name, position, scene);
+            camera = new WebVRFreeCamera(parsedCamera.name, position, scene);
 
         } else if (parsedCamera.type === "VRDeviceOrientationCamera") {
-            camera = new VRDeviceOrientationCamera(parsedCamera.name, position, scene);
+            camera = new VRDeviceOrientationFreeCamera(parsedCamera.name, position, scene);
 
         } else {
             // Free Camera is the default value

+ 1 - 0
Babylon/PostProcess/babylon.stereogramInterlacePostProcess.js

@@ -24,3 +24,4 @@ var BABYLON;
     })(BABYLON.PostProcess);
     BABYLON.StereogramInterlacePostProcess = StereogramInterlacePostProcess;
 })(BABYLON || (BABYLON = {}));
+//# sourceMappingURL=babylon.stereogramInterlacePostProcess.js.map

+ 5 - 5
Babylon/PostProcess/babylon.vrDistortionCorrectionPostProcess.js

@@ -9,18 +9,18 @@ var BABYLON;
     var VRDistortionCorrectionPostProcess = (function (_super) {
         __extends(VRDistortionCorrectionPostProcess, _super);
         //ANY
-        function VRDistortionCorrectionPostProcess(name, camera, isRightEye, cameraSettings) {
+        function VRDistortionCorrectionPostProcess(name, camera, isRightEye, vrMetrics) {
             var _this = this;
             _super.call(this, name, "vrDistortionCorrection", [
                 'LensCenter',
                 'Scale',
                 'ScaleIn',
                 'HmdWarpParam'
-            ], null, cameraSettings.PostProcessScaleFactor, camera, BABYLON.Texture.BILINEAR_SAMPLINGMODE, null, null);
+            ], null, vrMetrics.postProcessScaleFactor, camera, BABYLON.Texture.BILINEAR_SAMPLINGMODE, null, null);
             this._isRightEye = isRightEye;
-            this._distortionFactors = cameraSettings.DistortionK;
-            this._postProcessScaleFactor = cameraSettings.PostProcessScaleFactor;
-            this._lensCenterOffset = cameraSettings.LensCenterOffset;
+            this._distortionFactors = vrMetrics.distortionK;
+            this._postProcessScaleFactor = vrMetrics.postProcessScaleFactor;
+            this._lensCenterOffset = vrMetrics.lensCenterOffset;
             this.onSizeChanged = function () {
                 _this.aspectRatio = _this.width * .5 / _this.height;
                 _this._scaleIn = new BABYLON.Vector2(2, 2 / _this.aspectRatio);

+ 5 - 5
Babylon/PostProcess/babylon.vrDistortionCorrectionPostProcess.ts

@@ -11,18 +11,18 @@
         private _lensCenter: Vector2;
 
         //ANY
-        constructor(name: string, camera: Camera, isRightEye: boolean, cameraSettings: any) {
+        constructor(name: string, camera: Camera, isRightEye: boolean, vrMetrics: VRCameraMetrics) {
             super(name, "vrDistortionCorrection", [
                 'LensCenter',
                 'Scale',
                 'ScaleIn',
                 'HmdWarpParam'
-            ], null, cameraSettings.PostProcessScaleFactor, camera, BABYLON.Texture.BILINEAR_SAMPLINGMODE, null, null);
+            ], null, vrMetrics.postProcessScaleFactor, camera, BABYLON.Texture.BILINEAR_SAMPLINGMODE, null, null);
 
             this._isRightEye = isRightEye;
-            this._distortionFactors = cameraSettings.DistortionK;
-            this._postProcessScaleFactor = cameraSettings.PostProcessScaleFactor;
-            this._lensCenterOffset = cameraSettings.LensCenterOffset;
+            this._distortionFactors = vrMetrics.distortionK;
+            this._postProcessScaleFactor = vrMetrics.postProcessScaleFactor;
+            this._lensCenterOffset = vrMetrics.lensCenterOffset;
 
             this.onSizeChanged = () => {
                 this.aspectRatio = this.width * .5 / this.height;

+ 2 - 2
Babylon/Tools/babylon.sceneSerializer.js

@@ -97,10 +97,10 @@ var BABYLON;
         else if (camera instanceof BABYLON.VirtualJoysticksCamera) {
             serializationObject.type = "VirtualJoysticksCamera";
         }
-        else if (camera instanceof BABYLON.WebVRCamera) {
+        else if (camera instanceof BABYLON.WebVRFreeCamera) {
             serializationObject.type = "WebVRCamera";
         }
-        else if (camera instanceof BABYLON.VRDeviceOrientationCamera) {
+        else if (camera instanceof BABYLON.VRDeviceOrientationFreeCamera) {
             serializationObject.type = "VRDeviceOrientationCamera";
         }
         //special properties of specific cameras

+ 2 - 2
Babylon/Tools/babylon.sceneSerializer.ts

@@ -100,9 +100,9 @@
             serializationObject.type = "TouchCamera";
         } else if (camera instanceof VirtualJoysticksCamera) {
             serializationObject.type = "VirtualJoysticksCamera";
-        } else if (camera instanceof WebVRCamera) {
+        } else if (camera instanceof WebVRFreeCamera) {
             serializationObject.type = "WebVRCamera";
-        } else if (camera instanceof VRDeviceOrientationCamera) {
+        } else if (camera instanceof VRDeviceOrientationFreeCamera) {
             serializationObject.type = "VRDeviceOrientationCamera";
         } 
 

+ 1 - 2
Tools/Gulp/config.json

@@ -88,7 +88,7 @@
             "../../Babylon/PostProcess/babylon.convolutionPostProcess.js",
             "../../Babylon/PostProcess/babylon.filterPostProcess.js",
             "../../Babylon/PostProcess/babylon.fxaaPostProcess.js",
-            "../../Babylon/PostProcess/babylon.StereogramInterlacePostProcess.js",
+            "../../Babylon/PostProcess/babylon.stereogramInterlacePostProcess.js",
             "../../Babylon/LensFlare/babylon.lensFlare.js",
             "../../Babylon/LensFlare/babylon.lensFlareSystem.js",
             "../../Babylon/Physics/Plugins/babylon.cannonJSPlugin.js",
@@ -98,7 +98,6 @@
             "../../Babylon/Mesh/babylon.csg.js",
             "../../Babylon/PostProcess/babylon.vrDistortionCorrectionPostProcess.js",
             "../../Babylon/Tools/babylon.virtualJoystick.js",
-            "../../Babylon/Cameras/VR/babylon.vrCamera.js",
             "../../Babylon/Cameras/babylon.virtualJoysticksCamera.js",
             "../../Babylon/Materials/babylon.shaderMaterial.js",
             "../../Babylon/Mesh/babylon.mesh.vertexData.js",

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 406 - 239
babylon.2.1-beta.debug.js


A diferenza do arquivo foi suprimida porque é demasiado grande
+ 27 - 22
babylon.2.1-beta.js


A diferenza do arquivo foi suprimida porque é demasiado grande
+ 28 - 23
babylon.2.1-beta.noworker.js


+ 110 - 73
babylon.2.1.d.ts

@@ -1482,23 +1482,11 @@ declare module BABYLON {
     }
 }
 declare module BABYLON {
-    class AnaglyphArcRotateCamera extends ArcRotateCamera {
-        private _eyeSpace;
-        private _leftCamera;
-        private _rightCamera;
-        constructor(name: string, alpha: number, beta: number, radius: number, target: any, eyeSpace: number, scene: any);
-        _update(): void;
-        _updateCamera(camera: ArcRotateCamera): void;
-    }
     class AnaglyphFreeCamera extends FreeCamera {
-        private _eyeSpace;
-        private _leftCamera;
-        private _rightCamera;
-        private _transformMatrix;
         constructor(name: string, position: Vector3, eyeSpace: number, scene: Scene);
-        _getSubCameraPosition(eyeSpace: any, result: any): void;
-        _update(): void;
-        _updateCamera(camera: FreeCamera): void;
+    }
+    class AnaglyphArcRotateCamera extends ArcRotateCamera {
+        constructor(name: string, alpha: number, beta: number, radius: number, target: any, eyeSpace: number, scene: any);
     }
 }
 declare module BABYLON {
@@ -1559,25 +1547,71 @@ declare module BABYLON {
         _isSynchronizedViewMatrix(): boolean;
         attachControl(element: HTMLElement, noPreventDefault?: boolean): void;
         detachControl(element: HTMLElement): void;
-        _update(): void;
+        _checkInputs(): void;
         setPosition(position: Vector3): void;
         _getViewMatrix(): Matrix;
         private _onCollisionPositionChange;
         zoomOn(meshes?: AbstractMesh[]): void;
         focusOn(meshesOrMinMaxVectorAndDistance: any): void;
+        /**
+         * @override
+         * needs to be overridden, so sub has required properties to be copied
+         */
+        getSubCamera(name: string, isA: boolean): Camera;
+        /**
+         * @override
+         * needs to be overridden, adding copy of alpha, beta & radius
+         */
+        _updateSubCameras(): void;
     }
 }
 declare module BABYLON {
+    class VRCameraMetrics {
+        hResolution: number;
+        vResolution: number;
+        hScreenSize: number;
+        vScreenSize: number;
+        vScreenCenter: number;
+        eyeToScreenDistance: number;
+        lensSeparationDistance: number;
+        interpupillaryDistance: number;
+        distortionK: number[];
+        chromaAbCorrection: number[];
+        postProcessScaleFactor: number;
+        lensCenterOffset: number;
+        compensateDistorsion: boolean;
+        aspectRatio: number;
+        aspectRatioFov: number;
+        leftHMatrix: Matrix;
+        rightHMatrix: Matrix;
+        leftPreViewMatrix: Matrix;
+        rightPreViewMatrix: Matrix;
+        static GetDefault(): VRCameraMetrics;
+    }
     class Camera extends Node {
         position: Vector3;
         private static _PERSPECTIVE_CAMERA;
         private static _ORTHOGRAPHIC_CAMERA;
         private static _FOVMODE_VERTICAL_FIXED;
         private static _FOVMODE_HORIZONTAL_FIXED;
+        private static _SUB_CAMERA_MODE_NONE;
+        private static _SUB_CAMERA_MODE_ANAGLYPH;
+        private static _SUB_CAMERA_MODE_HORIZONTAL_STEREOGRAM;
+        private static _SUB_CAMERA_MODE_VERTICAL_STEREOGRAM;
+        private static _SUB_CAMERA_MODE_VR;
+        private static _SUB_CAMERAID_A;
+        private static _SUB_CAMERAID_B;
         static PERSPECTIVE_CAMERA: number;
         static ORTHOGRAPHIC_CAMERA: number;
         static FOVMODE_VERTICAL_FIXED: number;
         static FOVMODE_HORIZONTAL_FIXED: number;
+        static SUB_CAMERA_MODE_NONE: number;
+        static SUB_CAMERA_MODE_ANAGLYPH: number;
+        static SUB_CAMERA_MODE_HORIZONTAL_STEREOGRAM: number;
+        static SUB_CAMERA_MODE_VERTICAL_STEREOGRAM: number;
+        static SUB_CAMERA_MODE_VR: number;
+        static SUB_CAMERAID_A: number;
+        static SUB_CAMERAID_B: number;
         upVector: Vector3;
         orthoLeft: any;
         orthoRight: any;
@@ -1590,9 +1624,16 @@ declare module BABYLON {
         mode: number;
         isIntermediate: boolean;
         viewport: Viewport;
-        subCameras: any[];
         layerMask: number;
         fovMode: number;
+        subCameras: Camera[];
+        _subCameraMode: number;
+        _subCamHalfSpace: number;
+        private _vrMetrics;
+        private _vrHMatrix;
+        _vrPreViewMatrix: Matrix;
+        _vrWorkMatrix: Matrix;
+        _vrActualUp: Vector3;
         private _computedViewMatrix;
         _projectionMatrix: Matrix;
         private _worldMatrix;
@@ -1613,6 +1654,7 @@ declare module BABYLON {
         attachControl(element: HTMLElement): void;
         detachControl(element: HTMLElement): void;
         _update(): void;
+        _checkInputs(): void;
         attachPostProcess(postProcess: PostProcess, insertAt?: number): number;
         detachPostProcess(postProcess: PostProcess, atIndices?: any): number[];
         getWorldMatrix(): Matrix;
@@ -1621,6 +1663,17 @@ declare module BABYLON {
         _computeViewMatrix(force?: boolean): Matrix;
         getProjectionMatrix(force?: boolean): Matrix;
         dispose(): void;
+        setSubCameraMode(mode: number, halfSpace?: number, metrics?: VRCameraMetrics): void;
+        private _getVRProjectionMatrix();
+        setSubCamHalfSapce(halfSapce: number): void;
+        /**
+         * May needs to be overridden by children so sub has required properties to be copied
+         */
+        getSubCamera(name: string, isA: boolean): Camera;
+        /**
+         * May needs to be overridden by children
+         */
+        _updateSubCameras(): void;
     }
 }
 declare module BABYLON {
@@ -1652,7 +1705,7 @@ declare module BABYLON {
         constructor(name: string, position: Vector3, scene: Scene);
         private getRadians(degrees);
         private follow(cameraTarget);
-        _update(): void;
+        _checkInputs(): void;
     }
 }
 declare module BABYLON {
@@ -1691,7 +1744,6 @@ declare module BABYLON {
         _checkInputs(): void;
         _decideIfNeedsToMove(): boolean;
         _updatePosition(): void;
-        _update(): void;
     }
 }
 declare module BABYLON {
@@ -1719,6 +1771,7 @@ declare module BABYLON {
         _camMatrix: Matrix;
         _cameraTransformMatrix: Matrix;
         _cameraRotationMatrix: Matrix;
+        private _subCamTransformMatrix;
         _referencePoint: Vector3;
         _transformedReferencePoint: Vector3;
         _lookAtTemp: Matrix;
@@ -1735,8 +1788,20 @@ declare module BABYLON {
         getTarget(): Vector3;
         _decideIfNeedsToMove(): boolean;
         _updatePosition(): void;
-        _update(): void;
+        _checkInputs(): void;
         _getViewMatrix(): Matrix;
+        _getVRViewMatrix(): Matrix;
+        /**
+         * @override
+         * needs to be overridden, so sub has required properties to be copied
+         */
+        getSubCamera(name: string, isA: boolean): Camera;
+        /**
+         * @override
+         * needs to be overridden, adding copy of position, and rotation for VR, or target for rest
+         */
+        _updateSubCameras(): void;
+        private _getSubCamPosition(halfSpace, result);
     }
 }
 declare module BABYLON {
@@ -1767,67 +1832,22 @@ declare module BABYLON {
     }
 }
 declare module BABYLON {
-    class OculusCamera extends FreeCamera {
-        private _leftCamera;
-        private _rightCamera;
-        private _offsetOrientation;
-        private _deviceOrientationHandler;
-        constructor(name: string, position: Vector3, scene: Scene);
-        _update(): void;
-        _updateCamera(camera: FreeCamera): void;
-        _onOrientationEvent(evt: DeviceOrientationEvent): void;
-        attachControl(element: HTMLElement, noPreventDefault?: boolean): void;
-        detachControl(element: HTMLElement): void;
-    }
-}
-declare module BABYLON {
-    class OculusGamepadCamera extends FreeCamera {
-        private _leftCamera;
-        private _rightCamera;
-        private _offsetOrientation;
-        private _deviceOrientationHandler;
-        private _gamepad;
-        private _gamepads;
-        angularSensibility: number;
-        moveSensibility: number;
-        constructor(name: string, position: Vector3, scene: Scene);
-        private _onNewGameConnected(gamepad);
-        _update(): void;
-        _checkInputs(): void;
-        _updateCamera(camera: FreeCamera): void;
-        _onOrientationEvent(evt: DeviceOrientationEvent): void;
-        attachControl(element: HTMLElement, noPreventDefault?: boolean): void;
-        detachControl(element: HTMLElement): void;
-        dispose(): void;
-    }
-}
-declare module BABYLON {
-    class VRCamera extends FreeCamera {
-        private _leftCamera;
-        private _rightCamera;
+    class VRDeviceOrientationFreeCamera extends BABYLON.FreeCamera {
+        _alpha: number;
+        _beta: number;
+        _gamma: number;
         private _offsetOrientation;
         private _deviceOrientationHandler;
         constructor(name: string, position: Vector3, scene: Scene);
-        _update(): void;
-        _updateCamera(camera: FreeCamera): void;
         _onOrientationEvent(evt: DeviceOrientationEvent): void;
         attachControl(element: HTMLElement, noPreventDefault?: boolean): void;
         detachControl(element: HTMLElement): void;
     }
 }
-declare module BABYLON {
-    class VRDeviceOrientationCamera extends BABYLON.VRCamera {
-        _alpha: number;
-        _beta: number;
-        _gamma: number;
-        constructor(name: string, position: Vector3, scene: Scene);
-        _onOrientationEvent(evt: DeviceOrientationEvent): void;
-    }
-}
 declare var HMDVRDevice: any;
 declare var PositionSensorVRDevice: any;
 declare module BABYLON {
-    class WebVRCamera extends BABYLON.VRCamera {
+    class WebVRFreeCamera extends FreeCamera {
         _hmdDevice: any;
         _sensorDevice: any;
         _cacheState: any;
@@ -1836,7 +1856,7 @@ declare module BABYLON {
         _vrEnabled: boolean;
         constructor(name: string, position: Vector3, scene: Scene);
         private _getWebVRDevices(devices);
-        _update(): void;
+        _checkInputs(): void;
         attachControl(element: HTMLElement, noPreventDefault?: boolean): void;
         detachControl(element: HTMLElement): void;
     }
@@ -3076,6 +3096,7 @@ declare module BABYLON {
         scaleInPlace(scale: number): Vector2;
         scale(scale: number): Vector2;
         equals(otherVector: Vector2): boolean;
+        equalsWithEpsilon(otherVector: Vector2): boolean;
         length(): number;
         lengthSquared(): number;
         normalize(): Vector2;
@@ -3165,6 +3186,12 @@ declare module BABYLON {
         static Distance(value1: Vector3, value2: Vector3): number;
         static DistanceSquared(value1: Vector3, value2: Vector3): number;
         static Center(value1: Vector3, value2: Vector3): Vector3;
+        /**
+         * Given three orthogonal left-handed oriented Vector3 axis in space (target system),
+         * RotationFromAxis() returns the rotation Euler angles (ex : rotation.x, rotation.y, rotation.z) to apply
+         * to something in order to rotate it from its local system to the given target system.
+         */
+        static RotationFromAxis(axis1: Vector3, axis2: Vector3, axis3: Vector3): Vector3;
     }
     class Vector4 {
         x: number;
@@ -3673,6 +3700,7 @@ declare module BABYLON {
         matrix: Matrix;
         position: Vector3;
         rotation: Vector3;
+        rotationQuaternion: Quaternion;
         scaling: Vector3;
         static FromMesh(mesh: Mesh): CSG;
         private static FromPolygons(polygons);
@@ -4283,12 +4311,15 @@ declare module BABYLON {
     class PolygonMeshBuilder {
         private _swctx;
         private _points;
+        private _outlinepoints;
+        private _holes;
         private _name;
         private _scene;
         constructor(name: string, contours: Path2, scene: Scene);
         constructor(name: string, contours: Vector2[], scene: Scene);
         addHole(hole: Vector2[]): PolygonMeshBuilder;
-        build(updatable?: boolean): Mesh;
+        build(updatable?: boolean, depth?: number): Mesh;
+        private addSide(positions, normals, uvs, indices, bounds, points, depth, flip);
     }
 }
 declare module BABYLON {
@@ -4851,6 +4882,12 @@ declare module BABYLON {
     }
 }
 declare module BABYLON {
+    class StereogramInterlacePostProcess extends PostProcess {
+        private _stepSize;
+        constructor(name: string, camB: Camera, postProcessA: PostProcess, isStereogramHoriz: boolean, samplingMode?: number);
+    }
+}
+declare module BABYLON {
     class VolumetricLightScatteringPostProcess extends PostProcess {
         private _volumetricLightScatteringPass;
         private _volumetricLightScatteringRTT;
@@ -4935,7 +4972,7 @@ declare module BABYLON {
         private _scaleIn;
         private _scaleFactor;
         private _lensCenter;
-        constructor(name: string, camera: Camera, isRightEye: boolean, cameraSettings: any);
+        constructor(name: string, camera: Camera, isRightEye: boolean, vrMetrics: VRCameraMetrics);
     }
 }
 declare module BABYLON {

+ 3 - 1
what's new - 2.1 - proposal.md

@@ -55,4 +55,6 @@
  - delta in BoundingBox's intersectsPoint is now calculated correctly ([raananw](http://www.github.com/raananw)) 
  - textures cache fixed ([deltakosh](http://www.github.com/deltakosh))
  - **Breaking changes**
- - OculusCamera was renamed to VRCamera ([deltakosh](http://www.github.com/deltakosh))
+ - OculusCamera was removed ([deltakosh](http://www.github.com/deltakosh))
+ - VRDeviceOrientationCamera was renamed to VRDeviceOrientationFreeCamera ([deltakosh](http://www.github.com/deltakosh))
+ - WebVRCamera was renamed to WebVRFreeCamera ([deltakosh](http://www.github.com/deltakosh))