Sfoglia il codice sorgente

refactored freeCamera and followCamera to subclass targetCamera

Alex Bogartz 11 anni fa
parent
commit
31d8f311ac

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

@@ -36,7 +36,7 @@ var BABYLON;
             var vz = dz * this.cameraAcceleration * 2;
 
             if (vx > this.maxCameraSpeed || vx < -this.maxCameraSpeed) {
-                vx = vx < 1 ? -this.maxCameraSpeed : this.maxCameraSpeed; //max speed is 40
+                vx = vx < 1 ? -this.maxCameraSpeed : this.maxCameraSpeed; //max speed is 20
             }
 
             if (vy > this.maxCameraSpeed || vy < -this.maxCameraSpeed) {
@@ -50,7 +50,12 @@ 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);
+            this.follow(this.target);
+        };
         return FollowCamera;
-    })(FreeCamera);
+    })(TargetCamera);
     BABYLON.FollowCamera = FollowCamera;
 })(BABYLON || (BABYLON = {}));

+ 16 - 10
Babylon/Cameras/babylon.followCamera.ts

@@ -1,21 +1,22 @@
 module BABYLON {
-    export class FollowCamera extends FreeCamera {
+    export class FollowCamera extends TargetCamera {
 
-        public radius:number=12;
-        public rotationOffset:number=0;
-        public heightOffset:number=4;
-        public cameraAcceleration:number=0.05;
-        public maxCameraSpeed:number=20;
+        public radius:number = 12;
+        public rotationOffset:number = 0;
+        public heightOffset:number = 4;
+        public cameraAcceleration:number = 0.05;
+        public maxCameraSpeed:number = 20;
+        public target:BABYLON.AbstractMesh;
 
-        constructor(name: string, position: Vector3, scene: Scene) {
+        constructor(name:string, position:Vector3, scene:Scene) {
             super(name, position, scene);
         }
 
-        private getRadians (degrees):number {
+        private getRadians(degrees):number {
             return degrees * Math.PI / 180;
         }
 
-        public follow( cameraTarget:BABYLON.AbstractMesh) {
+        private follow(cameraTarget:BABYLON.AbstractMesh) {
             if (!cameraTarget)
                 return;
 
@@ -31,7 +32,7 @@
             var vz:number = dz * this.cameraAcceleration * 2;
 
             if (vx > this.maxCameraSpeed || vx < -this.maxCameraSpeed) {
-                vx = vx < 1 ? -this.maxCameraSpeed : this.maxCameraSpeed; //max speed is 40
+                vx = vx < 1 ? -this.maxCameraSpeed : this.maxCameraSpeed; //max speed is 20
             }
 
             if (vy > this.maxCameraSpeed || vy < -this.maxCameraSpeed) {
@@ -45,5 +46,10 @@
             this.position = new BABYLON.Vector3(this.position.x + vx, this.position.y + vy, this.position.z + vz);
             this.setTarget(cameraTarget.position);
         }
+
+        public _update():void {
+            super._update();
+            this.follow(this.target);
+        }
     }
 } 

+ 19 - 189
Babylon/Cameras/babylon.freeCamera.js

@@ -10,122 +10,21 @@ var BABYLON;
         __extends(FreeCamera, _super);
         function FreeCamera(name, position, scene) {
             _super.call(this, name, position, scene);
-            this.cameraDirection = new BABYLON.Vector3(0, 0, 0);
-            this.cameraRotation = new BABYLON.Vector2(0, 0);
-            this.rotation = new BABYLON.Vector3(0, 0, 0);
             this.ellipsoid = new BABYLON.Vector3(0.5, 1, 0.5);
             this.keysUp = [38];
             this.keysDown = [40];
             this.keysLeft = [37];
             this.keysRight = [39];
-            this.speed = 2.0;
             this.checkCollisions = false;
             this.applyGravity = false;
-            this.noRotationConstraint = false;
             this.angularSensibility = 2000.0;
-            this.lockedTarget = null;
             this._keys = [];
-            this._collider = new BABYLON.Collider();
+            this._collider = new Collider();
             this._needMoveForGravity = true;
-            this._currentTarget = BABYLON.Vector3.Zero();
-            this._viewMatrix = BABYLON.Matrix.Zero();
-            this._camMatrix = BABYLON.Matrix.Zero();
-            this._cameraTransformMatrix = BABYLON.Matrix.Zero();
-            this._cameraRotationMatrix = BABYLON.Matrix.Zero();
-            this._referencePoint = new BABYLON.Vector3(0, 0, 1);
-            this._transformedReferencePoint = BABYLON.Vector3.Zero();
             this._oldPosition = BABYLON.Vector3.Zero();
             this._diffPosition = BABYLON.Vector3.Zero();
             this._newPosition = BABYLON.Vector3.Zero();
-            this._lookAtTemp = BABYLON.Matrix.Zero();
-            this._tempMatrix = BABYLON.Matrix.Zero();
         }
-        FreeCamera.prototype._getLockedTargetPosition = function () {
-            if (!this.lockedTarget) {
-                return null;
-            }
-
-            return this.lockedTarget.position || this.lockedTarget;
-        };
-
-        // Cache
-        FreeCamera.prototype._initCache = function () {
-            _super.prototype._initCache.call(this);
-            this._cache.lockedTarget = new BABYLON.Vector3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
-            this._cache.rotation = new BABYLON.Vector3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
-        };
-
-        FreeCamera.prototype._updateCache = function (ignoreParentClass) {
-            if (!ignoreParentClass) {
-                _super.prototype._updateCache.call(this);
-            }
-
-            var lockedTargetPosition = this._getLockedTargetPosition();
-            if (!lockedTargetPosition) {
-                this._cache.lockedTarget = null;
-            } else {
-                if (!this._cache.lockedTarget) {
-                    this._cache.lockedTarget = lockedTargetPosition.clone();
-                } else {
-                    this._cache.lockedTarget.copyFrom(lockedTargetPosition);
-                }
-            }
-
-            this._cache.rotation.copyFrom(this.rotation);
-        };
-
-        // Synchronized
-        FreeCamera.prototype._isSynchronizedViewMatrix = function () {
-            if (!_super.prototype._isSynchronizedViewMatrix.call(this)) {
-                return false;
-            }
-
-            var lockedTargetPosition = this._getLockedTargetPosition();
-
-            return (this._cache.lockedTarget ? this._cache.lockedTarget.equals(lockedTargetPosition) : !lockedTargetPosition) && this._cache.rotation.equals(this.rotation);
-        };
-
-        // Methods
-        FreeCamera.prototype._computeLocalCameraSpeed = function () {
-            return this.speed * ((BABYLON.Tools.GetDeltaTime() / (BABYLON.Tools.GetFps() * 10.0)));
-        };
-
-        // Target
-        FreeCamera.prototype.setTarget = function (target) {
-            this.upVector.normalize();
-
-            BABYLON.Matrix.LookAtLHToRef(this.position, target, this.upVector, this._camMatrix);
-            this._camMatrix.invert();
-
-            this.rotation.x = Math.atan(this._camMatrix.m[6] / this._camMatrix.m[10]);
-
-            var vDir = target.subtract(this.position);
-
-            if (vDir.x >= 0.0) {
-                this.rotation.y = (-Math.atan(vDir.z / vDir.x) + Math.PI / 2.0);
-            } else {
-                this.rotation.y = (-Math.atan(vDir.z / vDir.x) - Math.PI / 2.0);
-            }
-
-            this.rotation.z = -Math.acos(BABYLON.Vector3.Dot(new BABYLON.Vector3(0, 1.0, 0), this.upVector));
-
-            if (isNaN(this.rotation.x)) {
-                this.rotation.x = 0;
-            }
-
-            if (isNaN(this.rotation.y)) {
-                this.rotation.y = 0;
-            }
-
-            if (isNaN(this.rotation.z)) {
-                this.rotation.z = 0;
-            }
-        };
-
-        FreeCamera.prototype.getTarget = function () {
-            return this._currentTarget;
-        };
-
         // Controls
         FreeCamera.prototype.attachControl = function (element, noPreventDefault) {
             var _this = this;
@@ -235,7 +134,7 @@ var BABYLON;
             element.addEventListener("mouseout", this._onMouseOut, false);
             element.addEventListener("mousemove", this._onMouseMove, false);
 
-            BABYLON.Tools.RegisterTopRootEvents([
+            Tools.RegisterTopRootEvents([
                 { name: "keydown", handler: this._onKeyDown },
                 { name: "keyup", handler: this._onKeyUp },
                 { name: "blur", handler: this._onLostFocus }
@@ -252,7 +151,7 @@ var BABYLON;
             element.removeEventListener("mouseout", this._onMouseOut);
             element.removeEventListener("mousemove", this._onMouseMove);
 
-            BABYLON.Tools.UnregisterTopRootEvents([
+            Tools.UnregisterTopRootEvents([
                 { name: "keydown", handler: this._onKeyDown },
                 { name: "keyup", handler: this._onKeyUp },
                 { name: "blur", handler: this._onLostFocus }
@@ -279,7 +178,7 @@ var BABYLON;
             this.getScene()._getNewPosition(this._oldPosition, velocity, this._collider, 3, this._newPosition);
             this._newPosition.subtractToRef(this._oldPosition, this._diffPosition);
 
-            if (this._diffPosition.length() > BABYLON.Engine.CollisionsEpsilon) {
+            if (this._diffPosition.length() > Engine.CollisionsEpsilon) {
                 this.position.addInPlace(this._diffPosition);
                 if (this.onCollide) {
                     this.onCollide(this._collider.collidedMesh);
@@ -313,97 +212,28 @@ var BABYLON;
             }
         };
 
-        FreeCamera.prototype._update = function () {
-            this._checkInputs();
-
-            var needToMove = this._needMoveForGravity || Math.abs(this.cameraDirection.x) > 0 || Math.abs(this.cameraDirection.y) > 0 || Math.abs(this.cameraDirection.z) > 0;
-            var needToRotate = Math.abs(this.cameraRotation.x) > 0 || Math.abs(this.cameraRotation.y) > 0;
-
-            // Move
-            if (needToMove) {
-                if (this.checkCollisions && this.getScene().collisionsEnabled) {
-                    this._collideWithWorld(this.cameraDirection);
-
-                    if (this.applyGravity) {
-                        var oldPosition = this.position;
-                        this._collideWithWorld(this.getScene().gravity);
-                        this._needMoveForGravity = (BABYLON.Vector3.DistanceSquared(oldPosition, this.position) != 0);
-                    }
-                } else {
-                    this.position.addInPlace(this.cameraDirection);
-                }
-            }
-
-            // Rotate
-            if (needToRotate) {
-                this.rotation.x += this.cameraRotation.x;
-                this.rotation.y += this.cameraRotation.y;
-
-                if (!this.noRotationConstraint) {
-                    var limit = (Math.PI / 2) * 0.95;
-
-                    if (this.rotation.x > limit)
-                        this.rotation.x = limit;
-                    if (this.rotation.x < -limit)
-                        this.rotation.x = -limit;
-                }
-            }
-
-            // Inertia
-            if (needToMove) {
-                if (Math.abs(this.cameraDirection.x) < BABYLON.Engine.Epsilon) {
-                    this.cameraDirection.x = 0;
-                }
-
-                if (Math.abs(this.cameraDirection.y) < BABYLON.Engine.Epsilon) {
-                    this.cameraDirection.y = 0;
-                }
-
-                if (Math.abs(this.cameraDirection.z) < BABYLON.Engine.Epsilon) {
-                    this.cameraDirection.z = 0;
-                }
-
-                this.cameraDirection.scaleInPlace(this.inertia);
-            }
-            if (needToRotate) {
-                if (Math.abs(this.cameraRotation.x) < BABYLON.Engine.Epsilon) {
-                    this.cameraRotation.x = 0;
-                }
-
-                if (Math.abs(this.cameraRotation.y) < BABYLON.Engine.Epsilon) {
-                    this.cameraRotation.y = 0;
-                }
-                this.cameraRotation.scaleInPlace(this.inertia);
-            }
+        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;
         };
 
-        FreeCamera.prototype._getViewMatrix = function () {
-            if (!this.lockedTarget) {
-                // Compute
-                if (this.upVector.x != 0 || this.upVector.y != 1.0 || this.upVector.z != 0) {
-                    BABYLON.Matrix.LookAtLHToRef(BABYLON.Vector3.Zero(), this._referencePoint, this.upVector, this._lookAtTemp);
-                    BABYLON.Matrix.RotationYawPitchRollToRef(this.rotation.y, this.rotation.x, this.rotation.z, this._cameraRotationMatrix);
-
-                    this._lookAtTemp.multiplyToRef(this._cameraRotationMatrix, this._tempMatrix);
-                    this._lookAtTemp.invert();
-                    this._tempMatrix.multiplyToRef(this._lookAtTemp, this._cameraRotationMatrix);
-                } else {
-                    BABYLON.Matrix.RotationYawPitchRollToRef(this.rotation.y, this.rotation.x, this.rotation.z, this._cameraRotationMatrix);
+        FreeCamera.prototype._updatePosition = function () {
+            if (this.checkCollisions && this.getScene().collisionsEnabled) {
+                this._collideWithWorld(this.cameraDirection);
+                if (this.applyGravity) {
+                    var oldPosition = this.position;
+                    this._collideWithWorld(this.getScene().gravity);
+                    this._needMoveForGravity = (BABYLON.Vector3.DistanceSquared(oldPosition, this.position) != 0);
                 }
-
-                BABYLON.Vector3.TransformCoordinatesToRef(this._referencePoint, this._cameraRotationMatrix, this._transformedReferencePoint);
-
-                // Computing target and final matrix
-                this.position.addToRef(this._transformedReferencePoint, this._currentTarget);
             } else {
-                this._currentTarget.copyFrom(this._getLockedTargetPosition());
+                this.position.addInPlace(this.cameraDirection);
             }
+        };
 
-            BABYLON.Matrix.LookAtLHToRef(this.position, this._currentTarget, this.upVector, this._viewMatrix);
-            return this._viewMatrix;
+        FreeCamera.prototype._update = function () {
+            this._checkInputs();
+            _super.prototype._update.call(this);
         };
         return FreeCamera;
-    })(BABYLON.Camera);
+    })(TargetCamera);
     BABYLON.FreeCamera = FreeCamera;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.freeCamera.js.map

+ 35 - 211
Babylon/Cameras/babylon.freeCamera.ts

@@ -1,146 +1,41 @@
 module BABYLON {
-    export class FreeCamera extends Camera {
-        public cameraDirection = new BABYLON.Vector3(0, 0, 0);
-        public cameraRotation = new BABYLON.Vector2(0, 0);
-        public rotation = new BABYLON.Vector3(0, 0, 0);
+    export class FreeCamera extends TargetCamera {
         public ellipsoid = new BABYLON.Vector3(0.5, 1, 0.5);
         public keysUp = [38];
         public keysDown = [40];
         public keysLeft = [37];
         public keysRight = [39];
-        public speed = 2.0;
         public checkCollisions = false;
         public applyGravity = false;
-        public noRotationConstraint = false;
         public angularSensibility = 2000.0;
-        public lockedTarget = null;
-        public onCollide: (collidedMesh: AbstractMesh) => void;
+        public onCollide:(collidedMesh:AbstractMesh) => void;
 
         private _keys = [];
         private _collider = new Collider();
         private _needMoveForGravity = true;
-        public _currentTarget = BABYLON.Vector3.Zero();
-        public _viewMatrix = BABYLON.Matrix.Zero();
-        private _camMatrix = BABYLON.Matrix.Zero();
-        private _cameraTransformMatrix = BABYLON.Matrix.Zero();
-        public _cameraRotationMatrix = BABYLON.Matrix.Zero();
-        public _referencePoint = new BABYLON.Vector3(0, 0, 1);
-        public _transformedReferencePoint = BABYLON.Vector3.Zero();
         private _oldPosition = BABYLON.Vector3.Zero();
         private _diffPosition = BABYLON.Vector3.Zero();
         private _newPosition = BABYLON.Vector3.Zero();
-        private _lookAtTemp = BABYLON.Matrix.Zero();
-        private _tempMatrix = BABYLON.Matrix.Zero();
-        private _attachedElement: HTMLElement;
-        private _localDirection: Vector3;
-        private _transformedDirection: Vector3;
-
-        private _onMouseDown: (e: MouseEvent) => any;
-        private _onMouseUp: (e: MouseEvent) => any;
-        private _onMouseOut: (e: MouseEvent) => any;
-        private _onMouseMove: (e: MouseEvent) => any;
-        private _onKeyDown: (e: KeyboardEvent) => any;
-        private _onKeyUp: (e: KeyboardEvent) => any;
-        public _onLostFocus: (e: FocusEvent) => any;
-        private _reset: () => void;
-
-        public _waitingLockedTargetId: string;
-
-        constructor(name: string, position: Vector3, scene: Scene) {
-            super(name, position, scene);
-        }
-
-        public _getLockedTargetPosition(): Vector3 {
-            if (!this.lockedTarget) {
-                return null;
-            }
-
-            return this.lockedTarget.position || this.lockedTarget;
-        }
-
-        // Cache
-        public _initCache() {
-            super._initCache();
-            this._cache.lockedTarget = new BABYLON.Vector3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
-            this._cache.rotation = new BABYLON.Vector3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
-        }
-
-        public _updateCache(ignoreParentClass?: boolean): void {
-            if (!ignoreParentClass) {
-                super._updateCache();
-            }
-
-            var lockedTargetPosition = this._getLockedTargetPosition();
-            if (!lockedTargetPosition) {
-                this._cache.lockedTarget = null;
-            }
-            else {
-                if (!this._cache.lockedTarget) {
-                    this._cache.lockedTarget = lockedTargetPosition.clone();
-                }
-                else {
-                    this._cache.lockedTarget.copyFrom(lockedTargetPosition);
-                }
-            }
-
-            this._cache.rotation.copyFrom(this.rotation);
-        }
-
-        // Synchronized
-        public _isSynchronizedViewMatrix(): boolean {
-            if (!super._isSynchronizedViewMatrix()) {
-                return false;
-            }
-
-            var lockedTargetPosition = this._getLockedTargetPosition();
-
-            return (this._cache.lockedTarget ? this._cache.lockedTarget.equals(lockedTargetPosition) : !lockedTargetPosition)
-                && this._cache.rotation.equals(this.rotation);
-        }
-
-        // Methods
-        public _computeLocalCameraSpeed(): number {
-            return this.speed * ((BABYLON.Tools.GetDeltaTime() / (BABYLON.Tools.GetFps() * 10.0)));
-        }
-
-        // Target
-        public setTarget(target: Vector3): void {
-            this.upVector.normalize();
-
-            BABYLON.Matrix.LookAtLHToRef(this.position, target, this.upVector, this._camMatrix);
-            this._camMatrix.invert();
-
-            this.rotation.x = Math.atan(this._camMatrix.m[6] / this._camMatrix.m[10]);
+        private _attachedElement:HTMLElement;
+        private _localDirection:Vector3;
+        private _transformedDirection:Vector3;
 
-            var vDir = target.subtract(this.position);
+        private _onMouseDown:(e:MouseEvent) => any;
+        private _onMouseUp:(e:MouseEvent) => any;
+        private _onMouseOut:(e:MouseEvent) => any;
+        private _onMouseMove:(e:MouseEvent) => any;
+        private _onKeyDown:(e:KeyboardEvent) => any;
+        private _onKeyUp:(e:KeyboardEvent) => any;
+        public _onLostFocus:(e:FocusEvent) => any;
 
-            if (vDir.x >= 0.0) {
-                this.rotation.y = (-Math.atan(vDir.z / vDir.x) + Math.PI / 2.0);
-            } else {
-                this.rotation.y = (-Math.atan(vDir.z / vDir.x) - Math.PI / 2.0);
-            }
-
-            this.rotation.z = -Math.acos(BABYLON.Vector3.Dot(new BABYLON.Vector3(0, 1.0, 0), this.upVector));
-
-            if (isNaN(this.rotation.x)) {
-                this.rotation.x = 0;
-            }
-
-            if (isNaN(this.rotation.y)) {
-                this.rotation.y = 0;
-            }
-
-            if (isNaN(this.rotation.z)) {
-                this.rotation.z = 0;
-            }
-        }
+        public _waitingLockedTargetId:string;
 
-        public getTarget(): Vector3 {
-            return this._currentTarget;
+        constructor(name:string, position:Vector3, scene:Scene) {
+            super(name, position, scene);
         }
 
         // Controls
-        public attachControl(element: HTMLElement, noPreventDefault?: boolean): void {
+        public attachControl(element:HTMLElement, noPreventDefault?:boolean):void {
             var previousPosition;
             var engine = this.getEngine();
 
@@ -260,7 +155,7 @@
             ]);
         }
 
-        public detachControl(element: HTMLElement): void {
+        public detachControl(element:HTMLElement):void {
             if (this._attachedElement != element) {
                 return;
             }
@@ -282,8 +177,8 @@
             }
         }
 
-        public _collideWithWorld(velocity: Vector3): void {
-            var globalPosition: Vector3;
+        public _collideWithWorld(velocity:Vector3):void {
+            var globalPosition:Vector3;
 
             if (this.parent) {
                 globalPosition = BABYLON.Vector3.TransformCoordinates(this.position, this.parent.getWorldMatrix());
@@ -305,7 +200,7 @@
             }
         }
 
-        public _checkInputs(): void {
+        public _checkInputs():void {
             if (!this._localDirection) {
                 this._localDirection = BABYLON.Vector3.Zero();
                 this._transformedDirection = BABYLON.Vector3.Zero();
@@ -332,98 +227,27 @@
             }
         }
 
-        public _update(): void {
-            this._checkInputs();
-
-            var needToMove = this._needMoveForGravity || Math.abs(this.cameraDirection.x) > 0 || Math.abs(this.cameraDirection.y) > 0 || Math.abs(this.cameraDirection.z) > 0;
-            var needToRotate = Math.abs(this.cameraRotation.x) > 0 || Math.abs(this.cameraRotation.y) > 0;
-
-            // Move
-            if (needToMove) {
-                if (this.checkCollisions && this.getScene().collisionsEnabled) {
-                    this._collideWithWorld(this.cameraDirection);
-
-
-                    if (this.applyGravity) {
-                        var oldPosition = this.position;
-                        this._collideWithWorld(this.getScene().gravity);
-                        this._needMoveForGravity = (BABYLON.Vector3.DistanceSquared(oldPosition, this.position) != 0);
-                    }
-                } else {
-                    this.position.addInPlace(this.cameraDirection);
-                }
-            }
-
-            // Rotate
-            if (needToRotate) {
-                this.rotation.x += this.cameraRotation.x;
-                this.rotation.y += this.cameraRotation.y;
-
-
-                if (!this.noRotationConstraint) {
-                    var limit = (Math.PI / 2) * 0.95;
-
-
-                    if (this.rotation.x > limit)
-                        this.rotation.x = limit;
-                    if (this.rotation.x < -limit)
-                        this.rotation.x = -limit;
-                }
-            }
-
-            // Inertia
-            if (needToMove) {
-                if (Math.abs(this.cameraDirection.x) < BABYLON.Engine.Epsilon) {
-                    this.cameraDirection.x = 0;
-                }
-
-                if (Math.abs(this.cameraDirection.y) < BABYLON.Engine.Epsilon) {
-                    this.cameraDirection.y = 0;
-                }
-
-                if (Math.abs(this.cameraDirection.z) < BABYLON.Engine.Epsilon) {
-                    this.cameraDirection.z = 0;
-                }
-
-                this.cameraDirection.scaleInPlace(this.inertia);
-            }
-            if (needToRotate) {
-                if (Math.abs(this.cameraRotation.x) < BABYLON.Engine.Epsilon) {
-                    this.cameraRotation.x = 0;
-                }
-
-                if (Math.abs(this.cameraRotation.y) < BABYLON.Engine.Epsilon) {
-                    this.cameraRotation.y = 0;
-                }
-                this.cameraRotation.scaleInPlace(this.inertia);
-            }
+        public _decideIfNeedsToMove():boolean {
+            return this._needMoveForGravity || Math.abs(this.cameraDirection.x) > 0 || Math.abs(this.cameraDirection.y) > 0 || Math.abs(this.cameraDirection.z) > 0;
         }
 
-        public _getViewMatrix(): Matrix {
-            if (!this.lockedTarget) {
-                // Compute
-                if (this.upVector.x != 0 || this.upVector.y != 1.0 || this.upVector.z != 0) {
-                    BABYLON.Matrix.LookAtLHToRef(BABYLON.Vector3.Zero(), this._referencePoint, this.upVector, this._lookAtTemp);
-                    BABYLON.Matrix.RotationYawPitchRollToRef(this.rotation.y, this.rotation.x, this.rotation.z, this._cameraRotationMatrix);
-
-
-                    this._lookAtTemp.multiplyToRef(this._cameraRotationMatrix, this._tempMatrix);
-                    this._lookAtTemp.invert();
-                    this._tempMatrix.multiplyToRef(this._lookAtTemp, this._cameraRotationMatrix);
-                } else {
-                    BABYLON.Matrix.RotationYawPitchRollToRef(this.rotation.y, this.rotation.x, this.rotation.z, this._cameraRotationMatrix);
+        public _updatePosition():void {
+            if (this.checkCollisions && this.getScene().collisionsEnabled) {
+                this._collideWithWorld(this.cameraDirection);
+                if (this.applyGravity) {
+                    var oldPosition = this.position;
+                    this._collideWithWorld(this.getScene().gravity);
+                    this._needMoveForGravity = (BABYLON.Vector3.DistanceSquared(oldPosition, this.position) != 0);
                 }
-
-                BABYLON.Vector3.TransformCoordinatesToRef(this._referencePoint, this._cameraRotationMatrix, this._transformedReferencePoint);
-
-                // Computing target and final matrix
-                this.position.addToRef(this._transformedReferencePoint, this._currentTarget);
             } else {
-                this._currentTarget.copyFrom(this._getLockedTargetPosition());
+                this.position.addInPlace(this.cameraDirection);
             }
+        }
 
-            BABYLON.Matrix.LookAtLHToRef(this.position, this._currentTarget, this.upVector, this._viewMatrix);
-            return this._viewMatrix;
+        public _update():void {
+            this._checkInputs();
+            super._update();
         }
+
     }
 } 

+ 202 - 0
Babylon/Cameras/babylon.targetCamera.js

@@ -0,0 +1,202 @@
+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 TargetCamera = (function (_super) {
+        __extends(TargetCamera, _super);
+        function TargetCamera(name, position, scene) {
+            _super.call(this, name, position, scene);
+            this.cameraDirection = new BABYLON.Vector3(0, 0, 0);
+            this.cameraRotation = new BABYLON.Vector2(0, 0);
+            this.rotation = new BABYLON.Vector3(0, 0, 0);
+            this.speed = 2.0;
+            this.noRotationConstraint = false;
+            this.lockedTarget = null;
+            this._currentTarget = BABYLON.Vector3.Zero();
+            this._viewMatrix = BABYLON.Matrix.Zero();
+            this._camMatrix = BABYLON.Matrix.Zero();
+            this._cameraTransformMatrix = BABYLON.Matrix.Zero();
+            this._cameraRotationMatrix = BABYLON.Matrix.Zero();
+            this._referencePoint = new BABYLON.Vector3(0, 0, 1);
+            this._transformedReferencePoint = BABYLON.Vector3.Zero();
+            this._lookAtTemp = BABYLON.Matrix.Zero();
+            this._tempMatrix = BABYLON.Matrix.Zero();
+        }
+        TargetCamera.prototype._getLockedTargetPosition = function () {
+            if (!this.lockedTarget) {
+                return null;
+            }
+
+            return this.lockedTarget.position || this.lockedTarget;
+        };
+
+        // Cache
+        TargetCamera.prototype._initCache = function () {
+            _super.prototype._initCache.call(this);
+            this._cache.lockedTarget = new BABYLON.Vector3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
+            this._cache.rotation = new BABYLON.Vector3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
+        };
+
+        TargetCamera.prototype._updateCache = function (ignoreParentClass) {
+            if (!ignoreParentClass) {
+                _super.prototype._updateCache.call(this);
+            }
+
+            var lockedTargetPosition = this._getLockedTargetPosition();
+            if (!lockedTargetPosition) {
+                this._cache.lockedTarget = null;
+            } else {
+                if (!this._cache.lockedTarget) {
+                    this._cache.lockedTarget = lockedTargetPosition.clone();
+                } else {
+                    this._cache.lockedTarget.copyFrom(lockedTargetPosition);
+                }
+            }
+
+            this._cache.rotation.copyFrom(this.rotation);
+        };
+
+        // Synchronized
+        TargetCamera.prototype._isSynchronizedViewMatrix = function () {
+            if (!_super.prototype._isSynchronizedViewMatrix.call(this)) {
+                return false;
+            }
+
+            var lockedTargetPosition = this._getLockedTargetPosition();
+
+            return (this._cache.lockedTarget ? this._cache.lockedTarget.equals(lockedTargetPosition) : !lockedTargetPosition) && this._cache.rotation.equals(this.rotation);
+        };
+
+        // Methods
+        TargetCamera.prototype._computeLocalCameraSpeed = function () {
+            return this.speed * ((BABYLON.Tools.GetDeltaTime() / (BABYLON.Tools.GetFps() * 10.0)));
+        };
+
+        // Target
+        TargetCamera.prototype.setTarget = function (target) {
+            this.upVector.normalize();
+
+            BABYLON.Matrix.LookAtLHToRef(this.position, target, this.upVector, this._camMatrix);
+            this._camMatrix.invert();
+
+            this.rotation.x = Math.atan(this._camMatrix.m[6] / this._camMatrix.m[10]);
+
+            var vDir = target.subtract(this.position);
+
+            if (vDir.x >= 0.0) {
+                this.rotation.y = (-Math.atan(vDir.z / vDir.x) + Math.PI / 2.0);
+            } else {
+                this.rotation.y = (-Math.atan(vDir.z / vDir.x) - Math.PI / 2.0);
+            }
+
+            this.rotation.z = -Math.acos(BABYLON.Vector3.Dot(new BABYLON.Vector3(0, 1.0, 0), this.upVector));
+
+            if (isNaN(this.rotation.x)) {
+                this.rotation.x = 0;
+            }
+
+            if (isNaN(this.rotation.y)) {
+                this.rotation.y = 0;
+            }
+
+            if (isNaN(this.rotation.z)) {
+                this.rotation.z = 0;
+            }
+        };
+
+        TargetCamera.prototype.getTarget = function () {
+            return this._currentTarget;
+        };
+
+        TargetCamera.prototype._decideIfNeedsToMove = function () {
+            return Math.abs(this.cameraDirection.x) > 0 || Math.abs(this.cameraDirection.y) > 0 || Math.abs(this.cameraDirection.z) > 0;
+        };
+
+        TargetCamera.prototype._updatePosition = function () {
+            this.position.addInPlace(this.cameraDirection);
+        };
+        TargetCamera.prototype._update = function () {
+            var needToMove = this._decideIfNeedsToMove();
+            var needToRotate = Math.abs(this.cameraRotation.x) > 0 || Math.abs(this.cameraRotation.y) > 0;
+
+            // Move
+            if (needToMove) {
+                this._updatePosition();
+            }
+
+            // Rotate
+            if (needToRotate) {
+                this.rotation.x += this.cameraRotation.x;
+                this.rotation.y += this.cameraRotation.y;
+
+                if (!this.noRotationConstraint) {
+                    var limit = (Math.PI / 2) * 0.95;
+
+                    if (this.rotation.x > limit)
+                        this.rotation.x = limit;
+                    if (this.rotation.x < -limit)
+                        this.rotation.x = -limit;
+                }
+            }
+
+            // Inertia
+            if (needToMove) {
+                if (Math.abs(this.cameraDirection.x) < BABYLON.Engine.Epsilon) {
+                    this.cameraDirection.x = 0;
+                }
+
+                if (Math.abs(this.cameraDirection.y) < BABYLON.Engine.Epsilon) {
+                    this.cameraDirection.y = 0;
+                }
+
+                if (Math.abs(this.cameraDirection.z) < BABYLON.Engine.Epsilon) {
+                    this.cameraDirection.z = 0;
+                }
+
+                this.cameraDirection.scaleInPlace(this.inertia);
+            }
+            if (needToRotate) {
+                if (Math.abs(this.cameraRotation.x) < BABYLON.Engine.Epsilon) {
+                    this.cameraRotation.x = 0;
+                }
+
+                if (Math.abs(this.cameraRotation.y) < BABYLON.Engine.Epsilon) {
+                    this.cameraRotation.y = 0;
+                }
+                this.cameraRotation.scaleInPlace(this.inertia);
+            }
+        };
+
+        TargetCamera.prototype._getViewMatrix = function () {
+            if (!this.lockedTarget) {
+                // Compute
+                if (this.upVector.x != 0 || this.upVector.y != 1.0 || this.upVector.z != 0) {
+                    BABYLON.Matrix.LookAtLHToRef(BABYLON.Vector3.Zero(), this._referencePoint, this.upVector, this._lookAtTemp);
+                    BABYLON.Matrix.RotationYawPitchRollToRef(this.rotation.y, this.rotation.x, this.rotation.z, this._cameraRotationMatrix);
+
+                    this._lookAtTemp.multiplyToRef(this._cameraRotationMatrix, this._tempMatrix);
+                    this._lookAtTemp.invert();
+                    this._tempMatrix.multiplyToRef(this._lookAtTemp, this._cameraRotationMatrix);
+                } else {
+                    BABYLON.Matrix.RotationYawPitchRollToRef(this.rotation.y, this.rotation.x, this.rotation.z, this._cameraRotationMatrix);
+                }
+
+                BABYLON.Vector3.TransformCoordinatesToRef(this._referencePoint, this._cameraRotationMatrix, this._transformedReferencePoint);
+
+                // Computing target and final matrix
+                this.position.addToRef(this._transformedReferencePoint, this._currentTarget);
+            } else {
+                this._currentTarget.copyFrom(this._getLockedTargetPosition());
+            }
+
+            BABYLON.Matrix.LookAtLHToRef(this.position, this._currentTarget, this.upVector, this._viewMatrix);
+            return this._viewMatrix;
+        };
+        return TargetCamera;
+    })(Camera);
+    BABYLON.TargetCamera = TargetCamera;
+})(BABYLON || (BABYLON = {}));

+ 209 - 0
Babylon/Cameras/babylon.targetCamera.ts

@@ -0,0 +1,209 @@
+module BABYLON {
+    export class TargetCamera extends Camera {
+
+        public cameraDirection = new BABYLON.Vector3(0, 0, 0);
+        public cameraRotation = new BABYLON.Vector2(0, 0);
+        public rotation = new BABYLON.Vector3(0, 0, 0);
+
+        public speed = 2.0;
+        public noRotationConstraint = false;
+        public lockedTarget = null;
+
+        public _currentTarget = BABYLON.Vector3.Zero();
+        public _viewMatrix = BABYLON.Matrix.Zero();
+        public _camMatrix = BABYLON.Matrix.Zero();
+        public _cameraTransformMatrix = BABYLON.Matrix.Zero();
+        public _cameraRotationMatrix = BABYLON.Matrix.Zero();
+        public _referencePoint = new BABYLON.Vector3(0, 0, 1);
+        public _transformedReferencePoint = BABYLON.Vector3.Zero();
+        public _lookAtTemp = BABYLON.Matrix.Zero();
+        public _tempMatrix = BABYLON.Matrix.Zero();
+
+        public _reset:() => void;
+
+        public _waitingLockedTargetId:string;
+
+        constructor(name:string, position:Vector3, scene:Scene) {
+            super(name, position, scene);
+        }
+
+        public _getLockedTargetPosition():Vector3 {
+            if (!this.lockedTarget) {
+                return null;
+            }
+
+            return this.lockedTarget.position || this.lockedTarget;
+        }
+
+        // Cache
+        public _initCache() {
+            super._initCache();
+            this._cache.lockedTarget = new BABYLON.Vector3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
+            this._cache.rotation = new BABYLON.Vector3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
+        }
+
+        public _updateCache(ignoreParentClass?:boolean):void {
+            if (!ignoreParentClass) {
+                super._updateCache();
+            }
+
+            var lockedTargetPosition = this._getLockedTargetPosition();
+            if (!lockedTargetPosition) {
+                this._cache.lockedTarget = null;
+            }
+            else {
+                if (!this._cache.lockedTarget) {
+                    this._cache.lockedTarget = lockedTargetPosition.clone();
+                }
+                else {
+                    this._cache.lockedTarget.copyFrom(lockedTargetPosition);
+                }
+            }
+
+            this._cache.rotation.copyFrom(this.rotation);
+        }
+
+        // Synchronized
+        public _isSynchronizedViewMatrix():boolean {
+            if (!super._isSynchronizedViewMatrix()) {
+                return false;
+            }
+
+            var lockedTargetPosition = this._getLockedTargetPosition();
+
+            return (this._cache.lockedTarget ? this._cache.lockedTarget.equals(lockedTargetPosition) : !lockedTargetPosition)
+                && this._cache.rotation.equals(this.rotation);
+        }
+
+        // Methods
+        public _computeLocalCameraSpeed():number {
+            return this.speed * ((BABYLON.Tools.GetDeltaTime() / (BABYLON.Tools.GetFps() * 10.0)));
+        }
+
+        // Target
+        public setTarget(target:Vector3):void {
+            this.upVector.normalize();
+
+            BABYLON.Matrix.LookAtLHToRef(this.position, target, this.upVector, this._camMatrix);
+            this._camMatrix.invert();
+
+            this.rotation.x = Math.atan(this._camMatrix.m[6] / this._camMatrix.m[10]);
+
+            var vDir = target.subtract(this.position);
+
+            if (vDir.x >= 0.0) {
+                this.rotation.y = (-Math.atan(vDir.z / vDir.x) + Math.PI / 2.0);
+            } else {
+                this.rotation.y = (-Math.atan(vDir.z / vDir.x) - Math.PI / 2.0);
+            }
+
+            this.rotation.z = -Math.acos(BABYLON.Vector3.Dot(new BABYLON.Vector3(0, 1.0, 0), this.upVector));
+
+            if (isNaN(this.rotation.x)) {
+                this.rotation.x = 0;
+            }
+
+            if (isNaN(this.rotation.y)) {
+                this.rotation.y = 0;
+            }
+
+            if (isNaN(this.rotation.z)) {
+                this.rotation.z = 0;
+            }
+        }
+
+        public getTarget():Vector3 {
+            return this._currentTarget;
+        }
+
+
+        public _decideIfNeedsToMove():boolean {
+            return Math.abs(this.cameraDirection.x) > 0 || Math.abs(this.cameraDirection.y) > 0 || Math.abs(this.cameraDirection.z) > 0;
+        }
+
+        public _updatePosition():void{
+            this.position.addInPlace(this.cameraDirection);
+        }
+        public _update():void {
+            var needToMove = this._decideIfNeedsToMove();
+            var needToRotate = Math.abs(this.cameraRotation.x) > 0 || Math.abs(this.cameraRotation.y) > 0;
+
+            // Move
+            if (needToMove) {
+                this._updatePosition();
+            }
+
+            // Rotate
+            if (needToRotate) {
+                this.rotation.x += this.cameraRotation.x;
+                this.rotation.y += this.cameraRotation.y;
+
+
+                if (!this.noRotationConstraint) {
+                    var limit = (Math.PI / 2) * 0.95;
+
+
+                    if (this.rotation.x > limit)
+                        this.rotation.x = limit;
+                    if (this.rotation.x < -limit)
+                        this.rotation.x = -limit;
+                }
+            }
+
+            // Inertia
+            if (needToMove) {
+                if (Math.abs(this.cameraDirection.x) < BABYLON.Engine.Epsilon) {
+                    this.cameraDirection.x = 0;
+                }
+
+                if (Math.abs(this.cameraDirection.y) < BABYLON.Engine.Epsilon) {
+                    this.cameraDirection.y = 0;
+                }
+
+                if (Math.abs(this.cameraDirection.z) < BABYLON.Engine.Epsilon) {
+                    this.cameraDirection.z = 0;
+                }
+
+                this.cameraDirection.scaleInPlace(this.inertia);
+            }
+            if (needToRotate) {
+                if (Math.abs(this.cameraRotation.x) < BABYLON.Engine.Epsilon) {
+                    this.cameraRotation.x = 0;
+                }
+
+                if (Math.abs(this.cameraRotation.y) < BABYLON.Engine.Epsilon) {
+                    this.cameraRotation.y = 0;
+                }
+                this.cameraRotation.scaleInPlace(this.inertia);
+            }
+        }
+
+
+        public _getViewMatrix():Matrix {
+            if (!this.lockedTarget) {
+                // Compute
+                if (this.upVector.x != 0 || this.upVector.y != 1.0 || this.upVector.z != 0) {
+                    BABYLON.Matrix.LookAtLHToRef(BABYLON.Vector3.Zero(), this._referencePoint, this.upVector, this._lookAtTemp);
+                    BABYLON.Matrix.RotationYawPitchRollToRef(this.rotation.y, this.rotation.x, this.rotation.z, this._cameraRotationMatrix);
+
+
+                    this._lookAtTemp.multiplyToRef(this._cameraRotationMatrix, this._tempMatrix);
+                    this._lookAtTemp.invert();
+                    this._tempMatrix.multiplyToRef(this._lookAtTemp, this._cameraRotationMatrix);
+                } else {
+                    BABYLON.Matrix.RotationYawPitchRollToRef(this.rotation.y, this.rotation.x, this.rotation.z, this._cameraRotationMatrix);
+                }
+
+                BABYLON.Vector3.TransformCoordinatesToRef(this._referencePoint, this._cameraRotationMatrix, this._transformedReferencePoint);
+
+                // Computing target and final matrix
+                this.position.addToRef(this._transformedReferencePoint, this._currentTarget);
+            } else {
+                this._currentTarget.copyFrom(this._getLockedTargetPosition());
+            }
+
+            BABYLON.Matrix.LookAtLHToRef(this.position, this._currentTarget, this.upVector, this._viewMatrix);
+            return this._viewMatrix;
+        }
+    }
+} 

+ 1 - 2
Babylon/Physics/Plugins/babylon.oimoJSPlugin.js

@@ -1,4 +1,4 @@
-var BABYLON;
+var BABYLON;
 (function (BABYLON) {
     var OimoJSPlugin = (function () {
         function OimoJSPlugin() {
@@ -304,4 +304,3 @@
     })();
     BABYLON.OimoJSPlugin = OimoJSPlugin;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.oimoJSPlugin.js.map

+ 36 - 37
Babylon/babylon.scene.js

@@ -11,7 +11,7 @@
             this.cameraToUseForPointers = null;
             // Fog
             this.fogMode = BABYLON.Scene.FOGMODE_NONE;
-            this.fogColor = new BABYLON.Color3(0.2, 0.2, 0.3);
+            this.fogColor = new Color3(0.2, 0.2, 0.3);
             this.fogDensity = 0.1;
             this.fogStart = 0;
             this.fogEnd = 1000.0;
@@ -53,7 +53,7 @@
             // Imported meshes
             this.importedMeshesFiles = new Array();
             this._actionManagers = new Array();
-            this._meshesForIntersections = new BABYLON.SmartArray(256);
+            this._meshesForIntersections = new SmartArray(256);
             this._totalVertices = 0;
             this._activeVertices = 0;
             this._activeParticles = 0;
@@ -66,30 +66,30 @@
             this._animationRatio = 0;
             this._renderId = 0;
             this._executeWhenReadyTimeoutId = -1;
-            this._toBeDisposed = new BABYLON.SmartArray(256);
+            this._toBeDisposed = new SmartArray(256);
             this._onReadyCallbacks = new Array();
             this._pendingData = [];
             this._onBeforeRenderCallbacks = new Array();
-            this._activeMeshes = new BABYLON.SmartArray(256);
-            this._processedMaterials = new BABYLON.SmartArray(256);
-            this._renderTargets = new BABYLON.SmartArray(256);
-            this._activeParticleSystems = new BABYLON.SmartArray(256);
-            this._activeSkeletons = new BABYLON.SmartArray(32);
+            this._activeMeshes = new SmartArray(256);
+            this._processedMaterials = new SmartArray(256);
+            this._renderTargets = new SmartArray(256);
+            this._activeParticleSystems = new SmartArray(256);
+            this._activeSkeletons = new SmartArray(32);
             this._activeAnimatables = new Array();
-            this._transformMatrix = BABYLON.Matrix.Zero();
-            this._scaledPosition = BABYLON.Vector3.Zero();
-            this._scaledVelocity = BABYLON.Vector3.Zero();
+            this._transformMatrix = Matrix.Zero();
+            this._scaledPosition = Vector3.Zero();
+            this._scaledVelocity = Vector3.Zero();
             this._engine = engine;
 
             engine.scenes.push(this);
 
-            this._renderingManager = new BABYLON.RenderingManager(this);
+            this._renderingManager = new RenderingManager(this);
 
-            this.postProcessManager = new BABYLON.PostProcessManager(this);
+            this.postProcessManager = new PostProcessManager(this);
 
-            this.postProcessRenderPipelineManager = new BABYLON.PostProcessRenderPipelineManager();
+            this.postProcessRenderPipelineManager = new PostProcessRenderPipelineManager();
 
-            this._boundingBoxRenderer = new BABYLON.BoundingBoxRenderer(this);
+            this._boundingBoxRenderer = new BoundingBoxRenderer(this);
 
             this.attachControl();
         }
@@ -228,16 +228,16 @@
                     if (pickResult.pickedMesh.actionManager) {
                         switch (evt.button) {
                             case 0:
-                                pickResult.pickedMesh.actionManager.processTrigger(BABYLON.ActionManager.OnLeftPickTrigger, BABYLON.ActionEvent.CreateNew(pickResult.pickedMesh));
+                                pickResult.pickedMesh.actionManager.processTrigger(BABYLON.ActionManager.OnLeftPickTrigger, ActionEvent.CreateNew(pickResult.pickedMesh));
                                 break;
                             case 1:
-                                pickResult.pickedMesh.actionManager.processTrigger(BABYLON.ActionManager.OnCenterPickTrigger, BABYLON.ActionEvent.CreateNew(pickResult.pickedMesh));
+                                pickResult.pickedMesh.actionManager.processTrigger(BABYLON.ActionManager.OnCenterPickTrigger, ActionEvent.CreateNew(pickResult.pickedMesh));
                                 break;
                             case 2:
-                                pickResult.pickedMesh.actionManager.processTrigger(BABYLON.ActionManager.OnRightPickTrigger, BABYLON.ActionEvent.CreateNew(pickResult.pickedMesh));
+                                pickResult.pickedMesh.actionManager.processTrigger(BABYLON.ActionManager.OnRightPickTrigger, ActionEvent.CreateNew(pickResult.pickedMesh));
                                 break;
                         }
-                        pickResult.pickedMesh.actionManager.processTrigger(BABYLON.ActionManager.OnPickTrigger, BABYLON.ActionEvent.CreateNew(pickResult.pickedMesh));
+                        pickResult.pickedMesh.actionManager.processTrigger(BABYLON.ActionManager.OnPickTrigger, ActionEvent.CreateNew(pickResult.pickedMesh));
                     }
                 }
 
@@ -248,17 +248,17 @@
 
             this._onKeyDown = function (evt) {
                 if (_this.actionManager) {
-                    _this.actionManager.processTrigger(BABYLON.ActionManager.OnKeyDownTrigger, BABYLON.ActionEvent.CreateNewFromScene(_this, evt));
+                    _this.actionManager.processTrigger(BABYLON.ActionManager.OnKeyDownTrigger, ActionEvent.CreateNewFromScene(_this, evt));
                 }
             };
 
             this._onKeyUp = function (evt) {
                 if (_this.actionManager) {
-                    _this.actionManager.processTrigger(BABYLON.ActionManager.OnKeyUpTrigger, BABYLON.ActionEvent.CreateNewFromScene(_this, evt));
+                    _this.actionManager.processTrigger(BABYLON.ActionManager.OnKeyUpTrigger, ActionEvent.CreateNewFromScene(_this, evt));
                 }
             };
 
-            var eventPrefix = BABYLON.Tools.GetPointerPrefix();
+            var eventPrefix = Tools.GetPointerPrefix();
             this._engine.getRenderingCanvas().addEventListener(eventPrefix + "move", this._onPointerMove, false);
             this._engine.getRenderingCanvas().addEventListener(eventPrefix + "down", this._onPointerDown, false);
 
@@ -267,7 +267,7 @@
         };
 
         Scene.prototype.detachControl = function () {
-            var eventPrefix = BABYLON.Tools.GetPointerPrefix();
+            var eventPrefix = Tools.GetPointerPrefix();
             this._engine.getRenderingCanvas().removeEventListener(eventPrefix + "move", this._onPointerMove);
             this._engine.getRenderingCanvas().removeEventListener(eventPrefix + "down", this._onPointerDown);
 
@@ -374,7 +374,7 @@
             this.stopAnimation(target);
 
             if (!animatable) {
-                animatable = new BABYLON.Animatable(this, target, from, to, loop, speedRatio, onAnimationEnd);
+                animatable = new Animatable(this, target, from, to, loop, speedRatio, onAnimationEnd);
             }
 
             // Local animations
@@ -716,7 +716,7 @@
                 mesh._preActivate();
 
                 // Intersections
-                if (mesh.actionManager && mesh.actionManager.hasSpecificTriggers([BABYLON.ActionManager.OnIntersectionEnterTrigger, BABYLON.ActionManager.OnIntersectionExitTrigger])) {
+                if (mesh.actionManager && mesh.actionManager.hasSpecificTriggers([ActionManager.OnIntersectionEnterTrigger, ActionManager.OnIntersectionExitTrigger])) {
                     this._meshesForIntersections.pushNoDuplicate(mesh);
                 }
 
@@ -917,17 +917,17 @@
                 for (var actionIndex = 0; actionIndex < sourceMesh.actionManager.actions.length; actionIndex++) {
                     var action = sourceMesh.actionManager.actions[actionIndex];
 
-                    if (action.trigger == BABYLON.ActionManager.OnIntersectionEnterTrigger || action.trigger == BABYLON.ActionManager.OnIntersectionExitTrigger) {
+                    if (action.trigger == ActionManager.OnIntersectionEnterTrigger || action.trigger == ActionManager.OnIntersectionExitTrigger) {
                         var otherMesh = action.getTriggerParameter();
 
                         var areIntersecting = otherMesh.intersectsMesh(sourceMesh, false);
                         var currentIntersectionInProgress = sourceMesh._intersectionsInProgress.indexOf(otherMesh);
 
-                        if (areIntersecting && currentIntersectionInProgress === -1 && action.trigger == BABYLON.ActionManager.OnIntersectionEnterTrigger) {
-                            sourceMesh.actionManager.processTrigger(BABYLON.ActionManager.OnIntersectionEnterTrigger, BABYLON.ActionEvent.CreateNew(sourceMesh));
+                        if (areIntersecting && currentIntersectionInProgress === -1 && action.trigger == ActionManager.OnIntersectionEnterTrigger) {
+                            sourceMesh.actionManager.processTrigger(ActionManager.OnIntersectionEnterTrigger, ActionEvent.CreateNew(sourceMesh));
                             sourceMesh._intersectionsInProgress.push(otherMesh);
-                        } else if (!areIntersecting && currentIntersectionInProgress > -1 && action.trigger == BABYLON.ActionManager.OnIntersectionExitTrigger) {
-                            sourceMesh.actionManager.processTrigger(BABYLON.ActionManager.OnIntersectionExitTrigger, BABYLON.ActionEvent.CreateNew(sourceMesh));
+                        } else if (!areIntersecting && currentIntersectionInProgress > -1 && action.trigger == ActionManager.OnIntersectionExitTrigger) {
+                            sourceMesh.actionManager.processTrigger(ActionManager.OnIntersectionExitTrigger, ActionEvent.CreateNew(sourceMesh));
 
                             var indexOfOther = sourceMesh._intersectionsInProgress.indexOf(otherMesh);
 
@@ -953,7 +953,7 @@
 
             // Actions
             if (this.actionManager) {
-                this.actionManager.processTrigger(BABYLON.ActionManager.OnEveryFrameTrigger, null);
+                this.actionManager.processTrigger(ActionManager.OnEveryFrameTrigger, null);
             }
 
             // Before render
@@ -1143,7 +1143,7 @@
             if (typeof maxCapacity === "undefined") { maxCapacity = 64; }
             if (typeof maxDepth === "undefined") { maxDepth = 2; }
             if (!this._selectionOctree) {
-                this._selectionOctree = new BABYLON.Octree(BABYLON.Octree.CreationFuncForMeshes, maxCapacity, maxDepth);
+                this._selectionOctree = new BABYLON.Octree(Octree.CreationFuncForMeshes, maxCapacity, maxDepth);
             }
 
             var min = new BABYLON.Vector3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
@@ -1155,8 +1155,8 @@
                 var minBox = mesh.getBoundingInfo().boundingBox.minimumWorld;
                 var maxBox = mesh.getBoundingInfo().boundingBox.maximumWorld;
 
-                BABYLON.Tools.CheckExtends(minBox, min, max);
-                BABYLON.Tools.CheckExtends(maxBox, min, max);
+                Tools.CheckExtends(minBox, min, max);
+                Tools.CheckExtends(maxBox, min, max);
             }
 
             // Update octree
@@ -1250,12 +1250,12 @@
             }
 
             if (this._pointerOverMesh && this._pointerOverMesh.actionManager) {
-                this._pointerOverMesh.actionManager.processTrigger(BABYLON.ActionManager.OnPointerOutTrigger, BABYLON.ActionEvent.CreateNew(this._pointerOverMesh));
+                this._pointerOverMesh.actionManager.processTrigger(ActionManager.OnPointerOutTrigger, ActionEvent.CreateNew(this._pointerOverMesh));
             }
 
             this._pointerOverMesh = mesh;
             if (this._pointerOverMesh && this._pointerOverMesh.actionManager) {
-                this._pointerOverMesh.actionManager.processTrigger(BABYLON.ActionManager.OnPointerOverTrigger, BABYLON.ActionEvent.CreateNew(this._pointerOverMesh));
+                this._pointerOverMesh.actionManager.processTrigger(ActionManager.OnPointerOverTrigger, ActionEvent.CreateNew(this._pointerOverMesh));
             }
         };
 
@@ -1382,4 +1382,3 @@
     })();
     BABYLON.Scene = Scene;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.scene.js.map

+ 1 - 1
Tools/Gulp/package.json

@@ -9,7 +9,7 @@
     "gulp-concat": "^2.2.0",
     "gulp-filter": "^0.4.1",
     "gulp-rename": "^1.2.0",
-    "gulp-tsc": "^0.8.0",
+    "gulp-tsc": "^0.9.2",
     "gulp-uglify": "^0.3.0",
     "gulp-util": "^2.2.14",
     "through": "^2.3.4"