1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
//! 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 use *;