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

/// Angular cone joint limit applied during Cyclic Coordinate Descent (CCD) IK solving.
#[derive(Clone, Copy, Data, Debug, New, PartialEq)]
pub struct IkBoneConstraint {
    /// Maximum allowed bend half-angle in radians from the parent bone axis (or `reference_axis` at root).
    #[get(type(copy))]
    pub(crate) max_cone_angle_rad: f32,
    /// Reference axis used at root joint index `0` when no parent bone exists.
    #[get(type(copy))]
    pub(crate) reference_axis: Vec3,
}

/// Result returned by analytic 2-bone inverse kinematics (`IkSolver3D::solve_two_bone`).
#[derive(Clone, Copy, Data, Debug, New, PartialEq)]
pub struct IkTwoBoneResult {
    /// Solved middle joint (elbow or knee) position in world space.
    #[get(type(copy))]
    pub(crate) joint_mid: Vec3,
    /// Solved end-effector position in world space.
    #[get(type(copy))]
    pub(crate) effector: Vec3,
    /// World orientation rotating `+Y` onto the upper bone segment.
    #[get(type(copy))]
    pub(crate) upper_rotation: Quat,
    /// World orientation rotating `+Y` onto the lower bone segment.
    #[get(type(copy))]
    pub(crate) lower_rotation: Quat,
    /// Residual Euclidean distance from `effector` to requested target.
    #[get(type(copy))]
    pub(crate) error: f32,
    /// Whether `error` satisfied reach tolerance.
    #[get(type(copy))]
    pub(crate) reached: bool,
}

/// Convergence report returned by iterative multi-bone IK solvers (FABRIK and CCD).
#[derive(Clone, Copy, Data, Debug, New, PartialEq)]
pub struct IkChainResult {
    /// Number of solver iterations executed.
    #[get(type(copy))]
    pub(crate) iterations: usize,
    /// Final Euclidean distance from end-effector to target.
    #[get(type(copy))]
    pub(crate) error: f32,
    /// Whether the final error met the caller's tolerance.
    #[get(type(copy))]
    pub(crate) reached: bool,
}

/// Stateless 3D Inverse Kinematics solver suite (Analytic 2-Bone, FABRIK, and cone-limited CCD).
#[derive(Clone, Copy, Data, Debug, Default, New, PartialEq)]
pub struct IkSolver3D {
    /// Default convergence tolerance in world units.
    #[get(type(copy))]
    pub(crate) default_tolerance: f32,
}

/// Triangle face stored inside the Expanding Polytope Algorithm (EPA) hull.
#[derive(Clone, Copy, Debug)]
pub(crate) struct EpaFace3D {
    /// Vertex indices `(i0, i1, i2)` in counter-clockwise outward winding.
    pub(crate) indices: [usize; 3],
    /// Outward unit face normal.
    pub(crate) normal: Vec3,
    /// Signed distance from the origin along `normal`.
    pub(crate) distance: f32,
}

/// Reusable scratch buffers for zero-allocation GJK + EPA collision queries.
#[derive(Clone, Debug, Default)]
pub(crate) struct GjkEpaScratch {
    /// Polytope vertices expanded during EPA.
    pub(crate) vertices: Vec<Vec3>,
    /// Active polytope boundary faces.
    pub(crate) faces: Vec<EpaFace3D>,
    /// Silhouette boundary half-edges gathered during polytope horizon stitching.
    pub(crate) loose_edges: Vec<(usize, usize)>,
}

/// Exact Minimum Translation Vector (MTV) contact produced by `GjkEpaSolver3D`.
#[derive(Clone, Copy, Data, Debug, New, PartialEq)]
pub struct GjkEpaContact3D {
    /// Unit separation normal pushing shape A out of shape B (translate A by `normal * depth`).
    #[get(type(copy))]
    pub(crate) normal: Vec3,
    /// Exact non-negative penetration depth along `normal`.
    #[get(type(copy))]
    pub(crate) depth: f32,
}

/// Reusable 3D Gilbert-Johnson-Keerthi (GJK) and Expanding Polytope Algorithm (EPA) convex collision solver.
#[derive(Clone, Data, Debug, Default)]
pub struct GjkEpaSolver3D {
    /// Pre-allocated EPA polytope scratch buffers.
    #[get(pub(crate))]
    #[get_mut(pub(crate))]
    #[set(pub(crate))]
    pub(crate) scratch: GjkEpaScratch,
}

/// Single Verlet / PBD particle with inverse mass (`0.0` denotes a permanently pinned anchor).
#[derive(Clone, Copy, Data, Debug, New, PartialEq)]
pub struct VerletParticle3D {
    /// Current world-space particle position.
    #[get(type(copy))]
    pub(crate) position: Vec3,
    /// Previous-step world-space position encoding implicit velocity.
    #[get(type(copy))]
    pub(crate) prev_position: Vec3,
    /// Reciprocal mass (`0.0` = immovable pinned anchor).
    #[get(type(copy))]
    pub(crate) inv_mass: f32,
}

/// Pairwise distance or bending constraint between two Verlet particles.
#[derive(Clone, Copy, Data, Debug, New, PartialEq)]
pub struct VerletDistanceConstraint {
    /// First particle index.
    #[get(type(copy))]
    pub(crate) index_a: usize,
    /// Second particle index.
    #[get(type(copy))]
    pub(crate) index_b: usize,
    /// Target rest distance between particles.
    #[get(type(copy))]
    pub(crate) rest_length: f32,
    /// Constraint projection stiffness in `(0.0, 1.0]`.
    #[get(type(copy))]
    pub(crate) stiffness: f32,
}

/// Solid sphere collider pushing dynamic Verlet particles out to `radius`.
#[derive(Clone, Copy, Data, Debug, New, PartialEq)]
pub struct VerletSphereCollider {
    /// World-space sphere center.
    #[get(type(copy))]
    pub(crate) center: Vec3,
    /// Positive sphere radius.
    #[get(type(copy))]
    pub(crate) radius: f32,
}

/// Solid infinite half-space plane collider enforcing `position · normal >= offset`.
#[derive(Clone, Copy, Data, Debug, New, PartialEq)]
pub struct VerletPlaneCollider {
    /// Unit outward plane normal.
    #[get(type(copy))]
    pub(crate) normal: Vec3,
    /// Signed plane offset along `normal`.
    #[get(type(copy))]
    pub(crate) offset: f32,
}

/// Position-Based Dynamics / Verlet 3D cloth grid solver with structural, shear, and bend constraints.
#[derive(Clone, Data, Debug)]
pub struct VerletClothSolver {
    /// Number of cloth vertex columns.
    #[get(type(copy))]
    pub(crate) cols: usize,
    /// Number of cloth vertex rows.
    #[get(type(copy))]
    pub(crate) rows: usize,
    /// Gravity acceleration vector (e.g. `(0, -9.81, 0)`).
    #[get(type(copy))]
    pub(crate) gravity: Vec3,
    /// Wind acceleration vector acting on free particles.
    #[get(type(copy))]
    pub(crate) wind: Vec3,
    /// Velocity damping factor per step in `(0.0, 1.0]`.
    #[get(type(copy))]
    pub(crate) damping: f32,
    /// Gauss-Seidel constraint projection iterations per step.
    #[get(type(copy))]
    pub(crate) solver_iterations: usize,
    /// Simulated cloth particle array of length `cols * rows`.
    pub(crate) particles: Vec<VerletParticle3D>,
    /// Structural, shear, and 2-hop bend distance constraints.
    pub(crate) constraints: Vec<VerletDistanceConstraint>,
    /// Registered solid sphere colliders.
    pub(crate) sphere_colliders: Vec<VerletSphereCollider>,
    /// Registered solid plane colliders.
    pub(crate) plane_colliders: Vec<VerletPlaneCollider>,
}

/// Position-Based Dynamics / Verlet 3D rope solver with distance and bend constraints.
#[derive(Clone, Data, Debug)]
pub struct VerletRopeSolver {
    /// Gravity acceleration vector.
    #[get(type(copy))]
    pub(crate) gravity: Vec3,
    /// External wind acceleration vector.
    #[get(type(copy))]
    pub(crate) wind: Vec3,
    /// Velocity damping factor per step in `(0.0, 1.0]`.
    #[get(type(copy))]
    pub(crate) damping: f32,
    /// Constraint projection iterations per step.
    #[get(type(copy))]
    pub(crate) solver_iterations: usize,
    /// Simulated rope particle chain.
    pub(crate) particles: Vec<VerletParticle3D>,
    /// Structural and 2-hop bend distance constraints.
    pub(crate) constraints: Vec<VerletDistanceConstraint>,
    /// Registered solid sphere colliders.
    pub(crate) sphere_colliders: Vec<VerletSphereCollider>,
    /// Registered solid plane colliders.
    pub(crate) plane_colliders: Vec<VerletPlaneCollider>,
}

/// Keyframe control point along a Catmull-Rom cinematic camera spline rail.
#[derive(Clone, Copy, Data, Debug, New, PartialEq)]
pub struct CameraSplinePoint {
    /// Camera eye position at this control point.
    #[get(type(copy))]
    pub(crate) position: Vec3,
    /// World look-at target position at this control point.
    #[get(type(copy))]
    pub(crate) look_target: Vec3,
    /// Vertical field of view in degrees.
    #[get(type(copy))]
    pub(crate) fov_deg: f32,
}

/// Configuration settings for `CameraRig3D` across Spring-Arm, Orbit, First-Person, Spline, and Shake modes.
#[derive(Clone, Copy, Data, Debug, PartialEq)]
pub struct CameraRigConfig {
    /// Active camera controller mode.
    #[get(type(copy))]
    pub(crate) mode: CameraRigMode,
    /// Desired spring-arm or orbit distance from pivot.
    #[get(type(copy))]
    pub(crate) arm_length: f32,
    /// Minimum arm length during obstacle pullback.
    #[get(type(copy))]
    pub(crate) arm_min_length: f32,
    /// Local target pivot offset (e.g., over-the-shoulder offset).
    #[get(type(copy))]
    pub(crate) pivot_offset: Vec3,
    /// Exponential position tracking stiffness (`1/s`).
    #[get(type(copy))]
    pub(crate) position_stiffness: f32,
    /// Exponential orientation tracking stiffness (`1/s`).
    #[get(type(copy))]
    pub(crate) rotation_stiffness: f32,
    /// Minimum vertical pitch angle in radians.
    #[get(type(copy))]
    pub(crate) min_pitch: f32,
    /// Maximum vertical pitch angle in radians.
    #[get(type(copy))]
    pub(crate) max_pitch: f32,
    /// Eye height above actor origin in `FirstPerson` mode.
    #[get(type(copy))]
    pub(crate) eye_height: f32,
    /// Vertical field of view in degrees.
    #[get(type(copy))]
    pub(crate) fov_deg: f32,
    /// Near clipping distance.
    #[get(type(copy))]
    pub(crate) near: f32,
    /// Far clipping distance.
    #[get(type(copy))]
    pub(crate) far: f32,
    /// Trauma linear decay rate per second.
    #[get(type(copy))]
    pub(crate) trauma_decay: f32,
    /// Maximum translational shake displacement at trauma `1.0`.
    #[get(type(copy))]
    pub(crate) shake_max_offset: f32,
    /// Maximum rotational shake angle in radians at trauma `1.0`.
    #[get(type(copy))]
    pub(crate) shake_max_angle_rad: f32,
    /// Perlin noise sampling frequency in Hz for trauma shake.
    #[get(type(copy))]
    pub(crate) shake_frequency: f32,
    /// Whether `SplineRail` mode wraps seamlessly from the last point back to the first.
    #[get(type(copy))]
    pub(crate) spline_loop: bool,
}

/// Solved world-space camera pose produced by `CameraRig3D` each frame.
#[derive(Clone, Copy, Data, Debug, New, PartialEq)]
pub struct CameraRigState {
    /// Final shaken eye position in world space.
    #[get(type(copy))]
    pub(crate) position: Vec3,
    /// Final look-at focus point in world space.
    #[get(type(copy))]
    pub(crate) target: Vec3,
    /// Final camera orientation quaternion.
    #[get(type(copy))]
    pub(crate) rotation: Quat,
    /// Final yaw angle in radians.
    #[get(type(copy))]
    pub(crate) yaw: f32,
    /// Final pitch angle in radians.
    #[get(type(copy))]
    pub(crate) pitch: f32,
    /// Final camera roll angle in radians (includes trauma roll shake).
    #[get(type(copy))]
    pub(crate) roll: f32,
    /// Active vertical field of view in degrees.
    #[get(type(copy))]
    pub(crate) fov_deg: f32,
}

/// Production 3D game camera rig supporting Spring-Arm, Orbit, First-Person, Catmull-Rom Spline, and Perlin Trauma Shake.
#[derive(Clone, Data, Debug)]
pub struct CameraRig3D {
    /// Camera rig configuration parameters.
    #[get(type(copy))]
    pub(crate) config: CameraRigConfig,
    /// Desired horizontal yaw angle in radians.
    #[get(type(copy))]
    pub(crate) desired_yaw: f32,
    /// Desired vertical pitch angle in radians.
    #[get(type(copy))]
    pub(crate) desired_pitch: f32,
    /// Current smoothed base eye position (prior to trauma shake offset).
    #[get(type(copy))]
    pub(crate) smooth_position: Vec3,
    /// Current smoothed look-at target (prior to trauma shake offset).
    #[get(type(copy))]
    pub(crate) smooth_target: Vec3,
    /// Current smoothed yaw angle.
    #[get(type(copy))]
    pub(crate) smooth_yaw: f32,
    /// Current smoothed pitch angle.
    #[get(type(copy))]
    pub(crate) smooth_pitch: f32,
    /// Current smoothed field of view in degrees.
    #[get(type(copy))]
    pub(crate) smooth_fov_deg: f32,
    /// Current spring-arm distance after obstacle pullback smoothing.
    #[get(type(copy))]
    pub(crate) current_arm_length: f32,
    /// Current trauma intensity in `[0.0, 1.0]`.
    #[get(type(copy))]
    pub(crate) trauma: f32,
    /// Elapsed continuous clock driving Perlin trauma shake.
    #[get(type(copy))]
    pub(crate) shake_clock: f32,
    /// Normalized parameter `[0.0, 1.0]` along `spline_points` in `SplineRail` mode.
    #[get(type(copy))]
    pub(crate) spline_t: f32,
    /// Cinematic Catmull-Rom spline control points.
    pub(crate) spline_points: Vec<CameraSplinePoint>,
    /// Deterministic Perlin noise field driving smooth continuous camera trauma shake.
    #[get(pub(crate))]
    #[get_mut(pub(crate))]
    #[set(pub(crate))]
    pub(crate) noise: NoiseField,
    /// Latest evaluated camera rig output state.
    #[get(type(copy))]
    pub(crate) state: CameraRigState,
}