euv-core 0.49.1

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::*;

/// Conservative reverse-Z Hierarchical Z-Buffer (Hi-Z) minimum-depth mip pyramid for O(1) occlusion culling.
#[derive(Clone, Data, Debug, Default)]
pub struct HiZPyramid {
    /// Viewport width in pixels covered by this Hi-Z pyramid.
    #[get(type(copy))]
    pub(crate) viewport_width: usize,
    /// Viewport height in pixels covered by this Hi-Z pyramid.
    #[get(type(copy))]
    pub(crate) viewport_height: usize,
    /// Base cell edge size in pixels (typically `8`).
    #[get(type(copy))]
    pub(crate) cell_size_px: usize,
    /// Whether the pyramid holds valid reverse-Z depth data for occlusion queries.
    #[get(type(copy))]
    pub(crate) valid: bool,
    /// Mip levels from finest (`levels[0]`) to coarsest (`1x1`), each storing conservative minimum `1/w`.
    #[get(skip)]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) levels: Vec<Vec<f32>>,
    /// Width and height in cells for each mip level aligned 1:1 with `levels`.
    #[get(skip)]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) level_dims: Vec<(usize, usize)>,
}

/// Single node inside a UE5 Nanite-style hierarchical cluster DAG storing triangle range, normal cone, and parent/self geometric errors.
#[derive(Clone, Copy, Data, Debug, PartialEq)]
pub struct NaniteClusterNode {
    /// Starting triangle index in the owning `Mesh3D::indices` slice.
    #[get(type(copy))]
    pub(crate) first_tri: u32,
    /// Number of triangles represented by this cluster node.
    #[get(type(copy))]
    pub(crate) tri_count: u32,
    /// Tight local-space bounding box enclosing all cluster triangles.
    #[get(type(copy))]
    pub(crate) bounds: AxisAlignedBox3D,
    /// Outward average normal cone axis for cluster backface culling.
    #[get(type(copy))]
    pub(crate) cone_axis: Vec3,
    /// Minimum dot product between member face normals and `cone_axis`.
    #[get(type(copy))]
    pub(crate) cone_cutoff: f32,
    /// Intrinsic local geometric error of this cluster in meters (`0.0` at leaf `LOD0`).
    #[get(type(copy))]
    pub(crate) cluster_error: f32,
    /// Intrinsic geometric error of this node's parent group in meters (`f32::INFINITY` at root).
    #[get(type(copy))]
    pub(crate) parent_error: f32,
    /// Hierarchy LOD depth (`0` = finest leaf cluster, higher = coarser group).
    #[get(type(copy))]
    pub(crate) lod_level: u8,
    /// Starting index of child nodes inside `NaniteClusterDag::nodes` (`0` for leaf nodes).
    #[get(type(copy))]
    pub(crate) child_start: u32,
    /// Number of child nodes (`0` for leaf clusters).
    #[get(type(copy))]
    pub(crate) child_count: u16,
}

/// Telemetry emitted by a single UE5 Nanite cluster DAG selection cut.
#[derive(Clone, Copy, Data, Debug, Default, PartialEq)]
pub struct NaniteCutStats {
    /// Cluster nodes selected for rasterization after frustum, cone, and Hi-Z culling.
    #[get(type(copy))]
    pub(crate) clusters_drawn: usize,
    /// Cluster nodes rejected by 6-plane view frustum culling.
    #[get(type(copy))]
    pub(crate) clusters_frustum_culled: usize,
    /// Cluster nodes rejected by outward normal-cone backface culling.
    #[get(type(copy))]
    pub(crate) clusters_cone_culled: usize,
    /// Cluster nodes rejected by conservative reverse-Z Hi-Z occlusion culling.
    #[get(type(copy))]
    pub(crate) clusters_hiz_culled: usize,
    /// Cluster nodes rejected because their projected screen area fell below one pixel.
    #[get(type(copy))]
    pub(crate) clusters_micro_culled: usize,
}

/// Hierarchical cluster Directed Acyclic Graph enabling continuous screen-error LOD cuts and combined frustum/cone/Hi-Z culling.
#[derive(Clone, Data, Debug, Default, PartialEq)]
pub struct NaniteClusterDag {
    /// Flat node array ordered bottom-up with root group nodes at `root_start..nodes.len()`.
    pub(crate) nodes: Vec<NaniteClusterNode>,
    /// Starting index of top-level root nodes in `nodes`.
    #[get(type(copy))]
    pub(crate) root_start: usize,
    /// Number of hierarchy levels in this DAG (`>= 1` for non-empty meshes).
    #[get(type(copy))]
    pub(crate) level_count: usize,
}

/// Immutable per-object view and culling context passed to `NaniteClusterDag::select_cut`.
#[derive(Clone, Copy, Data, Debug)]
pub struct NaniteCutContext<'a> {
    /// Active camera world position.
    #[get(type(copy))]
    pub(crate) camera_position: Vec3,
    /// Object local-to-world transform matrix.
    #[get(type(copy))]
    pub(crate) model_matrix: Mat4,
    /// Active frame view-projection matrix.
    #[get(type(copy))]
    pub(crate) view_projection: Mat4,
    /// Inverse-transpose 3x3 world normal basis.
    #[get(type(copy))]
    pub(crate) normal_basis: [Vec3; 3],
    /// Active 6-plane camera frustum.
    #[get(type(copy))]
    pub(crate) frustum: Frustum3D,
    /// Optional conservative reverse-Z Hi-Z occlusion pyramid.
    #[get(skip)]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) hiz_pyramid: Option<&'a HiZPyramid>,
    /// Whether normal-cone backface culling is enabled (closed positive-scale meshes).
    #[get(type(copy))]
    pub(crate) cull_backface: bool,
    /// Projected viewport focal length in pixels.
    #[get(type(copy))]
    pub(crate) focal_px: f32,
    /// Maximum tolerated geometric error in pixels before descending into finer child clusters.
    #[get(type(copy))]
    pub(crate) error_threshold_px: f32,
    /// Camera near clip plane distance in meters.
    #[get(type(copy))]
    pub(crate) near_plane: f32,
    /// Viewport width in pixels.
    #[get(type(copy))]
    pub(crate) viewport_width: f32,
    /// Viewport height in pixels.
    #[get(type(copy))]
    pub(crate) viewport_height: f32,
    /// Maximum triangle count of the owning mesh for bounds clamping.
    #[get(type(copy))]
    pub(crate) total_triangles: usize,
}