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

support of binary files starting with "solid " in isASCIIFile #3

Closed
wants to merge 1 commit into from

Conversation

aligator
Copy link

@aligator aligator commented May 23, 2020

There are some binary stl files which start with "solid ". This breaks the assumption that files with "solid " are always ascii files.

An example is the very popular 3DBenchy.stl from https://www.thingiverse.com/thing:763622/files

To fix this I used this method:
https://stackoverflow.com/a/7394842/353337
-> validate if the lenght field matches the actual file

I am not fully happy about my solution because it now opens the file two times.
I did this because otherwise it would be much more complicated code as the first 84 bits are already read and they would need a special treat in ascii parsing (as we cannot go "back" using the reader).

I have added a test case for this.

Edit:
by the way: as you wrote this in your readme:

Writing a slicer in Go (I hope someone does this one day)

I am trying exactly this. (But I use your lib only for stl loading as I need full control over the datatypes.)

@hschendel
Copy link
Owner

Hi,
thanks for supplying not just an issue but a PR :)
My idea for the ReadAll method was to use io.Reader so applications are not forced to open the STL from files. So I will now look into it to try to find an approach that works on the reader (and also try to remove my ugly first6 bytes construct).
My idea ist to actually look for whitespace followed by "facet" or "endsolid" to determine whether this is really an ASCII file. What do you think?

@aligator
Copy link
Author

I am not sure what's the best way.
I found some different solutions (all are referenced here: nschloe/meshio#530).
I think your suggested way should also work. It should be very unlikely that a binary file contains one of these words. and then the size of the file would not be needed as in my approach.

Another (hacky) way would be to start parsing as ASCII and as soon as it throws an error, try to parse as binary again...

@hschendel
Copy link
Owner

Hi @aligator,

I have now integrated your approach into the v1.0.4 release.
Furthermore I have added support for loading STL file contents into your own data structure, see e.g. stl.CopyFile, this might speed up ingestion of larger STL files into your slicer.

Thanks for your help. I am really happy to see GoSlice grow :)

@hschendel hschendel closed this Aug 9, 2020
@aligator
Copy link
Author

aligator commented Aug 9, 2020

Thank you 👍 will look into it tomorrow and hopefully be able to use your lib again instead of my fork.

Currently I'm a bit stuck with generating the support and also I have some other projects going on, but slowly it grows :-)

@aligator aligator deleted the better-is-ascii-check branch August 10, 2020 16:05
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

Successfully merging this pull request may close these issues.

2 participants