Explorar el Código

fire prePointerObservable with ray when using 6dof controller

Trevor Baron hace 7 años
padre
commit
fd45a47cbe
Se han modificado 3 ficheros con 39 adiciones y 4 borrados
  1. 3 3
      gui/src/3D/gui3DManager.ts
  2. 4 0
      src/Events/babylon.pointerEvents.ts
  3. 32 1
      src/babylon.scene.ts

+ 3 - 3
gui/src/3D/gui3DManager.ts

@@ -62,7 +62,7 @@ module BABYLON.GUI {
                     return;
                 }
 
-                pi.skipOnPointerObservable = this._doPicking(pi.type, pointerEvent)
+                pi.skipOnPointerObservable = this._doPicking(pi.type, pointerEvent, pi.ray)
             });
 
             // Scene
@@ -71,7 +71,7 @@ module BABYLON.GUI {
             new BABYLON.HemisphericLight("hemi", Vector3.Up(), this._utilityLayer.utilityLayerScene);
         }
 
-        private _doPicking(type: number, pointerEvent: PointerEvent): boolean {
+        private _doPicking(type: number, pointerEvent: PointerEvent, ray?:Ray): boolean {
             if (!this._utilityLayer || !this._utilityLayer.utilityLayerScene.activeCamera) {
                 return false;                
             }
@@ -80,7 +80,7 @@ module BABYLON.GUI {
             let buttonIndex = pointerEvent.button;
             var utilityScene = this._utilityLayer.utilityLayerScene;
 
-            let pickingInfo = utilityScene.pick(this._scene.pointerX, this._scene.pointerY);
+            let pickingInfo = ray ? utilityScene.pickWithRay(ray): utilityScene.pick(this._scene.pointerX, this._scene.pointerY);
             if (!pickingInfo || !pickingInfo.hit) {
                 var previousControlOver = this._lastControlOver[pointerId];
                 if (previousControlOver) {

+ 4 - 0
src/Events/babylon.pointerEvents.ts

@@ -47,6 +47,10 @@ module BABYLON {
      * Set the skipOnPointerObservable property to true if you want the engine to stop any process after this event is triggered, even not calling onPointerObservable
      */
     export class PointerInfoPre extends PointerInfoBase {
+        /**
+         * Ray from a pointer if availible (eg. 6dof controller)
+         */
+        public ray:Nullable<Ray> = null;
         constructor(type: number, event: PointerEvent | MouseWheelEvent, localX: number, localY: number) {
             super(type, event);
             this.skipOnPointerObservable = false;

+ 32 - 1
src/babylon.scene.ts

@@ -1621,6 +1621,16 @@
          */
         public simulatePointerMove(pickResult: PickingInfo, pointerEventInit?: PointerEventInit): Scene {
             let evt = new PointerEvent("pointermove", pointerEventInit);
+            // PreObservable support
+            if (this.onPrePointerObservable.hasObservers() && !this._pointerCaptures[evt.pointerId]) {
+                let type = evt.type === "mousewheel" || evt.type === "DOMMouseScroll" ? PointerEventTypes.POINTERWHEEL : PointerEventTypes.POINTERMOVE;
+                let pi = new PointerInfoPre(type, evt, this._unTranslatedPointerX, this._unTranslatedPointerY);
+                pi.ray = pickResult.ray;
+                this.onPrePointerObservable.notifyObservers(pi, type);
+                if (pi.skipOnPointerObservable) {
+                    return this;
+                }
+            }
             return this._processPointerMove(pickResult, evt);
         }
 
@@ -1691,6 +1701,16 @@
          */
         public simulatePointerDown(pickResult: PickingInfo, pointerEventInit?: PointerEventInit): Scene {
             let evt = new PointerEvent("pointerdown", pointerEventInit);
+            // PreObservable support
+            if (this.onPrePointerObservable.hasObservers()) {
+                let type = PointerEventTypes.POINTERDOWN;
+                let pi = new PointerInfoPre(type, evt, this._unTranslatedPointerX, this._unTranslatedPointerY);
+                pi.ray = pickResult.ray;
+                this.onPrePointerObservable.notifyObservers(pi, type);
+                if (pi.skipOnPointerObservable) {
+                    return this;
+                }
+            }
 
             return this._processPointerDown(pickResult, evt);
         }
@@ -1765,6 +1785,17 @@
             clickInfo.singleClick = true;
             clickInfo.ignore = true;
 
+            // PreObservable support
+            if (this.onPrePointerObservable.hasObservers()) {
+                let type = PointerEventTypes.POINTERUP;
+                let pi = new PointerInfoPre(type, evt, this._unTranslatedPointerX, this._unTranslatedPointerY);
+                pi.ray = pickResult.ray;
+                this.onPrePointerObservable.notifyObservers(pi, type);
+                if (pi.skipOnPointerObservable) {
+                    return this;
+                }
+            }
+
             return this._processPointerUp(pickResult, evt, clickInfo);
         }
 
@@ -5736,7 +5767,7 @@
          * @param fastCheck Launch a fast check only using the bounding boxes. Can be set to null
          * @returns a PickingInfo
          */
-        public pickWithRay(ray: Ray, predicate: (mesh: AbstractMesh) => boolean, fastCheck?: boolean): Nullable<PickingInfo> {
+        public pickWithRay(ray: Ray, predicate?: (mesh: AbstractMesh) => boolean, fastCheck?: boolean): Nullable<PickingInfo> {
             var result = this._internalPick(world => {
                 if (!this._pickWithRayInverseMatrix) {
                     this._pickWithRayInverseMatrix = Matrix.Identity();