Crate stl_io

source ·
Expand description

stl_io is a crate for reading and writing STL (STereoLithography) files. It can read both, binary and ascii STL in a safe manner. Writing is limited to binary STL, which is more compact anyway.

Examples

Read STL file:

use std::fs::OpenOptions;
let mut file = OpenOptions::new().read(true).open("mesh.stl").unwrap();
let stl = stl_io::read_stl(&mut file).unwrap();

Read number of triangles in a STL file:

use std::fs::OpenOptions;
let mut file = OpenOptions::new().read(true).open("mesh.stl").unwrap();
let size_hint = stl_io::create_stl_reader(&mut file).unwrap().size_hint();

Write STL file:

use std::fs::OpenOptions;
use stl_io::{Normal, Vertex};
let mesh = [stl_io::Triangle { normal: Normal::new([1.0, 0.0, 0.0]),
                               vertices: [Vertex::new([0.0, -1.0, 0.0]),
                                          Vertex::new([0.0, 1.0, 0.0]),
                                          Vertex::new([0.0, 0.0, 0.5])]}];
let mut file = OpenOptions::new().write(true).create_new(true).open("mesh.stl").unwrap();
stl_io::write_stl(&mut file, mesh.iter()).unwrap();

Structs

Struct for ascii STL reader.
Struct for binary STL reader.
STL Mesh in indexed form, consisting of a list of Vertices and a list of indexed Triangles.
STL Triangle in indexed form, consisting of a normal and three indices to vertices in the vertex list. This format is more compact, since in real world Meshes Triangles usually share vertices with other Triangles.
STL Triangle, consisting of a normal and three vertices. This is the format Triangles are usually stored in STL files.
Float Vector with approx_eq.

Traits

Iterates over all Triangles in a STL.

Functions

Attempts to create a TriangleIterator for either ascii or binary STL from std::io::Read.
Attempts to read either ascii or binary STL from std::io::Read.
Write to std::io::Write as documented in Wikipedia.

Type Definitions

STL Normal - a vector perpendicular to a Triangle in a 3D Mesh.
STL vertex - a corner of a Triangle in a 3D Mesh.