Browse Source

Merge pull request #9282 from RaananW/smallAnchorChange

[XR] Small changes to the anchor system
David Catuhe 4 years ago
parent
commit
ab73161f2c
1 changed files with 15 additions and 1 deletions
  1. 15 1
      src/XR/features/WebXRAnchorSystem.ts

+ 15 - 1
src/XR/features/WebXRAnchorSystem.ts

@@ -225,6 +225,13 @@ export class WebXRAnchorSystem extends WebXRAbstractFeature {
     }
 
     /**
+     * Get the list of anchors currently being tracked by the system
+     */
+    public get anchors(): IWebXRAnchor[] {
+        return this._trackedAnchors;
+    }
+
+    /**
      * detach this feature.
      * Will usually be called by the features manager
      *
@@ -239,6 +246,13 @@ export class WebXRAnchorSystem extends WebXRAbstractFeature {
             while (this._trackedAnchors.length) {
                 const toRemove = this._trackedAnchors.pop();
                 if (toRemove) {
+                    try {
+                        // try to natively remove it as well
+                        toRemove.remove();
+                    } catch (e) {
+                        // no-op
+                    }
+                    // as the xr frame loop is removed, we need to notify manually
                     this.onAnchorRemovedObservable.notifyObservers(toRemove);
                 }
             }
@@ -275,7 +289,7 @@ export class WebXRAnchorSystem extends WebXRAbstractFeature {
             toRemove.forEach((index) => {
                 const anchor = this._trackedAnchors.splice(index - idxTracker, 1)[0];
                 this.onAnchorRemovedObservable.notifyObservers(anchor);
-                idxTracker--;
+                idxTracker++;
             });
             // now check for new ones
             trackedAnchors.forEach((xrAnchor) => {