pub struct FluidGrid {Show 20 fields
pub width: usize,
pub height: usize,
pub dx: f32,
pub vx: Vec<f32>,
pub vy: Vec<f32>,
pub density: Vec<f32>,
pub temp: Vec<f32>,
pub color_r: Vec<f32>,
pub color_g: Vec<f32>,
pub color_b: Vec<f32>,
pub pressure: Vec<f32>,
pub obstacle: Vec<f32>,
pub viscosity: f32,
pub diffusion: f32,
pub buoyancy: f32,
pub ambient_temp: f32,
pub vorticity_strength: f32,
pub gravity: Vec2,
pub decay: f32,
pub time: f32,
/* private fields */
}Expand description
2D Eulerian fluid simulation grid.
Fields§
§width: usizeGrid width in cells.
height: usizeGrid height in cells.
dx: f32Physical size of one cell (world units).
vx: Vec<f32>Velocity X component (cell-centered).
vy: Vec<f32>Velocity Y component (cell-centered).
density: Vec<f32>Density / smoke field.
temp: Vec<f32>Temperature field (buoyancy driving).
color_r: Vec<f32>Color R channel for multi-fluid visualization.
color_g: Vec<f32>Color G channel.
color_b: Vec<f32>Color B channel.
pressure: Vec<f32>Pressure field (intermediate, used in projection).
obstacle: Vec<f32>Obstacle / solid mask: 1.0 = fluid, 0.0 = solid.
viscosity: f32Kinematic viscosity (m^2/s). Default 1e-4.
diffusion: f32Density diffusion coefficient.
buoyancy: f32Buoyancy lift coefficient (hot gas rises).
ambient_temp: f32Ambient temperature. Cells above this experience upward force.
vorticity_strength: f32Vorticity confinement strength (adds swirl detail). Default 0.3.
gravity: Vec2Gravity direction and magnitude.
decay: f32Global density decay per second (smoke dissipation).
time: f32Seconds elapsed since creation.
Implementations§
Source§impl FluidGrid
impl FluidGrid
Sourcepub fn new(width: usize, height: usize, dx: f32) -> Self
pub fn new(width: usize, height: usize, dx: f32) -> Self
Create a new fluid grid of given dimensions and cell size.
pub fn idx(&self, x: usize, y: usize) -> usize
Sourcepub fn add_velocity(&mut self, cx: usize, cy: usize, dvx: f32, dvy: f32)
pub fn add_velocity(&mut self, cx: usize, cy: usize, dvx: f32, dvy: f32)
Add velocity impulse at cell (cx, cy).
Sourcepub fn add_density(&mut self, cx: usize, cy: usize, amount: f32)
pub fn add_density(&mut self, cx: usize, cy: usize, amount: f32)
Add density at cell.
Sourcepub fn add_temperature(&mut self, cx: usize, cy: usize, dt: f32)
pub fn add_temperature(&mut self, cx: usize, cy: usize, dt: f32)
Add temperature at cell.
Sourcepub fn add_color(&mut self, cx: usize, cy: usize, r: f32, g: f32, b: f32)
pub fn add_color(&mut self, cx: usize, cy: usize, r: f32, g: f32, b: f32)
Add colored smoke/fluid at cell.
Sourcepub fn add_obstacle_circle(&mut self, cx: f32, cy: f32, radius: f32)
pub fn add_obstacle_circle(&mut self, cx: f32, cy: f32, radius: f32)
Paint a circular solid obstacle.
Sourcepub fn add_obstacle_rect(&mut self, x0: usize, y0: usize, x1: usize, y1: usize)
pub fn add_obstacle_rect(&mut self, x0: usize, y0: usize, x1: usize, y1: usize)
Paint a rectangular solid obstacle.
Sourcepub fn sample_velocity(&self, wx: f32, wy: f32) -> Vec2
pub fn sample_velocity(&self, wx: f32, wy: f32) -> Vec2
Sample velocity at world position (bilinear).
Sourcepub fn sample_density(&self, wx: f32, wy: f32) -> f32
pub fn sample_density(&self, wx: f32, wy: f32) -> f32
Sample density at world position.
Sourcepub fn sample_color(&self, wx: f32, wy: f32) -> (f32, f32, f32)
pub fn sample_color(&self, wx: f32, wy: f32) -> (f32, f32, f32)
Sample color at world position.
Sourcepub fn max_velocity(&self) -> f32
pub fn max_velocity(&self) -> f32
Maximum velocity magnitude in the grid.
Sourcepub fn total_density(&self) -> f32
pub fn total_density(&self) -> f32
Total density integral (conservation check).
Sourcepub fn splash(&mut self, cx: f32, cy: f32, radius: f32, strength: f32)
pub fn splash(&mut self, cx: f32, cy: f32, radius: f32, strength: f32)
Apply a circular velocity splash (radial outward impulse).
Sourcepub fn swirl(&mut self, cx: f32, cy: f32, radius: f32, strength: f32)
pub fn swirl(&mut self, cx: f32, cy: f32, radius: f32, strength: f32)
Apply a swirl vortex impulse (clockwise tangential velocity).
Sourcepub fn resize(&mut self, new_width: usize, new_height: usize)
pub fn resize(&mut self, new_width: usize, new_height: usize)
Resize the grid (clears all data).
Sourcepub fn to_rgba_density(&self, tint: (u8, u8, u8)) -> Vec<u8> ⓘ
pub fn to_rgba_density(&self, tint: (u8, u8, u8)) -> Vec<u8> ⓘ
Render the density field as a flat RGBA byte buffer (width × height × 4). Useful for debug visualization.
Sourcepub fn to_rgba_velocity(&self) -> Vec<u8> ⓘ
pub fn to_rgba_velocity(&self) -> Vec<u8> ⓘ
Render the velocity field as a flat RGBA byte buffer (speed-encoded).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for FluidGrid
impl RefUnwindSafe for FluidGrid
impl Send for FluidGrid
impl Sync for FluidGrid
impl Unpin for FluidGrid
impl UnsafeUnpin for FluidGrid
impl UnwindSafe for FluidGrid
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.