1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
//! Format I/O layer for Draco geometry.
//!
//! `draco-io` maps external 3D formats onto the geometry types from
//! `draco-core`. It handles file/container concerns such as OBJ, PLY, FBX,
//! glTF, GLB, scene hierarchy, and `KHR_draco_mesh_compression`; raw `.drc`
//! bitstream encoding and decoding stays in `draco-core`.
//!
//! # Supported Formats
//!
//! | Format | Read | Write | Draco compression |
//! |--------|------|-------|-------------------|
//! | OBJ | yes | yes | no |
//! | PLY | yes | yes | no |
//! | FBX | yes | yes | no |
//! | glTF | yes | yes | yes |
//! | GLB | yes | yes | yes |
//!
//! # Feature Model
//!
//! The default feature set enables all readers, all writers, optional
//! compression support, and point-cloud Draco decoding. For smaller builds, use
//! `default-features = false` and enable only the format features needed, such
//! as `gltf-reader`, `gltf-writer`, `obj-reader`, or `ply-writer`.
//!
//! # Geometry Contract
//!
//! `draco-io` maps source formats onto the Draco geometry model. Meshes use
//! triangle faces, `Position` is the required attribute, and `Normal`, `Color`,
//! `TexCoord`, and `Generic` are preserved when the file format can represent
//! them as Draco attributes. Scene support in the *geometry model* is limited to
//! names, hierarchy, transforms, and mesh parts; materials, textures, cameras,
//! lights, animation, skinning, structural metadata, and arbitrary format extras
//! are not represented in that model.
//!
//! # Document-preserving glTF compression
//!
//! Decoding into the geometry model and re-emitting a fresh glTF necessarily
//! drops anything the model does not represent (materials, textures, and so on).
//! When the goal is to Draco-compress an existing glTF/GLB **in place**, use
//! [`compress_gltf_bytes`]: it rewrites only the compressible mesh geometry and
//! carries the rest of the document through untouched — materials, textures,
//! images, samplers, cameras, nodes, animations, skins, `extras`, and unknown
//! extensions all survive.
//!
//! # Unified Trait API
//!
//! All readers implement [`Reader`] and all writers implement [`Writer`]:
//!
//! ```ignore
//! use draco_io::{Reader, Writer, ObjReader, ObjWriter};
//!
//! // Generic read function
//! fn load<R: Reader>(path: &str) -> io::Result<Mesh> {
//! let mut reader = R::open(path)?;
//! reader.read_mesh()
//! }
//!
//! // Generic write function
//! fn save<W: Writer>(mut writer: W, mesh: &Mesh) -> io::Result<()> {
//! writer.add_mesh(mesh, Some("Model"))?;
//! writer.write("output.ext")
//! }
//!
//! // Works with any format
//! let mesh = load::<ObjReader>("input.obj")?;
//! save(ObjWriter::new(), &mesh)?;
//! save(PlyWriter::new(), &mesh)?;
//! ```
//!
//! # Format-Specific Features
//!
//! While the trait provides a common interface, each writer has format-specific methods:
//!
//! ```ignore
//! // OBJ: Named groups
//! let mut obj = ObjWriter::new();
//! obj.add_mesh(&mesh, Some("Cube"));
//!
//! // PLY: Point clouds with colors
//! let mut ply = PlyWriter::new();
//! ply.add_points_with_colors(&points, &colors);
//!
//! // FBX: Optional compression
//! let mut fbx = FbxWriter::new().with_compression(true);
//! fbx.add_mesh(&mesh, Some("Model"));
//!
//! // glTF: Custom quantization, multiple output formats
//! let mut gltf = GltfWriter::new();
//! gltf.add_draco_mesh(&mesh, Some("Model"), None)?; // Use default quantization
//! gltf.write_glb("output.glb")?; // Binary GLB
//! gltf.write_gltf("out.gltf", "out.bin")?; // Separate files
//! gltf.write_gltf_embedded("embedded.gltf")?; // Pure text
//! ```
//!
//! # glTF/GLB with Draco Compression
//!
//! The `gltf_reader` and `gltf_writer` modules provide focused support for
//! Draco triangle meshes through `KHR_draco_mesh_compression`. They validate
//! the container enough to avoid silently dropping required glTF features; they
//! are not a full glTF SDK.
//!
//! Three output formats are available:
//!
//! - **GLB**: Binary container (single .glb file)
//! - **glTF + .bin**: JSON with separate binary file
//! - **glTF (embedded)**: Pure text JSON with base64 data URIs
//!
//! ## Reading Draco-compressed glTF
//!
//! ```ignore
//! use draco_io::gltf_reader::GltfReader;
//!
//! let reader = GltfReader::open("model.glb")?;
//! for (info, mesh) in reader.decode_all_draco_meshes()? {
//! println!("Mesh '{}' has {} faces",
//! info.mesh_name.unwrap_or_default(),
//! mesh.num_faces());
//! }
//! ```
//!
//! ## Writing Draco-compressed GLB
//!
//! ```ignore
//! use draco_io::gltf_writer::GltfWriter;
//!
//! let mut writer = GltfWriter::new();
//! writer.add_draco_mesh(&mesh, Some("MyMesh"), None)?; // Use default quantization
//!
//! // Option 1: Binary GLB (most compact)
//! writer.write_glb("output.glb")?;
//!
//! // Option 2: Separate JSON and binary
//! writer.write_gltf("output.gltf", "output.bin")?;
//!
//! // Option 3: Pure text with embedded data (no external files)
//! writer.write_gltf_embedded("output.gltf")?;
//! ```
// Reader modules.
// Reader-agnostic glTF geometry decode + shared error type. Available with the
// reader or the writer, so the compressor reuses it without the reader.
// Writer modules.
/// Document-preserving glTF Draco compression (keeps materials, textures, etc.).
///
/// The in-memory [`gltf_compress::compress_gltf_value`] needs only the writer;
/// the byte API ([`gltf_compress::compress_gltf_bytes`]) also needs the reader.
/// glTF/GLB writer with Draco mesh compression support.
/// Shared PLY storage-format enum.
// Traits module is always available
// Scene-graph layer (data model + traits) is only compiled for hierarchical
// formats (glTF, FBX) that actually carry a scene.
// Re-export main types for convenience
pub use ;
pub use FbxWriter;
// Reader-agnostic geometry decode + shared error type (reader or writer).
pub use ;
// In-memory compressor core: writer only.
pub use compress_gltf_value;
// Byte compressor API: needs the reader to parse + resolve buffers.
pub use ;
pub use ;
pub use ;
pub use ObjReader;
pub use ObjWriter;
pub use PlyFormat;
pub use PlyReader;
pub use PlyWriter;
pub use ;
pub use ;