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§

IndexedMesh
STL Mesh in indexed form, consisting of a list of Vertices and a list of indexed Triangles.
IndexedTriangle
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.
Triangle
STL Triangle, consisting of a normal and three vertices. This is the format Triangles are usually stored in STL files.
Vector
Float Vector with approx_eq.

Traits§

TriangleIterator
Iterates over all Triangles in a STL.

Functions§

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

Type Aliases§

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