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 repaintable part of a mesh.
///
/// Required if you want to repaint one part of a mesh and leave the rest:
/// derive it on an enum whose variants are the loaded mesh's material
/// names, and name that enum where the mesh implements
/// [`Mesh`](crate::mesh::Mesh).
pub trait Part: Hash + Eq + Clone + Debug {
    /// The part the material `name` resolves to, or `None` to leave that
    /// material as authored, which no draw repaints on its own.
    fn from_name(name: &str) -> Option<Self>;

    /// Every part, in the order [`index`](Part::index) counts them.
    ///
    /// Each of them must resolve exactly one material of every loaded mesh
    /// built over this vocabulary; otherwise startup fails.
    fn all() -> Vec<Self>;

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

/// The vocabulary of a mesh with no parts a draw repaints one at a time.
///
/// A mesh that states no part vocabulary reads as this one, so a game
/// never writes it. It has no value, so no draw of such a mesh can call
/// [`material_of`](crate::mesh::Instance::material_of);
/// [`material`](crate::mesh::Instance::material) repaints every slot of
/// any mesh.
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub enum NoParts {}

impl Part for NoParts {
    /// No material name resolves to a part.
    fn from_name(_name: &str) -> Option<Self> {
        None
    }

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

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