Skip to main content

bread_format/
lib.rs

1/*
2 * SPDX-FileCopyrightText: 2026 SynrgStudio
3 * SPDX-License-Identifier: Apache-2.0
4 */
5
6//! Reads and writes `.bread` files: triangle meshes and the scene that places
7//! them, stored small and without losing anything. The format is described in
8//! [`SPEC.md`](https://github.com/breadslicer-app/bread-format/blob/main/SPEC.md),
9//! in the repository.
10//!
11//! [`read_file`] and [`write_file`] read and write a whole file as a
12//! [`BreadFile`]: the scene, its meshes, and the documents programs keep
13//! about them, such as editable supports.
14//!
15//! A `.bread` file is a short header followed by chunks. Each chunk has a
16//! four-byte tag, its own version, and a payload compressed with zstd and
17//! guarded by a CRC-32. [`container`] reads and writes chunks without knowing
18//! what they hold; [`scene`] and [`mesh`] are the codecs of the scene chunk
19//! and of the mesh chunks it places, [`app`] carries the documents of the
20//! application chunks, [`preview`] the meshes that show supports to readers
21//! that do not rebuild them, [`surface`] the paint on the faces of models (with
22//! [`paint`] for the masks themselves), and
23//! [`role`] which leaves are supports or a raft rather than models.
24//! [`metadata`] says who made a file and how it may be used, and gives its
25//! parts lasting ids, and [`program`] keeps each program's own documents.
26//! [`volume`] keeps the volumes that act on a model without printing: support
27//! enforcers and blockers, modifiers and negative volumes. [`ownership`]
28//! checks, before saving, that an edit changed only what its program owns.
29//! [`stl`] reads STL files into meshes, to be written as `.bread`.
30
31pub mod app;
32mod bytes;
33pub mod container;
34pub mod file;
35pub mod mesh;
36pub mod mesh_v2;
37mod meta;
38pub mod metadata;
39pub mod ownership;
40pub mod paint;
41mod parallel;
42pub mod preview;
43pub mod program;
44pub mod role;
45pub mod scene;
46pub mod stl;
47pub mod surface;
48pub mod volume;
49
50#[cfg(test)]
51mod tests_app;
52#[cfg(test)]
53mod tests_container;
54#[cfg(test)]
55mod tests_file;
56#[cfg(test)]
57mod tests_mesh;
58#[cfg(test)]
59mod tests_mesh_v2;
60#[cfg(test)]
61mod tests_metadata;
62#[cfg(test)]
63mod tests_ownership;
64#[cfg(test)]
65mod tests_paint;
66#[cfg(test)]
67mod tests_preview;
68#[cfg(test)]
69mod tests_program;
70#[cfg(test)]
71mod tests_role;
72#[cfg(test)]
73mod tests_scene;
74#[cfg(test)]
75mod tests_stl;
76#[cfg(test)]
77mod tests_surface;
78#[cfg(test)]
79mod tests_volume;
80
81pub use app::{
82    DecodeDocumentsError, EncodeDocumentsError, HOLLOWS_TAG, HOLLOWS_VERSION, HollowEntry,
83    SETTINGS_TAG, SETTINGS_VERSION, SUPPORTS_TAG, SUPPORTS_VERSION, SupportEntry, decode_hollows,
84    decode_supports, encode_hollows, encode_supports,
85};
86pub use container::{BreadReader, BreadWriter, Chunk, ChunkTag, ReadBreadError};
87pub use file::{
88    BreadFile, ReadFileError, THUMBNAIL_TAG, THUMBNAIL_VERSION, WriteFileError, read_file,
89    supported_version, write_file,
90};
91pub use mesh::{
92    DecodeMeshError, EncodeMeshError, MESH_TAG, MESH_VERSION, Mesh, decode_mesh, encode_mesh,
93};
94pub use mesh_v2::{
95    Connectivity, MeshCoding, VertexCoding, decode_mesh_v2, encode_mesh_v2, encode_mesh_v2_with,
96};
97pub use meta::Meta;
98pub use metadata::{
99    EncodeMetadataError, METADATA_TAG, METADATA_VERSION, MetadataEntry, TEXT_KEYS, UUID_KEY,
100    decode_metadata, encode_metadata,
101};
102pub use ownership::{
103    BREADSLICER, Change, Data, Editor, Remap, Violation, check_edit, check_edit_remapped,
104};
105#[cfg(feature = "fingerprint")]
106pub use paint::mesh_fingerprint;
107pub use paint::{
108    DecodePaintError, EncodePaintError, FINGERPRINT_SIZE, MAX_PAINT_DEPTH, MUST_NOT_TOUCH,
109    MUST_TOUCH, PAINT_DETAIL, PAINT_SUPPORTS_BOTH_WAYS, PAINT_SUPPORTS_MUST_NOT_TOUCH,
110    PAINT_SUPPORTS_MUST_TOUCH, PaintDocument, PaintNode, PaintPiece, PaintRun, PaintRuns,
111    PaintTrees, PaintedTriangle, decode_paint, encode_paint,
112};
113pub use preview::{
114    DecodePreviewsError, EncodePreviewsError, SUPPORT_PREVIEW_TAG, SUPPORT_PREVIEW_VERSION,
115    SupportPreview, decode_previews, encode_previews,
116};
117pub use program::{
118    DecodeProgramDataError, EncodeProgramDataError, PROGRAM_TAG, PROGRAM_VERSION, ProgramEntry,
119    decode_program_data, encode_program_data, is_program_name,
120};
121pub use role::{
122    DecodeRolesError, EncodeRolesError, ROLE_RAFT, ROLE_SUPPORTS, ROLE_TAG, ROLE_VERSION,
123    RoleEntry, decode_roles, encode_roles,
124};
125pub use scene::{
126    DecodeSceneError, EncodeSceneError, Node, NodeKind, SCENE_TAG, SCENE_VERSION, Scene, Transform,
127    decode_scene, encode_scene,
128};
129pub use stl::{ReadStlError, read_stl};
130pub use surface::{
131    DecodeSurfaceError, EncodeSurfaceError, SURFACE_TAG, SURFACE_VERSION, SurfaceEntry,
132    decode_surface, decode_surface_v1, encode_surface,
133};
134pub use volume::{
135    DecodeVolumesError, EncodeVolumesError, VOLUME_MODIFIER, VOLUME_NEGATIVE,
136    VOLUME_SUPPORT_BLOCKER, VOLUME_SUPPORT_ENFORCER, VOLUME_TAG, VOLUME_UNCUT, VOLUME_VERSION,
137    VolumeEntry, decode_volumes, encode_volumes,
138};