A small C++ library for reading and writing STL mesh files.
- Supports ASCII and binary STL files
- Header-only library, no compilation required
- Single file, easy to add to your project
- Does not depend on any third-party libraries
- Works well with your existing mesh data structures
- Optional vertex deduplication after reading (to get a proper face-vertex data structure)
- CMake for tests and examples
- Tested with Visual Studio, GCC and Clang
- Automated builds, tests and code coverage analysis using GitHub Actions
- Download the header file
microstl.h
- Put the file into your include directory
- Include the file:
#include <microstl.h>
- Create a handler that receives the data and creates a mesh:
microstl::MeshReaderHandler meshHandler;
- Call the reader with the STL file path and the handler:
microstl::Reader::readStlFile("path/to/my.stl", meshHandler);
- Check return value of the reader for
microstl::Result::Success
and handle any errors - Access the triangle data in the mesh handler at
meshHandler.mesh.facets
You can find the complete example code here. Check out the examples folder for more examples. The file custom_handler.cpp shows how to write your own handler. Such a custom handler can be used to fill your existing mesh data structues.
The writer follows the same principle. You can use the included simple mesh data structures or you can implement a custom data provider to connect your own data structures.
- Requires at least a C++ 17 compiler
- Binary reader and writer works only on little-endian systems