瀏覽代碼

Merge branch 'master' of https://github.com/BabylonJS/Babylon.js

David `Deltakosh` Catuhe 5 年之前
父節點
當前提交
af6e9b91e7
共有 3 個文件被更改,包括 15 次插入4 次删除
  1. 1 0
      dist/preview release/what's new.md
  2. 2 1
      src/LibDeclarations/webxr.d.ts
  3. 12 3
      src/XR/features/WebXRHitTest.ts

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

@@ -168,6 +168,7 @@
 - All camera view matrices are now calculated by Babylon to support left and right handed systems ([RaananW](https://github.com/RaananW))
 - WebXR Features Manager now has the ability to check if a feature can be enabled, and set native features optional or required ([RaananW](https://github.com/RaananW))
 - Optional camera gaze mode added to the pointer selection feature ([RaananW](https://github.com/RaananW))
+- WebXR hit test can now define different entity type for the results ([#8687](https://github.com/BabylonJS/Babylon.js/issues/8687)) ([RaananW](https://github.com/RaananW))
 
 ### Collisions
 

+ 2 - 1
src/LibDeclarations/webxr.d.ts

@@ -185,7 +185,8 @@ declare class XRRay {
 
 declare enum XRHitTestTrackableType {
     "point",
-    "plane"
+    "plane",
+    "mesh"
 }
 
 interface XRHitResult {

+ 12 - 3
src/XR/features/WebXRHitTest.ts

@@ -32,6 +32,11 @@ export interface IWebXRHitTestOptions extends IWebXRLegacyHitTestOptions {
      * Instead of using viewer space for hit tests, use the reference space defined in the session manager
      */
     useReferenceSpace?: boolean;
+
+    /**
+     * Override the default entity type(s) of the hit-test result
+     */
+    entityTypes?: XRHitTestTrackableType[];
 }
 
 /**
@@ -80,15 +85,18 @@ export class WebXRHitTest extends WebXRAbstractFeature implements IWebXRHitTestF
             return;
         }
         const offsetRay = new XRRay(this.options.offsetRay || {});
-        const options: XRHitTestOptionsInit = {
+        const hitTestOptions: XRHitTestOptionsInit = {
             space: this.options.useReferenceSpace ? referenceSpace : this._xrSessionManager.viewerReferenceSpace,
             offsetRay: offsetRay,
         };
-        if (!options.space) {
+        if (this.options.entityTypes) {
+            hitTestOptions.entityTypes = this.options.entityTypes;
+        }
+        if (!hitTestOptions.space) {
             Tools.Warn("waiting for viewer reference space to initialize");
             return;
         }
-        this._xrSessionManager.session.requestHitTestSource(options).then((hitTestSource) => {
+        this._xrSessionManager.session.requestHitTestSource(hitTestOptions).then((hitTestSource) => {
             if (this._xrHitTestSource) {
                 this._xrHitTestSource.cancel();
             }
@@ -167,6 +175,7 @@ export class WebXRHitTest extends WebXRAbstractFeature implements IWebXRHitTestF
                 .requestHitTestSourceForTransientInput({
                     profile: "generic-touchscreen",
                     offsetRay,
+                    entityTypes: this.options.entityTypes
                 })
                 .then((hitSource) => {
                     this._transientXrHitTestSource = hitSource;