Skip to content

Commit 91bffea

Browse files
committed
Adding an optional pluginExtension parameter
This way if the filename doesn't have the right extension, a user will still be able to define what plugin they want to load. If not provided and no extension is available, the default plugin will be loaded (.babylon).
1 parent 83773c9 commit 91bffea

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/Loading/babylon.sceneLoader.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,9 @@
138138
return null;
139139
}
140140

141-
private static _loadData(rootUrl: string, sceneFilename: string, scene: Scene, onSuccess: (plugin: ISceneLoaderPlugin | ISceneLoaderPluginAsync, data: any) => void, onProgress: (event: ProgressEvent) => void, onError: (message: Nullable<string>, exception?: any) => void): void {
141+
private static _loadData(rootUrl: string, sceneFilename: string, scene: Scene, onSuccess: (plugin: ISceneLoaderPlugin | ISceneLoaderPluginAsync, data: any) => void, onProgress: (event: ProgressEvent) => void, onError: (message: Nullable<string>, exception?: any) => void, pluginExtension?: string): void {
142142
var directLoad = SceneLoader._getDirectLoad(sceneFilename);
143-
var registeredPlugin = directLoad ? SceneLoader._getPluginForDirectLoad(sceneFilename) : SceneLoader._getPluginForFilename(sceneFilename);
143+
var registeredPlugin = pluginExtension ? SceneLoader._getPluginForExtension(pluginExtension) : (directLoad ? SceneLoader._getPluginForDirectLoad(sceneFilename) : SceneLoader._getPluginForFilename(sceneFilename));
144144
var plugin = registeredPlugin.plugin;
145145
var useArrayBuffer = registeredPlugin.isBinary;
146146
var database: Database;
@@ -187,7 +187,7 @@
187187
}
188188
// Loading file from disk via input file or drag'n'drop
189189
else {
190-
var fileOrString = <any> sceneFilename;
190+
var fileOrString = <any>sceneFilename;
191191

192192
if (fileOrString.name) { // File
193193
Tools.ReadFile(fileOrString, dataCallback, onProgress, useArrayBuffer);
@@ -234,7 +234,7 @@
234234
* @param onProgress a callback with a progress event for each file being loaded
235235
* @param onError a callback with the scene, a message, and possibly an exception when import fails
236236
*/
237-
public static ImportMesh(meshNames: any, rootUrl: string, sceneFilename: string, scene: Scene, onSuccess: Nullable<(meshes: AbstractMesh[], particleSystems: ParticleSystem[], skeletons: Skeleton[]) => void> = null, onProgress: Nullable<(event: ProgressEvent) => void> = null, onError: Nullable<(scene: Scene, message: string, exception?: any) => void> = null): void {
237+
public static ImportMesh(meshNames: any, rootUrl: string, sceneFilename: string, scene: Scene, onSuccess: Nullable<(meshes: AbstractMesh[], particleSystems: ParticleSystem[], skeletons: Skeleton[]) => void> = null, onProgress: Nullable<(event: ProgressEvent) => void> = null, onError: Nullable<(scene: Scene, message: string, exception?: any) => void> = null, pluginExtension?: string): void {
238238
if (sceneFilename.substr && sceneFilename.substr(0, 1) === "/") {
239239
Tools.Error("Wrong sceneFilename parameter");
240240
return;
@@ -297,7 +297,7 @@
297297
}
298298
}, progressHandler, errorHandler);
299299
}
300-
}, progressHandler, errorHandler);
300+
}, progressHandler, errorHandler, pluginExtension);
301301
}
302302

303303
/**
@@ -309,8 +309,8 @@
309309
* @param onProgress a callback with a progress event for each file being loaded
310310
* @param onError a callback with the scene, a message, and possibly an exception when import fails
311311
*/
312-
public static Load(rootUrl: string, sceneFilename: any, engine: Engine, onSuccess?: (scene: Scene) => void, onProgress?: (event: ProgressEvent) => void, onError?: (scene: Scene, message: string, exception?: any) => void): void {
313-
SceneLoader.Append(rootUrl, sceneFilename, new Scene(engine), onSuccess, onProgress, onError);
312+
public static Load(rootUrl: string, sceneFilename: any, engine: Engine, onSuccess?: (scene: Scene) => void, onProgress?: (event: ProgressEvent) => void, onError?: (scene: Scene, message: string, exception?: any) => void, pluginExtension?: string): void {
313+
SceneLoader.Append(rootUrl, sceneFilename, new Scene(engine), onSuccess, onProgress, onError, pluginExtension);
314314
}
315315

316316
/**
@@ -322,7 +322,7 @@
322322
* @param onProgress a callback with a progress event for each file being loaded
323323
* @param onError a callback with the scene, a message, and possibly an exception when import fails
324324
*/
325-
public static Append(rootUrl: string, sceneFilename: any, scene: Scene, onSuccess?: (scene: Scene) => void, onProgress?: (event: ProgressEvent) => void, onError?: (scene: Scene, message: string, exception?: any) => void): void {
325+
public static Append(rootUrl: string, sceneFilename: any, scene: Scene, onSuccess?: (scene: Scene) => void, onProgress?: (event: ProgressEvent) => void, onError?: (scene: Scene, message: string, exception?: any) => void, pluginExtension?: string): void {
326326
if (sceneFilename.substr && sceneFilename.substr(0, 1) === "/") {
327327
Tools.Error("Wrong sceneFilename parameter");
328328
return;
@@ -387,7 +387,7 @@
387387
scene.getEngine().hideLoadingUI();
388388
});
389389
}
390-
}, progressHandler, errorHandler);
390+
}, progressHandler, errorHandler, pluginExtension);
391391
}
392392
};
393393
}

0 commit comments

Comments
 (0)