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
Source§impl Model
impl Model
pub fn compute_stats( &self, archiver: &mut impl ArchiveReader, ) -> Result<ModelStats>
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Model
impl<'de> Deserialize<'de> for Model
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for Model
impl RefUnwindSafe for Model
impl Send for Model
impl Sync for Model
impl Unpin for Model
impl UnwindSafe for Model
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more