소스 검색

Merge pull request #8900 from RaananW/hitTestWhenNoResults

[XR] Hit Test results can be an empty array
sebavan 5 년 전
부모
커밋
7f216c1a12
2개의 변경된 파일7개의 추가작업 그리고 10개의 파일을 삭제
  1. 2 0
      dist/preview release/what's new.md
  2. 5 10
      src/XR/features/WebXRHitTest.ts

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

@@ -183,6 +183,8 @@
 - Expose the overlay to which the XR Enter/Exit buttons are added to ([#8754](https://github.com/BabylonJS/Babylon.js/issues/8754)) ([RaananW](https://github.com/RaananW))
 - WebXR hand-tracking module is available, able to track hand-joints on selected devices including optional physics interactions ([RaananW](https://github.com/RaananW))
 - Fixed an issue with moving backwards in XR ([#8854](https://github.com/BabylonJS/Babylon.js/issues/8854)) ([RaananW](https://github.com/RaananW))
+- Hit-Test results can be an empty array ([#8887](https://github.com/BabylonJS/Babylon.js/issues/8887)) ([RaananW](https://github.com/RaananW))
+
 ### Collisions
 
 - Added an option to optimize collision detection performance ([jsdream](https://github.com/jsdream)) - [PR](https://github.com/BabylonJS/Babylon.js/pull/7810)

+ 5 - 10
src/XR/features/WebXRHitTest.ts

@@ -123,6 +123,7 @@ export class WebXRHitTest extends WebXRAbstractFeature implements IWebXRHitTestF
     public autoCloneTransformation: boolean = false;
     /**
      * Triggered when new babylon (transformed) hit test results are available
+     * Note - this will be called when results come back from the device. It can be an empty array!!
      */
     public onHitTestResultObservable: Observable<IWebXRHitResult[]> = new Observable();
     /**
@@ -175,7 +176,7 @@ export class WebXRHitTest extends WebXRAbstractFeature implements IWebXRHitTestF
                 .requestHitTestSourceForTransientInput({
                     profile: "generic-touchscreen",
                     offsetRay,
-                    entityTypes: this.options.entityTypes
+                    entityTypes: this.options.entityTypes,
                 })
                 .then((hitSource) => {
                     this._transientXrHitTestSource = hitSource;
@@ -223,17 +224,13 @@ export class WebXRHitTest extends WebXRAbstractFeature implements IWebXRHitTestF
 
         if (this._xrHitTestSource) {
             const results = frame.getHitTestResults(this._xrHitTestSource);
-            if (results.length) {
-                this._processWebXRHitTestResult(results);
-            }
+            this._processWebXRHitTestResult(results);
         }
         if (this._transientXrHitTestSource) {
             let hitTestResultsPerInputSource = frame.getHitTestResultsForTransientInput(this._transientXrHitTestSource);
 
             hitTestResultsPerInputSource.forEach((resultsPerInputSource) => {
-                if (resultsPerInputSource.results.length > 0) {
-                    this._processWebXRHitTestResult(resultsPerInputSource.results, resultsPerInputSource.inputSource);
-                }
+                this._processWebXRHitTestResult(resultsPerInputSource.results, resultsPerInputSource.inputSource);
             });
         }
     }
@@ -268,9 +265,7 @@ export class WebXRHitTest extends WebXRAbstractFeature implements IWebXRHitTestF
             results.push(result);
         });
 
-        if (results.length) {
-            this.onHitTestResultObservable.notifyObservers(results);
-        }
+        this.onHitTestResultObservable.notifyObservers(results);
     }
 }