Crate mesh_tools

Source
Expand description

§mesh-tools: A Rust library for exporting glTF/GLB files

This library provides a high-level API for creating and exporting 3D models in the glTF (GL Transmission Format) standard, which is a JSON-based format for 3D scenes and models, widely used for efficient transmission and loading of 3D content.

§Key Features

  • Create and manipulate 3D geometry (vertices, normals, UVs, indices)
  • Generate primitive shapes (boxes, spheres, planes, cylinders, etc.)
  • Define materials with physically-based rendering (PBR) properties
  • Support for textures and image data
  • Create complex hierarchical scenes with node parent-child relationships
  • Export models in both glTF (JSON+binary) and GLB (single binary) formats
  • Lightweight math types via the mint crate

§Math Types

This library uses the lightweight mint crate for mathematical types. A compatibility layer is provided in the compat module to make working with these types easy:

use mesh_tools::compat::{Point3, Vector2, Vector3};

// Use constructor functions
let position = mesh_tools::compat::point3::new(1.0, 2.0, 3.0);
let normal = mesh_tools::compat::vector3::new(0.0, 1.0, 0.0);
 
// Vector operations
let a = mesh_tools::compat::vector3::new(1.0, 0.0, 0.0);
let b = mesh_tools::compat::vector3::new(0.0, 1.0, 0.0);
let cross_product = mesh_tools::compat::cross(a, b);

§Basic Usage

use mesh_tools::GltfBuilder;

// Create a new glTF builder
let mut builder = GltfBuilder::new();

// Create a simple box mesh
let box_mesh = builder.create_box(1.0);

// Add a node referencing the mesh
let node = builder.add_node(
    Some("Box".to_string()),
    Some(box_mesh),
    None, // Default position
    None, // Default rotation
    None, // Default scale
);

// Create a scene containing the node
builder.add_scene(Some("Main Scene".to_string()), Some(vec![node]));

// Export to GLB format
builder.export_glb("output.glb").unwrap();

See the examples directory for more complex usage scenarios.

Re-exports§

pub use error::GltfError;
pub use error::Result;
pub use builder::GltfBuilder;
pub use constants::accessor_type;
pub use constants::buffer_view_target;
pub use constants::component_type;
pub use constants::sampler_filter;
pub use constants::sampler_wrap;
pub use constants::alpha_mode;
pub use constants::primitive_mode;
pub use models::*;

Modules§

builder
GltfBuilder: Main Builder Interface
compat
Compatibility layer for math types
constants
glTF Format Constants
error
Error Handling
material
Material Creation and Management
mesh
Mesh Creation and Manipulation
models
glTF Data Model Definitions
primitives
Primitive Shape Generation
texture
Texture Processing and Management

Structs§

Triangle
A triangle represented by three vertex indices