Expand description
XML-to-Model parsing pipeline for 3MF files.
This module converts XML content from a 3MF archive into the in-memory Model
structure. It handles the Core 3MF specification and all major extensions.
§Two Parsing Modes
The parser provides two modes optimized for different use cases:
§DOM Mode (Default)
The parse_model function loads the entire XML document into memory and constructs the complete
Model structure. This is:
- Fast: Single-pass parsing with efficient XML handling
- Simple: Returns a complete model ready to use
- Suitable for: Files under 100MB (typical use case)
use lib3mf_core::parser::parse_model;
use std::io::Cursor;
let xml_data = b"<model xmlns='http://schemas.microsoft.com/3dmanufacturing/core/2015/02'>...</model>";
let model = parse_model(Cursor::new(xml_data))?;
println!("Loaded {} objects", model.resources.iter_objects().count());§SAX/Streaming Mode (For Large Files)
The streaming module provides event-based parsing with constant memory usage via the
ModelVisitor trait. This is:
- Memory-efficient: Constant memory regardless of file size
- Suitable for: Files over 100MB, or memory-constrained environments
- More complex: Requires implementing visitor callbacks
See streaming module documentation for details.
§Parser Architecture
The parser is organized into specialized modules:
§Core Parsers
model_parser: Orchestrates parsing of the<model>root elementmesh_parser: Parses<mesh>geometry (vertices, triangles)material_parser: Parses material resources (base materials, colors, textures, composites)build_parser: Parses<build>section (what to print and where)component_parser: Parses<components>(object references and transformations)
§Extension Parsers
beamlattice_parser: Beam Lattice Extension (structural lattices)slice_parser: Slice Extension (2D layer-based geometry for DLP/SLA)volumetric_parser: Volumetric Extension (voxel data)boolean_parser: Boolean Operations Extension (CSG operations)displacement_parser: Displacement Extension (texture-driven surface modification)crypto_parser: Digital signature metadata (always available, parses XML only)secure_content_parser: Secure Content Extension (encryption/decryption, requirescryptofeature)
§Vendor Extensions
bambu_config: Bambu Studio project files (plates, filament data, print times)
§Crypto vs Secure Content
The parser distinguishes between two related modules:
crypto_parser: Always available. Parses XML structure of<Signature>elements but doesn’t verify them. This allows reading signed files without crypto dependencies.secure_content_parser: Behindcryptofeature. Handles encryption/decryption and signature verification. Requires base64, aes-gcm, rsa, sha1, sha2, x509-parser dependencies.
§Error Handling
All parsing functions return Result<T, Lib3mfError>:
- InvalidStructure: Malformed XML, missing required attributes, spec violations
- Io: File reading errors, ZIP errors
- ResourceNotFound: References to non-existent resource IDs
- FeatureNotEnabled: Trying to use
secure_content_parserwithoutcryptofeature
The parser never panics on invalid input.
Re-exports§
pub use bambu_config::parse_model_settings;pub use crypto_parser::parse_signature;pub use model_parser::parse_model;pub use xml_parser::XmlParser;