This directory contains examples demonstrating various features and use cases of the lib3mf_rust library.
Demonstrates how to create and parse a simple 3MF file in memory, inspecting model data, metadata, objects, and build items.
cargo run --example parse_3mfShows how to create a new 3MF model from scratch, add geometry, materials, colors, and metadata, then write it to a file.
cargo run --example write_3mfCreates colored_cube.3mf in the current directory.
Demonstrates how to configure the parser to accept specific extensions and handle files requiring unsupported extensions.
# Accept all extensions
cargo run --example extension_support test_files/material/kinect_scan.3mf all
# Core only
cargo run --example extension_support test_files/core/box.3mf core-only
# Core + Materials
cargo run --example extension_support test_files/material/kinect_scan.3mf core-matShows how to handle parsing errors, validate file structure, and provide meaningful error messages.
cargo run --example validation_errors test_files/core/box.3mf permissive
cargo run --example validation_errors test_files/core/box.3mf strictDemonstrates how to register and handle custom/proprietary 3MF extensions with element and validation handlers.
cargo run --example custom_extensionDemonstrates triangle mesh operations including volume computation, bounding boxes, transformations, and build volume analysis.
cargo run --example mesh_analysis test_files/core/box.3mfShows how to subdivide meshes for displacement mapping and other mesh processing operations. Demonstrates midpoint and Loop subdivision methods.
cargo run --example mesh_subdivisionShows how to work with build items, parse transformation matrices, and apply transformations to geometry.
cargo run --example build_transformations test_files/core/box.3mfDemonstrates how components are parsed and validated in 3MF files.
cargo run --example componentsShows how to access advanced materials including Texture2D, composite materials, and multi-properties.
cargo run --example advanced_materials test_files/material/kinect_scan.3mfDemonstrates extracting material and color information for rendering, mapping colors to triangles.
cargo run --example extract_colors test_files/material/kinect_scan.3mfShows how to parse and access beam lattice data including beamsets, beams, and beam properties.
cargo run --example beam_lattice_demoDemonstrates slice extension support for layer-by-layer manufacturing.
cargo run --example slice_extension_demoShows how to validate and access production extension data including UUIDs and paths.
cargo run --example production_handler_demoDemonstrates validation of secure content in 3MF models.
cargo run --example secure_content_handlerShows how to use polygon clipping operations for resolving self-intersections in slice data.
cargo run --example polygon_clipping_demoConverts 3MF files to STL (STereoLithography) format for 3D printing.
cargo run --example export_to_stl test_files/core/box.3mf output.stlConverts 3MF files to OBJ format with MTL material file for 3D modeling tools.
cargo run --example export_to_obj test_files/core/box.3mf output.objShows how to check for and extract thumbnail images from 3MF files.
cargo run --example extract_thumbnail test_files/core/box.3mfBeginner:
parse_3mf.rs- Start here to understand basic parsingwrite_3mf.rs- Learn to create 3MF filesextension_support.rs- Understand extension configuration
Intermediate:
mesh_analysis.rs- Work with mesh geometrymesh_subdivision.rs- Mesh subdivision for displacement mappingbuild_transformations.rs- Handle transformationsvalidation_errors.rs- Robust error handlingextract_colors.rs- Material and color mappingexport_to_stl.rs/export_to_obj.rs- Format conversion
Advanced:
custom_extension.rs- Implement custom extensionspolygon_clipping_demo.rs- Advanced polygon operations- Extension-specific demos for specialized use cases
3D Printing Applications:
parse_3mf.rs- Load modelsexport_to_stl.rs- Convert for slicersslice_extension_demo.rs- Pre-sliced datamesh_analysis.rs- Validate printability
3D Modeling Tools:
export_to_obj.rs- Export for modeling softwarebuild_transformations.rs- Instance placementcomponents.rs- Assembly hierarchies
Manufacturing Systems:
production_handler_demo.rs- Production workflowsvalidation_errors.rs- Quality controlbeam_lattice_demo.rs- Lattice structures
Rendering/Visualization:
extract_colors.rs- Color data for renderingmesh_analysis.rs- Bounding boxes and volumesmesh_subdivision.rs- Mesh refinement for displacement mappingextract_thumbnail.rs- Preview images
- All examples require the library to be built:
cargo build - Test files are located in the
test_files/directory at the repository root - Many examples accept command-line arguments - run without arguments to see usage
- Examples are self-contained and can be used as templates for your own code
- See the main README.md for library documentation and installation instructions
When adding new examples:
- Add clear documentation comments at the top explaining what the example demonstrates
- Include command-line usage instructions
- Make examples self-contained and runnable
- Update this README with the new example
- Group by category (basic/extensions/utilities)