schematic_mesher/
lib.rs

1//! # Schematic Mesher
2//!
3//! A Rust library for generating 3D meshes from Minecraft schematics.
4//!
5//! ## Overview
6//!
7//! This library takes a Minecraft schematic and resource pack as input,
8//! and produces a 3D mesh (GLB/glTF) with a texture atlas as output.
9//!
10//! ## Quick Start
11//!
12//! ```ignore
13//! use schematic_mesher::{load_resource_pack, Mesher, export_glb};
14//!
15//! // Load a resource pack
16//! let pack = load_resource_pack("path/to/pack.zip")?;
17//!
18//! // Create a mesher
19//! let mesher = Mesher::new(pack);
20//!
21//! // Generate mesh from blocks (using BlockSource trait)
22//! let output = mesher.mesh(&my_block_source)?;
23//!
24//! // Export to GLB
25//! let glb_bytes = export_glb(&output)?;
26//! ```
27//!
28//! ## Library Integration
29//!
30//! For integrating with existing block storage (like Nucleation), implement the
31//! `BlockSource` trait or use `mesh_blocks()` with an iterator of blocks:
32//!
33//! ```ignore
34//! use schematic_mesher::{Mesher, InputBlock, BlockPosition, BoundingBox};
35//!
36//! // Create blocks from your schematic
37//! let blocks: Vec<(BlockPosition, InputBlock)> = /* ... */;
38//! let bounds = BoundingBox::new([0, 0, 0], [16, 16, 16]);
39//!
40//! // Mesh with references
41//! let output = mesher.mesh_blocks(
42//!     blocks.iter().map(|(pos, block)| (*pos, block)),
43//!     bounds
44//! )?;
45//! ```
46
47pub mod error;
48pub mod types;
49pub mod resource_pack;
50pub mod resolver;
51pub mod mesher;
52pub mod atlas;
53pub mod export;
54
55// Re-export main types for convenience
56pub use error::{MesherError, Result};
57pub use types::{Direction, Axis, BlockPosition, BoundingBox, InputBlock, BlockSource};
58pub use resource_pack::{ResourcePack, BlockModel, ModelElement, BlockstateDefinition};
59pub use mesher::{Mesher, MesherConfig, MesherOutput, Mesh, Vertex, TintColors, TintProvider};
60pub use atlas::TextureAtlas;
61pub use export::gltf::export_glb;
62pub use export::obj::{export_obj, ObjExport};
63pub use export::raw::{export_raw, RawMeshData};
64
65/// Load a resource pack from a file path (ZIP or directory).
66pub fn load_resource_pack<P: AsRef<std::path::Path>>(path: P) -> Result<ResourcePack> {
67    resource_pack::loader::load_from_path(path)
68}
69
70/// Load a resource pack from bytes (for WASM compatibility).
71pub fn load_resource_pack_from_bytes(data: &[u8]) -> Result<ResourcePack> {
72    resource_pack::loader::load_from_bytes(data)
73}
74
75#[cfg(feature = "wasm")]
76pub mod wasm;