wolph / numpy-stl

Simple library to make working with STL files (and 3D objects in general) fast and easy.

Home Page:http://numpy-stl.readthedocs.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Parsing ASCII STL ending with "end solid" raises exception

mf-badams opened this issue · comments

Simple cube STL that ends with end solid rather than the expected endsolid: cube.stl.gz

Try to load this with:

import stl
mesh = stl.mesh.Mesh.from_file('cube.stl')

Results in the following exception:

exception (False, "b'end solid cube' should start with b'facet normal'")
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/stl/stl.py", line 71, in load
    name, data = cls._load_ascii(
  File "/usr/local/lib/python3.9/site-packages/stl/stl.py", line 237, in _load_ascii
    return name, numpy.fromiter(iterator, dtype=cls.dtype)
  File "/usr/local/lib/python3.9/site-packages/stl/stl.py", line 209, in _ascii_reader
    normals = get('facet normal')
  File "/usr/local/lib/python3.9/site-packages/stl/stl.py", line 181, in get
    raise RuntimeError(
RuntimeError: (False, "b'end solid cube' should start with b'facet normal'")

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/brady.adams/parse.py", line 3, in <module>
    mesh = stl.mesh.Mesh.from_file('cube.stl')
  File "/usr/local/lib/python3.9/site-packages/stl/stl.py", line 377, in from_file
    name, data = cls.load(
  File "/usr/local/lib/python3.9/site-packages/stl/stl.py", line 91, in load
    name, data = cls._load_binary(fh, header,
  File "/usr/local/lib/python3.9/site-packages/stl/stl.py", line 111, in _load_binary
    assert count < MAX_COUNT, ('File too large, got %d triangles which '
AssertionError: File too large, got 807415856 triangles which exceeds the maximum of 100000000

I recognize end solid does not conform to the spec for ASCII STL format, but I've seen a handful of STLs that contain this format leading me to believe some software out there is writing STLs with this invalid format. Would this project be receptive to a PR that would allow for end solid?

It's the first time I've seen it, but I've added support for it :)

Thanks @wolph!