mirage-engine 0.1.1

Mirage, an immediate-mode 3D engine for simple games on desktop and the browser
Documentation
//! Meshes: the two traits a game's mesh types implement, the data they
//! build, the draws of them, and the set of every mesh a game draws.
//!
//! A mesh is a type of the game's own — `Ship`, `Crate` — or one of the
//! engine's primitives. It implements [`Catalog`], which lists every value
//! of it a game ever draws, and [`Mesh`], whose `build` returns the
//! [`MeshData`] that value is made of, out of the [`Assets`] startup
//! loaded. [`meshes!`](crate::meshes) holds the types a game draws in one
//! set, and [`Game::Meshes`](crate::Game::Meshes) names that set. A draw
//! is [`Mesh::at`] over a value, set up by the calls on [`Instance`], and
//! passed to [`ctx.draw`](crate::FrameContext::draw), which takes a mesh of
//! the game's own set and no other; startup builds and uploads everything
//! the set catalogs, so a game whose meshes fit
//! [`Config::with_mesh_memory`](crate::Config::with_mesh_memory), `256`
//! MiB unless set, builds none of them in a frame.
//!
//! A `build` that names what startup did not load stops startup, under the
//! mesh type's own name.
//!
//! [`Catalog`]: crate::Catalog
//! [`Assets`]: crate::Assets

use core::hash::Hash;

pub(crate) use animation::{Animation, Keys, Mixed, Moves, Timeline, Track};
pub use clip::{Clip, NoClips};
pub use data::{MeshData, MeshError, Vertex};
pub use geometry::Geometry;
pub(crate) use geometry::{BoundingSphere, MeshPlane};
pub use instance::Instance;
pub(crate) use instance::{Draw, Placement};
pub use part::{NoParts, Part};
pub(crate) use pose::{Palette, Posing, Sampled, Skinned};
pub use primitives::{Cube, Plane, Quad, Sphere};
pub(crate) use rig::{Joint, Local, Placed, Rig, Weighted};
pub use set::Meshes;
pub use sheet::{Frame, Sheet};
pub use slot::Slot;

use crate::{Assets, Catalog, Transform};

/// A type that is a mesh: a draw is a value of it and a transform.
///
/// Values are cache keys: equal values must build the same mesh. [`Catalog`]
/// proves every named asset loads before the first frame. `P` names the
/// parts a draw repaints one at a time; a mesh with none leaves it at
/// [`NoParts`], and one with parts implements the trait for its own
/// [`Part`] enum and no other. `C` names the clips it is posed by, the same
/// way, over [`NoClips`] and its own [`Clip`] enum.
pub trait Mesh<P: Part = NoParts, C: Clip = NoClips>: Catalog + Hash + Eq + Clone {
    /// Builds this value's mesh, the first time a draw needs it.
    ///
    /// Must not read a file or the network; loaded data is in `assets`.
    fn build(&self, assets: &Assets) -> MeshData<P, C>;

    /// Places this mesh in the world, as a draw of a game whose styles are
    /// `S`.
    fn at<S: crate::SurfaceStyles>(self, transform: impl Into<Transform>) -> Instance<Self, S> {
        Instance::new(self, transform.into())
    }
}

mod animation;
mod clip;
mod data;
mod geometry;
mod instance;
mod part;
mod pose;
mod primitives;
mod rig;
mod set;
mod sheet;
mod slot;