Download crates/mb3-dat/src/lib.rs from nmarshall/nanobrush: direct link, hf CLI and curl.
- Browser
- Download file 2.5 kB
-
https://huggingface.co/nmarshall/nanobrush/resolve/main/crates/mb3-dat/src/lib.rs
- Command line
-
hf download hf://nmarshall/nanobrush/crates/mb3-dat/src/lib.rs
-
curl -L -o lib.rs https://huggingface.co/nmarshall/nanobrush/resolve/main/crates/mb3-dat/src/lib.rs
2.5 kB
| //! Safe, strict MB3 DAT serialization, independent of the editor or renderer. | |
| //! | |
| //! See `docs/RUST_DAT.md` for compatibility and resource limits. No geometry is | |
| //! computed or validated. Decoding owns its results and never retains the input. | |
| //! | |
| //! ``` | |
| //! use mb3_dat::{Document, Limits, Version, World, decode, encode}; | |
| //! let document = Document { version: Version::V201512200, world: World::default() }; | |
| //! let bytes = encode(&document, &Limits::default())?; | |
| //! assert_eq!(decode(&bytes, &Limits::default())?, document); | |
| //! # Ok::<(), mb3_dat::Error>(()) | |
| //! ``` | |
| mod codec; | |
| pub use codec::{Error, ErrorKind, Limits, decode, encode, read, write}; | |
| pub type Vec3 = [f32; 3]; | |
| pub enum Version { | |
| V201501280 = 201501280, | |
| V201512200 = 201512200, | |
| } | |
| pub struct Document { | |
| pub version: Version, | |
| pub world: World, | |
| } | |
| /// Table order and sparse indices are preserved; no converter optimization runs. | |
| pub struct World { | |
| pub computed: bool, | |
| pub string_properties: Vec<String>, | |
| pub uv_properties: Vec<String>, | |
| pub brushes: Vec<Brush>, | |
| pub patches: Vec<Patch9>, | |
| } | |
| pub struct Brush { | |
| pub planes: Vec<Plane>, | |
| } | |
| /// Sparse entries must be unique and sorted by index when encoding. Decoding | |
| /// sorts wire entries by index. An absent entry differs from an empty value. | |
| pub struct Property<T> { | |
| pub index: u32, | |
| pub value: T, | |
| } | |
| pub struct Uv { | |
| pub u: Vec3, | |
| pub v: Vec3, | |
| pub u_scale: f32, | |
| pub u_shift: f32, | |
| pub v_scale: f32, | |
| pub v_shift: f32, | |
| } | |
| pub struct Plane { | |
| pub p0: Vec3, | |
| pub u: Vec3, | |
| pub v: Vec3, | |
| pub strings: Vec<Property<String>>, | |
| pub uv: Vec<Property<Uv>>, | |
| /// Some (including an empty polygon) iff the world's computed flag is true. | |
| pub polygon: Option<Vec<Vec3>>, | |
| } | |
| pub struct Patch9 { | |
| pub anchors_u: u32, | |
| pub anchors_v: u32, | |
| pub quads_u: u32, | |
| pub quads_v: u32, | |
| pub anchors: Vec<Vec3>, | |
| /// Some iff the world's computed flag is true. | |
| pub computed: Option<PatchComputed>, | |
| } | |
| pub struct PatchComputed { | |
| pub points: Vec<Vec3>, | |
| pub normals: Vec<Vec3>, | |
| } | |
| mod tests; | |