desMaker Posted December 14, 2015 Share Posted December 14, 2015 Hello, i want to import a File with the BABYLON.SceneLoader.ImportMesh, but i don't have a URL, because the file comes form a Form. i have input form: <html> ... <input type="file" id="upload_file" name="upload" /> ... </html> and i try to import my Mesh (.babylon-File) out of the form, without uploading it.But i don't know how to import a file without a given URL. Please Help me :-) <script>... var inputElement = document.getElementById("upload_file"); inputElement.addEventListener("change", function handleFiles(event) { var fileList = this.files[0]; // The first parameter can be used to specify which mesh to import. Here we import all meshes BABYLON.SceneLoader.ImportMesh("", "", "data:" + fileList, scene, function (newMeshes) { // Set the target of the camera to the first imported mesh camera.target = newMeshes[0]; }); }, false);...</scrip> Thanks! Quote Link to comment Share on other sites More sharing options...
RaananW Posted December 14, 2015 Share Posted December 14, 2015 Hi, Look into the File API, Blob and FileReader (https://developer.mozilla.org/en-US/docs/Web/API/FileReader) , might come in handy. After you load the file and you have its content, you can use Babylon's import function to load the scene. You can see how I used a blob url to load a scene in the material loader - https://github.com/RaananW/BabylonJS-Material-Editor/blob/master/MaterialEditor/canvas/CanvasService.ts#L48 Quote Link to comment Share on other sites More sharing options...
desMaker Posted December 15, 2015 Author Share Posted December 15, 2015 Thanks, it was exactly what I was looking for! Here is my code: var inputElement = document.getElementById("input"); inputElement.addEventListener("change", function handleFiles(event) { var fileList = this.files[0]; var reader = new FileReader(); reader.addEventListener("loadend", function () { var data = reader.result; // The first parameter can be used to specify which mesh to import. Here we import all meshes BABYLON.SceneLoader.ImportMesh("", "", "data:" + data, scene, function (newMeshes) { }); }); reader.readAsText(fileList); }, false); JCPalmer 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.