Skip to main content

mirage_engine/mesh/
clip.rs

1use core::fmt::Debug;
2use core::hash::Hash;
3
4/// A name for one clip a mesh is posed by.
5///
6/// Required if you want to pose a mesh by the animations its source holds:
7/// derive it on an enum whose variants are those animations' names, and name
8/// that enum where the mesh implements [`Mesh`](crate::mesh::Mesh).
9pub trait Clip: Hash + Eq + Clone + Debug {
10    /// The clip the animation `name` resolves to, or `None` to leave that
11    /// animation alone, which no draw poses by.
12    fn from_name(name: &str) -> Option<Self>;
13
14    /// Every clip, in the order [`index`](Clip::index) counts them.
15    ///
16    /// Each of them must resolve exactly one animation of every source a
17    /// mesh built over this vocabulary loads; otherwise startup fails.
18    fn all() -> Vec<Self>;
19
20    /// This clip's position in [`all`](Clip::all).
21    fn index(&self) -> u32;
22}
23
24/// The vocabulary of a mesh no clip poses.
25///
26/// A mesh that states no clip vocabulary reads as this one, so a game never
27/// writes it. It has no value, so nothing a draw of such a mesh states can
28/// name a clip.
29#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
30pub enum NoClips {}
31
32impl Clip for NoClips {
33    /// No animation name resolves to a clip.
34    fn from_name(_name: &str) -> Option<Self> {
35        None
36    }
37
38    fn all() -> Vec<Self> {
39        Vec::new()
40    }
41
42    fn index(&self) -> u32 {
43        match *self {}
44    }
45}