euv-core 0.56.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::*;

/// Declarative configuration for 3D Marching Cubes liquid surface reconstruction in `LiquidSurfaceMesher`.
#[derive(Clone, Copy, Data, Debug, PartialEq)]
pub struct LiquidMesherConfig {
    /// Uniform 3D scalar-field voxel spacing in meters.
    #[get(type(copy))]
    pub(crate) voxel_size: f32,
    /// Metaball kernel influence support radius in meters.
    #[get(type(copy))]
    pub(crate) influence_radius: f32,
    /// Scalar isosurface extraction threshold separating liquid from air.
    #[get(type(copy))]
    pub(crate) iso_level: f32,
    /// Enables anisotropic particle covariance stretching for smoother sheets and liquid threads.
    #[get(type(copy))]
    pub(crate) anisotropic: bool,
    /// Anisotropic directional elongation gain in `[0.0, 0.85]`.
    #[get(type(copy))]
    pub(crate) anisotropy_strength: f32,
    /// Extra empty voxel margin padded around the particle AABB so surfaces close cleanly.
    #[get(type(copy))]
    pub(crate) padding_cells: usize,
    /// Maximum grid cells along any axis (clamped to `8..=LIQUID_MESHER_MAX_GRID_DIM`).
    #[get(type(copy))]
    pub(crate) max_grid_dim: usize,
    /// Welds shared cube-edge vertices in O(1) so extracted `Mesh3D` is watertight and indexed cleanly.
    #[get(type(copy))]
    pub(crate) weld_vertices: bool,
    /// Computes smooth vertex normals directly from the central-difference scalar-field gradient.
    #[get(type(copy))]
    pub(crate) smooth_normals_from_gradient: bool,
}

/// Configuration descriptor for crisp 2D screen-space metaball RGBA8 liquid rasterization.
#[derive(Clone, Copy, Data, Debug, PartialEq)]
pub struct LiquidRaster2DDesc {
    /// Output raster image width in pixels.
    #[get(type(copy))]
    pub(crate) width: usize,
    /// Output raster image height in pixels.
    #[get(type(copy))]
    pub(crate) height: usize,
    /// World-space minimum corner `(min_x, min_y)` mapped to the lower-left pixel.
    #[get(type(copy))]
    pub(crate) world_min: Vec2,
    /// World-space maximum corner `(max_x, max_y)` mapped to the upper-right pixel.
    #[get(type(copy))]
    pub(crate) world_max: Vec2,
    /// 2D metaball influence radius in world units.
    #[get(type(copy))]
    pub(crate) influence_radius: f32,
    /// Scalar isosurface threshold defining the crisp liquid-air boundary.
    #[get(type(copy))]
    pub(crate) iso_level: f32,
    /// Deep interior Beer-Lambert liquid color in linear RGB.
    #[get(type(copy))]
    pub(crate) deep_color: Vec3,
    /// Shallow edge / refracted liquid tint in linear RGB.
    #[get(type(copy))]
    pub(crate) shallow_color: Vec3,
    /// Specular Fresnel rim highlight color in linear RGB.
    #[get(type(copy))]
    pub(crate) specular_color: Vec3,
    /// Background RGBA8 clear color outside the liquid silhouette.
    #[get(type(copy))]
    pub(crate) background_rgba: [u8; 4],
}

/// Reusable scratch storage keeping repeated Marching Cubes and 2D metaball raster passes allocation-free after warmup.
#[derive(Clone, Data, Debug, Default, PartialEq)]
pub(crate) struct LiquidMesherScratch {
    /// 3D metaball scalar density grid (`nx * ny * nz`).
    pub(crate) scalar_field: Vec<f32>,
    /// O(1) flat edge-index to welded vertex-index lookup table (`nx * ny * nz * 3`).
    pub(crate) edge_vertices: Vec<u32>,
    /// Per-particle anisotropic axis scaling vectors `(sx, sy, sz)` for ellipsoid splatting.
    pub(crate) aniso_scales: Vec<Vec3>,
    /// 2D screen-space metaball scalar buffer (`width * height`).
    pub(crate) raster_field: Vec<f32>,
}

/// Bundled 3D scalar-field grid metadata passed to Marching Cubes helpers.
#[derive(Clone, Copy, Data, Debug, New, PartialEq)]
pub(crate) struct ScalarGrid3DDesc {
    /// Grid vertex count along X.
    #[get(type(copy))]
    pub(crate) nx: usize,
    /// Grid vertex count along Y.
    #[get(type(copy))]
    pub(crate) ny: usize,
    /// Grid vertex count along Z.
    #[get(type(copy))]
    pub(crate) nz: usize,
    /// World-space minimum grid origin.
    #[get(type(copy))]
    pub(crate) origin: Vec3,
    /// Uniform voxel spacing in meters.
    #[get(type(copy))]
    pub(crate) voxel_size: f32,
}

/// Reconstructs smooth watertight 3D `Mesh3D` surfaces and crisp 2D RGBA8 metaball rasters from SPH particles.
#[derive(Clone, Data, Debug, PartialEq)]
pub struct LiquidSurfaceMesher {
    /// Sanitized mesher configuration.
    #[get(type(copy))]
    pub(crate) config: LiquidMesherConfig,
    /// Reusable scalar-field, edge-welding, and 2D raster scratch buffers.
    pub(crate) scratch: LiquidMesherScratch,
}