Переглянути джерело

attached is readonly from outside

Raanan Weber 5 роки тому
батько
коміт
57ba36768c

+ 8 - 5
src/Cameras/XR/features/WebXRAnchorSystem.ts

@@ -81,10 +81,13 @@ export class WebXRAnchorSystem implements IWebXRFeature {
      */
      */
     public onAnchorRemovedObservable: Observable<IWebXRAnchor> = new Observable();
     public onAnchorRemovedObservable: Observable<IWebXRAnchor> = new Observable();
 
 
+    private _attached: boolean = false;
     /**
     /**
-     * Set to true when attached
+     * Is this feature attached
      */
      */
-    public attached: boolean = false;
+    public get attached() {
+        return this._attached;
+    }
     private _planeDetector: WebXRPlaneDetector;
     private _planeDetector: WebXRPlaneDetector;
     private _hitTestModule: WebXRHitTestLegacy;
     private _hitTestModule: WebXRHitTestLegacy;
 
 
@@ -128,7 +131,7 @@ export class WebXRAnchorSystem implements IWebXRFeature {
     attach(): boolean {
     attach(): boolean {
         this._observerTracked = this._xrSessionManager.onXRFrameObservable.add(() => {
         this._observerTracked = this._xrSessionManager.onXRFrameObservable.add(() => {
             const frame = this._xrSessionManager.currentFrame;
             const frame = this._xrSessionManager.currentFrame;
-            if (!this.attached || !this._enabled || !frame) { return; }
+            if (!this._attached || !this._enabled || !frame) { return; }
             // const timestamp = this.xrSessionManager.currentTimestamp;
             // const timestamp = this.xrSessionManager.currentTimestamp;
 
 
             const trackedAnchors = frame.trackedAnchors;
             const trackedAnchors = frame.trackedAnchors;
@@ -166,7 +169,7 @@ export class WebXRAnchorSystem implements IWebXRFeature {
             this._xrSessionManager.session.addEventListener('select', this._onSelect, false);
             this._xrSessionManager.session.addEventListener('select', this._onSelect, false);
         }
         }
 
 
-        this.attached = true;
+        this._attached = true;
         return true;
         return true;
     }
     }
 
 
@@ -177,7 +180,7 @@ export class WebXRAnchorSystem implements IWebXRFeature {
      * @returns true if successful.
      * @returns true if successful.
      */
      */
     detach(): boolean {
     detach(): boolean {
-        this.attached = false;
+        this._attached = false;
 
 
         this._xrSessionManager.session.removeEventListener('select', this._onSelect);
         this._xrSessionManager.session.removeEventListener('select', this._onSelect);
 
 

+ 7 - 4
src/Cameras/XR/features/WebXRBackgroundRemover.ts

@@ -54,10 +54,13 @@ export class WebXRBackgroundRemover implements IWebXRFeature {
      */
      */
     public onBackgroundStateChangedObservable: Observable<boolean> = new Observable();
     public onBackgroundStateChangedObservable: Observable<boolean> = new Observable();
 
 
+    private _attached: boolean = false;
     /**
     /**
-     * Set to true when attached
+     * Is this feature attached
      */
      */
-    public attached: boolean = false;
+    public get attached() {
+        return this._attached;
+    }
 
 
     /**
     /**
      * constructs a new background remover module
      * constructs a new background remover module
@@ -81,7 +84,7 @@ export class WebXRBackgroundRemover implements IWebXRFeature {
     attach(): boolean {
     attach(): boolean {
         this._setBackgroundState(false);
         this._setBackgroundState(false);
 
 
-        this.attached = true;
+        this._attached = true;
 
 
         return true;
         return true;
     }
     }
@@ -95,7 +98,7 @@ export class WebXRBackgroundRemover implements IWebXRFeature {
     detach(): boolean {
     detach(): boolean {
         this._setBackgroundState(true);
         this._setBackgroundState(true);
 
 
-        this.attached = false;
+        this._attached = false;
 
 
         return true;
         return true;
     }
     }

+ 8 - 5
src/Cameras/XR/features/WebXRHitTestLegacy.ts

@@ -58,10 +58,13 @@ export class WebXRHitTestLegacy implements IWebXRFeature {
      */
      */
     public static readonly Version = 1;
     public static readonly Version = 1;
 
 
+    private _attached: boolean = false;
     /**
     /**
-     * Set to true when attached
+     * Is this feature attached
      */
      */
-    public attached: boolean = false;
+    public get attached() {
+        return this._attached;
+    }
 
 
     /**
     /**
      * Execute a hit test on the current running session using a select event returned from a transient input (such as touch)
      * Execute a hit test on the current running session using a select event returned from a transient input (such as touch)
@@ -137,7 +140,7 @@ export class WebXRHitTestLegacy implements IWebXRFeature {
             const mat = new Matrix();
             const mat = new Matrix();
             this._xrFrameObserver = this._xrSessionManager.onXRFrameObservable.add((frame) => {
             this._xrFrameObserver = this._xrSessionManager.onXRFrameObservable.add((frame) => {
                 // make sure we do nothing if (async) not attached
                 // make sure we do nothing if (async) not attached
-                if (!this.attached) {
+                if (!this._attached) {
                     return;
                     return;
                 }
                 }
                 let pose = frame.getViewerPose(this._xrSessionManager.referenceSpace);
                 let pose = frame.getViewerPose(this._xrSessionManager.referenceSpace);
@@ -154,7 +157,7 @@ export class WebXRHitTestLegacy implements IWebXRFeature {
                 WebXRHitTestLegacy.XRHitTestWithRay(this._xrSessionManager.session, ray, this._xrSessionManager.referenceSpace).then(this._onHitTestResults);
                 WebXRHitTestLegacy.XRHitTestWithRay(this._xrSessionManager.session, ray, this._xrSessionManager.referenceSpace).then(this._onHitTestResults);
             });
             });
         }
         }
-        this.attached = true;
+        this._attached = true;
 
 
         return true;
         return true;
     }
     }
@@ -173,7 +176,7 @@ export class WebXRHitTestLegacy implements IWebXRFeature {
             this._xrSessionManager.onXRFrameObservable.remove(this._xrFrameObserver);
             this._xrSessionManager.onXRFrameObservable.remove(this._xrFrameObserver);
             this._xrFrameObserver = null;
             this._xrFrameObserver = null;
         }
         }
-        this.attached = false;
+        this._attached = false;
         return true;
         return true;
     }
     }
 
 

+ 8 - 5
src/Cameras/XR/features/WebXRPlaneDetector.ts

@@ -74,10 +74,13 @@ export class WebXRPlaneDetector implements IWebXRFeature {
      */
      */
     public onPlaneUpdatedObservable: Observable<IWebXRPlane> = new Observable();
     public onPlaneUpdatedObservable: Observable<IWebXRPlane> = new Observable();
 
 
+    private _attached: boolean = false;
     /**
     /**
-     * Set to true when attached
+     * Is this feature attached
      */
      */
-    public attached: boolean = false;
+    public get attached() {
+        return this._attached;
+    }
     private _enabled: boolean = false;
     private _enabled: boolean = false;
     private _detectedPlanes: Array<IWebXRPlane> = [];
     private _detectedPlanes: Array<IWebXRPlane> = [];
     private _lastFrameDetected: XRPlaneSet = new Set();
     private _lastFrameDetected: XRPlaneSet = new Set();
@@ -110,7 +113,7 @@ export class WebXRPlaneDetector implements IWebXRFeature {
 
 
         this._observerTracked = this._xrSessionManager.onXRFrameObservable.add(() => {
         this._observerTracked = this._xrSessionManager.onXRFrameObservable.add(() => {
             const frame = this._xrSessionManager.currentFrame;
             const frame = this._xrSessionManager.currentFrame;
-            if (!this.attached || !this._enabled || !frame) { return; }
+            if (!this._attached || !this._enabled || !frame) { return; }
             // const timestamp = this.xrSessionManager.currentTimestamp;
             // const timestamp = this.xrSessionManager.currentTimestamp;
 
 
             const detectedPlanes = frame.worldInformation.detectedPlanes;
             const detectedPlanes = frame.worldInformation.detectedPlanes;
@@ -145,7 +148,7 @@ export class WebXRPlaneDetector implements IWebXRFeature {
             }
             }
         });
         });
 
 
-        this.attached = true;
+        this._attached = true;
         return true;
         return true;
     }
     }
 
 
@@ -156,7 +159,7 @@ export class WebXRPlaneDetector implements IWebXRFeature {
      * @returns true if successful.
      * @returns true if successful.
      */
      */
     detach(): boolean {
     detach(): boolean {
-        this.attached = false;
+        this._attached = false;
 
 
         if (this._observerTracked) {
         if (this._observerTracked) {
             this._xrSessionManager.onXRFrameObservable.remove(this._observerTracked);
             this._xrSessionManager.onXRFrameObservable.remove(this._observerTracked);

+ 12 - 4
src/Cameras/XR/features/webXRMotionControllerTeleportation.ts

@@ -53,7 +53,15 @@ export class WebXRMotionControllerTeleportation implements IWebXRFeature {
     public static readonly Version = 1;
     public static readonly Version = 1;
 
 
     private _observerTracked: Nullable<Observer<XRFrame>>;
     private _observerTracked: Nullable<Observer<XRFrame>>;
-    public attached: boolean = false;
+
+    private _attached: boolean = false;
+    /**
+     * Is this feature attached
+     */
+    public get attached() {
+        return this._attached;
+    }
+
     private _tmpRay = new Ray(new Vector3(), new Vector3());
     private _tmpRay = new Ray(new Vector3(), new Vector3());
     private _tmpVector = new Vector3();
     private _tmpVector = new Vector3();
 
 
@@ -98,7 +106,7 @@ export class WebXRMotionControllerTeleportation implements IWebXRFeature {
         this._observerTracked = this._xrSessionManager.onXRFrameObservable.add(() => {
         this._observerTracked = this._xrSessionManager.onXRFrameObservable.add(() => {
             const frame = this._xrSessionManager.currentFrame;
             const frame = this._xrSessionManager.currentFrame;
             const scene = this._xrSessionManager.scene;
             const scene = this._xrSessionManager.scene;
-            if (!this.attached || !frame) { return; }
+            if (!this._attached || !frame) { return; }
 
 
             // render target if needed
             // render target if needed
             const targetMesh = this._options.teleportationTargetMesh;
             const targetMesh = this._options.teleportationTargetMesh;
@@ -153,7 +161,7 @@ export class WebXRMotionControllerTeleportation implements IWebXRFeature {
             }
             }
         });
         });
 
 
-        this.attached = true;
+        this._attached = true;
         return true;
         return true;
     }
     }
 
 
@@ -417,7 +425,7 @@ export class WebXRMotionControllerTeleportation implements IWebXRFeature {
      * @returns true if successful.
      * @returns true if successful.
      */
      */
     detach(): boolean {
     detach(): boolean {
-        this.attached = false;
+        this._attached = false;
 
 
         if (this._observerTracked) {
         if (this._observerTracked) {
             this._xrSessionManager.onXRFrameObservable.remove(this._observerTracked);
             this._xrSessionManager.onXRFrameObservable.remove(this._observerTracked);

+ 0 - 2
src/Cameras/XR/webXRFeaturesManager.ts

@@ -238,7 +238,6 @@ export class WebXRFeaturesManager implements IDisposable {
         const feature = this._features[featureName];
         const feature = this._features[featureName];
         if (feature && feature.enabled && !feature.featureImplementation.attached) {
         if (feature && feature.enabled && !feature.featureImplementation.attached) {
             feature.featureImplementation.attach();
             feature.featureImplementation.attach();
-            feature.featureImplementation.attached = true;
         }
         }
     }
     }
 
 
@@ -250,7 +249,6 @@ export class WebXRFeaturesManager implements IDisposable {
         const feature = this._features[featureName];
         const feature = this._features[featureName];
         if (feature && feature.featureImplementation.attached) {
         if (feature && feature.featureImplementation.attached) {
             feature.featureImplementation.detach();
             feature.featureImplementation.detach();
-            feature.featureImplementation.attached = false;
         }
         }
     }
     }