Skip to main content

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///     printable: None,
27/// });
28/// assert_eq!(build.items.len(), 1);
29/// ```
30#[derive(Debug, Clone, Default, Serialize, Deserialize)]
31pub struct Build {
32    /// The list of objects to manufacture.
33    pub items: Vec<BuildItem>,
34}
35
36/// A reference to an object that should be manufactured.
37///
38/// Build items specify which objects from the resource collection should be
39/// printed and where they should be positioned on the build platform. Each
40/// item can apply a transformation to position/rotate the object.
41///
42/// Only objects with types that can appear in the build (not `ObjectType::Other`)
43/// are valid build item references.
44#[derive(Debug, Clone, Serialize, Deserialize)]
45pub struct BuildItem {
46    /// The ID of the object to manufacture.
47    pub object_id: ResourceId,
48
49    /// Production Extension UUID for tracking this build item instance (optional).
50    #[serde(skip_serializing_if = "Option::is_none")]
51    pub uuid: Option<Uuid>,
52
53    /// External reference path for production tracking (optional).
54    #[serde(skip_serializing_if = "Option::is_none")]
55    pub path: Option<String>,
56
57    /// Part number for this build item instance (optional).
58    #[serde(skip_serializing_if = "Option::is_none")]
59    pub part_number: Option<String>,
60
61    /// Transformation matrix positioning the object on the build platform.
62    /// Defaults to identity (origin position, no rotation).
63    /// The transformation is applied using the glam Mat4 type.
64    #[serde(default = "default_transform", skip_serializing_if = "is_identity")]
65    pub transform: Mat4,
66
67    /// Whether this item should be printed (Bambu/OrcaSlicer extension).
68    /// `Some(true)` means printable, `Some(false)` means display-only, `None` means unspecified.
69    #[serde(skip_serializing_if = "Option::is_none")]
70    pub printable: Option<bool>,
71}
72
73fn default_transform() -> Mat4 {
74    Mat4::IDENTITY
75}
76
77fn is_identity(transform: &Mat4) -> bool {
78    *transform == Mat4::IDENTITY
79}