Skip to main content

Module parser

Module parser 

Source
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 element
  • mesh_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, requires crypto feature)

§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: Behind crypto feature. 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_parser without crypto feature

The parser never panics on invalid input.

Re-exports§

pub use bambu_config::parse_model_settings;
pub use bambu_config::parse_profile_config;
pub use bambu_config::parse_project_settings;
pub use bambu_config::parse_slice_info;
pub use crypto_parser::parse_signature;
pub use model_parser::parse_model;
pub use xml_parser::XmlParser;

Modules§

bambu_config
Bambu Studio project file parsers (plate info, filament config, print settings). Bambu Studio config file parsers.
beamlattice_parser
Beam Lattice Extension parser.
boolean_parser
Boolean Operations Extension parser.
build_parser
Build element parser (<build> and <item> elements).
component_parser
Component and components element parser.
crypto_parser
XML-DSIG crypto structure parser (always available; no crypto operations).
displacement_parser
Displacement Extension parser.
material_parser
Materials and Properties Extension parser.
mesh_parser
Mesh geometry parser (<vertices> and <triangles>).
model_parser
Root model XML parser — main entry point for DOM-mode parsing.
secure_content_parser
Secure Content Extension parser (requires crypto feature).
slice_parser
Slice Extension parser.
streaming
SAX/streaming parser for memory-efficient processing of large 3MF files.
visitor
ModelVisitor trait for streaming parser callbacks.
volumetric_parser
Volumetric Extension parser.
xml_parser
Low-level XML parser primitives used by all parser modules.