فهرست منبع

another update from hololite

Trevor Baron 7 سال پیش
والد
کامیت
9dd7bc88f7
1فایلهای تغییر یافته به همراه30 افزوده شده و 19 حذف شده
  1. 30 19
      src/babylon.assetContainer.ts

+ 30 - 19
src/babylon.assetContainer.ts

@@ -1,4 +1,10 @@
 module BABYLON {
+    export class KeepAssets {
+        cameras: BABYLON.Camera[] = [];
+        meshes: BABYLON.Mesh[] = [];
+        geometries: BABYLON.Geometry[] = [];
+        materials: BABYLON.Material[] = [];
+    }
     export class AssetContainer {
         public scene: Scene;
 
@@ -116,39 +122,44 @@ module BABYLON {
             })
         }
         
-        moveAllFromScene(keepCameras?: BABYLON.Camera[]): void {
-            Array.prototype.push.apply(this.actionManagers, this.scene._actionManagers);
-            Array.prototype.push.apply(this.animations, this.scene.animations);
-
-            if (keepCameras === undefined) {
-                keepCameras = [];
-            }
-            for (let camera of this.scene.cameras) {
-                let moveCamera = true;
-                for (let keepCamera of keepCameras) {
-                    if (camera === keepCamera) {
-                        moveCamera = false;
+        private moveAssets<T>(sourceAssets: T[], targetAssets: T[], keepAssets: T[]): void {
+            for (let asset of sourceAssets) {
+                let move = true;
+                for (let keepAsset of keepAssets) {
+                    if (asset === keepAsset) {
+                        move = false;
                         break;
                     }
                 }
-
-                if (moveCamera) {
-                    this.cameras.push(camera);
+    
+                if (move) {
+                    targetAssets.push(asset);
                 }
             }
+        }
+
+        moveAllFromScene(keepAssets?: KeepAssets): void {
 
-            Array.prototype.push.apply(this.geometries, this.scene.getGeometries());
+            if (keepAssets === undefined) {
+                keepAssets = new KeepAssets();
+            }
+    
+            this.moveAssets(this.scene.cameras, this.cameras, keepAssets.cameras);
+            this.moveAssets(this.scene.meshes, this.meshes, keepAssets.meshes);
+            this.moveAssets(this.scene.getGeometries(), this.geometries, keepAssets.geometries);
+            this.moveAssets(this.scene.materials, this.materials, keepAssets.materials);
+    
+            Array.prototype.push.apply(this.actionManagers, this.scene._actionManagers);
+            Array.prototype.push.apply(this.animations, this.scene.animations);
             Array.prototype.push.apply(this.lensFlareSystems, this.scene.lensFlareSystems);
             Array.prototype.push.apply(this.lights, this.scene.lights);
-            Array.prototype.push.apply(this.materials, this.scene.materials);
-            Array.prototype.push.apply(this.meshes, this.scene.meshes);
             Array.prototype.push.apply(this.morphTargetManagers, this.scene.morphTargetManagers);
             Array.prototype.push.apply(this.multiMaterials, this.scene.multiMaterials);
             Array.prototype.push.apply(this.skeletons, this.scene.skeletons);
             Array.prototype.push.apply(this.particleSystems, this.scene.particleSystems);
             Array.prototype.push.apply(this.sounds, this.scene.mainSoundTrack.soundCollection);
             Array.prototype.push.apply(this.transformNodes, this.scene.transformNodes);
-
+    
             this.removeAllFromScene();
         }
     }