nightshade 0.13.0

A cross-platform data-oriented game engine.
Documentation
//! Lattice deformation for mesh bending and warping.
//!
//! Deform meshes by manipulating a 3D grid of control points (Free-Form Deformation):
//!
//! - [`Lattice`]: 3D grid of control points that deforms space
//! - [`LatticeInfluenced`]: Component marking a mesh as affected by a lattice
//! - `create_lattice_entity`: Create a new lattice
//! - `register_entity_for_lattice_deformation`: Bind a mesh to a lattice
//! - `lattice_deformation_system`: Apply deformations each frame
//!
//! Requires the `lattice` feature.
//!
//! # How Lattice Deformation Works
//!
//! A lattice is a 3D grid of points surrounding a mesh. Moving these points
//! warps the space inside, deforming any mesh vertices within the lattice bounds.
//! This technique is useful for:
//!
//! - Bending rigid objects (swords, pipes)
//! - Squash and stretch effects
//! - Terrain deformation
//! - Character bulging/flexing
//!
//! # Basic Setup
//!
//! ```ignore
//! use nightshade::ecs::lattice::{create_lattice_entity, register_entity_for_lattice_deformation};
//!
//! // Create a lattice covering a region
//! let lattice = create_lattice_entity(
//!     world,
//!     Vec3::new(-2.0, 0.0, -2.0),   // Bounds min
//!     Vec3::new(2.0, 4.0, 2.0),     // Bounds max
//!     [3, 4, 3],                     // Grid dimensions (X, Y, Z)
//! );
//!
//! // Register a mesh to be deformed by this lattice
//! register_entity_for_lattice_deformation(world, mesh_entity, lattice);
//! ```
//!
//! # Manipulating Control Points
//!
//! Displace lattice points to deform the mesh:
//!
//! ```ignore
//! if let Some(lattice) = world.core.get_lattice_mut(lattice_entity) {
//!     // Bend the top of the lattice
//!     let [nx, ny, nz] = lattice.dimensions;
//!
//!     for x in 0..nx {
//!         for z in 0..nz {
//!             // Push top row sideways
//!             lattice.set_displacement(x, ny - 1, z, Vec3::new(1.0, 0.0, 0.0));
//!         }
//!     }
//! }
//! ```
//!
//! # Animated Deformation
//!
//! ```ignore
//! fn run_systems(&mut self, world: &mut World) {
//!     let time = world.resources.window.timing.uptime_milliseconds as f32 / 1000.0;
//!
//!     if let Some(lattice) = world.core.get_lattice_mut(lattice_entity) {
//!         // Wobble effect
//!         let offset = (time * 2.0).sin() * 0.5;
//!         lattice.set_displacement(1, 2, 1, Vec3::new(offset, 0.0, 0.0));
//!     }
//!
//!     // Apply deformations
//!     lattice_deformation_system(world);
//! }
//! ```
//!
//! # Falloff for Smooth Blending
//!
//! Control how deformation fades outside lattice bounds:
//!
//! ```ignore
//! let lattice = Lattice::new(bounds_min, bounds_max, [4, 4, 4])
//!     .with_falloff(2.0);  // Smooth falloff over 2 units outside bounds
//! ```
//!
//! # Reset Deformation
//!
//! Return lattice to undeformed state:
//!
//! ```ignore
//! if let Some(lattice) = world.core.get_lattice_mut(lattice_entity) {
//!     lattice.reset_displacements();
//! }
//! ```
//!
//! # Debug Visualization
//!
//! Draw lattice points and connections:
//!
//! ```ignore
//! use nightshade::ecs::lattice::debug::{LatticeDebugState, lattice_debug_draw};
//!
//! let mut debug_state = LatticeDebugState::default();
//! lattice_debug_draw(world, &mut debug_state);
//! ```
//!
//! # Grid Dimensions
//!
//! Higher resolution = smoother deformation but more control points:
//!
//! | Dimensions | Points | Use Case |
//! |------------|--------|----------|
//! | [2, 2, 2] | 8 | Simple bend/twist |
//! | [3, 3, 3] | 27 | General deformation |
//! | [4, 4, 4] | 64 | Detailed control |
//! | [2, 8, 2] | 32 | Long bending objects |
//!
//! # Performance Notes
//!
//! - Deformation is computed via morph targets on the GPU
//! - Only updates when lattice or mesh transform changes
//! - Multiple meshes can share a single lattice
//!
//! [`Lattice`]: components::Lattice
//! [`LatticeInfluenced`]: components::LatticeInfluenced

pub mod components;
#[cfg(feature = "lattice")]
pub mod debug;
#[cfg(feature = "lattice")]
pub mod systems;

pub use components::*;