Skip to content

davidf2281/EssTeeEll

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

EssTeeEll

Multithreaded Parsing of Binary STL Files in Swift

screenshot

A skeleton macOS app that will parse and display STL files, as generated by most CAD software as the intermediate format before slicing and 3D printing.

I've made this public in case anyone is interested in the parsing side of things; the app itself simply generates a SceneKit 3D view of the model to demonstrate that the parsing works. Think of this repo as an elaborate gist; the parsing routines are part of a future, larger effort to develop a slicer for specific niche 3D-printing use cases.

Only parsing of binary files is supported. Technically STL files can also be in ASCII format but it's rare these days so hasn't been implemented at this stage.

Parsing is fully multithreaded to use all available cores and avoids memory-copy operations as far as possible by preferring manually managed UnsafeMutablePointer buffers over higher-level constructs, so you'll find performance is pretty good.

Note that there are currently no checks in place for available memory, which would need to be implemented in a production context.

Usage

The relevant STL parsing method is parseBinary(fileURL:) (which calls readFacetData, processFacetDataBuffer and parseMesh) which you'll find in MeshParser.swift.

The result of a call to parseBinary along with a valid URL is a Solid struct which mirrors the STL format's arrangement and terminology: a Solid has a name and an array of Facet structs. Each Facet has a defining outerloop of vertices along with a facet normal.

MeshParser publishes its state and parsingProgress properties via Combine, so alternatively you can instantiate one with a file URL, call its start() method and observe its progress. When its state changes to .parsed, the solid property will contain the result.

About

Multithreaded Parsing of Binary STL Files in Swift

Resources

License

Stars

Watchers

Forks

Languages