I recommend you to check code of BabylonJS sandbox which supports model import from local file system: https://sandbox.babylonjs.com/
In this example you have two ways to import a local model to the scene:
- drag model to the canvas
- click on Upload button on the right bottom corner. File select
dialog will be opened. You can choose multiple files
View 268-291 code lines of the script used in BabylonJS sandbox (https://sandbox.babylonjs.com/index.js):
filesInput = new BABYLON.FilesInput(engine, null, sceneLoaded, null, null, null, startProcessingFiles, null, sceneError);
filesInput.onProcessFileCallback = (function(file, name, extension) {
if (filesInput._filesToLoad && filesInput._filesToLoad.length === 1 && extension) {
if (extension.toLowerCase() === "dds" || extension.toLowerCase() === "env") {
BABYLON.FilesInput.FilesToLoad[name] = file;
skyboxPath = "file:" + file.correctName;
return false;
}
}
return true;
}).bind(this);
filesInput.monitorElementForDragNDrop(canvas);
htmlInput.addEventListener('change', function(event) {
// Handling data transfer via drag'n'drop
if (event && event.dataTransfer && event.dataTransfer.files) {
filesToLoad = event.dataTransfer.files;
}
// Handling files from input files
if (event && event.target && event.target.files) {
filesToLoad = event.target.files;
}
filesInput.loadFiles(event);
}, false);
As you can see there is used a BabylonJS class FilesInput. More info about FilesInput class: https://doc.babylonjs.com/api/classes/babylon.filesinput