Model

Struct Model 

Source
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: Unit

The 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: ResourceCollection

Collection of all resources (objects, materials) used in the build.

§build: Build

The 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

Source

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: The ValidationLevel to 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

Source

pub fn compute_stats( &self, archiver: &mut impl ArchiveReader, ) -> Result<ModelStats>

Source§

impl Model

Source

pub fn write<W: Write + Seek>(&self, writer: W) -> Result<()>

Source§

impl Model

Source

pub fn write_xml<W: Write>( &self, writer: W, thumbnail_relationships: Option<&HashMap<String, String>>, ) -> Result<()>

Trait Implementations§

Source§

impl Clone for Model

Source§

fn clone(&self) -> Model

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Model

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Model

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Model

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for Model

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

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§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,