wavefront-obj-io
Streaming, callback-based Wavefront OBJ and MTL reader and writer in Rust. For round-trip pipelines and large files.
When to use this crate
- You want to process OBJ files without allocating a
Meshstruct - e.g. push vertices straight into a GPU buffer. - You want to round-trip an OBJ file (read then write back) without losing fidelity.
- You're building an OBJ format converter / preprocessor / validator.
- You need to handle files too large to comfortably fit in memory.
When not to use this crate
If you just want let mesh = load(path)?, use
tobj. It is the right tool for that job
and this crate intentionally does not compete with it.
Example
use ;
use Cursor;
;
let obj = "v 0 0 0\nv 1 0 0\nv 0 1 0\n";
let mut counter = default;
read_obj_file.unwrap;
assert_eq!;
Features
- Streaming, SAX-style callback API on
ObjReader/ObjWritertraits. - Configurable float precision (
f32orf64) via theObjFloatgeneric. - Standard OBJ directive coverage:
v,vt,vn,f,o,#,mtllib,usemtl,g,s,l,p. - MTL directive coverage:
newmtl,Ka,Kd,Ks,Ke,Ns,Ni,d,Tr,illum, and themap_*/bump/disp/decal/refltexture-map family. - Strict-by-default
read_unknowncallback - opt in to lenient parsing for NURBS / display / vendor directives. - Typed
ObjErrorwith structuredParseErrorKindfor pattern-matching; bidirectionalFrombetweenObjErrorandio::Error. - WASM-compatible, no platform-specific dependencies.
Documentation
https://docs.rs/wavefront-obj-io
Development
This project uses Conventional Commits
for commit messages, and rustfmt + clippy for formatting and linting.
Running the tests
WASM tests for server-side WASM (wasmtime)
# Install the target and wasmtime (one-time setup)
WASM build for browser
License
MIT