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

/// Single timestamped 3D transform keyframe inside an `AnimationClip3D`.
#[derive(Clone, Copy, Data, Debug, New, PartialEq)]
pub struct Keyframe3D {
    /// Keyframe time offset in seconds.
    #[get(type(copy))]
    pub(crate) time_secs: f32,
    /// Local joint or node transform at `time_secs`.
    #[get(type(copy))]
    pub(crate) transform: Transform3D,
}

/// Named bone joint inside a hierarchical `SkeletonRig3D`.
#[derive(Clone, Data, Debug, PartialEq)]
pub struct SkeletonJoint3D {
    /// Human-readable joint identifier (e.g., `"root"`, `"spine"`, `"turret"`).
    pub(crate) name: String,
    /// Optional parent joint index (`None` for root bone).
    #[get(skip)]
    pub(crate) parent: Option<usize>,
    /// Bind-pose local transform relative to parent.
    #[get(type(copy))]
    pub(crate) rest_transform: Transform3D,
}

/// Per-joint keyframe track animating one joint index over time.
#[derive(Clone, Data, Debug, PartialEq)]
pub struct JointTrack3D {
    /// Target joint index inside `SkeletonRig3D::joints`.
    #[get(type(copy))]
    pub(crate) joint_index: usize,
    /// Chronologically sorted keyframes.
    pub(crate) keyframes: Vec<Keyframe3D>,
}

/// Reusable skeletal/transform animation clip with duration and looping control.
#[derive(Clone, Data, Debug, PartialEq)]
pub struct AnimationClip3D {
    /// Clip name.
    pub(crate) name: String,
    /// Total clip duration in seconds.
    #[get(type(copy))]
    pub(crate) duration_secs: f32,
    /// Whether playback wraps seamlessly at `duration_secs`.
    #[get(type(copy))]
    pub(crate) looping: bool,
    /// Per-joint keyframe tracks.
    pub(crate) tracks: Vec<JointTrack3D>,
}

/// Per-vertex 4-bone linear-blend skeletal skinning weights.
#[derive(Clone, Copy, Data, Debug, New, PartialEq)]
pub struct SkinWeight3D {
    /// Four influencing joint indices into `SkeletonRig3D::joints`.
    #[get(type(copy))]
    pub(crate) joint_indices: [u16; 4],
    /// Normalized blend weights corresponding to `joint_indices`.
    #[get(type(copy))]
    pub(crate) weights: [f32; 4],
}

/// Hierarchical 3D skeletal rig evaluating forward kinematics across bone chains.
#[derive(Clone, Data, Debug, Default, PartialEq)]
pub struct SkeletonRig3D {
    /// Ordered joint hierarchy (parents precede children).
    pub(crate) joints: Vec<SkeletonJoint3D>,
}

/// Real Blender/glTF 2.0 armature skin binding scene-graph joints and inverse bind matrices for LBS and DQS deformation.
#[derive(Clone, Data, Debug, Default, PartialEq)]
pub struct Skin3D {
    /// Human-readable armature or skin label.
    pub(crate) name: String,
    /// Ordered joint node indices into `SceneGraph3D::nodes`.
    pub(crate) joints: Vec<u32>,
    /// Optional skeleton root node index inside `SceneGraph3D::nodes`.
    #[get(type(copy))]
    pub(crate) skeleton_root: Option<u32>,
    /// Column-major inverse bind matrices aligned 1:1 with `joints`.
    pub(crate) inverse_bind_matrices: Vec<Mat4>,
    /// Active deformation mode (`LinearBlend` or `DualQuaternion`).
    #[get(type(copy))]
    pub(crate) skinning_mode: SkinningMode,
}

/// Reusable pre-allocated skinning and shape-key scratch arena guaranteeing zero steady-state heap allocations per frame.
#[derive(Clone, Data, Debug, Default, PartialEq)]
pub struct SkinPaletteScratch3D {
    /// Reusable bone palette matrices `inv(M_mesh_world) * M_joint_world[j] * M_inv_bind[j]`.
    pub(crate) skin_matrices: Vec<Mat4>,
    /// Reusable exact cofactor 3x3 normal bases aligned 1:1 with `skin_matrices`.
    pub(crate) skin_normal_matrices: Vec<[Vec3; 3]>,
    /// Reusable rigid dual quaternions aligned 1:1 with `skin_matrices` for volume-preserving DQS.
    pub(crate) skin_dual_quats: Vec<DualQuat>,
    /// Reusable post-morph intermediate vertex buffer (applied before skinning).
    pub(crate) morphed_vertices: Vec<Vertex3D>,
    /// Reusable final deformed vertex buffer output by LBS or DQS skinning.
    pub(crate) skinned_vertices: Vec<Vertex3D>,
}

/// Single Non-Linear Animation (NLA) playback layer supporting override/additive blending, joint bitmasks, and smooth crossfades.
#[derive(Clone, Copy, Data, Debug, PartialEq)]
pub struct NlaLayer3D {
    /// Index into `AnimationMixer3D::clips`.
    #[get(type(copy))]
    pub(crate) clip_index: usize,
    /// Active layer blend weight in `[0.0, 1.0]`.
    #[get(type(copy))]
    pub(crate) weight: f32,
    /// Layer composition operator (`Override` or `Additive`).
    #[get(type(copy))]
    pub(crate) blend_mode: NlaBlendMode,
    /// Playback wrap mode (`Loop`, `Clamp`, or `PingPong`).
    #[get(type(copy))]
    pub(crate) repeat_mode: NlaRepeatMode,
    /// Current local playback time in seconds.
    #[get(type(copy))]
    pub(crate) time_secs: f32,
    /// Playback speed multiplier (`1.0` = real time).
    #[get(type(copy))]
    pub(crate) time_scale: f32,
    /// Elapsed seconds inside an active weight crossfade ramp.
    #[get(type(copy))]
    pub(crate) fade_elapsed_secs: f32,
    /// Total duration of an active weight crossfade ramp (`0.0` = inactive).
    #[get(type(copy))]
    pub(crate) fade_duration_secs: f32,
    /// Starting weight captured when crossfade began.
    #[get(type(copy))]
    pub(crate) fade_start_weight: f32,
    /// Target weight approached at end of crossfade.
    #[get(type(copy))]
    pub(crate) fade_target_weight: f32,
    /// 64-bit node/joint eligibility bitmask (`u64::MAX` enables all nodes).
    #[get(type(copy))]
    pub(crate) joint_mask: u64,
    /// Whether this layer is active during mixer evaluation.
    #[get(type(copy))]
    pub(crate) enabled: bool,
}

/// Pre-allocated Structure-of-Arrays scratch workspace used by `AnimationMixer3D` for zero-allocation NLA evaluation.
#[derive(Clone, Data, Debug, Default, PartialEq)]
pub struct AnimationPoseScratch3D {
    /// Accumulated local node translations.
    pub(crate) node_translations: Vec<Vec3>,
    /// Accumulated local node unit quaternions.
    pub(crate) node_rotations: Vec<Quat>,
    /// Accumulated local node non-uniform scales.
    pub(crate) node_scales: Vec<Vec3>,
    /// Flags marking nodes whose translation was modified this tick.
    pub(crate) node_touched_translation: Vec<bool>,
    /// Flags marking nodes whose rotation was modified this tick.
    pub(crate) node_touched_rotation: Vec<bool>,
    /// Flags marking nodes whose scale was modified this tick.
    pub(crate) node_touched_scale: Vec<bool>,
    /// Accumulated flat morph weights mirroring `SceneGraph3D::morph_weights`.
    pub(crate) morph_weights: Vec<f32>,
    /// Flags marking morph weight entries modified this tick.
    pub(crate) morph_touched: Vec<bool>,
    /// Temporary scalar sample buffer reused across all channel evaluations.
    pub(crate) sampler_values: Vec<f32>,
}

/// Multi-layer glTF 2.0 & Blender NLA animation mixer supporting STEP/LINEAR/CUBICSPLINE channels, morph weights, and zero-allocation ticking.
#[derive(Clone, Data, Debug, Default, PartialEq)]
pub struct AnimationMixer3D {
    /// Registered animation clips (Blender Actions / glTF animations).
    pub(crate) clips: Vec<ImportedAnimationClip3D>,
    /// Active NLA playback layers evaluated from index `0` upward.
    pub(crate) layers: Vec<NlaLayer3D>,
    /// Reusable pose accumulation scratch workspace.
    pub(crate) pose_scratch: AnimationPoseScratch3D,
    /// Captured bind/rest local translations for additive blending and reset.
    pub(crate) rest_translations: Vec<Vec3>,
    /// Captured bind/rest local rotations for additive blending and reset.
    pub(crate) rest_rotations: Vec<Quat>,
    /// Captured bind/rest local scales for additive blending and reset.
    pub(crate) rest_scales: Vec<Vec3>,
    /// Captured bind/rest morph weights for additive blending and reset.
    pub(crate) rest_morph_weights: Vec<f32>,
}