-
Notifications
You must be signed in to change notification settings - Fork 521
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@jscad/stl-deserializer in the browser? #1332
Comments
@tsdexter just a simple question... is this a custom website? Or just want to get the contents of an STL file via the JSCAD website? |
@z3dev it's a custom site, I want to get the |
@z3dev I would also need to load/import them via browser |
debugging it, I see that when using
|
@z3dev I added a reproduction to the issue (I'm not using the |
@z3dev nevermind, I figured it out. Just have to read the file in as a string, instead of raw. function readFileAsText(file: File): Promise<string> {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.onload = (event) => resolve(event.target?.result as string);
reader.onerror = (error) => reject(error);
reader.readAsText(file);
});
}
async function handleFilesSelect(e) {
const { acceptedFiles, fileRejections } = e.detail;
files.accepted = [...files.accepted, ...acceptedFiles];
files.rejected = [...files.rejected, ...fileRejections];
const fileText = await readFileAsText(files.accepted[0]);
const geometry = stlDeserializer.deserialize(
{ output: 'geometry', filename: files.accepted[0].name },
fileText
);
console.log({geometry}); // working
} |
Can the stl-deserializer be used in the browser? There is only a node example and the code below is not working (I have tried with multiple STLs exported from jscad and other sources)
Expected Behavior
geometry is logged in the console
Actual Behavior
Steps to Reproduce the Problem
use the below file handler on a file input and open the jscad logo
jscad.stl
exported from jscad.appreproduction: https://codesandbox.io/p/sandbox/jscad-react-js-demo-forked-hfgxh8
download and unzip attached file and then choose the unzipped
jscad.stl
in the file picker:jscad.zip
Specifications
"@jscad/stl-deserializer": "^2.1.23",
The text was updated successfully, but these errors were encountered: