mirage_engine/mesh/mod.rs
1//! Meshes: the two traits a game's mesh types implement, the data they
2//! build, the draws of them, and the set of every mesh a game draws.
3//!
4//! A mesh is a type of the game's own — `Ship`, `Crate` — or one of the
5//! engine's primitives. It implements [`Catalog`], which lists every value
6//! of it a game ever draws, and [`Mesh`], whose `build` returns the
7//! [`MeshData`] that value is made of, out of the [`Assets`] startup
8//! loaded. [`meshes!`](crate::meshes) holds the types a game draws in one
9//! set, and [`Game::Meshes`](crate::Game::Meshes) names that set. A draw
10//! is [`Mesh::at`] over a value, set up by the calls on [`Instance`], and
11//! passed to [`ctx.draw`](crate::FrameContext::draw), which takes a mesh of
12//! the game's own set and no other; startup builds and uploads everything
13//! the set catalogs, so a game whose meshes fit
14//! [`Config::with_mesh_memory`](crate::Config::with_mesh_memory), `256`
15//! MiB unless set, builds none of them in a frame.
16//!
17//! A `build` that names what startup did not load stops startup, under the
18//! mesh type's own name.
19//!
20//! [`Catalog`]: crate::Catalog
21//! [`Assets`]: crate::Assets
22
23use core::hash::Hash;
24
25pub(crate) use animation::{Animation, Keys, Mixed, Moves, Timeline, Track};
26pub use clip::{Clip, NoClips};
27pub(crate) use data::MeshError;
28pub use data::{Built, MeshData, Vertex};
29pub(crate) use geometry::{BoundingSphere, Geometry, MeshPlane};
30pub use instance::Instance;
31pub(crate) use instance::{Draw, Placement};
32pub use part::{NoParts, Part};
33pub(crate) use pose::{Palette, Posing, Sampled, Skinned};
34pub use primitives::{Cube, Plane, Quad, Sphere};
35pub(crate) use rig::{Joint, Local, Placed, Rig, Weighted};
36pub use set::{Meshes, NoMeshes};
37pub use sheet::{Frame, Sheet};
38pub use slot::Slot;
39
40use crate::{Assets, Catalog, Transform};
41
42/// A type that is a mesh: a draw is a value of it and a transform.
43///
44/// Values are cache keys: equal values must build the same mesh. [`Catalog`]
45/// proves every named asset loads before the first frame. `P` names the
46/// parts a draw repaints one at a time; a mesh with none leaves it at
47/// [`NoParts`], and one with parts implements the trait for its own
48/// [`Part`] enum and no other. `C` names the clips it is posed by, the same
49/// way, over [`NoClips`] and its own [`Clip`] enum.
50pub trait Mesh<P: Part = NoParts, C: Clip = NoClips>: Catalog + Hash + Eq + Clone {
51 /// Builds this value's mesh, the first time a draw needs it.
52 ///
53 /// Must not read a file or the network; loaded data is in `assets`.
54 fn build(&self, assets: &Assets) -> MeshData<P, C>;
55
56 /// Places this mesh in the world, as a draw of a game whose styles are
57 /// `S`.
58 fn at<S: crate::SurfaceStyles>(self, transform: impl Into<Transform>) -> Instance<Self, S> {
59 Instance::new(self, transform.into())
60 }
61}
62
63mod animation;
64mod clip;
65mod data;
66mod geometry;
67mod instance;
68mod part;
69mod pose;
70mod primitives;
71mod rig;
72mod set;
73mod sheet;
74mod slot;