Преглед изворни кода

Merge remote-tracking branch 'remotes/BabylonJS/master' into ourOwnBabylonJS

Gwenaël Hagenmuller пре 11 година
родитељ
комит
4c273e50f0

+ 24 - 0
Babylon/Cameras/Controllers/babylon.globalAxisFactorsFilter.js

@@ -0,0 +1,24 @@
+"use strict";
+
+var BABYLON = BABYLON || {};
+
+(function () {
+	BABYLON.globalAxisFactorsFilter = function (scene, target, xFactor, yFactor, zFactor) {
+		BABYLON.inputFilter.call(this, scene,target);
+		this.xFactor = xFactor;
+		this.yFactor = yFactor;
+		this.zFactor = zFactor;
+
+		this._globalMovement = new BABYLON.Vector3(0, 0, 0);
+	};
+	BABYLON.globalAxisFactorsFilter.prototype = Object.create(BABYLON.inputFilter.prototype);
+	BABYLON.globalAxisFactorsFilter.prototype.moveRelative = function (relativeMovement) {
+		var orientation = this.getOrientation();
+		BABYLON.Vector3.TransformNormalToRef(relativeMovement, this.getOrientationMatrix(), this._globalMovement);
+		this._globalMovement.x *= this.xFactor;
+		this._globalMovement.y *= this.yFactor;
+		this._globalMovement.z *= this.zFactor;
+		BABYLON.Vector3.TransformNormalToRef(this._globalMovement, this.getInvertOrientationMatrix(), relativeMovement);
+		this.target.moveRelative(relativeMovement);
+	};
+})();

+ 20 - 0
Babylon/Cameras/Controllers/babylon.gravityInputController.js

@@ -0,0 +1,20 @@
+"use strict";
+
+var BABYLON = BABYLON || {};
+
+(function () {
+    BABYLON.GravityInputController = function (scene, target) {
+        BABYLON.inputController.call(this, scene, target);
+        this._moveVectorGlobal = new BABYLON.Vector3(0, 0, 0);
+        this._moveVectorLocal = new BABYLON.Vector3(0, 0, 0);
+        this._fallSpeed = .6;
+    };
+    BABYLON.GravityInputController.prototype = Object.create(BABYLON.inputController.prototype);
+    BABYLON.GravityInputController.prototype.update = function () {
+        this._moveVectorGlobal.x = 0;
+        this._moveVectorGlobal.y = -this._fallSpeed * BABYLON.Tools.GetDeltaTime() / 1000.0;
+        this._moveVectorGlobal.z = 0;
+        BABYLON.Vector3.TransformNormalToRef(this._moveVectorGlobal, this.target.getInvertOrientationMatrix(), this._moveVectorLocal);
+        this.target.moveRelative(this._moveVectorLocal);
+    };
+})();

+ 41 - 0
Babylon/Cameras/Controllers/babylon.inputCollisionFilter.js

@@ -0,0 +1,41 @@
+"use strict";
+
+var BABYLON = BABYLON || {};
+
+(function () {
+	BABYLON.inputCollisionFilter = function (scene, target, ellipsoid) {
+		BABYLON.inputFilter.call(this, scene, target);
+		this._transformedDirection = new BABYLON.Vector3();
+		this._tempNewPosition = new BABYLON.Vector3();
+		this._tempNewPosition2 = new BABYLON.Vector3();
+		this._ellipsoid = ellipsoid || new BABYLON.Vector3(.5,.5,.5);
+		this._collider = new BABYLON.Collider();
+		this._collidedPosition = new BABYLON.Vector3(0, 0, 0);
+		this._cameraHeight = 1.7;
+		this._positionBottom = new BABYLON.Vector3(0, 0, 0);
+	};
+	BABYLON.inputCollisionFilter.prototype = Object.create(BABYLON.inputFilter.prototype);
+	BABYLON.inputCollisionFilter.prototype.moveRelative = function (relativeMovement) {
+		var rotation = this.getOrientation();
+		BABYLON.Vector3.TransformNormalToRef(relativeMovement, this.getOrientationMatrix(), this._transformedDirection);
+		this.getPosition().addToRef(this._transformedDirection, this._tempNewPosition);
+		//this._tempNewPosition.y -= this._ellipsoid.y;
+		this._collider.radius = this._ellipsoid;
+		var p = this.getPosition();
+		this._positionBottom.x = p.x;
+		this._positionBottom.y = p.y;
+		this._positionBottom.z = p.z;
+		this._positionBottom.y +=  this._ellipsoid.y - this._cameraHeight;
+
+		this.scene._getNewPosition(this._positionBottom, this._transformedDirection, this._collider, 3, this._collidedPosition);
+
+
+		this._collidedPosition.subtractToRef(this._positionBottom, this._tempNewPosition2);
+		if (this._tempNewPosition2.length() > BABYLON.Engine.collisionsEpsilon * 5) {
+
+		    BABYLON.Vector3.TransformNormalToRef(this._tempNewPosition2, this.getInvertOrientationMatrix(), this._tempNewPosition);
+		    this.target.moveRelative(this._tempNewPosition);
+		} 
+
+	};
+})();

+ 34 - 0
Babylon/Cameras/Controllers/babylon.inputController.js

@@ -22,6 +22,8 @@ var BABYLON = BABYLON || {};
 	BABYLON.inputControllerTarget.prototype.rotateRelative = function (relativeOrientation) {
 
 	};
+	BABYLON.inputControllerTarget.prototype.getOrientationMatrix = function () { return new BABYLON.Matrix(); };
+	BABYLON.inputControllerTarget.prototype.getInvertOrientationMatrix = function () { return new BABYLON.Matrix(); };
 
 	BABYLON.inputControllerMultiTarget = function (targets) {
 	    this.targets = targets;
@@ -39,6 +41,11 @@ var BABYLON = BABYLON || {};
 	BABYLON.inputControllerMultiTarget.prototype.getOrientation = function () {
 		return this.targets[0].getOrientation();
 	};
+
+
+	BABYLON.inputControllerMultiTarget.prototype.getOrientationMatrix = function () { return this.targets[0].getOrientationMatrix(); };
+	BABYLON.inputControllerMultiTarget.prototype.getInvertOrientationMatrix = function () { return this.targets[0].getInvertOrientationMatrix(); };
+
 	BABYLON.inputControllerMultiTarget.prototype.moveRelative = function (movementVector) {
 		for (var i = 0; i < this.targets.length; ++i) {
 			this.targets[i].moveRelative(movementVector);
@@ -82,4 +89,31 @@ var BABYLON = BABYLON || {};
 
 	};
 
+	BABYLON.inputFilter = function (scene, target) {
+	    BABYLON.inputController.call(this, scene, target);
+	};
+	BABYLON.inputFilter.prototype = Object.create(BABYLON.inputController.prototype);
+	BABYLON.inputFilter.prototype.update = function () {
+	    if (this.controllers) {
+	        for (var i = 0; i < this.controllers.length; ++i) {
+	            this.controllers[i].update();
+	        }
+	    }
+	};
+
+	BABYLON.inputFilter.prototype.getPosition = function () {
+	    return this.target.getPosition();
+	};
+	BABYLON.inputFilter.prototype.getOrientation = function () {
+	    return this.target.getOrientation();
+	};
+	BABYLON.inputFilter.prototype.getOrientationMatrix = function () { return this.target.getOrientationMatrix(); };
+	BABYLON.inputFilter.prototype.getInvertOrientationMatrix = function () { return this.target.getInvertOrientationMatrix(); };
+	BABYLON.inputFilter.prototype.moveRelative = function (movementVector) {
+	    this.target.moveRelative(movementVector);
+	};
+
+	BABYLON.inputFilter.prototype.rotateRelative = function (relativeOrientation) {
+	    this.target.rotateRelative(relativeOrientation);
+	};
 })();

+ 39 - 136
Babylon/Cameras/Controllers/babylon.oculusController.js

@@ -3,148 +3,51 @@
 var BABYLON = BABYLON || {};
 
 (function () {
-    BABYLON.OculusOrientedCamera = function (name, position, scene, isLeftEye, ovrSettings, neutralOrientation) {
-        BABYLON.Camera.call(this, name, position, scene);
-        this._referenceDirection = new BABYLON.Vector3(0, 0, 1);
-        this._referenceUp = new BABYLON.Vector3(0, 1, 0);
-        this._actualDirection = new BABYLON.Vector3(1, 0, 0);
-        this._actualUp = new BABYLON.Vector3(0, 1, 0);
-        this._currentTargetPoint = new BABYLON.Vector3(0, 0, 0);
-        this._currentOrientation = neutralOrientation || { yaw: 0.0, pitch: 0.0, roll: 0.0 };
-        this._currentViewMatrix = new BABYLON.Matrix();
-        this._currentOrientationMatrix = new BABYLON.Matrix();
-        this._tempMatrix = new BABYLON.Matrix();
-        if (isLeftEye) {
-            this.viewport = new BABYLON.Viewport(0, 0, 0.5, 1.0);
-        } else {
-            this.viewport = new BABYLON.Viewport(0.5, 0, 0.5, 1.0);
-        }
-
-        this._aspectRatioAspectRatio = ovrSettings.HResolution / (2 * ovrSettings.VResolution);
-        this._aspectRatioFov = (2 * Math.atan((ovrSettings.PostProcessScaleFactor * ovrSettings.VScreenSize) / (2 * ovrSettings.EyeToScreenDistance)));
-        var hMeters = (ovrSettings.HScreenSize / 4) - (ovrSettings.LensSeparationDistance / 2);
-        var h = (4 * hMeters) / ovrSettings.HScreenSize;
-        this._hMatrix = BABYLON.Matrix.Translation(isLeftEye ? h : -h, 0, 0);
-
-        this._projectionMatrix = new BABYLON.Matrix();
-        this._preViewMatrix = BABYLON.Matrix.Translation(isLeftEye ? .5 * ovrSettings.InterpupillaryDistance : -.5 * ovrSettings.InterpupillaryDistance, 0, 0);
-        new BABYLON.oculusDistortionCorrectionPostProcess("Oculus Distortion", this, !isLeftEye, ovrSettings);
-        this.resetProjectionMatrix();
-        this.resetViewMatrix();
-    };
-    
-    BABYLON.OculusOrientedCamera.buildOculusStereoCamera = function (scene, name, canvas, minZ, maxZ, position, neutralOrientation, useFXAA, ovrSettings) {
-        position = position || new BABYLON.Vector2(0, 0);
-        neutralOrientation = neutralOrientation || { yaw: 0.0, pitch: 0.0, roll: 0.0 };
-        //var controller =  new BABYLON.OculusController();
-        ovrSettings = ovrSettings || BABYLON.OculusController.CameraSettings_OculusRiftDevKit2013_Metric;
-
-        var leftCamera = new BABYLON.OculusOrientedCamera(name + "_left", position, scene, true, ovrSettings, neutralOrientation);
-        leftCamera.minZ = minZ;
-        leftCamera.maxZ = maxZ;
-        if (useFXAA) {
-            new BABYLON.FxaaPostProcess("fxaa_left", 1.0, leftCamera);
-        }
-
-        var rightCamera = new BABYLON.OculusOrientedCamera(name + "_right", position, scene, false, ovrSettings, neutralOrientation);
-        rightCamera.minZ = minZ;
-        rightCamera.maxZ = maxZ;
-        if (useFXAA) {
-            new BABYLON.FxaaPostProcess("fxaa_right", 1.0, rightCamera);
-        }
-        scene.activeCameras = [];
-        scene.activeCameras.push(leftCamera);
-        scene.activeCameras.push(rightCamera);
-        leftCamera.attachControl(canvas);
-        rightCamera.attachControl(canvas);
-        var multiTarget = new BABYLON.inputControllerMultiTarget([leftCamera, rightCamera]);
-        var controller = new BABYLON.OculusController(scene, multiTarget);
-        var moveController = new BABYLON.keyboardMoveController(scene, multiTarget);
-        moveController.attachToCanvas(canvas);
-        var result = {
-            leftCamera: leftCamera, rightCamera: rightCamera, intermediateControllerTarget: multiTarget,
-            oculusController: controller,
-            keyboardController: moveController
-        };
-        result.dispose = function () {
-            this.leftCamera.detachControl(canvas);
-            this.rightCamera.detachControl(canvas);
-            this.leftCamera.dispose();
-            this.rightCamera.dispose();
-            this.oculusController.dispose();
-            this.keyboardController.detachFromCanvas(canvas);
-            this.keyboardController.dispose();
-        }.bind(result);
-        return result;
+    BABYLON.OculusController = function (scene, target) {
+        BABYLON.inputController.call(this, scene, target);
+        this._deviceOrientationHandler = this.onOrientationEvent.bind(this);
+        this._tempOrientation = { yaw: 0.0, pitch: 0.0, roll: 0.0 };
+        this._relativeOrientation = { yaw: 0.0, pitch: 0.0, roll: 0.0 };
+        window.addEventListener("deviceorientation", this._deviceOrientationHandler);
     };
-    
-    BABYLON.OculusOrientedCamera.prototype = Object.create(BABYLON.Camera.prototype);
-
-    BABYLON.OculusOrientedCamera.prototype.resetViewMatrix = function () {
-        BABYLON.Matrix.RotationYawPitchRollToRef(
-            this._currentOrientation.yaw,
-            this._currentOrientation.pitch,
-            -this._currentOrientation.roll
-            , this._currentOrientationMatrix);
-
-        BABYLON.Vector3.TransformCoordinatesToRef(this._referenceDirection, this._currentOrientationMatrix, this._actualDirection);
-        BABYLON.Vector3.TransformCoordinatesToRef(this._referenceUp, this._currentOrientationMatrix, this._actualUp);
 
-        BABYLON.Vector3.FromFloatsToRef(this.position.x + this._actualDirection.x, this.position.y + this._actualDirection.y, this.position.z + this._actualDirection.z, this._currentTargetPoint);
-        BABYLON.Matrix.LookAtLHToRef(this.position, this._currentTargetPoint, this._actualUp, this._tempMatrix);
-        this._tempMatrix.multiplyToRef(this._preViewMatrix, this._currentViewMatrix);
-        return this._currentViewMatrix;
-    };
-    BABYLON.OculusOrientedCamera.prototype.getViewMatrix = function () {
+    BABYLON.OculusController.prototype = Object.create(BABYLON.inputController.prototype);
 
-        return this._currentViewMatrix;
-    };
+    BABYLON.OculusController.prototype.onOrientationEvent = function (ev) {
+        this._tempOrientation.yaw = ev.alpha / 180 * Math.PI;
+        this._tempOrientation.pitch = ev.beta / 180 * Math.PI;
+        this._tempOrientation.roll = ev.gamma / 180 * Math.PI;
 
-    BABYLON.OculusOrientedCamera.prototype._update = function () {
-        //if (!this._referenceOculusOrientation) {
-        //    this._referenceOculusOrientation = { yaw: this._controller._currentOrientation.yaw, pitch: this._controller._currentOrientation.pitch, roll: this._controller._currentOrientation.roll };
-        //}
-        //else {
-        //    this._currentOrientation.yaw = this._controller._currentOrientation.yaw - this._referenceOculusOrientation.yaw;
-        //    this._currentOrientation.pitch = this._controller._currentOrientation.pitch - this._referenceOculusOrientation.pitch;
-        //    this._currentOrientation.roll = this._controller._currentOrientation.roll - this._referenceOculusOrientation.roll;
-        //}
-        if (this.controllers) {
-            for (var i = 0; i < this.controllers.length; ++i) {
-                this.controllers[i].update();
-            }
+        if (!this._lastOrientation) {
+            this._lastOrientation = Object.create(this._tempOrientation);
         }
-    };
-
-    BABYLON.OculusOrientedCamera.prototype.resetProjectionMatrix = function () {
-        BABYLON.Matrix.PerspectiveFovLHToRef(this._aspectRatioFov, this._aspectRatioAspectRatio, this.minZ, this.maxZ, this._tempMatrix);
-        this._tempMatrix.multiplyToRef(this._hMatrix, this._projectionMatrix);
-        return this._projectionMatrix;
-    };
-
-    BABYLON.OculusOrientedCamera.prototype.getProjectionMatrix = function (force) {
-        return this._projectionMatrix;
-    };
-
-    // implementation of inputControllerTarget
-    BABYLON.OculusOrientedCamera.prototype.getOrientation = function () {
-        return this._currentOrientation;
-    };
-    BABYLON.OculusOrientedCamera.prototype.getPosition = function () {
-        return this.position;
-    };
-    BABYLON.OculusOrientedCamera.prototype.moveRelative = function (movementVector) {
-        if (!this._tempMoveVector) {
-            this._tempMoveVector = new BABYLON.Vector3(0, 0, 0);
+        else {
+            this._relativeOrientation.yaw = this._tempOrientation.yaw - this._lastOrientation.yaw;
+            this._relativeOrientation.pitch = this._tempOrientation.pitch - this._lastOrientation.pitch;
+            this._relativeOrientation.roll = this._tempOrientation.roll - this._lastOrientation.roll;
+
+            var temp = this._tempOrientation;
+            this._tempOrientation = this._lastOrientation;
+            this._lastOrientation = temp;
+            this.target.rotateRelative(this._relativeOrientation);
         }
-        BABYLON.Vector3.TransformCoordinatesToRef(movementVector, this._currentOrientationMatrix, this._tempMoveVector);
-        this.position.addInPlace(this._tempMoveVector);
-        this.resetViewMatrix();
     };
-    BABYLON.OculusOrientedCamera.prototype.rotateRelative = function (rotation) {
-        this._currentOrientation.yaw += rotation.yaw;
-        this._currentOrientation.pitch += rotation.pitch;
-        this._currentOrientation.roll += rotation.roll;
-        this.resetViewMatrix();
+    BABYLON.OculusController.prototype.dispose = function () {
+        window.removeEventListener("deviceorientation", this._deviceOrientationHandler);
+    };
+
+    BABYLON.OculusController.CameraSettings_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
     };
 })();

+ 0 - 134
Babylon/Cameras/babylon.oculusCamera.js

@@ -1,134 +0,0 @@
-"use strict";
-
-var BABYLON = BABYLON || {};
-
-(function () {
-    BABYLON.OculusController = function () {
-        this._currentOrientation = { yaw: 0, pitch: 0, roll: 0 };
-        this._deviceOrientationHandler = this.onOrientationEvent.bind(this);
-        window.addEventListener("deviceorientation", this._deviceOrientationHandler);
-    };
-
-    BABYLON.OculusController.prototype.onOrientationEvent = function (ev) {
-        var yaw = ev.alpha / 180 * Math.PI;
-        if(!this._referenceYaw){
-            this._referenceYaw= yaw;
-        }
-        this._currentOrientation.yaw = yaw - this._referenceYaw;
-        this._currentOrientation.pitch = ev.beta / 180 * Math.PI;
-        this._currentOrientation.roll = ev.gamma / 180 * Math.PI;
-    };
-    BABYLON.OculusController.prototype.dispose = function () {
-        window.removeEventListener("deviceorientation", this._deviceOrientationHandler);
-    };
-
-    BABYLON.OculusController.prototype.getCurrentOrientation = function () {
-        return this._currentOrientation;
-    };
-
-    BABYLON.OculusController.CameraSettings_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
-    };
-
-    BABYLON.OculusOrientedCamera = function (name, position, scene, controller, isLeftEye, ovrSettings, neutralOrientation) {
-        BABYLON.Camera.call(this, name, position, scene);
-        this._controller = controller;
-        this._referenceDirection = new BABYLON.Vector3(0, 0, 1);
-        this._referenceUp = new BABYLON.Vector3(0, 1, 0);
-        this._actualDirection = new BABYLON.Vector3(1, 0, 0);
-        this._actualUp = new BABYLON.Vector3(0, 1, 0);
-        this._currentTargetPoint = new BABYLON.Vector3(0, 0, 0);
-        this._currentOculusOrientation = { yaw: 0.0, pitch: 0.0, roll: 0.0 };
-        this._currentViewMatrix = new BABYLON.Matrix();
-        this._currentOculusOrientationMatrix = new BABYLON.Matrix();
-        this._tempMatrix = new BABYLON.Matrix();
-        neutralOrientation = neutralOrientation || { yaw: 0.0, pitch: 0.0, roll: 0.0 };
-        this._neutralOrientation = neutralOrientation;
-        if (isLeftEye) {
-            this.viewport = new BABYLON.Viewport(0, 0, 0.5, 1.0);
-        } else {
-            this.viewport = new BABYLON.Viewport(0.5, 0, 0.5, 1.0);
-        }
-
-        this._aspectRatioAspectRatio = ovrSettings.HResolution / (2 * ovrSettings.VResolution);
-        this._aspectRatioFov = (2 * Math.atan((ovrSettings.PostProcessScaleFactor * ovrSettings.VScreenSize) / (2 * ovrSettings.EyeToScreenDistance))) ;
-        var hMeters = (ovrSettings.HScreenSize / 4) - (ovrSettings.LensSeparationDistance / 2);
-        var h = (4 * hMeters) / ovrSettings.HScreenSize;
-        this._hMatrix = BABYLON.Matrix.Translation(isLeftEye ? h : -h, 0, 0);
-
-        this._projectionMatrix = new BABYLON.Matrix();
-        this._preViewMatrix = BABYLON.Matrix.Translation(isLeftEye ? .5 * ovrSettings.InterpupillaryDistance : -.5 * ovrSettings.InterpupillaryDistance, 0, 0);
-        new BABYLON.oculusDistortionCorrectionPostProcess("Oculus Distortion", this, !isLeftEye, ovrSettings);
-    };
-    BABYLON.OculusOrientedCamera.buildOculusStereoCamera = function (scene, name, canvas, minZ, maxZ, position, neutralOrientation, useFXAA, controller, ovrSettings) {
-        position = position || new BABYLON.Vector2(0, 0);
-        neutralOrientation = neutralOrientation || { yaw: 0.0, pitch: 0.0, roll: 0.0 };
-        controller = controller || new BABYLON.OculusController();
-        ovrSettings = ovrSettings || BABYLON.OculusController.CameraSettings_OculusRiftDevKit2013_Metric;
-
-        var leftCamera = new BABYLON.OculusOrientedCamera(name + "_left", position, scene, controller, true, ovrSettings, neutralOrientation);
-        leftCamera.minZ = minZ;
-        leftCamera.maxZ = maxZ;
-        if (useFXAA) {
-            new BABYLON.FxaaPostProcess("fxaa_left", 1.0, leftCamera);
-        }
-
-        var rightCamera = new BABYLON.OculusOrientedCamera(name + "_right", position, scene, controller, false, ovrSettings, neutralOrientation);
-        rightCamera.minZ = minZ;
-        rightCamera.maxZ = maxZ;
-        if (useFXAA) {
-            new BABYLON.FxaaPostProcess("fxaa_right", 1.0, rightCamera);
-        }
-        scene.activeCameras = [];
-        scene.activeCameras.push(leftCamera);
-        scene.activeCameras.push(rightCamera);
-        leftCamera.attachControl(canvas);
-        rightCamera.attachControl(canvas);
-    };
-    BABYLON.OculusOrientedCamera.prototype = Object.create(BABYLON.Camera.prototype);
-
-    BABYLON.OculusOrientedCamera.prototype.getViewMatrix = function () {
-
-        BABYLON.Matrix.RotationYawPitchRollToRef(
-            this._currentOculusOrientation.yaw + this._neutralOrientation.yaw,
-            this._currentOculusOrientation.pitch + this._neutralOrientation.pitch,
-            -this._currentOculusOrientation.roll + this._neutralOrientation.roll
-            , this._currentOculusOrientationMatrix);
-
-        BABYLON.Vector3.TransformCoordinatesToRef(this._referenceDirection, this._currentOculusOrientationMatrix, this._actualDirection);
-        BABYLON.Vector3.TransformCoordinatesToRef(this._referenceUp, this._currentOculusOrientationMatrix, this._actualUp);
-        
-        BABYLON.Vector3.FromFloatsToRef(this.position.x + this._actualDirection.x, this.position.y + this._actualDirection.y, this.position.z + this._actualDirection.z, this._currentTargetPoint);
-        BABYLON.Matrix.LookAtLHToRef(this.position, this._currentTargetPoint, this._actualUp, this._tempMatrix);
-        this._tempMatrix.multiplyToRef(this._preViewMatrix, this._currentViewMatrix);
-        return this._currentViewMatrix;
-    };
-
-    BABYLON.OculusOrientedCamera.prototype._update = function () {
-        if (!this._referenceOculusOrientation) {
-            this._referenceOculusOrientation = { yaw: this._controller._currentOrientation.yaw, pitch: this._controller._currentOrientation.pitch, roll: this._controller._currentOrientation.roll };
-        }
-        else {
-            this._currentOculusOrientation.yaw = this._controller._currentOrientation.yaw - this._referenceOculusOrientation.yaw;
-            this._currentOculusOrientation.pitch = this._controller._currentOrientation.pitch - this._referenceOculusOrientation.pitch;
-            this._currentOculusOrientation.roll = this._controller._currentOrientation.roll - this._referenceOculusOrientation.roll;
-        }
-    };
-
-    BABYLON.OculusOrientedCamera.prototype.getProjectionMatrix = function (force) {
-        BABYLON.Matrix.PerspectiveFovLHToRef(this._aspectRatioFov, this._aspectRatioAspectRatio, this.minZ, this.maxZ, this._tempMatrix);
-        this._tempMatrix.multiplyToRef(this._hMatrix, this._projectionMatrix);
-        return this._projectionMatrix;
-    };
-})();

+ 29 - 63
Babylon/Cameras/babylon.oculusOrientedCamera.js

@@ -3,54 +3,6 @@
 var BABYLON = BABYLON || {};
 
 (function () {
-    BABYLON.OculusController = function (scene, target) {
-        BABYLON.inputController.call(this, scene, target);
-        this._deviceOrientationHandler = this.onOrientationEvent.bind(this);
-        this._tempOrientation = { yaw: 0.0, pitch: 0.0, roll: 0.0 };
-        this._relativeOrientation = { yaw: 0.0, pitch: 0.0, roll: 0.0 };
-        window.addEventListener("deviceorientation", this._deviceOrientationHandler);
-    };
-
-    BABYLON.OculusController.prototype = Object.create(BABYLON.inputController.prototype);
-
-    BABYLON.OculusController.prototype.onOrientationEvent = function (ev) {
-        this._tempOrientation.yaw = ev.alpha / 180 * Math.PI;
-        this._tempOrientation.pitch = ev.beta / 180 * Math.PI;
-        this._tempOrientation.roll = ev.gamma / 180 * Math.PI;
-
-        if (!this._lastOrientation) {
-            this._lastOrientation = Object.create(this._tempOrientation);
-        }
-        else {
-            this._relativeOrientation.yaw = this._tempOrientation.yaw - this._lastOrientation.yaw;
-            this._relativeOrientation.pitch = this._tempOrientation.pitch - this._lastOrientation.pitch;
-            this._relativeOrientation.roll = this._tempOrientation.roll - this._lastOrientation.roll;
-
-            var temp = this._tempOrientation;
-            this._tempOrientation = this._lastOrientation;
-            this._lastOrientation = temp;
-            this.target.rotateRelative(this._relativeOrientation);
-        }
-    };
-    BABYLON.OculusController.prototype.dispose = function () {
-        window.removeEventListener("deviceorientation", this._deviceOrientationHandler);
-    };
-
-    BABYLON.OculusController.CameraSettings_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
-    };
-
     BABYLON.OculusOrientedCamera = function (name, position, scene, isLeftEye, ovrSettings, neutralOrientation) {
         BABYLON.Camera.call(this, name, position, scene);
         this._referenceDirection = new BABYLON.Vector3(0, 0, 1);
@@ -58,10 +10,12 @@ var BABYLON = BABYLON || {};
         this._actualDirection = new BABYLON.Vector3(1, 0, 0);
         this._actualUp = new BABYLON.Vector3(0, 1, 0);
         this._currentTargetPoint = new BABYLON.Vector3(0, 0, 0);
-        this._currentOrientation = neutralOrientation || { yaw: 0.0, pitch: 0.0, roll: 0.0 };
+        this._currentOrientation = Object.create(neutralOrientation || { yaw: 0.0, pitch: 0.0, roll: 0.0 });
         this._currentViewMatrix = new BABYLON.Matrix();
         this._currentOrientationMatrix = new BABYLON.Matrix();
+        this._currentInvertOrientationMatrix = new BABYLON.Matrix();
         this._tempMatrix = new BABYLON.Matrix();
+        
         if (isLeftEye) {
             this.viewport = new BABYLON.Viewport(0, 0, 0.5, 1.0);
         } else {
@@ -76,12 +30,12 @@ var BABYLON = BABYLON || {};
 
         this._projectionMatrix = new BABYLON.Matrix();
         this._preViewMatrix = BABYLON.Matrix.Translation(isLeftEye ? .5 * ovrSettings.InterpupillaryDistance : -.5 * ovrSettings.InterpupillaryDistance, 0, 0);
-        new BABYLON.oculusDistortionCorrectionPostProcess("Oculus Distortion", this, !isLeftEye, ovrSettings);
+        new BABYLON.OculusDistortionCorrectionPostProcess("Oculus Distortion", this, !isLeftEye, ovrSettings);
         this.resetProjectionMatrix();
         this.resetViewMatrix();
     };
     
-    BABYLON.OculusOrientedCamera.buildOculusStereoCamera = function (scene, name, canvas, minZ, maxZ, position, neutralOrientation, useFXAA, ovrSettings) {
+    BABYLON.OculusOrientedCamera.BuildOculusStereoCamera = function (scene, name, canvas, minZ, maxZ, position, neutralOrientation, useFXAA, disableGravity,disableCollisions, ovrSettings) {
         position = position || new BABYLON.Vector2(0, 0);
         neutralOrientation = neutralOrientation || { yaw: 0.0, pitch: 0.0, roll: 0.0 };
         //var controller =  new BABYLON.OculusController();
@@ -107,7 +61,18 @@ var BABYLON = BABYLON || {};
         rightCamera.attachControl(canvas);
         var multiTarget = new BABYLON.inputControllerMultiTarget([leftCamera, rightCamera]);
         var controller = new BABYLON.OculusController(scene, multiTarget);
-        var moveController = new BABYLON.keyboardMoveController(scene, multiTarget);
+        var moveTarget = multiTarget;
+        if (!disableCollisions) {
+            var collisionFilter = new BABYLON.inputCollisionFilter(scene, multiTarget);
+            moveTarget = collisionFilter;
+        }
+        if (!disableGravity) {
+
+            var globalAxisFactorFilter = new BABYLON.globalAxisFactorsFilter(scene, moveTarget, 1, 0, 1);
+            var gravityController = new BABYLON.GravityInputController(scene, moveTarget);
+            moveTarget = globalAxisFactorFilter;
+        }
+        var moveController = new BABYLON.keyboardMoveController(scene, moveTarget);
         moveController.attachToCanvas(canvas);
         var result = {
             leftCamera: leftCamera, rightCamera: rightCamera, intermediateControllerTarget: multiTarget,
@@ -134,9 +99,10 @@ var BABYLON = BABYLON || {};
             this._currentOrientation.pitch,
             -this._currentOrientation.roll
             , this._currentOrientationMatrix);
+        this._currentOrientationMatrix.invertToRef(this._currentInvertOrientationMatrix);
 
-        BABYLON.Vector3.TransformCoordinatesToRef(this._referenceDirection, this._currentOrientationMatrix, this._actualDirection);
-        BABYLON.Vector3.TransformCoordinatesToRef(this._referenceUp, this._currentOrientationMatrix, this._actualUp);
+        BABYLON.Vector3.TransformNormalToRef(this._referenceDirection, this._currentOrientationMatrix, this._actualDirection);
+        BABYLON.Vector3.TransformNormalToRef(this._referenceUp, this._currentOrientationMatrix, this._actualUp);
 
         BABYLON.Vector3.FromFloatsToRef(this.position.x + this._actualDirection.x, this.position.y + this._actualDirection.y, this.position.z + this._actualDirection.z, this._currentTargetPoint);
         BABYLON.Matrix.LookAtLHToRef(this.position, this._currentTargetPoint, this._actualUp, this._tempMatrix);
@@ -149,14 +115,6 @@ var BABYLON = BABYLON || {};
     };
 
     BABYLON.OculusOrientedCamera.prototype._update = function () {
-        //if (!this._referenceOculusOrientation) {
-        //    this._referenceOculusOrientation = { yaw: this._controller._currentOrientation.yaw, pitch: this._controller._currentOrientation.pitch, roll: this._controller._currentOrientation.roll };
-        //}
-        //else {
-        //    this._currentOrientation.yaw = this._controller._currentOrientation.yaw - this._referenceOculusOrientation.yaw;
-        //    this._currentOrientation.pitch = this._controller._currentOrientation.pitch - this._referenceOculusOrientation.pitch;
-        //    this._currentOrientation.roll = this._controller._currentOrientation.roll - this._referenceOculusOrientation.roll;
-        //}
         if (this.controllers) {
             for (var i = 0; i < this.controllers.length; ++i) {
                 this.controllers[i].update();
@@ -164,6 +122,14 @@ var BABYLON = BABYLON || {};
         }
     };
 
+    BABYLON.OculusOrientedCamera.prototype.getOrientationMatrix = function () {
+        return this._currentOrientationMatrix;
+    };
+
+    BABYLON.OculusOrientedCamera.prototype.getInvertOrientationMatrix = function () {
+        return this._currentInvertOrientationMatrix;
+    };
+
     BABYLON.OculusOrientedCamera.prototype.resetProjectionMatrix = function () {
         BABYLON.Matrix.PerspectiveFovLHToRef(this._aspectRatioFov, this._aspectRatioAspectRatio, this.minZ, this.maxZ, this._tempMatrix);
         this._tempMatrix.multiplyToRef(this._hMatrix, this._projectionMatrix);
@@ -185,7 +151,7 @@ var BABYLON = BABYLON || {};
         if (!this._tempMoveVector) {
             this._tempMoveVector = new BABYLON.Vector3(0, 0, 0);
         }
-        BABYLON.Vector3.TransformCoordinatesToRef(movementVector, this._currentOrientationMatrix, this._tempMoveVector);
+        BABYLON.Vector3.TransformNormalToRef(movementVector, this._currentOrientationMatrix, this._tempMoveVector);
         this.position.addInPlace(this._tempMoveVector);
         this.resetViewMatrix();
     };

+ 0 - 34
Babylon/Collisions/babylon.collisionPlane.js

@@ -1,34 +0,0 @@
-var BABYLON = BABYLON || {};
-
-(function () {
-    BABYLON.CollisionPlane = function (origin, normal) {
-        this.normal = normal;
-        this.origin = origin;
-
-        normal.normalize();
-
-        this.equation = [];
-        this.equation[0] = normal.x;
-        this.equation[1] = normal.y;
-        this.equation[2] = normal.z;
-        this.equation[3] = -(normal.x * origin.x + normal.y * origin.y + normal.z * origin.z);
-    };
-
-    // Methods
-    BABYLON.CollisionPlane.prototype.isFrontFacingTo = function (direction, epsilon) {
-        var dot = BABYLON.Vector3.Dot(this.normal, direction);
-
-        return (dot <= epsilon);
-    };
-
-    BABYLON.CollisionPlane.prototype.signedDistanceTo = function (point) {
-        return BABYLON.Vector3.Dot(point, this.normal) + this.equation[3];
-    };
-
-    // Statics
-    BABYLON.CollisionPlane.CreateFromPoints = function (p1, p2, p3) {
-        var normal = BABYLON.Vector3.Cross(p2.subtract(p1), p3.subtract(p1));
-
-        return new BABYLON.CollisionPlane(p1, normal);
-    };
-})();

+ 5 - 0
Babylon/Mesh/babylon.mesh.js

@@ -896,6 +896,11 @@ var BABYLON = BABYLON || {};
             this._indexBuffer = null;
         }
 
+        // Physics
+        if (this.getPhysicsImpostor() != BABYLON.PhysicsEngine.NoImpostor) {
+            this.setPhysicsState({ impostor: BABYLON.PhysicsEngine.NoImpostor });
+        }
+
         // Remove from scene
         var index = this._scene.meshes.indexOf(this);
         this._scene.meshes.splice(index, 1);

+ 13 - 4
Babylon/PostProcess/babylon.convolutionPostProcess.js

@@ -3,16 +3,25 @@
 var BABYLON = BABYLON || {};
 
 (function () {
-    BABYLON.ConvolutionPostProcess = function (name, kernelMatrix, ratio, camera, samplingMode, engine, reusable) {
-        BABYLON.PostProcess.call(this, name, "convolution", ["kernelMatrix"], null, ratio, camera, samplingMode, engine, reusable);
+    BABYLON.ConvolutionPostProcess = function (name, kernel, ratio, camera, samplingMode, engine, reusable) {
+        BABYLON.PostProcess.call(this, name, "convolution", ["kernel", "screenSize"], null, ratio, camera, samplingMode, engine, reusable);
         
-        this.kernelMatrix = kernelMatrix;
+        this.kernel = kernel;
         var that = this;
         this.onApply = function (effect) {
-            effect.setMatrix("kernelMatrix", that.kernelMatrix);
+            effect.setFloat2("screenSize", that.width, that.height);
+            effect.setArray("kernel", that.kernel);
         };
     };
     
     BABYLON.ConvolutionPostProcess.prototype = Object.create(BABYLON.PostProcess.prototype);
+    
+    // Based on http://en.wikipedia.org/wiki/Kernel_(image_processing)
+    BABYLON.ConvolutionPostProcess.EdgeDetect0Kernel = [1, 0, -1, 0, 0, 0, -1, 0, 1];
+    BABYLON.ConvolutionPostProcess.EdgeDetect1Kernel = [0, 1, 0, 1, -4, 1, 0, 1, 0];
+    BABYLON.ConvolutionPostProcess.EdgeDetect2Kernel = [-1, -1, -1, -1, 8, -1, -1, -1, -1];
+    BABYLON.ConvolutionPostProcess.SharpenKernel = [0, -1, 0, -1, 5, -1, 0, -1, 0];
+    BABYLON.ConvolutionPostProcess.EmbossKernel = [-2, -1, 0, -1, 1, 1, 0, 1, 2];
+    BABYLON.ConvolutionPostProcess.GaussianKernel = [0, 1, 0, 1, 1, 1, 0, 1, 0];
 
 })();

+ 18 - 0
Babylon/PostProcess/babylon.filterPostProcess.js

@@ -0,0 +1,18 @@
+"use strict";
+
+var BABYLON = BABYLON || {};
+
+(function () {
+    BABYLON.FilterPostProcess = function (name, kernelMatrix, ratio, camera, samplingMode, engine, reusable) {
+        BABYLON.PostProcess.call(this, name, "filter", ["kernelMatrix"], null, ratio, camera, samplingMode, engine, reusable);
+        
+        this.kernelMatrix = kernelMatrix;
+        var that = this;
+        this.onApply = function (effect) {
+            effect.setMatrix("kernelMatrix", that.kernelMatrix);
+        };
+    };
+    
+    BABYLON.FilterPostProcess.prototype = Object.create(BABYLON.PostProcess.prototype);
+
+})();

+ 4 - 4
Babylon/PostProcess/babylon.oculusDistortionCorrectionPostProcess.js

@@ -3,7 +3,7 @@
 var BABYLON = BABYLON || {};
 
 (function () {
-    BABYLON.oculusDistortionCorrectionPostProcess = function (name, camera, isRightEye, cameraSettings) {
+    BABYLON.OculusDistortionCorrectionPostProcess = function (name, camera, isRightEye, cameraSettings) {
         BABYLON.PostProcess.call(this, name, "oculusDistortionCorrection", [
 			'LensCenter',
 		    'Scale',
@@ -16,14 +16,14 @@ var BABYLON = BABYLON || {};
         this._lensCenterOffset = cameraSettings.LensCenterOffset;
     };
 
-    BABYLON.oculusDistortionCorrectionPostProcess.prototype = Object.create(BABYLON.PostProcess.prototype);
-    BABYLON.oculusDistortionCorrectionPostProcess.prototype.onSizeChanged = function () {
+    BABYLON.OculusDistortionCorrectionPostProcess.prototype = Object.create(BABYLON.PostProcess.prototype);
+    BABYLON.OculusDistortionCorrectionPostProcess.prototype.onSizeChanged = function () {
         this.aspectRatio = this.width * .5 / this.height;
         this._scaleIn = new BABYLON.Vector2(2, 2 / this.aspectRatio);
         this._scaleFactor = new BABYLON.Vector2(.5 * (1/this._postProcessScaleFactor), .5 * (1/this._postProcessScaleFactor) * this.aspectRatio);
         this._lensCenter = new BABYLON.Vector2(this._isRightEye ? 0.5 - this._lensCenterOffset * 0.5 : 0.5 + this._lensCenterOffset * 0.5, 0.5);
     };
-    BABYLON.oculusDistortionCorrectionPostProcess.prototype.onApply = function (effect) {
+    BABYLON.OculusDistortionCorrectionPostProcess.prototype.onApply = function (effect) {
         effect.setFloat2("LensCenter", this._lensCenter.x, this._lensCenter.y);
         effect.setFloat2("Scale", this._scaleFactor.x, this._scaleFactor.y);
         effect.setFloat2("ScaleIn", this._scaleIn.x, this._scaleIn.y);

+ 30 - 5
Babylon/Shaders/convolution.fragment.fx

@@ -6,12 +6,37 @@ precision mediump float;
 varying vec2 vUV;
 uniform sampler2D textureSampler;
 
-uniform mat4 kernelMatrix;
+uniform vec2 screenSize;
+uniform float kernel[9];
 
-void main(void) 
+void main(void)
 {
-	vec3 baseColor = texture2D(textureSampler, vUV).rgb;
-	vec3 updatedColor = (kernelMatrix * vec4(baseColor, 1.0)).rgb;
+	vec2 onePixel = vec2(1.0, 1.0) / screenSize;
+	vec4 colorSum =
+		texture2D(textureSampler, vUV + onePixel * vec2(-1, -1)) * kernel[0] +
+		texture2D(textureSampler, vUV + onePixel * vec2(0, -1)) * kernel[1] +
+		texture2D(textureSampler, vUV + onePixel * vec2(1, -1)) * kernel[2] +
+		texture2D(textureSampler, vUV + onePixel * vec2(-1, 0)) * kernel[3] +
+		texture2D(textureSampler, vUV + onePixel * vec2(0, 0)) * kernel[4] +
+		texture2D(textureSampler, vUV + onePixel * vec2(1, 0)) * kernel[5] +
+		texture2D(textureSampler, vUV + onePixel * vec2(-1, 1)) * kernel[6] +
+		texture2D(textureSampler, vUV + onePixel * vec2(0, 1)) * kernel[7] +
+		texture2D(textureSampler, vUV + onePixel * vec2(1, 1)) * kernel[8];
 
-	gl_FragColor = vec4(updatedColor, 1.0);
+	float kernelWeight =
+		kernel[0] +
+		kernel[1] +
+		kernel[2] +
+		kernel[3] +
+		kernel[4] +
+		kernel[5] +
+		kernel[6] +
+		kernel[7] +
+		kernel[8];
+
+	if (kernelWeight <= 0.0) {
+		kernelWeight = 1.0;
+	}
+
+	gl_FragColor = vec4((colorSum / kernelWeight).rgb, 1);
 }

+ 17 - 0
Babylon/Shaders/filter.fragment.fx

@@ -0,0 +1,17 @@
+#ifdef GL_ES
+precision mediump float;
+#endif
+
+// Samplers
+varying vec2 vUV;
+uniform sampler2D textureSampler;
+
+uniform mat4 kernelMatrix;
+
+void main(void)
+{
+	vec3 baseColor = texture2D(textureSampler, vUV).rgb;
+	vec3 updatedColor = (kernelMatrix * vec4(baseColor, 1.0)).rgb;
+
+	gl_FragColor = vec4(updatedColor, 1.0);
+}

+ 1 - 0
Tools/BuildOurOwnBabylonJS/BuildOurOwnBabylonJS/babylonJS.xml

@@ -15,6 +15,7 @@
   <script src="Babylon/LensFlare/babylon.lensFlareSystem.js"></script>
   <script src="Babylon/LensFlare/babylon.lensFlare.js"></script>
   <script src="Babylon/PostProcess/babylon.fxaaPostProcess.js"></script>
+  <script src="Babylon/PostProcess/babylon.filterPostProcess.js"></script>
   <script src="Babylon/PostProcess/babylon.convolutionPostProcess.js"></script>
   <script src="Babylon/PostProcess/babylon.blackAndWhitePostProcess.js"></script>
   <script src="Babylon/PostProcess/babylon.refractionPostProcess.js"></script>

Разлика између датотеке није приказан због своје велике величине
+ 4 - 3
babylon.1.9.0.js


+ 4 - 0
readme.md

@@ -61,14 +61,18 @@ Online [sandbox](http://www.babylonjs.com/sandbox) where you can test your .baby
  - Render target textures
  - Dynamic textures (canvas)
  - Video textures
+ - Compressed (DDS) textures
 -  Cameras (Perspective and orthographic):
  - Arc rotate camera
  - Free camera
  - Touch camera
+ - Virtual Joysticks camera
+ - Oculus Rift camera
 -  Meshes: 
  - Mesh cloning
  - Dynamic meshes
  - Height maps
+ - Constructive solid geometries
 -  Import: 
  - Babylon scene file can be converted from .OBJ, .FBX, .MXB
  - Exporter for Blender