浏览代码

Merge pull request #3235 from brianzinn/master

add ray length and update mesh selection predicate
Trevor Baron 7 年之前
父节点
当前提交
b9204959cc
共有 2 个文件被更改,包括 27 次插入9 次删除
  1. 26 9
      src/Cameras/VR/babylon.vrExperienceHelper.ts
  2. 1 0
      src/Cameras/VR/babylon.webVRCamera.ts

+ 26 - 9
src/Cameras/VR/babylon.vrExperienceHelper.ts

@@ -35,6 +35,7 @@ module BABYLON {
         public onExitingVR: () => void;
         public onExitingVR: () => void;
         public onControllerMeshLoaded: (controller: WebVRController) => void;
         public onControllerMeshLoaded: (controller: WebVRController) => void;
 
 
+        private _rayLength: number;
         private _useCustomVRButton: boolean = false;
         private _useCustomVRButton: boolean = false;
         private _teleportationRequested: boolean = false;
         private _teleportationRequested: boolean = false;
         private _teleportationEnabledOnLeftController: boolean = false;
         private _teleportationEnabledOnLeftController: boolean = false;
@@ -62,9 +63,18 @@ module BABYLON {
         private _currentMeshSelected: Nullable<AbstractMesh>;
         private _currentMeshSelected: Nullable<AbstractMesh>;
         public onNewMeshSelected = new Observable<AbstractMesh>();
         public onNewMeshSelected = new Observable<AbstractMesh>();
 
 
-        private _meshSelectionPredicate: (mesh: AbstractMesh) => boolean;
-        public meshSelectionPredicate: (mesh: AbstractMesh) => boolean;
+        private _raySelectionPredicate: (mesh: AbstractMesh) => boolean;
+
+        /**
+         * To be optionaly changed by user to define custom ray selection
+         */
+        public raySelectionPredicate: (mesh: AbstractMesh) => boolean;
 
 
+        /**
+         * To be optionaly changed by user to define custom selection logic (after ray selection)
+         */
+        public meshSelectionPredicate: (mesh: AbstractMesh) => boolean;
+        
         private _currentHit: Nullable<PickingInfo>;
         private _currentHit: Nullable<PickingInfo>;
         private _pointerDownOnMeshAsked = false;
         private _pointerDownOnMeshAsked = false;
         private _isActionableMesh = false;
         private _isActionableMesh = false;
@@ -117,6 +127,10 @@ module BABYLON {
                         this._btnVR = webVROptions.customVRButton;
                         this._btnVR = webVROptions.customVRButton;
                     }
                     }
                 }
                 }
+
+                if (webVROptions.rayLength) {
+                    this._rayLength = webVROptions.rayLength
+                }
             }
             }
 
 
             if (!this._useCustomVRButton) {
             if (!this._useCustomVRButton) {
@@ -404,17 +418,20 @@ module BABYLON {
             this._createGazeTracker();
             this._createGazeTracker();
             this._createTeleportationCircles();
             this._createTeleportationCircles();
 
 
-            // To be optionnaly changed by user to define his custom selection logic
+            this.raySelectionPredicate = (mesh) => {
+                return true;
+            }
+
             this.meshSelectionPredicate = (mesh) => {
             this.meshSelectionPredicate = (mesh) => {
                 return true;
                 return true;
             }
             }
 
 
-            this._meshSelectionPredicate = (mesh) => {
+            this._raySelectionPredicate = (mesh) => {
                 if (mesh.name.indexOf(this._floorMeshName) !== -1 || (mesh.isVisible && mesh.name.indexOf("gazeTracker") === -1 
                 if (mesh.name.indexOf(this._floorMeshName) !== -1 || (mesh.isVisible && mesh.name.indexOf("gazeTracker") === -1 
                         && mesh.name.indexOf("teleportationCircle") === -1
                         && mesh.name.indexOf("teleportationCircle") === -1
                         && mesh.name.indexOf("torusTeleportation") === -1
                         && mesh.name.indexOf("torusTeleportation") === -1
                         && mesh.name.indexOf("laserPointer") === -1)) {
                         && mesh.name.indexOf("laserPointer") === -1)) {
-                    return true;
+                    return this.raySelectionPredicate(mesh);
                 }
                 }
                 return false;
                 return false;
             }
             }
@@ -906,18 +923,18 @@ module BABYLON {
                 (this._leftLaserPointer && !this._leftLaserPointer.isVisible && !this._rightLaserPointer) || 
                 (this._leftLaserPointer && !this._leftLaserPointer.isVisible && !this._rightLaserPointer) || 
                 (this._rightLaserPointer && !this._rightLaserPointer.isVisible && !this._leftLaserPointer) || 
                 (this._rightLaserPointer && !this._rightLaserPointer.isVisible && !this._leftLaserPointer) || 
                 (this._rightLaserPointer && this._leftLaserPointer && !this._rightLaserPointer.isVisible && !this._leftLaserPointer.isVisible)) {
                 (this._rightLaserPointer && this._leftLaserPointer && !this._rightLaserPointer.isVisible && !this._leftLaserPointer.isVisible)) {
-                    ray = this.currentVRCamera.getForwardRay();
+                    ray = this.currentVRCamera.getForwardRay(this._rayLength);
                 
                 
             } else {
             } else {
                 if (this._leftLaserPointer && this._leftLaserPointer.isVisible) {
                 if (this._leftLaserPointer && this._leftLaserPointer.isVisible) {
-                    ray = (<any>this.currentVRCamera).leftController.getForwardRay();
+                    ray = (<any>this.currentVRCamera).leftController.getForwardRay(this._rayLength);
                 }
                 }
                 else {
                 else {
-                    ray = (<any>this.currentVRCamera).rightController.getForwardRay();
+                    ray = (<any>this.currentVRCamera).rightController.getForwardRay(this._rayLength);
                 }
                 }
             }
             }
         
         
-            var hit = this._scene.pickWithRay(ray, this._meshSelectionPredicate);
+            var hit = this._scene.pickWithRay(ray, this._raySelectionPredicate);
 
 
             // Moving the gazeTracker on the mesh face targetted
             // Moving the gazeTracker on the mesh face targetted
             if (hit && hit.pickedPoint) {
             if (hit && hit.pickedPoint) {

+ 1 - 0
src/Cameras/VR/babylon.webVRCamera.ts

@@ -37,6 +37,7 @@ module BABYLON {
         defaultLightingOnControllers?: boolean; // creating a default HemiLight only on controllers
         defaultLightingOnControllers?: boolean; // creating a default HemiLight only on controllers
         useCustomVRButton?: boolean; // if you don't want to use the default VR button of the helper
         useCustomVRButton?: boolean; // if you don't want to use the default VR button of the helper
         customVRButton?: HTMLButtonElement; //if you'd like to provide your own button to the VRHelper
         customVRButton?: HTMLButtonElement; //if you'd like to provide your own button to the VRHelper
+        rayLength?: number; // to change the length of the ray for gaze/controllers.
     }
     }
 
 
     export class WebVRFreeCamera extends FreeCamera implements PoseControlled {
     export class WebVRFreeCamera extends FreeCamera implements PoseControlled {