Trevor Baron 6 年 前
コミット
0ced091563

+ 12 - 1
src/Cameras/XR/babylon.webXRExperienceHelper.ts

@@ -20,7 +20,7 @@ module BABYLON {
      * Helper class used to enable XR
      * @see https://doc.babylonjs.com/how_to/webxr
      */
-    export class WebXRExperienceHelper {
+    export class WebXRExperienceHelper implements IDisposable {
         /**
          * Container which stores the xr camera and controllers as children. This can be used to move the camera/user as the camera's position is updated by the xr device
          */
@@ -117,6 +117,17 @@ module BABYLON {
             });
         }
 
+        /**
+         * Disposes of the experience helper
+         */
+        public dispose() {
+            this.camera.dispose();
+            this.container.dispose();
+            this._removeCanvas();
+            this.onStateChangedObservable.clear();
+            this._sessionManager.dispose();
+        }
+
         // create canvas used to mirror/vr xr content in fullscreen
         private _createCanvas() {
             this._removeCanvas();

+ 8 - 1
src/Cameras/XR/babylon.webXRSessionManager.ts

@@ -3,7 +3,7 @@ module BABYLON {
      * Manages an XRSession
      * @see https://doc.babylonjs.com/how_to/webxr
      */
-    export class WebXRSessionManager {
+    export class WebXRSessionManager implements IDisposable {
         /**
          * Fires every time a new xrFrame arrives which can be used to update the camera
          */
@@ -160,5 +160,12 @@ module BABYLON {
 
              return renderTargetTexture;
         }
+
+        /**
+         * Disposes of the session manager
+         */
+        public dispose() {
+            this.onXRFrameObservable.clear();
+        }
     }
 }