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

Cannot read binary STL file with a header that starts with "solid" #530

Closed
s1291 opened this issue Nov 22, 2019 · 3 comments · Fixed by #534
Closed

Cannot read binary STL file with a header that starts with "solid" #530

s1291 opened this issue Nov 22, 2019 · 3 comments · Fixed by #534

Comments

@s1291
Copy link
Contributor

s1291 commented Nov 22, 2019

According to wikipedia, binary STL files should never begin with "solid" because that may lead some software to assume that this is an ASCII STL file.
However, a lot of binary files start with solid (E.g. Binary stl files from SolidWorks, ..etc). Those files could be read by many software (Paraview, Blender, meshlab, ...etc).

Currently, meshio couldn't read these binary files.

Here is an example of two binary stl files (with and without header):

To solve the issue, the _read_binary function should look like:

...
  with open(filename, mode) as fh:
            header = fh.read(80)
            size, = struct.unpack('@i', fh.read(4))
            data = numpy.fromfile(fh, dtype=cls.dtype, count=size)
...

And the function read_buffer must be fixed to detect the type of the stl file (ascii or binary)

PS: numpy-stl could read both types of binary stl files(i,e: with and without header)

@nschloe
Copy link
Owner

nschloe commented Nov 22, 2019

And the function read_buffer must be fixed to detect the type of the stl file (ascii or binary)

Any idea how?

@s1291
Copy link
Contributor Author

s1291 commented Nov 22, 2019

This is discussed here:

Or we can follow the approach here

Furthermore, as pointed in this answer:

Additionally you could check for further keywords like "facet" or "vertex" to be sure it's ASCII. These words should only occur in the ASCII format (or in the useless binary header), but there is a little chance that the binary floats coincidentally form these words. So you could also check if the keywords are in the right order.

@nschloe
Copy link
Owner

nschloe commented Nov 24, 2019

Thanks for the links. The issue is fixed now and will be part of the next release.

razielgn added a commit to nablaflow/stl_io that referenced this issue Sep 26, 2023
See nschloe/meshio#530

Some binary files from Solidworks start with `solid` and have a `\n` on
the 80th byte, tricking the parser into thinking that it's ascii, not binary.
razielgn added a commit to nablaflow/stl_io that referenced this issue Sep 27, 2023
See nschloe/meshio#530

Some binary files from Solidworks start with `solid` and have a `\n` on
the 80th byte, tricking the parser into thinking that it's ascii, not binary.
razielgn added a commit to nablaflow/stl_io that referenced this issue Oct 17, 2023
See nschloe/meshio#530

Some binary files from Solidworks start with `solid` and have a `\n` on
the 80th byte, tricking the parser into thinking that it's ascii, not binary.
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 a pull request may close this issue.

2 participants