Browse Source

Merge pull request #5457 from TrevorDev/assetContainerDispose

assetcontainer dispose
David Catuhe 6 năm trước cách đây
mục cha
commit
a02dab8267
2 tập tin đã thay đổi với 44 bổ sung0 xóa
  1. 1 0
      dist/preview release/what's new.md
  2. 43 0
      src/babylon.assetContainer.ts

+ 1 - 0
dist/preview release/what's new.md

@@ -59,6 +59,7 @@
 - Add updateUpVectorFromRotation to target camera to allow the up vector to be computed from rotation ([TrevorDev](https://github.com/TrevorDev))
 - Added opacity texture support to `GridMaterial` ([Deltakosh](https://github.com/deltakosh))
 - Added support for deserializing morph target animations in animation groups
+- AssetContainer dispose method ([TrevorDev](https://github.com/TrevorDev))
 
 ### glTF Loader
 

+ 43 - 0
src/babylon.assetContainer.ts

@@ -125,6 +125,49 @@ module BABYLON {
             }
         }
 
+        /**
+         * Disposes all the assets in the container
+         */
+        public dispose() {
+            this.cameras.forEach((o) => {
+                o.dispose();
+            });
+            this.lights.forEach((o) => {
+                o.dispose();
+            });
+            this.meshes.forEach((o) => {
+                o.dispose();
+            });
+            this.skeletons.forEach((o) => {
+                o.dispose();
+            });
+            this.animationGroups.forEach((o) => {
+                o.dispose();
+            });
+            this.multiMaterials.forEach((o) => {
+                o.dispose();
+            });
+            this.materials.forEach((o) => {
+                o.dispose();
+            });
+            this.geometries.forEach((o) => {
+                o.dispose();
+            });
+            this.transformNodes.forEach((o) => {
+                o.dispose();
+            });
+            this.actionManagers.forEach((o) => {
+                o.dispose();
+            });
+            this.textures.forEach((o) => {
+                o.dispose();
+            });
+
+            for (let component of this.scene._serializableComponents) {
+                component.dispose();
+            }
+        }
+
         private _moveAssets<T>(sourceAssets: T[], targetAssets: T[], keepAssets: T[]): void {
             if (!sourceAssets) {
                 return;