Module stl

Module stl 

Source
Expand description

STL format import and export (binary and ASCII).

This module provides conversion between STL files and 3MF Model structures. Both binary and ASCII STL formats are supported.

§STL Formats

§Binary STL

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)

§ASCII STL

The ASCII STL format is a text-based format with keyword-delimited geometry:

  • Keywords are case-insensitive (real-world files use both uppercase and lowercase)
  • Multiple solids per file are supported (each becomes a separate object)
  • Solid names with spaces are supported

§Auto-Detection

StlImporter::read() automatically detects the format using the file size formula. Use StlImporter::read_binary() or StlImporter::read_ascii() for explicit format selection.

§Examples

§Importing STL (auto-detect)

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

let file = File::open("model.stl")?;
let model = StlImporter::read(file)?;
println!("Imported {} objects", model.build.items.len());

§Exporting Binary STL

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

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

§Exporting ASCII STL

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

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

Structs§

AsciiStlExporter
Exports 3MF Model structures to ASCII STL files.
BinaryStlExporter
Exports 3MF Model structures to binary STL files.
StlImporter
Imports STL files (binary or ASCII) into 3MF Model structures.

Enums§

StlFormat
Detected STL file format.

Functions§

detect_stl_format
Detects whether an STL file is binary or ASCII.