lib3mf_core/model/
build.rs

1use crate::model::ResourceId;
2use glam::Mat4;
3use serde::{Deserialize, Serialize};
4use uuid::Uuid;
5
6/// The build section defining what objects to print and where.
7///
8/// The build section is the "print job" in a 3MF model. It specifies which
9/// objects should be manufactured and their positions/orientations on the
10/// build platform. Only objects referenced in the build will be printed;
11/// other objects in the model are available for reference but won't be
12/// manufactured unless included in a build item.
13///
14/// # Examples
15///
16/// ```
17/// use lib3mf_core::model::{Build, BuildItem, ResourceId};
18///
19/// let mut build = Build::default();
20/// build.items.push(BuildItem {
21///     object_id: ResourceId(1),
22///     uuid: None,
23///     path: None,
24///     part_number: None,
25///     transform: glam::Mat4::IDENTITY,
26/// });
27/// assert_eq!(build.items.len(), 1);
28/// ```
29#[derive(Debug, Clone, Default, Serialize, Deserialize)]
30pub struct Build {
31    /// The list of objects to manufacture.
32    pub items: Vec<BuildItem>,
33}
34
35/// A reference to an object that should be manufactured.
36///
37/// Build items specify which objects from the resource collection should be
38/// printed and where they should be positioned on the build platform. Each
39/// item can apply a transformation to position/rotate the object.
40///
41/// Only objects with types that can appear in the build (not `ObjectType::Other`)
42/// are valid build item references.
43#[derive(Debug, Clone, Serialize, Deserialize)]
44pub struct BuildItem {
45    /// The ID of the object to manufacture.
46    pub object_id: ResourceId,
47
48    /// Production Extension UUID for tracking this build item instance (optional).
49    #[serde(skip_serializing_if = "Option::is_none")]
50    pub uuid: Option<Uuid>,
51
52    /// External reference path for production tracking (optional).
53    #[serde(skip_serializing_if = "Option::is_none")]
54    pub path: Option<String>,
55
56    /// Part number for this build item instance (optional).
57    #[serde(skip_serializing_if = "Option::is_none")]
58    pub part_number: Option<String>,
59
60    /// Transformation matrix positioning the object on the build platform.
61    /// Defaults to identity (origin position, no rotation).
62    /// The transformation is applied using the glam Mat4 type.
63    #[serde(default = "default_transform", skip_serializing_if = "is_identity")]
64    pub transform: Mat4,
65}
66
67fn default_transform() -> Mat4 {
68    Mat4::IDENTITY
69}
70
71fn is_identity(transform: &Mat4) -> bool {
72    *transform == Mat4::IDENTITY
73}