4 releases (2 breaking)

0.3.1 Nov 27, 2022
0.3.0 Oct 30, 2022
0.2.0 Oct 30, 2022
0.1.0 Oct 30, 2022

#127 in Data formats

Download history 64/week @ 2024-02-18 16/week @ 2024-02-25 2/week @ 2024-03-03

82 downloads per month
Used in r_tracer

MIT license

26KB
608 lines

Introduction

pk_stl is a Rust library for reading and writing STL files, and has no additional dependencies other than the standard library. It can read and write both ASCII and binary STL files.

STL File Support

There are two main STL file formats: binary and ascii.

Binary ASCII
Read Yes Yes
Write Yes Yes

Additionally, this library does not suppport any additional attributes attached to the triangles or model, but this features will be in a future release. If metadata from the header is needed, this library does provide access to the contents of the header.

Documentation

For full documentaiton run:

cargo doc --open

Or visit https://docs.rs/pk_stl/latest/pk_stl


lib.rs:

STL file parsing and writing.

This crate provides a simple interface for reading and writing STL files. It is written entirely in Rust with no dependencies, and it can read and write both ASCII and binary STL files.

Examples

use pk_stl::parse_stl;

// Files may be loaded from bytes or from ascii.
let content = include_bytes!("../tests/test_cube.stl");
let model = parse_stl(content).unwrap();

// Models can be converted between ascii and binary.
let ascii_content = model.as_ascii();

// The header of this model is "OpenSCAD Model\n" because this file happens
// to be the output of OpenSCAD.
assert_eq!(ascii_content.lines().next(), Some("solid OpenSCAD Model"));

No runtime deps