瀏覽代碼

Merge pull request #5166 from TrevorDev/pointerIdNotWorkingFirefox

startDrag will use any mouse by default as a pointerID
David Catuhe 7 年之前
父節點
當前提交
eabc05b8ed
共有 2 個文件被更改,包括 22 次插入6 次删除
  1. 1 1
      dist/preview release/what's new.md
  2. 21 5
      src/Behaviors/Mesh/babylon.pointerDragBehavior.ts

+ 1 - 1
dist/preview release/what's new.md

@@ -119,7 +119,7 @@
 - Added Video Recorder [Issue 4708](https://github.com/BabylonJS/Babylon.js/issues/4708) ([sebavan](http://www.github.com/sebavan))
 - Added support for main WebGL2 texture formats ([PeapBoy](https://github.com/NicolasBuecher))
 - Added fadeInOutBehavior and tooltipText for holographic buttons ([TrevorDev](https://github.com/TrevorDev))
-- StartDrag method added to pointerDragBehavior to simulate the start of a drag ([TrevorDev](https://github.com/TrevorDev))
+- StartDrag method added to pointerDragBehavior used to simulate the start of a drag ([TrevorDev](https://github.com/TrevorDev))
 - Added EdgesLineRenderer to address [#4919](https://github.com/BabylonJS/Babylon.js/pull/4919) ([barteq100](https://github.com/barteq100))
 - Added ```ambientTextureImpactOnAnalyticalLights``` in PBRMaterial to allow fine grained control of the AmbientTexture on the analytical diffuse light ([sebavan](http://www.github.com/sebavan))
 - BoundingBoxGizmo scalePivot field that can be used to always scale objects from the bottom ([TrevorDev](https://github.com/TrevorDev))

+ 21 - 5
src/Behaviors/Mesh/babylon.pointerDragBehavior.ts

@@ -3,6 +3,7 @@ module BABYLON {
      * A behavior that when attached to a mesh will allow the mesh to be dragged around the screen based on pointer events
      */
     export class PointerDragBehavior implements Behavior<Mesh> {
+        private static _AnyMouseID = -2;
         private _attachedNode: Mesh; 
         private _dragPlane: Mesh;
         private _scene:Scene;
@@ -159,6 +160,15 @@ module BABYLON {
                     }
                 }else if(pointerInfo.type == BABYLON.PointerEventTypes.POINTERMOVE){
                     var pointerId = (<PointerEvent>pointerInfo.event).pointerId;
+
+                    // If drag was started with anyMouseID specified, set pointerID to the next mouse that moved
+                    if(this.currentDraggingPointerID === PointerDragBehavior._AnyMouseID && pointerId !== PointerDragBehavior._AnyMouseID && (<PointerEvent>pointerInfo.event).pointerType == "mouse"){
+                        if(this._lastPointerRay[this.currentDraggingPointerID]){
+                            this._lastPointerRay[pointerId] = this._lastPointerRay[this.currentDraggingPointerID];
+                            delete this._lastPointerRay[this.currentDraggingPointerID];
+                        }
+                        this.currentDraggingPointerID = pointerId;
+                    }
                     
                     // Keep track of last pointer ray, this is used simulating the start of a drag in startDrag()
                     if(!this._lastPointerRay[pointerId]){
@@ -204,19 +214,25 @@ module BABYLON {
         private _lastPointerRay:{[key: number]: Ray} = {};
         /**
          * Simulates the start of a pointer drag event on the behavior
-         * @param pointerId pointerID of the pointer that should be simulated (Default: 1 for mouse pointer)
+         * @param pointerId pointerID of the pointer that should be simulated (Default: Any mouse pointer ID)
          * @param fromRay initial ray of the pointer to be simulated (Default: Ray from camera to attached mesh)
          * @param startPickedPoint picked point of the pointer to be simulated (Default: attached mesh position)
          */
-        public startDrag(pointerId = 1, fromRay?:Ray, startPickedPoint?:Vector3){
+        public startDrag(pointerId:number = PointerDragBehavior._AnyMouseID, fromRay?:Ray, startPickedPoint?:Vector3){
             this._startDrag(pointerId, fromRay, startPickedPoint);
-            if(this._lastPointerRay[pointerId]){
+            
+            var lastRay =  this._lastPointerRay[pointerId];
+            if(pointerId === PointerDragBehavior._AnyMouseID){
+                lastRay = this._lastPointerRay[<any>Object.keys(this._lastPointerRay)[0]];
+            }
+            
+            if(lastRay){
                 // if there was a last pointer ray drag the object there
-                this._moveDrag(this._lastPointerRay[pointerId]);
+                this._moveDrag(lastRay);
             }
         }
 
-        private _startDrag(pointerId = 1, fromRay?:Ray, startPickedPoint?:Vector3){
+        private _startDrag(pointerId:number, fromRay?:Ray, startPickedPoint?:Vector3){
             if(!this._scene.activeCamera || this.dragging || !this._attachedNode){
                 return;
             }