mesh_tools/
lib.rs

1//! # mesh-tools: A Rust library for exporting glTF/GLB files
2//!
3//! This library provides a high-level API for creating and exporting 3D models in the
4//! [glTF](https://www.khronos.org/gltf/) (GL Transmission Format) standard, which is a 
5//! JSON-based format for 3D scenes and models, widely used for efficient transmission and loading 
6//! of 3D content.
7//!
8//! ## Key Features
9//! 
10//! - Create and manipulate 3D geometry (vertices, normals, UVs, indices)
11//! - Generate primitive shapes (boxes, spheres, planes, cylinders, etc.)
12//! - Define materials with physically-based rendering (PBR) properties
13//! - Support for textures and image data
14//! - Create complex hierarchical scenes with node parent-child relationships
15//! - Export models in both glTF (JSON+binary) and GLB (single binary) formats
16//! - Lightweight math types via the mint crate
17//!
18//! ## Math Types
19//!
20//! This library uses the lightweight [mint](https://crates.io/crates/mint) crate for mathematical types.
21//! A compatibility layer is provided in the `compat` module to make working with these types easy:
22//!
23//! ```rust
24//! use mesh_tools::compat::{Point3, Vector2, Vector3};
25//!
26//! // Use constructor functions
27//! let position = mesh_tools::compat::point3::new(1.0, 2.0, 3.0);
28//! let normal = mesh_tools::compat::vector3::new(0.0, 1.0, 0.0);
29//! 
30//! // Vector operations
31//! let a = mesh_tools::compat::vector3::new(1.0, 0.0, 0.0);
32//! let b = mesh_tools::compat::vector3::new(0.0, 1.0, 0.0);
33//! let cross_product = mesh_tools::compat::cross(a, b);
34//! ```
35//!
36//! ## Basic Usage
37//!
38//! ```rust
39//! use mesh_tools::GltfBuilder;
40//!
41//! // Create a new glTF builder
42//! let mut builder = GltfBuilder::new();
43//!
44//! // Create a simple box mesh
45//! let box_mesh = builder.create_box(1.0);
46//!
47//! // Add a node referencing the mesh
48//! let node = builder.add_node(
49//!     Some("Box".to_string()),
50//!     Some(box_mesh),
51//!     None, // Default position
52//!     None, // Default rotation
53//!     None, // Default scale
54//! );
55//!
56//! // Create a scene containing the node
57//! builder.add_scene(Some("Main Scene".to_string()), Some(vec![node]));
58//!
59//! // Export to GLB format
60//! builder.export_glb("output.glb").unwrap();
61//! ```
62//!
63//! See the examples directory for more complex usage scenarios.
64
65// Public modules
66pub mod texture;     // Texture and image handling
67pub mod primitives;  // Geometry generation primitives
68pub mod error;       // Error types and results
69pub mod models;      // glTF data model definitions
70pub mod constants;   // glTF format constants
71pub mod compat;      // Compatibility layer for mint math types
72pub mod material;    // Material creation and management
73pub mod mesh;        // Mesh creation and manipulation
74pub mod builder;     // Main GltfBuilder implementation
75
76// Internal implementation modules
77mod builder_primitives;       // Implementations for primitive shape creation
78mod builder_texture;          // Implementations for texture handling
79mod builder_material;         // Implementations for material handling
80mod builder_material_specular; // Implementations for specular material handling
81mod builder_animation;        // Implementations for animation handling
82
83// Re-exports
84pub use error::{GltfError, Result};
85pub use models::*;
86pub use builder::GltfBuilder;
87pub use builder_primitives::Triangle;
88
89// Constants re-exports
90pub use constants::accessor_type;
91pub use constants::buffer_view_target;
92pub use constants::component_type;
93pub use constants::sampler_filter;
94pub use constants::sampler_wrap;
95pub use constants::alpha_mode;
96pub use constants::primitive_mode;
97pub use builder_animation::{AnimationPath, InterpolationType};