浏览代码

add loadAssets to other plugins

Trevor Baron 7 年之前
父节点
当前提交
56a51f99a8

+ 14 - 0
loaders/src/OBJ/babylon.objFileLoader.ts

@@ -264,6 +264,20 @@ module BABYLON {
             return this.importMesh(null, scene, data, rootUrl, null, null, null);
         }
 
+        public loadAssets(scene: Scene, data: string, rootUrl: string, onError?: (message: string, exception?: any) => void):Nullable<AssetContainer>{
+            var container = new AssetContainer(scene);
+            var result = this.importMesh(null, scene, data, rootUrl, container.meshes, null, null);
+            if(result){
+                container.removeAllFromScene();
+                return container;
+            }
+            return null;
+        }
+
+        public loadAssetContainer(){
+
+        }
+
         /**
          * Read the OBJ file and create an Array of meshes.
          * Each mesh contains all information given by the OBJ and the MTL file.

+ 10 - 0
loaders/src/STL/babylon.stlFileLoader.ts

@@ -86,6 +86,16 @@ module BABYLON {
             return result;
         }
 
+        public loadAssets(scene: Scene, data: string, rootUrl: string, onError?: (message: string, exception?: any) => void):Nullable<AssetContainer>{
+            var container = new AssetContainer(scene);
+            var result = this.importMesh(null, scene, data, rootUrl, container.meshes, null, null);
+            if(result){
+                container.removeAllFromScene();
+                return container;
+            }
+            return null;
+        }
+
         private isBinary (data: any) {
 
             // check if file size is correct for binary stl

+ 23 - 0
loaders/src/glTF/babylon.glTFFileLoader.ts

@@ -239,6 +239,29 @@ module BABYLON {
             }
         }
 
+        public loadAssetsAsync(scene: Scene, data: string | ArrayBuffer, rootUrl: string, onSuccess: (assets:AssetContainer) => void, onProgress?: (event: SceneLoaderProgressEvent) => void, onError?: (message: string, exception?: any) => void): void {
+            try {
+                const loaderData = this._parse(data);
+                this._loader = this._getLoader(loaderData);
+                this._loader.importMeshAsync(null, scene, loaderData, rootUrl,  (meshes: AbstractMesh[], particleSystems: ParticleSystem[], skeletons: Skeleton[]) => {
+                    var container = new AssetContainer(scene);
+                    container.meshes.concat(meshes)
+                    container.particleSystems.concat(particleSystems)
+                    container.skeletons.concat(skeletons)
+                    container.removeAllFromScene();
+                    onSuccess(container)
+                }, onProgress, onError);
+            }
+            catch (e) {
+                if (onError) {
+                    onError(e.message, e);
+                }
+                else {
+                    Tools.Error(e.message);
+                }
+            }
+        }
+
         public canDirectLoad(data: string): boolean {
             return ((data.indexOf("scene") !== -1) && (data.indexOf("node") !== -1));
         }