Bläddra i källkod

New ```BABYLON.Scene.cameraToUseForPointers``` property that defines this parameter if you are using multiple cameras and you want to specify which one should be used for pointer position

David Catuhe 11 år sedan
förälder
incheckning
d2bb421127

+ 3 - 3
Babylon/Cameras/babylon.freeCamera.ts

@@ -23,7 +23,7 @@
         private _viewMatrix = BABYLON.Matrix.Zero();
         private _camMatrix = BABYLON.Matrix.Zero();
         private _cameraTransformMatrix = BABYLON.Matrix.Zero();
-        private _cameraRotationMatrix = BABYLON.Matrix.Zero();
+        public _cameraRotationMatrix = BABYLON.Matrix.Zero();
         private _referencePoint = BABYLON.Vector3.Zero();
         private _transformedReferencePoint = BABYLON.Vector3.Zero();
         private _oldPosition = BABYLON.Vector3.Zero();
@@ -41,7 +41,7 @@
         private _onMouseMove: (e: MouseEvent) => any;
         private _onKeyDown: (e: KeyboardEvent) => any;
         private _onKeyUp: (e: KeyboardEvent) => any;
-        private _onLostFocus: (e: FocusEvent) => any;
+        public _onLostFocus: (e: FocusEvent) => any;
         private _reset: () => void;
 
         constructor(name: string, position: Vector3, scene: Scene) {
@@ -97,7 +97,7 @@
         }
 
         // Methods
-        private _computeLocalCameraSpeed(): number {
+        public _computeLocalCameraSpeed(): number {
             return this.speed * ((BABYLON.Tools.GetDeltaTime() / (BABYLON.Tools.GetFps() * 10.0)));
         }
 

+ 128 - 128
Babylon/Cameras/babylon.touchCamera.js

@@ -1,140 +1,140 @@
-"use strict";
-
-var BABYLON = BABYLON || {};
-
-(function () {
-    BABYLON.TouchCamera = function (name, position, scene) {
-        BABYLON.FreeCamera.call(this, name, position, scene);
-            
-        // Offset
-        this._offsetX = null;
-        this._offsetY = null;
-        this._pointerCount = 0;
-        this._pointerPressed = [];
-
-        this.angularSensibility = 200000.0;
-        this.moveSensibility = 500.0;
-    };
-
-    BABYLON.TouchCamera.prototype = Object.create(BABYLON.FreeCamera.prototype);
-
-
-    // Controls
-    BABYLON.TouchCamera.prototype.attachControl = function (canvas, noPreventDefault) {
-        var previousPosition;
-        var that = this;
-        
-        if (this._attachedCanvas) {
-            return;
+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) {
+    // We're mainly based on the logic defined into the FreeCamera code
+    var TouchCamera = (function (_super) {
+        __extends(TouchCamera, _super);
+        function TouchCamera(name, position, scene) {
+            _super.call(this, name, position, scene);
+            this._offsetX = null;
+            this._offsetY = null;
+            this._pointerCount = 0;
+            this._pointerPressed = [];
+            this.angularSensibility = 200000.0;
+            this.moveSensibility = 500.0;
         }
-        this._attachedCanvas = canvas;
-
-        if (this._onPointerDown === undefined) {
-
-            this._onPointerDown = function(evt) {
+        TouchCamera.prototype.attachControl = function (canvas, noPreventDefault) {
+            var _this = this;
+            var previousPosition;
+
+            if (this._attachedCanvas) {
+                return;
+            }
+            this._attachedCanvas = canvas;
+
+            if (this._onPointerDown === undefined) {
+                this._onPointerDown = function (evt) {
+                    if (!noPreventDefault) {
+                        evt.preventDefault();
+                    }
+
+                    _this._pointerPressed.push(evt.pointerId);
+
+                    if (_this._pointerPressed.length !== 1) {
+                        return;
+                    }
+
+                    previousPosition = {
+                        x: evt.clientX,
+                        y: evt.clientY
+                    };
+                };
 
-                if (!noPreventDefault) {
-                    evt.preventDefault();
-                }
+                this._onPointerUp = function (evt) {
+                    if (!noPreventDefault) {
+                        evt.preventDefault();
+                    }
 
-                that._pointerPressed.push(evt.pointerId);
+                    var index = _this._pointerPressed.indexOf(evt.pointerId);
 
-                if (that._pointerPressed.length !== 1) {
-                    return;
-                }
+                    if (index === -1) {
+                        return;
+                    }
+                    _this._pointerPressed.splice(index, 1);
 
-                previousPosition = {
-                    x: evt.clientX,
-                    y: evt.clientY
+                    if (index != 0) {
+                        return;
+                    }
+                    previousPosition = null;
+                    _this._offsetX = null;
+                    _this._offsetY = null;
                 };
-            };
-
-            this._onPointerUp = function(evt) {
-                if (!noPreventDefault) {
-                    evt.preventDefault();
-                }
-
-                var index = that._pointerPressed.indexOf(evt.pointerId);
-
-                if (index === -1) {
-                    return;
-                }
-                that._pointerPressed.splice(index, 1);
-
-                if (index != 0) {
-                    return;
-                }
-                previousPosition = null;
-                that._offsetX = null;
-                that._offsetY = null;
-            };
-
-            this._onPointerMove = function(evt) {
-                if (!noPreventDefault) {
-                    evt.preventDefault();
-                }
-
-                if (!previousPosition) {
-                    return;
-                }
-
-                var index = that._pointerPressed.indexOf(evt.pointerId);
-
-                if (index != 0) {
-                    return;
-                }
-
-                that._offsetX = evt.clientX - previousPosition.x;
-                that._offsetY = -(evt.clientY - previousPosition.y);
-            };
-
-            this._onLostFocus = function() {
-                that._offsetX = null;
-                that._offsetY = null;
-            };
-        }
 
-        canvas.addEventListener("pointerdown", this._onPointerDown);
-        canvas.addEventListener("pointerup", this._onPointerUp);
-        canvas.addEventListener("pointerout", this._onPointerUp);
-        canvas.addEventListener("pointermove", this._onPointerMove);
+                this._onPointerMove = function (evt) {
+                    if (!noPreventDefault) {
+                        evt.preventDefault();
+                    }
 
-        BABYLON.Tools.RegisterTopRootEvents([
-            { name: "blur", handler: this._onLostFocus }
-        ]);
-    };
+                    if (!previousPosition) {
+                        return;
+                    }
 
-    BABYLON.TouchCamera.prototype.detachControl = function (canvas) {
-        if (this._attachedCanvas != canvas) {
-            return;
-        }
+                    var index = _this._pointerPressed.indexOf(evt.pointerId);
 
-        canvas.removeEventListener("pointerdown", this._onPointerDown);
-        canvas.removeEventListener("pointerup", this._onPointerUp);
-        canvas.removeEventListener("pointerout", this._onPointerUp);
-        canvas.removeEventListener("pointermove", this._onPointerMove);
-
-        BABYLON.Tools.UnregisterTopRootEvents([
-            { name: "blur", handler: this._onLostFocus }
-        ]);
-        
-        this._attachedCanvas = null;
-    };
-    
-    BABYLON.TouchCamera.prototype._checkInputs = function () {
-        if (!this._offsetX) {
-            return;
-        }
-        this.cameraRotation.y += this._offsetX / this.angularSensibility;
+                    if (index != 0) {
+                        return;
+                    }
 
-        if (this._pointerPressed.length > 1) {
-            this.cameraRotation.x += -this._offsetY / this.angularSensibility;
-        } else {
-            var speed = this._computeLocalCameraSpeed();
-            var direction = new BABYLON.Vector3(0, 0, speed * this._offsetY / this.moveSensibility);
+                    _this._offsetX = evt.clientX - previousPosition.x;
+                    _this._offsetY = -(evt.clientY - previousPosition.y);
+                };
 
-            BABYLON.Matrix.RotationYawPitchRollToRef(this.rotation.y, this.rotation.x, 0, this._cameraRotationMatrix);
-            this.cameraDirection.addInPlace(BABYLON.Vector3.TransformCoordinates(direction, this._cameraRotationMatrix));
-        }
-    };
-})();
+                this._onLostFocus = function () {
+                    _this._offsetX = null;
+                    _this._offsetY = null;
+                };
+            }
+
+            canvas.addEventListener("pointerdown", this._onPointerDown);
+            canvas.addEventListener("pointerup", this._onPointerUp);
+            canvas.addEventListener("pointerout", this._onPointerUp);
+            canvas.addEventListener("pointermove", this._onPointerMove);
+
+            BABYLON.Tools.RegisterTopRootEvents([
+                { name: "blur", handler: this._onLostFocus }
+            ]);
+        };
+
+        TouchCamera.prototype.detachControl = function (canvas) {
+            if (this._attachedCanvas != canvas) {
+                return;
+            }
+
+            canvas.removeEventListener("pointerdown", this._onPointerDown);
+            canvas.removeEventListener("pointerup", this._onPointerUp);
+            canvas.removeEventListener("pointerout", this._onPointerUp);
+            canvas.removeEventListener("pointermove", this._onPointerMove);
+
+            BABYLON.Tools.UnregisterTopRootEvents([
+                { name: "blur", handler: this._onLostFocus }
+            ]);
+
+            this._attachedCanvas = null;
+        };
+
+        TouchCamera.prototype._checkInputs = function () {
+            if (!this._offsetX) {
+                return;
+            }
+            this.cameraRotation.y += this._offsetX / this.angularSensibility;
+
+            if (this._pointerPressed.length > 1) {
+                this.cameraRotation.x += -this._offsetY / this.angularSensibility;
+            } else {
+                var speed = this._computeLocalCameraSpeed();
+                var direction = new BABYLON.Vector3(0, 0, speed * this._offsetY / this.moveSensibility);
+
+                BABYLON.Matrix.RotationYawPitchRollToRef(this.rotation.y, this.rotation.x, 0, this._cameraRotationMatrix);
+                this.cameraDirection.addInPlace(BABYLON.Vector3.TransformCoordinates(direction, this._cameraRotationMatrix));
+            }
+        };
+        return TouchCamera;
+    })(BABYLON.FreeCamera);
+    BABYLON.TouchCamera = TouchCamera;
+})(BABYLON || (BABYLON = {}));
+//# sourceMappingURL=babylon.touchCamera.js.map

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

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

+ 3 - 0
Babylon/Mesh/babylon.abstractMesh.js

@@ -117,6 +117,9 @@ var BABYLON;
         };
 
         AbstractMesh.prototype.getBoundingInfo = function () {
+            if (!this._boundingInfo) {
+                this._updateBoundingInfo();
+            }
             return this._boundingInfo;
         };
 

+ 3 - 0
Babylon/Mesh/babylon.abstractMesh.ts

@@ -116,6 +116,9 @@
         }
 
         public getBoundingInfo(): BoundingInfo {
+            if (!this._boundingInfo) {
+                this._updateBoundingInfo();
+            }
             return this._boundingInfo;
         }
 

+ 7 - 2
Babylon/babylon.scene.js

@@ -179,6 +179,11 @@
 
             this._pointerX = evt.clientX - canvasRect.left;
             this._pointerY = evt.clientY - canvasRect.top;
+
+            if (this.cameraToUseForPointers) {
+                this._pointerX = this._pointerX - this.cameraToUseForPointers.viewport.x * this._engine.getRenderWidth();
+                this._pointerY = this._pointerY - this.cameraToUseForPointers.viewport.y * this._engine.getRenderHeight();
+            }
         };
 
         // Pointers handling
@@ -191,7 +196,7 @@
 
                 var pickResult = _this.pick(_this._pointerX, _this._pointerY, function (mesh) {
                     return mesh.isPickable && mesh.isVisible && mesh.isReady() && mesh.actionManager && mesh.actionManager.hasPointerTriggers;
-                });
+                }, false, _this.cameraToUseForPointers);
 
                 if (pickResult.hit) {
                     _this.setPointerOverMesh(pickResult.pickedMesh);
@@ -216,7 +221,7 @@
 
                 _this._updatePointerPosition(evt);
 
-                var pickResult = _this.pick(_this._pointerX, _this._pointerY, predicate);
+                var pickResult = _this.pick(_this._pointerX, _this._pointerY, predicate, false, _this.cameraToUseForPointers);
 
                 if (pickResult.hit) {
                     if (pickResult.pickedMesh.actionManager) {

+ 11 - 2
Babylon/babylon.scene.ts

@@ -29,6 +29,7 @@
         private _onPointerMove: (evt: PointerEvent) => void;
         private _onPointerDown: (evt: PointerEvent) => void;
         public onPointerDown: (evt: PointerEvent, pickInfo: PickingInfo) => void;
+        public cameraToUseForPointers: Camera; // Define this parameter if you are using multiple cameras and you want to specify which one should be sued for pointer position
         private _pointerX: number;
         private _pointerY: number;
         private _meshUnderPointer: AbstractMesh;
@@ -249,6 +250,11 @@
 
             this._pointerX = evt.clientX - canvasRect.left;
             this._pointerY = evt.clientY - canvasRect.top;
+
+            if (this.cameraToUseForPointers) {
+                this._pointerX = this._pointerX - this.cameraToUseForPointers.viewport.x * this._engine.getRenderWidth();
+                this._pointerY = this._pointerY - this.cameraToUseForPointers.viewport.y * this._engine.getRenderHeight();
+            }
         }
 
         // Pointers handling
@@ -258,7 +264,10 @@
 
                 this._updatePointerPosition(evt);
 
-                var pickResult = this.pick(this._pointerX, this._pointerY, (mesh: AbstractMesh): boolean => mesh.isPickable && mesh.isVisible && mesh.isReady() && mesh.actionManager && mesh.actionManager.hasPointerTriggers);
+                var pickResult = this.pick(this._pointerX, this._pointerY,
+                    (mesh: AbstractMesh): boolean => mesh.isPickable && mesh.isVisible && mesh.isReady() && mesh.actionManager && mesh.actionManager.hasPointerTriggers,
+                    false,
+                    this.cameraToUseForPointers);
 
                 if (pickResult.hit) {
                     this.setPointerOverMesh(pickResult.pickedMesh);
@@ -284,7 +293,7 @@
 
                 this._updatePointerPosition(evt);
 
-                var pickResult = this.pick(this._pointerX, this._pointerY, predicate);
+                var pickResult = this.pick(this._pointerX, this._pointerY, predicate, false, this.cameraToUseForPointers);
 
                 if (pickResult.hit) {
                     if (pickResult.pickedMesh.actionManager) {

Filskillnaden har hållts tillbaka eftersom den är för stor
+ 1 - 1
babylon.1.13-beta-debug.js


Filskillnaden har hållts tillbaka eftersom den är för stor
+ 5 - 5
babylon.1.13-beta.js