David Catuhe 5 years ago
parent
commit
73e7b64c75

+ 0 - 1
loaders/src/OBJ/objFileLoader.ts

@@ -291,7 +291,6 @@ export class OBJFileLoader implements ISceneLoaderPluginAsync, ISceneLoaderPlugi
                     }
                 }
             });
-            container.removeAllFromScene();
             return container;
         });
     }

+ 0 - 1
loaders/src/STL/stlFileLoader.ts

@@ -137,7 +137,6 @@ export class STLFileLoader implements ISceneLoaderPlugin {
     public loadAssetContainer(scene: Scene, data: string, rootUrl: string, onError?: (message: string, exception?: any) => void): AssetContainer {
         var container = new AssetContainer(scene);
         this.importMesh(null, scene, data, rootUrl, container.meshes, null, null);
-        container.removeAllFromScene();
         return container;
     }
 

+ 0 - 1
loaders/src/glTF/glTFFileLoader.ts

@@ -594,7 +594,6 @@ export class GLTFFileLoader implements IDisposable, ISceneLoaderPluginAsync, ISc
                 Array.prototype.push.apply(container.animationGroups, result.animationGroups);
                 Array.prototype.push.apply(container.materials, materials);
                 Array.prototype.push.apply(container.textures, textures);
-                container.removeAllFromScene();
                 return container;
             });
         });

+ 5 - 0
src/Loading/sceneLoader.ts

@@ -901,6 +901,8 @@ export class SceneLoader {
             return null;
         }
 
+        scene._blockEntityCollection = true;
+
         const fileInfo = SceneLoader._getFileInfo(rootUrl, sceneFilename);
         if (!fileInfo) {
             return null;
@@ -914,6 +916,8 @@ export class SceneLoader {
         };
 
         var errorHandler = (message: Nullable<string>, exception?: any) => {
+            scene._blockEntityCollection = false;
+
             let errorMessage = "Unable to load assets from " + fileInfo.url + (message ? ": " + message : "");
 
             if (exception && exception.message) {
@@ -940,6 +944,7 @@ export class SceneLoader {
         } : undefined;
 
         var successHandler = (assets: AssetContainer) => {
+            scene._blockEntityCollection = false;
             if (onSuccess) {
                 try {
                     onSuccess(assets);

+ 34 - 2
src/scene.ts

@@ -152,6 +152,10 @@ export class Scene extends AbstractScene implements IAnimatable {
     /** @hidden */
     public readonly _isScene = true;
 
+    
+    /** @hidden */
+    public _blockEntityCollection = false;
+
     /**
      * Gets or sets a boolean that indicates if the scene must clear the render buffer before rendering a frame
      */
@@ -2038,7 +2042,9 @@ export class Scene extends AbstractScene implements IAnimatable {
      * @param recursive if all child meshes should also be added to the scene
      */
     public addMesh(newMesh: AbstractMesh, recursive = false) {
-        this.meshes.push(newMesh);
+        if (!this._blockEntityCollection) {
+            this.meshes.push(newMesh);
+        }
 
         newMesh._resyncLightSources();
 
@@ -2374,6 +2380,9 @@ export class Scene extends AbstractScene implements IAnimatable {
      * @param newSkeleton The skeleton to add
      */
     public addSkeleton(newSkeleton: Skeleton): void {
+        if (this._blockEntityCollection) {
+            return;
+        }
         this.skeletons.push(newSkeleton);
         this.onNewSkeletonAddedObservable.notifyObservers(newSkeleton);
     }
@@ -2383,6 +2392,9 @@ export class Scene extends AbstractScene implements IAnimatable {
      * @param newParticleSystem The particle system to add
      */
     public addParticleSystem(newParticleSystem: IParticleSystem): void {
+        if (this._blockEntityCollection) {
+            return;
+        }
         this.particleSystems.push(newParticleSystem);
     }
 
@@ -2391,6 +2403,9 @@ export class Scene extends AbstractScene implements IAnimatable {
      * @param newAnimation The animation to add
      */
     public addAnimation(newAnimation: Animation): void {
+        if (this._blockEntityCollection) {
+            return;
+        }
         this.animations.push(newAnimation);
     }
 
@@ -2399,6 +2414,9 @@ export class Scene extends AbstractScene implements IAnimatable {
      * @param newAnimationGroup The animation group to add
      */
     public addAnimationGroup(newAnimationGroup: AnimationGroup): void {
+        if (this._blockEntityCollection) {
+            return;
+        }
         this.animationGroups.push(newAnimationGroup);
     }
 
@@ -2407,6 +2425,9 @@ export class Scene extends AbstractScene implements IAnimatable {
      * @param newMultiMaterial The multi-material to add
      */
     public addMultiMaterial(newMultiMaterial: MultiMaterial): void {
+        if (this._blockEntityCollection) {
+            return;
+        }
         this.multiMaterials.push(newMultiMaterial);
     }
 
@@ -2415,7 +2436,11 @@ export class Scene extends AbstractScene implements IAnimatable {
      * @param newMaterial The material to add
      */
     public addMaterial(newMaterial: Material): void {
-        newMaterial._indexInSceneMaterialArray = this.materials.length;
+        if (this._blockEntityCollection) {
+            return;
+        }
+
+        newMaterial._indexInSceneMaterialArray = this.materials.length;        
         this.materials.push(newMaterial);
         this.onNewMaterialAddedObservable.notifyObservers(newMaterial);
     }
@@ -2425,6 +2450,9 @@ export class Scene extends AbstractScene implements IAnimatable {
      * @param newMorphTargetManager The morph target to add
      */
     public addMorphTargetManager(newMorphTargetManager: MorphTargetManager): void {
+        if (this._blockEntityCollection) {
+            return;
+        }
         this.morphTargetManagers.push(newMorphTargetManager);
     }
 
@@ -2433,6 +2461,10 @@ export class Scene extends AbstractScene implements IAnimatable {
      * @param newGeometry The geometry to add
      */
     public addGeometry(newGeometry: Geometry): void {
+        if (this._blockEntityCollection) {
+            return;
+        }
+        
         if (this.geometriesByUniqueId) {
             this.geometriesByUniqueId[newGeometry.uniqueId] = this.geometries.length;
         }