Load GLB file from local drive

Hi, I need help loading glb models from the local file system through file upload…
I have searched for a lot of method and most of them did not work for me.
e.g

let file = document.getElementById('large-importer').files[0];
				var urlx = URL.createObjectURL(new Blob([file]));

				BABYLON.SceneLoader.ImportMesh("", urlx, '', scene, function(){alert(200)}, ".glb");

, I wanted to use BABYLON FilesInput, but I dont know how…
thanks for your reply

@carolhmj could you have a look into this one ?

1 Like

Sure! A good starting point would be taking a look into this discussion. The question was about STL files, but the solutions there apply to GLB as well: STL file browser - Questions - Babylon.js (babylonjs.com)

2 Likes

Thanks, this solves most of my problem…
Btw, do you know how I can load a model without extension? I want to use AssetsManager for that too, thanks.

If the provided model doesn’t have an extension, Babylon is going to try loading it as if it was a .babylon file. If you want to provide the model’s correct type, you can use the methods in SceneLoader, which accept an “pluginExtension” parameter: SceneLoader | Babylon.js Documentation (babylonjs.com)

1 Like

We could also pass the file object directly to LoadAsync method. This worked for me:

// class SceneLoader
static LoadAsync(rootUrl: string, sceneFilename?: string | File, engine?: Nullable<Engine>, onProgress?: Nullable<(event: ISceneLoaderProgressEvent) => void>, pluginExtension?: Nullable<string>): Promise<Scene>;
const file: File = fileInput.files[0]
SceneLoader.loadAsync('', file, engine)
1 Like