euv-core 0.57.0

Core cross-platform runtime for euv featuring arena-based fine-grained reactivity, deterministic layout, flat scene graph, multi-mode rendering, and direct OS platform adapters.
Documentation
use super::*;

/// Single directional Gerstner wave train synthesized from a JONSWAP sea-state cascade.
#[derive(Clone, Copy, Data, Debug, Default, New, PartialEq)]
pub struct GerstnerWaveComponent {
    /// Unit horizontal propagation direction `(dx, dz)`.
    #[get(type(copy))]
    pub(crate) direction: Vec2,
    /// Spatial wavelength in meters (`lambda > 0`).
    #[get(type(copy))]
    pub(crate) wavelength_m: f32,
    /// Vertical wave amplitude in meters.
    #[get(type(copy))]
    pub(crate) amplitude_m: f32,
    /// Dimensionless horizontal steepness contribution `k * H_i` (`sum <= OCEAN_MAX_TOTAL_STEEPNESS`).
    #[get(type(copy))]
    pub(crate) steepness: f32,
    /// Deterministic initial phase offset in radians.
    #[get(type(copy))]
    pub(crate) phase_offset: f32,
    /// Dispersion angular frequency multiplier.
    #[get(type(copy))]
    pub(crate) speed_multiplier: f32,
    /// Cascade tier index (`0` = macro swell, `1` = mid gravity, `2` = fine chop).
    #[get(type(copy))]
    pub(crate) cascade_index: u8,
}

/// Physical optical shading parameters for ocean Beer-Lambert absorption, Fresnel, SSS, and seabed caustics.
#[derive(Clone, Copy, Data, Debug, PartialEq)]
pub struct OceanOpticalConfig {
    /// Linear RGB Beer-Lambert extinction coefficients in `m^-1`.
    #[get(type(copy))]
    pub(crate) absorption_coeff: Vec3,
    /// Deep abyssal water scattering color in linear RGB.
    #[get(type(copy))]
    pub(crate) deep_scatter_color: Vec3,
    /// Shallow sunlit coastal scatter tint in linear RGB.
    #[get(type(copy))]
    pub(crate) shallow_tint_color: Vec3,
    /// Backlit emerald crest subsurface scattering tint in linear RGB.
    #[get(type(copy))]
    pub(crate) sss_color: Vec3,
    /// Aerated crest whitecap foam linear RGB color.
    #[get(type(copy))]
    pub(crate) foam_color: Vec3,
    /// Schlick Fresnel normal-incidence reflectance (`0.02` for water).
    #[get(type(copy))]
    pub(crate) fresnel_f0: f32,
    /// Backlit crest subsurface scattering intensity gain.
    #[get(type(copy))]
    pub(crate) sss_strength: f32,
    /// Seabed projected caustics intensity multiplier.
    #[get(type(copy))]
    pub(crate) caustics_strength: f32,
    /// Jacobian surface-folding determinant threshold below which whitecap foam emerges.
    #[get(type(copy))]
    pub(crate) foam_jacobian_threshold: f32,
}

/// Complete declarative configuration for `OceanSurface3D`.
#[derive(Clone, Copy, Data, Debug, PartialEq)]
pub struct OceanConfig {
    /// Base sea-state preset controlling default spectral energy and optics.
    #[get(type(copy))]
    pub(crate) preset: OceanPreset,
    /// Wind speed at 10 m reference elevation in meters per second.
    #[get(type(copy))]
    pub(crate) wind_speed_mps: f32,
    /// Dominant wind propagation direction `(dx, dz)` (normalized internally).
    #[get(type(copy))]
    pub(crate) wind_direction: Vec2,
    /// Wind fetch distance over open water in kilometers for JONSWAP peak frequency scaling.
    #[get(type(copy))]
    pub(crate) fetch_km: f32,
    /// Global horizontal Gerstner choppiness multiplier in `[0.0, 1.5]`.
    #[get(type(copy))]
    pub(crate) choppiness: f32,
    /// Mean resting sea-surface elevation along world `+Y` in meters.
    #[get(type(copy))]
    pub(crate) mean_water_level_y: f32,
    /// Gravitational acceleration in `m/s^2` driving deep-water dispersion `omega = sqrt(g * k)`.
    #[get(type(copy))]
    pub(crate) gravity_mps2: f32,
    /// Number of directional wave cascades (`1..=4`).
    #[get(type(copy))]
    pub(crate) cascade_count: u8,
    /// Deterministic PRNG seed for wave phases and directional jitter.
    #[get(type(copy))]
    pub(crate) seed: u64,
    /// Physical optical parameters for absorption, Fresnel, SSS, and caustics.
    #[get(type(copy))]
    pub(crate) optics: OceanOpticalConfig,
}

/// Analytical geometric evaluation of `OceanSurface3D` at a single undisplaced horizontal coordinate.
#[derive(Clone, Copy, Data, Debug, Default, New, PartialEq)]
pub struct OceanSurfaceSample {
    /// Displaced world-space surface position `(x + dx, mean_y + dy, z + dz)`.
    #[get(type(copy))]
    pub(crate) displaced_position: Vec3,
    /// Pure 3D wave displacement vector `(dx, dy, dz)` relative to `(x, mean_y, z)`.
    #[get(type(copy))]
    pub(crate) displacement: Vec3,
    /// Exact analytical upward-pointing unit surface normal `(dP/dz × dP/dx).normalize()`.
    #[get(type(copy))]
    pub(crate) normal: Vec3,
    /// Exact analytical partial derivative `dP/dx`.
    #[get(type(copy))]
    pub(crate) tangent_x: Vec3,
    /// Exact analytical partial derivative `dP/dz`.
    #[get(type(copy))]
    pub(crate) tangent_z: Vec3,
    /// Horizontal surface-folding Jacobian determinant (`< 1.0` compressed crest, `> 1.0` stretched trough).
    #[get(type(copy))]
    pub(crate) jacobian: f32,
    /// Whitecap crest foam coverage mask in `[0.0, 1.0]`.
    #[get(type(copy))]
    pub(crate) foam_mask: f32,
}

/// Physical optical shading evaluation for an `OceanSurfaceSample`.
#[derive(Clone, Copy, Data, Debug, Default, New, PartialEq)]
pub struct OceanOpticalSample {
    /// Beer-Lambert depth transmittance `exp(-absorption_coeff * depth_m)` in `[0.0, 1.0]^3`.
    #[get(type(copy))]
    pub(crate) transmittance: Vec3,
    /// Schlick Fresnel reflection coefficient in `[fresnel_f0, 1.0]`.
    #[get(type(copy))]
    pub(crate) fresnel: f32,
    /// Backlit emerald subsurface scattering linear RGB radiance contribution.
    #[get(type(copy))]
    pub(crate) subsurface_scatter: Vec3,
    /// Analytical seabed caustics projection intensity (`>= 0.0`).
    #[get(type(copy))]
    pub(crate) caustics_intensity: f32,
    /// Physically combined linear RGB water surface radiance.
    #[get(type(copy))]
    pub(crate) water_color: Vec3,
}

/// Descriptor for building a projected-grid / LOD ocean `Mesh3D` patch.
#[derive(Clone, Copy, Data, Debug, PartialEq)]
pub struct OceanPatchDesc {
    /// World-space horizontal center `(cx, cz)` of the patch (typically camera anchor).
    #[get(type(copy))]
    pub(crate) center_xz: Vec2,
    /// Total patch width along world X in meters.
    #[get(type(copy))]
    pub(crate) extent_x: f32,
    /// Total patch depth along world Z in meters.
    #[get(type(copy))]
    pub(crate) extent_z: f32,
    /// Grid subdivision count along X (`2..=256`).
    #[get(type(copy))]
    pub(crate) subdivisions_x: usize,
    /// Grid subdivision count along Z (`2..=256`).
    #[get(type(copy))]
    pub(crate) subdivisions_z: usize,
    /// Radial LOD non-linearity (`0.0` = uniform grid, `> 0.0` = denser triangles near center).
    #[get(type(copy))]
    pub(crate) lod_radial_falloff: f32,
    /// Reference seabed elevation along Y for Beer-Lambert depth tinting in vertex colors.
    #[get(type(copy))]
    pub(crate) seabed_y: f32,
}

/// Reusable multi-cascade directional Gerstner + JONSWAP ocean surface synthesis and optics engine.
#[derive(Clone, Data, Debug, PartialEq)]
pub struct OceanSurface3D {
    /// Sanitized ocean sea-state and optical configuration.
    #[get(type(copy))]
    pub(crate) config: OceanConfig,
    /// Synthesized directional Gerstner wave components across all cascades.
    pub(crate) waves: Vec<GerstnerWaveComponent>,
    /// Current elapsed simulation time in seconds.
    #[get(type(copy))]
    pub(crate) sim_time_secs: f32,
}

/// Distributed hull buoyancy probe point expressed in local vessel coordinates.
#[derive(Clone, Copy, Data, Debug, Default, New, PartialEq)]
pub struct PontoonSamplePoint {
    /// Local-space offset from hull center of mass in meters.
    #[get(type(copy))]
    pub(crate) local_offset: Vec3,
    /// Maximum displaced water volume in `m^3` represented by this probe when fully submerged.
    #[get(type(copy))]
    pub(crate) submerged_volume_m3: f32,
    /// Vertical draft transition half-height in meters controlling smooth submersion.
    #[get(type(copy))]
    pub(crate) sample_radius_m: f32,
}

/// Rigid-body hydrodynamic parameters for `BuoyantHull3D`.
#[derive(Clone, Copy, Data, Debug, PartialEq)]
pub struct BuoyantHullConfig {
    /// Total hull rigid-body mass in kilograms.
    #[get(type(copy))]
    pub(crate) mass_kg: f32,
    /// Principal rotational inertia tensor diagonal `(Ix, Iy, Iz)` in `kg*m^2`.
    #[get(type(copy))]
    pub(crate) inertia_diag: Vec3,
    /// Ambient fluid density in `kg/m^3` (`1025.0` seawater, `1000.0` fresh water).
    #[get(type(copy))]
    pub(crate) fluid_density_kgm3: f32,
    /// Gravitational acceleration in `m/s^2`.
    #[get(type(copy))]
    pub(crate) gravity_mps2: f32,
    /// Linear viscous hydrodynamic drag coefficient (`N / (m/s)`).
    #[get(type(copy))]
    pub(crate) linear_drag: f32,
    /// Quadratic hydrodynamic pressure drag coefficient (`N / (m/s)^2`).
    #[get(type(copy))]
    pub(crate) quadratic_drag: f32,
    /// Angular water damping coefficient (`N*m / (rad/s)`).
    #[get(type(copy))]
    pub(crate) angular_drag: f32,
    /// Restoring torque aligning hull up-axis with local wave surface normal.
    #[get(type(copy))]
    pub(crate) slope_alignment_torque: f32,
    /// Maximum linear speed clamp in `m/s` preventing runaway energy injection.
    #[get(type(copy))]
    pub(crate) max_linear_speed: f32,
    /// Maximum angular speed clamp in `rad/s`.
    #[get(type(copy))]
    pub(crate) max_angular_speed: f32,
}

/// Rigid-body 3D floating vessel/object simulator coupled to `OceanSurface3D` or `WaveHeightfield2D`.
#[derive(Clone, Data, Debug, PartialEq)]
pub struct BuoyantHull3D {
    /// Sanitized hydrodynamic rigid-body configuration.
    #[get(type(copy))]
    pub(crate) config: BuoyantHullConfig,
    /// World-space center of mass position in meters.
    #[get(type(copy))]
    pub(crate) position: Vec3,
    /// World-space linear velocity in meters per second.
    #[get(type(copy))]
    pub(crate) velocity: Vec3,
    /// World-space unit orientation quaternion.
    #[get(type(copy))]
    pub(crate) orientation: Quat,
    /// World-space angular velocity vector in radians per second.
    #[get(type(copy))]
    pub(crate) angular_velocity: Vec3,
    /// Distributed hull/pontoon buoyancy sample points in local coordinates.
    pub(crate) pontoons: Vec<PontoonSamplePoint>,
    /// Aggregate fraction of total pontoon volume currently submerged (`0.0..=1.0`).
    #[get(type(copy))]
    pub(crate) submerged_fraction: f32,
    /// Net Archimedes upward buoyancy force vector from the most recent physics step.
    #[get(type(copy))]
    pub(crate) buoyancy_force: Vec3,
}