Module stl

Module stl 

Source
Expand description

Binary STL format import and export.

This module provides conversion between binary STL files and 3MF Model structures.

§STL Format

The binary STL format consists of:

  • 80-byte header (typically unused, set to zeros)
  • 4-byte little-endian unsigned integer triangle count
  • For each triangle:
    • 12 bytes: normal vector (3 × f32, often ignored by importers)
    • 12 bytes: vertex 1 (x, y, z as f32)
    • 12 bytes: vertex 2 (x, y, z as f32)
    • 12 bytes: vertex 3 (x, y, z as f32)
    • 2 bytes: attribute byte count (typically 0)

Note: ASCII STL format is not supported.

§Examples

§Importing STL

use lib3mf_converters::stl::StlImporter;
use std::fs::File;

let file = File::open("model.stl")?;
let model = StlImporter::read(file)?;
println!("Imported {} vertices",
    model.resources.iter_objects()
        .filter_map(|obj| match &obj.geometry {
            lib3mf_core::model::Geometry::Mesh(m) => Some(m.vertices.len()),
            _ => None,
        })
        .sum::<usize>()
);

§Exporting STL

use lib3mf_converters::stl::StlExporter;
use lib3mf_core::model::Model;
use std::fs::File;

let file = File::create("output.stl")?;
StlExporter::write(&model, file)?;

Structs§

StlExporter
Exports 3MF Model structures to binary STL files.
StlImporter
Imports binary STL files into 3MF Model structures.