0x00019913 / meshy

Slicing, measurements, transformations, and visualizations on polygon meshes.
https://0x00019913.github.io/meshy/
MIT License
96 stars 30 forks source link

Can we dynamically upload a stl file from the localstorage? #2

Closed RASHMI232 closed 6 years ago

RASHMI232 commented 6 years ago

Import button is used to get stl from user input. Can we remove the button and dynamically fetch a particular stl file from local storage path and continue with meshy display.

gitsmile93 commented 6 years ago

Yeah...i had the same question, Can we automate the process of fetching the file from a stored path without having to manually import? And show "Thickness issues" if any in red(below threshold-without having to click on view thickness, but show printability issues then & there)

0x00019913 commented 6 years ago

If I understand correctly, you want to programmatically import, check for printability issues, and delete meshes?

It should be possible, but, because I don't know how much of my code you're using, I can only explain how things work in meshy. (I'll rework this architecture later, but this is how things are now.)

First, there's a Stage object (stage.js) that handles the user interface. When the user tries to import a mesh, the Stage creates a Model object (model.js) that actually does the importing and handles the geometry until it's deleted. When you press the import button, this happens:

  1. Stage calls the .click() method on a hidden HTML input element.
  2. This brings up the file selection dialogue. The user selects a file and accepts.
  3. This invokes the input element's onchange handler, which calls Stage's handleFile method - its argument is a Javascript File object.
  4. This invokes the Model object's importer, which does the importing.

I'm using this roundabout method because we need that input element to give us the dialogue to find the file; after it returns the file, we import it.

So, to bypass the import button, you just need to create a File object based on the file you want to import, then call Stage's handleFile with that file as an argument. How do you create the File object? By using your own input element if you're not using mine. Just look at stage.js, the code's pretty simple.

If you're not using my Stage code at all (I presume you're using model.js), then you can call Model's import function with that file. It also takes a callback.

RASHMI232 commented 6 years ago

Thank u for replying... Sir, Im changing code in stage.js where var fileInput = document.createElement("input"); its taking input from user then calling handleFile(). I tried changing userinput to file Object where I pass file from local storage. But since Im new to javascript.. I had been said from experienced people that we cant get files from localStorage, For security reasons we cant fetch file using javascript, it has to be taken from user. Sir, is it right or we can fetch using js.. Please help me out with this, it would be great suggestion to proceed with next step.

0x00019913 commented 6 years ago

I think that's pretty much the full story. If you have some Javascript running in your browser, you don't want it accessing files on your computer without your approval, so you need the user to manually select the necessary files. I've been using vanilla Javascript, so I haven't touched Node in a long time, but I believe Node's File System module allows you to do this. Or maybe not, you'll have to check.

Moreover, is that actually an issue? Under what circumstances would your service want to fetch files without being told to do so by the user? The input element even allows you to select multiple files, so I assume that's all you need.

For saving, meshy just dumps the exported file in the default download directory. As far as I know, it's not common for web apps to allow saving to a specific directory. There's this thing, but you'll have to see for yourself if it works.