Skip to main content

WaveHeightfield2D

Struct WaveHeightfield2D 

Source
pub struct WaveHeightfield2D { /* private fields */ }
Expand description

Interactive 2D shallow-water damped wave heightfield with absorbing sponge boundaries and solid obstacle reflections.

Implementations§

Source§

impl WaveHeightfield2D

Interactive 2D shallow-water wave simulation, wake injection, obstacle masking, and sampling API.

Source

pub fn from_config(config: WaveHeightfieldConfig) -> Self

Constructs a pre-allocated WaveHeightfield2D solver from config.

§Arguments
  • WaveHeightfieldConfig - Desired wave grid configuration.
§Returns
  • Self - Pre-allocated zero-steady-state-allocation wave solver.
Source

pub fn reset(&mut self)

Resets wave heights, velocities, foam, and simulation time to calm rest while preserving obstacles.

Source

pub fn step(&mut self, dt_secs: f32)

Advances the shallow-water wave heightfield by dt_secs using CFL-clamped damped Verlet integration with zero heap allocations.

§Arguments
  • f32 - Elapsed frame time in seconds.
Source

pub fn inject_splash( &mut self, world_x: f32, world_z: f32, radius_m: f32, amplitude_m: f32, )

Injects a circular splash disturbance at (world_x, world_z) with radius radius_m and peak amplitude amplitude_m.

§Arguments
  • f32 - World X splash center coordinate.
  • f32 - World Z splash center coordinate.
  • f32 - Splash footprint radius in meters.
  • f32 - Displacement amplitude in meters (negative pushes water down to radiate a ring).
Source

pub fn inject_boat_wake( &mut self, world_x: f32, world_z: f32, velocity_xz: Vec2, hull_radius_m: f32, wake_strength: f32, )

Injects an expanding Kelvin boat wake along a moving vessel’s horizontal velocity vector.

§Arguments
  • f32 - World X hull center coordinate.
  • f32 - World Z hull center coordinate.
  • Vec2 - Horizontal vessel velocity (vx, vz) in meters per second.
  • f32 - Characteristic hull beam radius in meters.
  • f32 - Dimensionless wake intensity multiplier.
Source

pub fn inject_raindrop(&mut self, world_x: f32, world_z: f32, intensity: f32)

Injects a localized raindrop ripple impulse at (world_x, world_z).

§Arguments
  • f32 - World X impact coordinate.
  • f32 - World Z impact coordinate.
  • f32 - Dimensionless raindrop intensity in [0.0, 2.0].
Source

pub fn set_obstacle_rect( &mut self, min_x: f32, min_z: f32, max_x: f32, max_z: f32, solid: bool, )

Marks or clears a world-space axis-aligned rectangular solid obstacle mask.

§Arguments
  • f32 - Minimum world X coordinate.
  • f32 - Minimum world Z coordinate.
  • f32 - Maximum world X coordinate.
  • f32 - Maximum world Z coordinate.
  • bool - true to mark cells as reflective solid obstacles, false to restore fluid.
Source

pub fn set_obstacle_circle( &mut self, center_x: f32, center_z: f32, radius_m: f32, solid: bool, )

Marks or clears a world-space circular solid obstacle mask (e.g., pier piling or rock).

§Arguments
  • f32 - Center world X coordinate.
  • f32 - Center world Z coordinate.
  • f32 - Circle radius in meters.
  • bool - true to mark cells as reflective solid obstacles, false to restore fluid.
Source

pub fn clear_obstacles(&mut self)

Clears all solid obstacle masks back to fluid.

Source

pub fn is_obstacle_cell(&self, col: usize, row: usize) -> bool

Queries whether cell (col, row) is currently flagged as a solid obstacle.

§Arguments
  • usize - Column index along X.
  • usize - Row index along Z.
§Returns
  • bool - true when the cell is solid.
Source

pub fn sample_displacement(&self, world_x: f32, world_z: f32) -> f32

Bilinearly samples the wave displacement relative to base_water_y at world (world_x, world_z).

§Arguments
  • f32 - World X coordinate.
  • f32 - World Z coordinate.
§Returns
  • f32 - Signed vertical wave displacement in meters.
Source

pub fn sample_height(&self, world_x: f32, world_z: f32) -> f32

Bilinearly samples the absolute world-space surface height base_water_y + displacement at (world_x, world_z).

§Arguments
  • f32 - World X coordinate.
  • f32 - World Z coordinate.
§Returns
  • f32 - World-space water surface Y coordinate in meters.
Source

pub fn sample_height_and_normal( &self, world_x: f32, world_z: f32, ) -> (f32, Vec3)

Samples both absolute world-space surface height and analytical central-difference surface normal at (world_x, world_z).

§Arguments
  • f32 - World X coordinate.
  • f32 - World Z coordinate.
§Returns
  • (f32, Vec3) - Pair (world_surface_y, unit_upward_normal).
Source

pub fn sample_foam(&self, world_x: f32, world_z: f32) -> f32

Bilinearly samples accumulated wake foam intensity in [0.0, 1.0] at (world_x, world_z).

§Arguments
  • f32 - World X coordinate.
  • f32 - World Z coordinate.
§Returns
  • f32 - Wake foam coverage factor in [0.0, 1.0].
Source

pub fn total_wave_energy(&self) -> f32

Computes total discrete shallow-water Hamiltonian wave energy (kinetic + potential) across all fluid cells.

§Returns
  • f32 - Non-negative discrete mechanical wave energy.
Source

pub fn max_abs_height(&self) -> f32

Returns the maximum absolute displacement amplitude across the entire heightfield.

§Returns
  • f32 - Maximum |h| in meters.
Source

pub fn build_mesh(&self, name: &str, material: PbrMaterial) -> Mesh3D

Builds an indexed Mesh3D representing the current wave surface with analytical normals and vertex foam colors.

§Arguments
  • &str - Asset mesh name (falls back to WAKE_DEFAULT_MESH_NAME when empty).
  • PbrMaterial - Water surface PBR material.
§Returns
  • Mesh3D - Renderable triangle mesh for the heightfield surface.
Source§

impl WaveHeightfield2D

Implements impl #impl_generics #name #ty_generics #where_clause.

Source

pub fn get_config(&self) -> WaveHeightfieldConfig

Source

pub fn get_mut_config(&mut self) -> &mut WaveHeightfieldConfig

Source

pub fn set_config(&mut self, val: WaveHeightfieldConfig) -> &mut Self

Source

pub fn get_heights_curr(&self) -> &Vec<f32>

Source

pub fn get_mut_heights_curr(&mut self) -> &mut Vec<f32>

Source

pub fn set_heights_curr(&mut self, val: Vec<f32>) -> &mut Self

Source

pub fn get_heights_prev(&self) -> &Vec<f32>

Source

pub fn get_mut_heights_prev(&mut self) -> &mut Vec<f32>

Source

pub fn set_heights_prev(&mut self, val: Vec<f32>) -> &mut Self

Source

pub fn get_heights_next(&self) -> &Vec<f32>

Source

pub fn get_mut_heights_next(&mut self) -> &mut Vec<f32>

Source

pub fn set_heights_next(&mut self, val: Vec<f32>) -> &mut Self

Source

pub fn get_obstacle_mask(&self) -> &Vec<u8> ⓘ

Source

pub fn get_mut_obstacle_mask(&mut self) -> &mut Vec<u8> ⓘ

Source

pub fn set_obstacle_mask(&mut self, val: Vec<u8>) -> &mut Self

Source

pub fn get_foam(&self) -> &Vec<f32>

Source

pub fn get_mut_foam(&mut self) -> &mut Vec<f32>

Source

pub fn set_foam(&mut self, val: Vec<f32>) -> &mut Self

Source

pub fn get_cell_damping(&self) -> &Vec<f32>

Source

pub fn get_mut_cell_damping(&mut self) -> &mut Vec<f32>

Source

pub fn set_cell_damping(&mut self, val: Vec<f32>) -> &mut Self

Source

pub fn get_last_dt_sub(&self) -> f32

Source

pub fn get_mut_last_dt_sub(&mut self) -> &mut f32

Source

pub fn set_last_dt_sub(&mut self, val: f32) -> &mut Self

Source

pub fn get_sim_time_secs(&self) -> f32

Source

pub fn get_mut_sim_time_secs(&mut self) -> &mut f32

Source

pub fn set_sim_time_secs(&mut self, val: f32) -> &mut Self

Trait Implementations§

Source§

impl Clone for WaveHeightfield2D

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for WaveHeightfield2D

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for WaveHeightfield2D

Default calm WaveHeightfield2D solver.

Source§

fn default() -> Self

Creates a WaveHeightfield2D using WaveHeightfieldConfig::default().

§Returns
  • Self - Calm pre-allocated heightfield solver.
Source§

impl PartialEq for WaveHeightfield2D

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for WaveHeightfield2D

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.