| Crates.io | threemf2 |
| lib.rs | threemf2 |
| version | 0.1.2 |
| created_at | 2025-11-30 21:15:41.879533+00 |
| updated_at | 2025-11-30 21:58:49.465876+00 |
| description | 3MF (3D Manufacturing Format) file format support |
| homepage | https://github.com/vshashi01/threemf2 |
| repository | https://github.com/vshashi01/threemf2 |
| max_upload_size | |
| id | 1958859 |
| size | 1,682,759 |
Library for reading and writing 3MF (3D Manufacturing Format) packages with both eager and lazy loading support.
This repository uses a Cargo workspace with threemf2 (main crate), threemf2-benches (benchmarks), and threemf2-tests (integration tests with large data). The threemf2 crate provides a compact core model representation and I/O helpers for reading/writing 3MF packages with multiple loading strategies optimized for different use cases.
| 3MF Specifications | Type | Read1 | Write2 | Current supported version |
|---|---|---|---|---|
| 3MF Core Spec | Core | MUST | MUST | 1.3.0 |
| Triangle Set | Extension | MUST | OPTIONAL | Core Spec 1.3.0 |
| Production | Extension | MUST | OPTIONAL | 1.1.2 |
| Beam Lattice | Extension | MUST | OPTIONAL | 1.2.0 |
Note: This library is still in active development, expect frequent API changes!!
Note1: Reading these data are currently MUST, which means if the data exists in the 3MF Model the library will automatically read it
Note2: Write these data are currently optional however they are available by default in the mapping of the Rust types and are not conditionally compiled.
threemf2 provides:
Model, Object, Mesh, etc.)ThreemfPackage - Eager loading for complete data accessThreemfPackageLazyReader - Lazy loading for memory-constrained environmentsbuilder_example.rs for the most basic starter guide.Choose the right loading strategy for your use case:
Key types and files:
model, object, resources, mesh, transform, etc.io::ThreemfPackage — eager loading entry pointio::ThreemfPackageLazyReader — lazy loading entry pointThis crate uses optional Cargo features to control functionality. Enable only what you need.
write — Enable writing 3MF data (adds ToXml derive to all 3MF types using instant_xml)memory-optimized-read — Enable memory-efficient reading (adds FromXml derive to all 3MF types using instant_xml)speed-optimized-read — Enable fast reading (adds serde::Deserialize derive to all 3MF types using serde_roxmltree)io-write — Package writing with ZIP creation (requires write)io-memory-optimized-read — Package reading with memory optimization (requires memory-optimized-read)io-speed-optimized-read — Package reading with speed optimization (requires speed-optimized-read)io-lazy-read — Lazy loading functionality (requires io-memory-optimized-read)io-write, io-memory-optimized-read, io-lazy-read, write, memory-optimized-read
# Basic reading
threemf2 = "0.1"
# Full I/O with lazy loading (default)
threemf2 = { version = "0.1", features = ["io-lazy-read"] }
# Memory-constrained environments
threemf2 = { version = "0.1", features = ["io-lazy-read"], default-features = false }
# High-performance reading
threemf2 = { version = "0.1", features = ["io-speed-optimized-read"] }
The threemf2/examples/ directory contains runnable examples for different use cases:
write.rs - Create and write 3MF packagesbuilder_example.rs - Using ModelBuilder for ergonomic model constructionunpack.rs - Lazy loading with ThreemfPackageLazyReaderio_memory_optimized_read.rs - Memory-efficient readingio_speed_optimized_read.rs - High-performance readingstring_extraction.rs - Access raw XML contentbeamlattice_write.rs - Working with beam lattice extensionsRun examples with:
cargo run --example write --features io-write
cargo run --example unpack --features io-lazy-read
The benchmarks use Criterion.rs as the benchmark harness on stable Rust channel.
Benchmarks are located in the threemf2-benches crate. To run them, use cargo bench --package threemf2-benches. The files used for the benchmarks are on Git LFS, so ensure git lfs is enabled.
reader - Benchmarks the different serialization options instant-xml and serde-roxmltree on an uncompressed 3MF model file.
threemf_reader - Benchmarks the different reader methods on ThreemfPackage.
threemf_write - Benchmarks the writer method on a full 3MF package.
Model - Root 3MF model with resources and build configurationObject - 3D objects (meshes or component assemblies)Mesh - Triangle mesh geometry with vertices and trianglesComponent - Object references with transformsThreemfPackage - Eager loading - loads all data upfrontThreemfPackageLazyReader - Lazy loading - loads metadata first, data on-demandio cratequery module enables easy retrieval of data from the 3MF Package or 3MF model.builder enables easy creation of 3MF Model.# Build with all features
cargo build --all-features
# Check formatting and linting
cargo fmt --all -- --check
cargo clippy --all-targets --all-features -- -D warnings
# Run all tests in the workspace (includes threemf2, threemf2-tests)
cargo test
# Run tests for specific crates
cargo test --package threemf2 # Core tests (CI-focused)
cargo test --package threemf2-tests # Integration tests with large data (requires Git LFS)
# Install cargo-all-features and run tests for multiple feature combinations at once
cargo all-features test
# Run benchmarks
cargo bench --package threemf2-benches
This project and its source code are released under MIT or Apache 2.0 licenses.
Contributions are welcome.
cargo all-features test:We welcome contributions created with the assistance of AI tools. However, all contributors must:
cargo-all-features, see above)AI tools can be excellent for productivity, but human oversight and understanding remain essential for maintaining code quality.
By contributing you agree to license your contributions under MIT or Apache 2.0 licenses.