Procházet zdrojové kódy

Merge pull request #4334 from TrevorDev/vrPointerEvents

fire more pointer events when using 6dof controllers, comment…
David Catuhe před 7 roky
rodič
revize
052b356cfc

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

@@ -36,6 +36,7 @@
 - Support for model drag and drop onto the canvas ([RaananW](https://github.com/RaananW))
 
 ## Bug fixes
+- VR experience helper will now fire pointer events even when no mesh is currently hit ([TrevorDev](https://github.com/TrevorDev))
 
 ### Core Engine
 

+ 13 - 10
src/Cameras/VR/babylon.vrExperienceHelper.ts

@@ -83,13 +83,13 @@ module BABYLON {
 
         public _selectionPointerDown() {
             this._pointerDownOnMeshAsked = true;
-            if (this._currentMeshSelected && this._currentHit) {
+            if (this._currentHit) {
                 this.scene.simulatePointerDown(this._currentHit, {pointerId: this._id});
             }
         }
 
         public _selectionPointerUp() {
-            if (this._currentMeshSelected && this._currentHit) {
+            if (this._currentHit) {
                 this.scene.simulatePointerUp(this._currentHit, {pointerId: this._id});
             }
             this._pointerDownOnMeshAsked = false;
@@ -679,7 +679,7 @@ module BABYLON {
             //create easing functions
             this._circleEase = new CircleEase();
             this._circleEase.setEasingMode(EasingFunction.EASINGMODE_EASEINOUT);
-
+            
             if(this.webVROptions.floorMeshes){
                 this.enableTeleportation({floorMeshes: this.webVROptions.floorMeshes});
             }
@@ -1581,9 +1581,17 @@ module BABYLON {
              
             var ray = gazer._getForwardRay(this._rayLength);
             var hit = this._scene.pickWithRay(ray, this._raySelectionPredicate);
+            if(hit){
+                // Populate the contrllers mesh that can be used for drag/drop
+                if((<any>gazer)._laserPointer){
+                    hit.originMesh = (<any>gazer)._laserPointer.parent;
+                }
+                this._scene.simulatePointerMove(hit, {pointerId: gazer._id});
+            }
+            gazer._currentHit = hit;
 
             // Moving the gazeTracker on the mesh face targetted
-            if (hit && hit.pickedPoint) {
+            if (hit && hit.pickedPoint) {                
                 if (this._displayGaze) {
                     let multiplier = 1;
 
@@ -1634,12 +1642,8 @@ module BABYLON {
                 gazer._updatePointerDistance();   
                 gazer._gazeTracker.isVisible = false;
             }
-
+            
             if (hit && hit.pickedMesh) {
-                gazer._currentHit = hit;
-                if (gazer._pointerDownOnMeshAsked) {
-                    this._scene.simulatePointerMove(gazer._currentHit, {pointerId: gazer._id});
-                }
                 // The object selected is the floor, we're in a teleportation scenario
                 if (this._teleportationInitialized && this._isTeleportationFloor(hit.pickedMesh) && hit.pickedPoint) {
                     // Moving the teleportation area to this targetted point
@@ -1687,7 +1691,6 @@ module BABYLON {
                 }
             }
             else {
-                gazer._currentHit = null;
                 this._notifySelectedMeshUnselected(gazer._currentMeshSelected);
                 gazer._currentMeshSelected = null;
                 //this._teleportationAllowed = false;

+ 40 - 2
src/Collisions/babylon.pickingInfo.ts

@@ -7,18 +7,52 @@
         }
     }
 
+    /**
+     * Information about the result of picking within a scene
+     * See https://doc.babylonjs.com/babylon101/picking_collisions
+     */
     export class PickingInfo {
+        /**
+         * If the pick collided with an object
+         */
         public hit = false;
+        /**
+         * Distance away where the pick collided
+         */
         public distance = 0;
+        /**
+         * The location of pick collision
+         */
         public pickedPoint: Nullable<Vector3> = null;
+        /**
+         * The mesh corrisponding the the pick collision
+         */
         public pickedMesh: Nullable<AbstractMesh> = null;
+        /** (See getTextureCoordinates) The barycentric U coordinate that is used when calulating the texture coordinates of the collision.*/
         public bu = 0;
+        /** (See getTextureCoordinates) The barycentric V coordinate that is used when calulating the texture coordinates of the collision.*/
         public bv = 0;
+        /** The id of the face on the mesh that was picked  */
         public faceId = -1;
+        /** Id of the the submesh that was picked */
         public subMeshId = 0;
+        /** If a sprite was picked, this will be the sprite the pick collided with */
         public pickedSprite: Nullable<Sprite> = null;
-
-        // Methods
+        /**
+         * If a mesh was used to do the picking (eg. 6dof controller) this will be populated.
+         */
+        public originMesh: Nullable<AbstractMesh> = null;
+        /**
+         * The ray that was used to perform the picking.
+         */
+        public ray: Nullable<Ray> = null;
+
+        /**
+         * Gets the normal corrispodning to the face the pick collided with
+         * @param useWorldCoordinates If the resulting normal should be relative to the world (default: false)
+         * @param useVerticesNormals If the vertices normals should be used to calculate the normal instead of the normal map
+         * @returns The normal corrispodning to the face the pick collided with
+         */
         public getNormal(useWorldCoordinates = false, useVerticesNormals = true): Nullable<Vector3> {
             if (!this.pickedMesh || !this.pickedMesh.isVerticesDataPresent(VertexBuffer.NormalKind)) {
                 return null;
@@ -64,6 +98,10 @@
             return Vector3.Normalize(result);
         }
 
+        /**
+         * Gets the texture coordinates of where the pick occured
+         * @returns the vector containing the coordnates of the texture
+         */
         public getTextureCoordinates(): Nullable<Vector2> {
             if (!this.pickedMesh || !this.pickedMesh.isVerticesDataPresent(VertexBuffer.UVKind)) {
                 return null;

+ 5 - 1
src/babylon.scene.ts

@@ -5716,7 +5716,7 @@
          * @returns a PickingInfo
          */
         public pickWithRay(ray: Ray, predicate: (mesh: AbstractMesh) => boolean, fastCheck?: boolean): Nullable<PickingInfo> {
-            return this._internalPick(world => {
+            var result = this._internalPick(world => {
                 if (!this._pickWithRayInverseMatrix) {
                     this._pickWithRayInverseMatrix = Matrix.Identity();
                 }
@@ -5729,6 +5729,10 @@
                 Ray.TransformToRef(ray, this._pickWithRayInverseMatrix, this._cachedRayForTransform);
                 return this._cachedRayForTransform;
             }, predicate, fastCheck);
+            if(result){
+                result.ray = ray;
+            }
+            return result;
         }
 
         /**