danini-the-panini / mittsu

3D Graphics Library for Ruby.
https://github.com/danini-the-panini/mittsu
MIT License
525 stars 33 forks source link

STL Loader #119

Closed Floppy closed 2 weeks ago

Floppy commented 9 months ago

This PR adds a loader for STLs, currently ASCII encoding only. Binary support will be following shortly, either in this PR or a followup.

STL is a pretty simple format, so there's not a lot in the way of tests, but I've tried to cover what edge cases I can think of. STLs are always triangles, so there's no quad support like the OBJ loader has.

Part of #116

Floppy commented 9 months ago

Binary support added in now as well.

Floppy commented 9 months ago

Converted to draft for a little while, I've got an error in the example code or model. Just working that out now.

Floppy commented 9 months ago

Looks like it's reading files with EOL conversion somewhere, rather than just as straight binary. Just trying to find out where that's happening.

Floppy commented 9 months ago

OK, all good now. Tests pass including an EOL conversion test, and the example runs too.

Screenshot 2024-02-19 at 18 00 33

If you're happy with it, merge away :)

Floppy commented 9 months ago

Woohoo, green!

Floppy commented 7 months ago

I've optimised the loader so it combines vertices on the fly during load - this should be more CPU and memory efficient when loading (which I'm doing a lot).

Incidentally, this loader code is now active in the latest release of Manyfold (https://manyfold.app), where I'm using it for checking for mesh holes. It's using my fork, in advance of this making it into an official Mittsu release.