pub struct Model {
pub unit: Unit,
pub language: Option<String>,
pub metadata: HashMap<String, String>,
pub resources: ResourceCollection,
pub build: Build,
pub attachments: HashMap<String, Vec<u8>>,
pub existing_relationships: HashMap<String, Vec<Relationship>>,
}Expand description
Root element of a 3MF document.
The Model contains all information required to describe a 3D model, including:
- Resources (Meshes, Materials, Textures)
- Build instructions (Item positioning)
- Metadata (Authors, Copyright, etc.)
Fields§
§unit: UnitThe unit of measurement for geometry coordinates.
language: Option<String>The language of the model content (e.g., “en-US”).
metadata: HashMap<String, String>Arbitrary metadata key-value pairs.
resources: ResourceCollectionCollection of all resources (objects, materials) used in the build.
build: BuildThe build definition, containing instances of objects to be printed.
attachments: HashMap<String, Vec<u8>>Binary attachments (Textures, Thumbnails, etc.) stored by package path. Key: Path in archive (e.g., “Metadata/thumbnail.png”, “3D/Textures/diffuse.png”) Value: Binary content
existing_relationships: HashMap<String, Vec<Relationship>>Existing OPC relationships loaded from the archive. Key: Relationship file path (e.g., “3D/_rels/3dmodel.model.rels”) Value: Parsed relationships
Implementations§
Source§impl Model
impl Model
Sourcepub fn validate(&self, level: ValidationLevel) -> ValidationReport
pub fn validate(&self, level: ValidationLevel) -> ValidationReport
Validates the 3MF model at the specified validation level.
The validation system is progressive, with four levels of increasing strictness:
- Minimal: Basic structural checks (required attributes, valid XML structure)
- Standard: Reference integrity checks (resource IDs exist, build references valid objects)
- Strict: Full spec compliance (metadata presence, no unknown attributes)
- Paranoid: Deep geometry analysis (manifoldness, self-intersection, orientation consistency)
§Parameters
level: TheValidationLevelto apply. Higher levels include all checks from lower levels.
§Returns
A ValidationReport containing all errors, warnings,
and info messages found during validation. Check has_errors()
to determine if the model passed validation.
§Examples
use lib3mf_core::{Model, validation::ValidationLevel};
let model = Model::default();
// Quick structural check
let report = model.validate(ValidationLevel::Minimal);
assert!(!report.has_errors());
// Recommended for production use
let report = model.validate(ValidationLevel::Standard);
if report.has_errors() {
for item in &report.items {
eprintln!("Error: {}", item.message);
}
}
// Deep inspection (expensive, for critical applications)
let report = model.validate(ValidationLevel::Paranoid);§Performance
- Minimal: Very fast, suitable for quick checks
- Standard: Fast, recommended for most use cases
- Strict: Moderate, includes metadata and attribute checks
- Paranoid: Slow, performs O(n²) geometry checks with BVH acceleration