浏览代码

Add optional predicates to WebXR laser pointer selection

Michael Smith 5 年之前
父节点
当前提交
722ce4bb36
共有 2 个文件被更改,包括 19 次插入2 次删除
  1. 3 0
      dist/preview release/what's new.md
  2. 16 2
      src/XR/features/WebXRControllerPointerSelection.ts

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

@@ -29,6 +29,9 @@
 ### Materials
 - Added the `roughness` and `albedoScaling` parameters to PBR sheen ([Popov72](https://github.com/Popov72))
 
+### WebXR
+- Added optional ray and mesh selection predicates to `WebXRControllerPointerSelection` ([Exolun](https://github.com/Exolun))
+
 ## Bugs
 
 - Fix infinite loop in `GlowLayer.unReferenceMeshFromUsingItsOwnMaterial` ([Popov72](https://github.com/Popov72)

+ 16 - 2
src/XR/features/WebXRControllerPointerSelection.ts

@@ -163,6 +163,16 @@ export class WebXRControllerPointerSelection extends WebXRAbstractFeature {
     public selectionMeshPickedColor: Color3 = new Color3(0.3, 0.3, 1.0);
 
     /**
+     * To be optionaly changed by user to define custom selection logic (after ray selection)
+     */
+    public meshSelectionPredicate: (mesh: AbstractMesh) => boolean;
+
+    /**
+     * To be optionaly changed by user to define custom ray selection
+     */
+    public raySelectionPredicate: (mesh: AbstractMesh) => boolean;
+
+    /**
      * constructs a new background remover module
      * @param _xrSessionManager the session manager for this module
      * @param _options read-only options to be used in this module
@@ -248,7 +258,7 @@ export class WebXRControllerPointerSelection extends WebXRAbstractFeature {
 
             // Every frame check collisions/input
             controllerData.xrController.getWorldPointerRayToRef(controllerData.tmpRay);
-            controllerData.pick = this._scene.pickWithRay(controllerData.tmpRay);
+            controllerData.pick = this._scene.pickWithRay(controllerData.tmpRay, this.raySelectionPredicate);
 
             const pick = controllerData.pick;
 
@@ -273,7 +283,11 @@ export class WebXRControllerPointerSelection extends WebXRAbstractFeature {
                     controllerData.selectionMesh.position.addInPlace(pickNormal.scale(deltaFighting));
                 }
                 controllerData.selectionMesh.isVisible = true && this.displaySelectionMesh;
-                controllerData.meshUnderPointer = pick.pickedMesh;
+                if (this.meshSelectionPredicate && pick.pickedMesh && this.meshSelectionPredicate(pick.pickedMesh)) {
+                    controllerData.meshUnderPointer = pick.pickedMesh;
+                } else {
+                    controllerData.meshUnderPointer = pick.pickedMesh;
+                }
             } else {
                 controllerData.selectionMesh.isVisible = false;
                 controllerData.meshUnderPointer = null;