Pārlūkot izejas kodu

make sure no xr hit results are executed when session ended

Raanan Weber 5 gadi atpakaļ
vecāks
revīzija
04de6945af
1 mainītis faili ar 12 papildinājumiem un 8 dzēšanām
  1. 12 8
      src/XR/features/WebXRHitTest.ts

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

@@ -3,8 +3,9 @@ import { WebXRSessionManager } from '../webXRSessionManager';
 import { Observable } from '../../Misc/observable';
 import { Vector3, Matrix, Quaternion } from '../../Maths/math.vector';
 import { WebXRAbstractFeature } from './WebXRAbstractFeature';
-import { IWebXRLegacyHitTestOptions, IWebXRLegacyHitResult } from './WebXRHitTestLegacy';
+import { IWebXRLegacyHitTestOptions, IWebXRLegacyHitResult, IWebXRHitTestFeature } from './WebXRHitTestLegacy';
 import { Tools } from '../../Misc/tools';
+import { Nullable } from '../../types';
 
 /**
  * Options used for hit testing (version 2)
@@ -53,6 +54,11 @@ export interface IWebXRHitResult extends IWebXRLegacyHitResult {
      * Rotation of the hit test result
      */
     rotationQuaternion: Quaternion;
+
+    /**
+     * The native hit test result
+     */
+    xrHitResult: XRHitTestResult;
 }
 
 /**
@@ -62,13 +68,13 @@ export interface IWebXRHitResult extends IWebXRLegacyHitResult {
  *
  * Tested on chrome (mobile) 80.
  */
-export class WebXRHitTest extends WebXRAbstractFeature {
+export class WebXRHitTest extends WebXRAbstractFeature implements IWebXRHitTestFeature<IWebXRHitResult> {
     private _tmpMat: Matrix = new Matrix();
     private _tmpPos: Vector3 = new Vector3();
     private _tmpQuat: Quaternion = new Quaternion();
-    private _transientXrHitTestSource: XRTransientInputHitTestSource;
+    private _transientXrHitTestSource: Nullable<XRTransientInputHitTestSource>;
     // in XR space z-forward is negative
-    private _xrHitTestSource: XRHitTestSource;
+    private _xrHitTestSource: Nullable<XRHitTestSource>;
     private initHitTestSource = (referenceSpace: XRReferenceSpace) => {
         if (!referenceSpace) {
             return;
@@ -108,10 +114,6 @@ export class WebXRHitTest extends WebXRAbstractFeature {
      */
     public autoCloneTransformation: boolean = false;
     /**
-     * Populated with the last native XR Hit Results
-     */
-    public lastNativeXRHitResults: XRHitResult[] = [];
-    /**
      * Triggered when new babylon (transformed) hit test results are available
      */
     public onHitTestResultObservable: Observable<IWebXRHitResult[]> = new Observable();
@@ -176,10 +178,12 @@ export class WebXRHitTest extends WebXRAbstractFeature {
         }
         if (this._xrHitTestSource) {
             this._xrHitTestSource.cancel();
+            this._xrHitTestSource = null;
         }
         this._xrSessionManager.onXRReferenceSpaceChanged.removeCallback(this.initHitTestSource);
         if (this._transientXrHitTestSource) {
             this._transientXrHitTestSource.cancel();
+            this._transientXrHitTestSource = null;
         }
         return true;
     }