ChristophSchranz / Tweaker-3

A performant auto-rotate software for objects in 3D Printing, whose parameter are trained by an evolutionary algorithm.
GNU General Public License v3.0
91 stars 25 forks source link

Chokes on binary STL #2

Closed stuartpb closed 5 years ago

stuartpb commented 5 years ago

I tried running python Tweaker.py -i gauntlet.stl -x -p -r with this file and I got this error:

Traceback (most recent call last):
  File "/home/stuart/Downloads/Tweaker-3/FileHandler.py", line 26, in load_mesh
    objs = self.load_ascii_stl(f)
  File "/home/stuart/Downloads/Tweaker-3/FileHandler.py", line 72, in load_ascii_stl
    for line in f:
  File "/usr/lib/python3.7/codecs.py", line 322, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x9e in position 81: invalid start byte

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "Tweaker.py", line 120, in <module>
    objs = FileHandler.load_mesh(args.inputfile)
  File "/home/stuart/Downloads/Tweaker-3/FileHandler.py", line 30, in load_mesh
    objs = self.load_binary_stl(f)
  File "/home/stuart/Downloads/Tweaker-3/FileHandler.py", line 91, in load_binary_stl
    f.read(80-5)
  File "/usr/lib/python3.7/codecs.py", line 322, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x9e in position 76: invalid start byte
ChristophSchranz commented 5 years ago

Thank you for the detailed description of the issue. I could reproduce the issue and think it's a file issue. I've imported it into Cura (3.4.0) and I could autorotate it via the autorotation plugin and when I exported the same model from Cura into a binary STL, then i was also able to autorotate it.

python3 Tweaker.py -i UM2_gauntlet.stl

Do you know from which software this file origins?

Please try also to import and save the file again with your slicing program.

ChristophSchranz commented 5 years ago

As it seems that the issue is caused by a corrupt binary STL format, I close this issue. If there is any problem in the tweaker, please re-open it.

jkotowicz1 commented 3 years ago

I stumbled on this and it seems like it's a problem with reading some binary STL files in general. I try to Tweak binary .stl exported from Rhinoceros, and I get this:

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/ubuntu/Scripts/Tweaker-3/Tweaker.py", line 121, in <module>
    objs = FileHandler.load_mesh(args.inputfile)
  File "/home/ubuntu/Scripts/Tweaker-3/FileHandler.py", line 30, in load_mesh
    objs = self.load_binary_stl(f)
  File "/home/ubuntu/Scripts/Tweaker-3/FileHandler.py", line 91, in load_binary_stl
    f.read(80 - 5)
  File "/usr/lib/python3.8/codecs.py", line 322, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x9e in position 76: invalid start byte

But when I convert this binary STL to ASCII STL with this Python script Binary STL to ASCII it runs just fine. I run Tweaker with Python 3 (3.8.5). Linked script works for me only when run with Python 2 (2.7.18) though.

I can reproduce this error with quite a few files, from different sources. If it helps, I can send you other files that doesn't work. I'm no expert in coding, but can it be just some UTF-8 encoding error in Python 3? Tweaker Binary-ASCII.zip