mirage-engine 0.1.1

Mirage, an immediate-mode 3D engine for simple games on desktop and the browser
Documentation
use core::fmt::Debug;
use core::hash::Hash;

/// A name for one clip a mesh is posed by.
///
/// Required if you want to pose a mesh by the animations its source holds:
/// derive it on an enum whose variants are those animations' names, and name
/// that enum where the mesh implements [`Mesh`](crate::mesh::Mesh).
pub trait Clip: Hash + Eq + Clone + Debug {
    /// The clip the animation `name` resolves to, or `None` to leave that
    /// animation alone, which no draw poses by.
    fn from_name(name: &str) -> Option<Self>;

    /// Every clip, in the order [`index`](Clip::index) counts them.
    ///
    /// Each of them must resolve exactly one animation of every source a
    /// mesh built over this vocabulary loads; otherwise startup fails.
    fn all() -> Vec<Self>;

    /// This clip's position in [`all`](Clip::all).
    fn index(&self) -> u32;
}

/// The vocabulary of a mesh no clip poses.
///
/// A mesh that states no clip vocabulary reads as this one, so a game never
/// writes it. It has no value, so nothing a draw of such a mesh states can
/// name a clip.
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub enum NoClips {}

impl Clip for NoClips {
    /// No animation name resolves to a clip.
    fn from_name(_name: &str) -> Option<Self> {
        None
    }

    fn all() -> Vec<Self> {
        Vec::new()
    }

    fn index(&self) -> u32 {
        match *self {}
    }
}