Skip to content
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 CLI fails to load some STL files #1365

Closed
eldanb opened this issue Oct 26, 2024 · 5 comments
Closed

jscad CLI fails to load some STL files #1365

eldanb opened this issue Oct 26, 2024 · 5 comments

Comments

@eldanb
Copy link
Contributor

eldanb commented Oct 26, 2024

When running a project through the Jscad CLI some imported STL files may file.

This may also be related to issue #1333.

It seems like registerDeserializer in registerExtensions.js registers a wrapper that loads the file using fs.readFileSync, passing utf-8 as the encoding. However if the file is binary, this may cause codepage translation to corrupt it.
Patching locally to use 'binary' as the encoding works for these STL files but obviously may cause other problems if there are importers that assume utf8....

Example project failing:

example_project.zip

CLI command invocation:

node "node_modules/@jscad/cli/cli.js" "/Users/eldan/Desktop/jscadproject" -o "/var/folders/d4/2ffmpbdn51ld1mb7_k7gj4240000gn/T/vscode-jscad-GbnSqf/output.stl"

Output:

bad triangle vertice coords/normal: 1
bad triangle vertice coords/normal: 1
bad triangle vertice coords/normal: 1
bad triangle vertice coords/normal: 1
bad triangle vertice coords/normal: 1
bad triangle vertice coords/normal: 1
bad triangle vertice coords/normal: 1
WARNING: import errors: 7 (some triangles might be misaligned or missing)
Error: point 1503 must be an array of X, Y, Z values
at /Users/eldan/dev/priv/vscode-jscad/node_modules/@jscad/modeling/src/primitives/polyhedron.js:50:41
at Array.forEach ()
at Object.polyhedron (/Users/eldan/dev/priv/vscode-jscad/node_modules/@jscad/modeling/src/primitives/polyhedron.js:49:10)
at toPolyhedron (/Users/eldan/dev/priv/vscode-jscad/node_modules/@jscad/stl-deserializer/index.js:372:21)
at elementFormatterObject (/Users/eldan/dev/priv/vscode-jscad/node_modules/@jscad/stl-deserializer/index.js:54:80)
at deserializeBinarySTL (/Users/eldan/dev/priv/vscode-jscad/node_modules/@jscad/stl-deserializer/index.js:273:11)
at deserialize (/Users/eldan/dev/priv/vscode-jscad/node_modules/@jscad/stl-deserializer/index.js:62:34)
at _require.extensions. [as .stl] (/Users/eldan/dev/priv/vscode-jscad/node_modules/@jscad/core/src/io/registerExtensions.js:20:20)
at Module.load (node:internal/modules/cjs/loader:1282:32)
at Module._load (node:internal/modules/cjs/loader:1098:12)

@eldanb
Copy link
Contributor Author

eldanb commented Oct 26, 2024

Perhaps best to load files as binary and allow the actual serializers to decode as utf-8 if they require text?

@z3dev
Copy link
Member

z3dev commented Oct 26, 2024

Perhaps best to load files as binary and allow the actual serializers to decode as utf-8 if they require text?

@eldanb thanks for the nice details.

in core/web/walkfiletree.js, STL files are treated as binary, and the deserializer actually checks for text versus binary format. So, I think that your analysis is correct.

So, if you have time then please create a PR with your change. A reference to the STL file would be nice as well.

@eldanb
Copy link
Contributor Author

eldanb commented Nov 2, 2024

Opened #1366

@z3dev
Copy link
Member

z3dev commented Nov 10, 2024

@eldanb please try the new release. If satisfied then close this issue as well.

thanks for the fixes!

@eldanb
Copy link
Contributor Author

eldanb commented Nov 10, 2024

Looks great. Thanks so much.

@eldanb eldanb closed this as completed Nov 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants