Expand description
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:
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:
// 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
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
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")?;Re-exports§
pub use fbx_reader::FbxMemoryReader;fbx-readerpub use fbx_reader::FbxReader;fbx-readerpub use fbx_writer::FbxWriter;fbx-writerpub use gltf_geometry::decode_geometry;gltf-readerorgltf-writerpub use gltf_geometry::AccessorSource;gltf-readerorgltf-writerpub use gltf_geometry::DecodedAccessor;gltf-readerorgltf-writerpub use gltf_geometry::GltfError;gltf-readerorgltf-writerpub use gltf_compress::compress_gltf_value;gltf-writerpub use gltf_compress::compress_gltf_bytes;gltf-readerandgltf-writerpub use gltf_compress::compress_gltf_bytes_with_base_path;gltf-readerandgltf-writerpub use gltf_reader::DracoPrimitiveInfo;gltf-readerpub use gltf_reader::GltfReader;gltf-readerpub use gltf_writer::GltfWriteError;gltf-writerpub use gltf_writer::GltfWriter;gltf-writerpub use obj_reader::ObjReader;obj-readerpub use obj_writer::ObjWriter;obj-writerpub use ply_format::PlyFormat;pub use ply_reader::PlyReader;ply-readerpub use ply_writer::PlyWriter;ply-writerpub use scene::flatten_to_scene;scenepub use scene::MeshInstance;scenepub use scene::Scene;scenepub use scene::SceneNode;scenepub use scene::SceneReader;scenepub use scene::SceneWriter;scenepub use scene::Transform;scenepub use traits::PointCloudReader;pub use traits::PointCloudWriter;pub use traits::ReadFromBytes;pub use traits::Reader;pub use traits::WriteToBytes;pub use traits::Writer;
Modules§
- fbx_
reader fbx-reader - FBX binary format reader for meshes.
- fbx_
writer fbx-writer - FBX binary format writer for meshes.
- gltf_
compress gltf-writer - Document-preserving glTF Draco compression (keeps materials, textures, etc.).
- gltf_
geometry gltf-readerorgltf-writer - Reader-agnostic glTF geometry decoding.
- gltf_
reader gltf-reader - glTF/GLB reader with full scene graph and mesh decoding support.
- gltf_
writer gltf-writer - glTF/GLB writer with Draco mesh compression support. glTF/GLB writer with Draco mesh compression support.
- obj_
reader obj-reader - OBJ format reader for meshes and point clouds.
- obj_
writer obj-writer - OBJ format writer for meshes and point clouds.
- ply_
format - Shared PLY storage-format enum.
- ply_
reader ply-reader - PLY format reader for meshes and point clouds.
- ply_
writer ply-writer - PLY format writer for meshes and point clouds.
- scene
scene - Scene-graph layer: data model and traits for formats that represent hierarchy.
- traits
- Common traits for readers and writers.