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, and
22//! [`role`] which leaves are supports or a raft rather than models.
23//! [`metadata`] says who made a file and how it may be used, and gives its
24//! parts lasting ids.
25//! [`stl`] reads STL files into meshes, to be written as `.bread`.
26
27pub mod app;
28mod bytes;
29pub mod container;
30pub mod file;
31pub mod mesh;
32pub mod mesh_v2;
33mod meta;
34pub mod metadata;
35mod parallel;
36pub mod preview;
37pub mod role;
38pub mod scene;
39pub mod stl;
40pub mod surface;
41
42#[cfg(test)]
43mod tests_app;
44#[cfg(test)]
45mod tests_container;
46#[cfg(test)]
47mod tests_file;
48#[cfg(test)]
49mod tests_mesh;
50#[cfg(test)]
51mod tests_mesh_v2;
52#[cfg(test)]
53mod tests_metadata;
54#[cfg(test)]
55mod tests_preview;
56#[cfg(test)]
57mod tests_role;
58#[cfg(test)]
59mod tests_scene;
60#[cfg(test)]
61mod tests_stl;
62#[cfg(test)]
63mod tests_surface;
64
65pub use app::{
66    DecodeDocumentsError, EncodeDocumentsError, HOLLOWS_TAG, HOLLOWS_VERSION, HollowEntry,
67    SETTINGS_TAG, SETTINGS_VERSION, SUPPORTS_TAG, SUPPORTS_VERSION, SupportEntry, decode_hollows,
68    decode_supports, encode_hollows, encode_supports,
69};
70pub use container::{BreadReader, BreadWriter, Chunk, ChunkTag, ReadBreadError};
71pub use file::{
72    BreadFile, ReadFileError, THUMBNAIL_TAG, THUMBNAIL_VERSION, WriteFileError, read_file,
73    supported_version, write_file,
74};
75pub use mesh::{
76    DecodeMeshError, EncodeMeshError, MESH_TAG, MESH_VERSION, Mesh, decode_mesh, encode_mesh,
77};
78pub use mesh_v2::{
79    Connectivity, MeshCoding, VertexCoding, decode_mesh_v2, encode_mesh_v2, encode_mesh_v2_with,
80};
81pub use meta::Meta;
82pub use metadata::{
83    EncodeMetadataError, METADATA_TAG, METADATA_VERSION, MetadataEntry, TEXT_KEYS, UUID_KEY,
84    decode_metadata, encode_metadata,
85};
86pub use preview::{
87    DecodePreviewsError, EncodePreviewsError, SUPPORT_PREVIEW_TAG, SUPPORT_PREVIEW_VERSION,
88    SupportPreview, decode_previews, encode_previews,
89};
90pub use role::{
91    DecodeRolesError, EncodeRolesError, ROLE_RAFT, ROLE_SUPPORTS, ROLE_TAG, ROLE_VERSION,
92    RoleEntry, decode_roles, encode_roles,
93};
94pub use scene::{
95    DecodeSceneError, EncodeSceneError, Node, NodeKind, SCENE_TAG, SCENE_VERSION, Scene, Transform,
96    decode_scene, encode_scene,
97};
98pub use stl::{ReadStlError, read_stl};
99pub use surface::{
100    DecodeSurfaceError, EncodeSurfaceError, SURFACE_TAG, SURFACE_VERSION, SurfaceEntry,
101    decode_surface, encode_surface,
102};