Selaa lähdekoodia

make sure detach works correctly

Raanan Weber 5 vuotta sitten
vanhempi
commit
9bf7f733fd

+ 2 - 0
src/Cameras/XR/features/WebXRBackgroundRemover.ts

@@ -20,6 +20,8 @@ export interface WebXRBackgroundRemoverOptions {
 
 
 export class WebXRBackgroundRemover implements WebXRFeature {
 export class WebXRBackgroundRemover implements WebXRFeature {
 
 
+    public static Name = Name;
+
     public onBackgroundStateChanged: Observable<boolean> = new Observable();
     public onBackgroundStateChanged: Observable<boolean> = new Observable();
 
 
     constructor(private xrSessionManager: WebXRSessionManager, public readonly options: WebXRBackgroundRemoverOptions = {}) {
     constructor(private xrSessionManager: WebXRSessionManager, public readonly options: WebXRBackgroundRemoverOptions = {}) {

+ 2 - 1
src/Cameras/XR/features/index.ts

@@ -1,3 +1,4 @@
 export * from "./WebXRHitTest";
 export * from "./WebXRHitTest";
 export * from "./WebXRAnchorSystem";
 export * from "./WebXRAnchorSystem";
-export * from "./WebXRPlaneDetector";
+export * from "./WebXRPlaneDetector";
+export * from "./WebXRBackgroundRemover";

+ 15 - 11
src/Cameras/XR/webXRFeaturesManager.ts

@@ -59,16 +59,17 @@ export class WebXRFeaturesManager implements IDisposable {
         });
         });
     }
     }
 
 
-    public enableFeature(featureName: string, options: any = {}, attachIfPossible: boolean = true): WebXRFeature {
-        const feature = this.features[featureName];
+    public enableFeature(featureName: string | { Name: string }, options: any = {}, attachIfPossible: boolean = true): WebXRFeature {
+        const name = typeof featureName === 'string' ? featureName : featureName.Name;
+        const feature = this.features[name];
         if (!feature || !feature.featureImplementation) {
         if (!feature || !feature.featureImplementation) {
-            const constructFunction = WebXRFeaturesManager.ConstructFeature(featureName, this.xrSessionManager, options);
+            const constructFunction = WebXRFeaturesManager.ConstructFeature(name, this.xrSessionManager, options);
             if (!constructFunction) {
             if (!constructFunction) {
                 // report error?
                 // report error?
-                throw new Error(`feature not found - ${featureName}`);
+                throw new Error(`feature not found - ${name}`);
             }
             }
 
 
-            this.features[featureName] = {
+            this.features[name] = {
                 featureImplementation: constructFunction(),
                 featureImplementation: constructFunction(),
                 attached: false,
                 attached: false,
                 enabled: true
                 enabled: true
@@ -81,17 +82,18 @@ export class WebXRFeaturesManager implements IDisposable {
         // if session started already, request and enable
         // if session started already, request and enable
         if (this.xrSessionManager.session && !feature.attached && attachIfPossible) {
         if (this.xrSessionManager.session && !feature.attached && attachIfPossible) {
             // enable feature
             // enable feature
-            this.attachFeature(featureName);
+            this.attachFeature(name);
         }
         }
 
 
-        return this.features[featureName].featureImplementation;
+        return this.features[name].featureImplementation;
     }
     }
 
 
-    public disableFeature(featureName: string) {
-        const feature = this.features[featureName];
+    public disableFeature(featureName: string | { Name: string }) {
+        const name = typeof featureName === 'string' ? featureName : featureName.Name;
+        const feature = this.features[name];
         if (feature && feature.enabled) {
         if (feature && feature.enabled) {
             feature.enabled = false;
             feature.enabled = false;
-            this.detachFeature(featureName);
+            this.detachFeature(name);
         }
         }
     }
     }
 
 
@@ -99,13 +101,15 @@ export class WebXRFeaturesManager implements IDisposable {
         const feature = this.features[featureName];
         const feature = this.features[featureName];
         if (feature && feature.enabled && !feature.attached) {
         if (feature && feature.enabled && !feature.attached) {
             feature.featureImplementation.attach();
             feature.featureImplementation.attach();
+            feature.attached = true;
         }
         }
     }
     }
 
 
     public detachFeature(featureName: string) {
     public detachFeature(featureName: string) {
         const feature = this.features[featureName];
         const feature = this.features[featureName];
-        if (feature && !feature.attached) {
+        if (feature && feature.attached) {
             feature.featureImplementation.detach();
             feature.featureImplementation.detach();
+            feature.attached = false;
         }
         }
     }
     }