Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

时间线

简单来说,时间线的本质是类型擦除后的 AnimationCell<T> 的容器,若干条时间线组合在一起即表示了整个场景的完整动画。

因为 AnimationCell<T> 带有范性参数,所以也就涉及类型擦除,满足于 T: AnyExtractCoreItemAnimationCell<T> 会被擦除为 Box<dyn CoreItemAnimation>

impl<T: AnyExtractCoreItem> CoreItemAnimation for AnimationCell<T> {
    fn eval_alpha_dyn(&self, alpha: f64) -> DynItem {
        DynItem(Box::new(self.eval_alpha(alpha)))
    }
    fn eval_alpha_core_item(&self, alpha: f64) -> Vec<CoreItem> {
        self.eval_alpha(alpha).extract()
    }
    // ...
}
/// A timeline for a animations.
#[derive(Default)]
pub struct Timeline {
    anims: Vec<Box<dyn CoreItemAnimation>>,
    // Followings are states use while constructing
    cur_sec: f64,
    /// The start time of the planning static anim.
    /// When it is some, it means that it is showing and has a planning static anim.
    planning_static_start_sec: Option<f64>,
}

在编写动画时的一系列操作(如 forwardplay 等)最后都会转变为对 Timeline 内部属性的操作,最终达成的结果就是在其 anims 属性中完成此条时间线所有动 AnimationCell 的编码(即“把动画在时间上放到正确的位置”)。