Selaa lähdekoodia

move remove code to assetContainer class, add add* functions for arrays in scene

Trevor Baron 7 vuotta sitten
vanhempi
commit
a6cd8b5b60

+ 1 - 43
src/Loading/Plugins/babylon.babylonFileLoader.ts

@@ -951,49 +951,7 @@
                     ActionManager.Parse(parsedData.actions, null, scene);
                 }
                 
-                container.cameras.forEach((o)=>{
-                    scene.removeCamera(o);
-                });
-                container.lights.forEach((o)=>{
-                    scene.removeLight(o);
-                });
-                container.meshes.forEach((o)=>{
-                    scene.removeMesh(o);
-                });
-                container.skeletons.forEach((o)=>{
-                    scene.removeSkeleton(o);
-                });
-                container.particleSystems.forEach((o)=>{
-                    scene.removeParticleSystem(o);
-                });
-                container.particleSystems.forEach((o)=>{
-                    scene.removeParticleSystem(o);
-                });
-                container.animations.forEach((o)=>{
-                    scene.removeAnimation(o);
-                });
-                container.multiMaterials.forEach((o)=>{
-                    scene.removeMultiMaterial(o);
-                });
-                container.materials.forEach((o)=>{
-                    scene.removeMaterial(o);
-                });
-                container.morphTargetManagers.forEach((o)=>{
-                    scene.removeMorphTargetManager(o);
-                });
-                container.geometries.forEach((o)=>{
-                    scene.removeGeometry(o);
-                });
-                container.transformNodes.forEach((o)=>{
-                    scene.removeTransformNode(o);
-                });
-                container.lensFlareSystems.forEach((o)=>{
-                    scene.removeLensFlareSystem(o);
-                });
-                container.actionManagers.forEach((o)=>{
-                    scene.removeActionManager(o);
-                });
-                // TODO, do shadow generators need to be removed somehow?
+                container.removeAllFromScene();
 
                 return container;
 

+ 43 - 1
src/babylon.assetContainer.ts

@@ -26,7 +26,49 @@ module BABYLON {
             // TODO
         }
         removeAllFromScene(){
-            // TODO
+            this.cameras.forEach((o)=>{
+                this.scene.removeCamera(o);
+            });
+            this.lights.forEach((o)=>{
+                this.scene.removeLight(o);
+            });
+            this.meshes.forEach((o)=>{
+                this.scene.removeMesh(o);
+            });
+            this.skeletons.forEach((o)=>{
+                this.scene.removeSkeleton(o);
+            });
+            this.particleSystems.forEach((o)=>{
+                this.scene.removeParticleSystem(o);
+            });
+            this.particleSystems.forEach((o)=>{
+                this.scene.removeParticleSystem(o);
+            });
+            this.animations.forEach((o)=>{
+                this.scene.removeAnimation(o);
+            });
+            this.multiMaterials.forEach((o)=>{
+                this.scene.removeMultiMaterial(o);
+            });
+            this.materials.forEach((o)=>{
+                this.scene.removeMaterial(o);
+            });
+            this.morphTargetManagers.forEach((o)=>{
+                this.scene.removeMorphTargetManager(o);
+            });
+            this.geometries.forEach((o)=>{
+                this.scene.removeGeometry(o);
+            });
+            this.transformNodes.forEach((o)=>{
+                this.scene.removeTransformNode(o);
+            });
+            this.lensFlareSystems.forEach((o)=>{
+                this.scene.removeLensFlareSystem(o);
+            });
+            this.actionManagers.forEach((o)=>{
+                this.scene.removeActionManager(o);
+            });
+            // TODO, do shadow generators need to be removed somehow?
         }
     }
 }

+ 36 - 0
src/babylon.scene.ts

@@ -2385,6 +2385,42 @@
             this.onNewCameraAddedObservable.notifyObservers(newCamera);
         }
 
+        public addSkeleton(newSkeleton:Skeleton){
+            this.skeletons.push(newSkeleton)
+        }
+
+        public addParticleSystem(newParticleSystem:ParticleSystem){
+            this.particleSystems.push(newParticleSystem)
+        }
+
+        public addAnimation(newAnimation:Animation){
+            this.animations.push(newAnimation)
+        }
+
+        public addMultiMaterial(newMultiMaterial:MultiMaterial){
+            this.multiMaterials.push(newMultiMaterial)
+        }
+
+        public addMaterial(newMaterial:Material){
+            this.materials.push(newMaterial)
+        }
+
+        public addMorphTargetManager(newMorphTargetManager:MorphTargetManager){
+            this.morphTargetManagers.push(newMorphTargetManager)
+        }
+
+        public addGeometry(newGeometrie:Geometry){
+            this._geometries.push(newGeometrie)
+        }
+
+        public addLensFlareSystem(newLensFlareSystem:LensFlareSystem){
+            this.lensFlareSystems.push(newLensFlareSystem)
+        }
+
+        public addActionManager(newActionManager:ActionManager){
+            this._actionManagers.push(newActionManager)
+        }
+
         /**
          * Switch active camera
          * @param {Camera} newCamera - new active camera