wc3 0.2.0

Read, edit, and write Warcraft III models, BLP textures, and MPQ archives
Documentation
//! Timed animation values and spline tangents.

use crate::model::{mdl, mdx};

/// A keyframe with a timestamp in milliseconds.
pub trait Keyframe {
    /// Signed frame time; negative times represent animation lead-in.
    fn frame(&self) -> i32;
}

/// An interpolation mode shared by all keys in a track.
#[derive(Clone, Copy, Debug, Eq, PartialEq, mdl::Read, mdl::Write)]
#[mdl(value)]
pub enum Interpolation {
    #[mdl(name = "DontInterp")]
    /// Holds the preceding key value until the next key.
    Step,
    /// Interpolates between adjacent values without tangents.
    Linear,
    /// Uses outgoing and incoming Hermite tangents.
    Hermite,
    /// Uses outgoing and incoming Bezier control points.
    Bezier,
}

/// A keyframe without interpolation tangents.
#[derive(Clone, Debug, PartialEq, mdx::Read, mdx::Write)]
pub struct ValueKeyframe<T> {
    /// Signed frame time in milliseconds; negative times represent animation lead-in.
    pub frame: i32,
    /// The value at this frame.
    pub value: T,
}

/// A keyframe with both interpolation tangents.
#[derive(Clone, Debug, PartialEq, mdx::Read, mdx::Write)]
pub struct TangentKeyframe<T> {
    /// Signed frame time in milliseconds; negative times represent animation lead-in.
    pub frame: i32,
    /// The value at this frame.
    pub value: T,
    /// Incoming tangent.
    pub in_tangent: T,
    /// Outgoing tangent.
    pub out_tangent: T,
}

impl<T> Keyframe for ValueKeyframe<T> {
    fn frame(&self) -> i32 {
        self.frame
    }
}

impl<T> Keyframe for TangentKeyframe<T> {
    fn frame(&self) -> i32 {
        self.frame
    }
}