Skip to content
This repository was archived by the owner on Nov 3, 2025. It is now read-only.

Latest commit

 

History

History
65 lines (52 loc) · 1.81 KB

File metadata and controls

65 lines (52 loc) · 1.81 KB

STL File Reader and Writer

Reads and writes STL files for 3D Geometry.

Install

Header only

Dependencies:

Small and Fast Reference

Use one of the read functions in namespace tyti::stl.

Possible scalar values for the template float, double, default is float.

//////////////////////////////////////////////////////////////
// Reader Functions:
template<typename T, typename IterT>
inline bool read(basic_solid<T>& out, IterT begin, IterT end)
template<typename T, typename IterT>
inline std::pair< basic_solid<T>, bool > read(IterT begin, IterT end)
template<typename IterT>
inline std::pair< solid, bool > read(IterT begin, IterT end)

//////////////////////////////////////////////////////////////
// Writer Functions: (streamT is an output stream type)
template<typename T, typename streamT>
void write(streamT& out, const basic_solid<T>& s, bool binary)
template<typename T, typename streamT>
void write_binary(streamT& out, const basic_solid<T>&s)
template<typename T, typename streamT>
void write_ascii(streamT& out, const basic_solid<T>&s)

//////////////////////////////////////////////////////////////
// Output DataType:
template<typename T>
struct basic_solid
{
    using vec3 = basic_vec3<T>;
    using scalar_type = T;
    std::string header; //solid name or header
    std::vector<vec3> normals;
    std::vector<vec3> vertices;
    std::vector<std::uint16_t> attributes; //only available in binary files
};

typedef basic_solid<float> solid;
typedef basic_solid<float> dsolid;

template<typename T>
struct basic_vec3
{
    using scalar_type = T;
    T data[3];
};

typedef basic_vec3<float> vec3;
typedef basic_vec3<float> dvec3;

License

MIT License © Matthias Möller. Made with ♥ in Germany.