1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
//! ECS components for entity-based rendering.
//!
//! This module provides components for rendering entities using the `hecs` ECS library.
//! Entities with [`Transform`](crate::Transform) and [`RenderMesh`] components are
//! automatically rendered when [`Frame::render_world`](crate::Frame::render_world) is called.
//!
//! # Example
//!
//! ```ignore
//! use hoplite::*;
//!
//! run(|ctx| {
//! ctx.enable_mesh_rendering();
//! let cube = ctx.mesh_cube();
//!
//! // Spawn an entity with mesh components
//! ctx.world.spawn((
//! Transform::new().position(Vec3::new(0.0, 0.0, -5.0)),
//! RenderMesh::new(cube, Color::RED),
//! ));
//!
//! move |frame| {
//! frame.render_world();
//! }
//! });
//! ```
use crateColor;
/// Type-safe handle to a mesh stored in the MeshQueue.
///
/// Obtained from mesh creation methods like [`SetupContext::mesh_cube`](crate::SetupContext::mesh_cube).
/// This newtype wrapper prevents accidentally passing texture indices where mesh indices are expected.
///
/// # Example
///
/// ```ignore
/// let cube: MeshId = ctx.mesh_cube();
/// frame.mesh(cube).draw(); // Type-safe: can't pass a TextureId here
/// ```
usize);
/// Type-safe handle to a texture stored in the MeshQueue.
///
/// Obtained from texture creation methods like [`SetupContext::texture_from_file`](crate::SetupContext::texture_from_file).
/// This newtype wrapper prevents accidentally passing mesh indices where texture indices are expected.
///
/// # Example
///
/// ```ignore
/// let tex: TextureId = ctx.texture_from_file("brick.png")?;
/// frame.mesh(cube).texture(tex).draw(); // Type-safe: can't pass a MeshId here
/// ```
usize);
// Keep MeshHandle and TextureHandle as aliases for backwards compatibility in ECS contexts
/// Alias for [`MeshId`] - used in ECS components.
pub type MeshHandle = MeshId;
/// Alias for [`TextureId`] - used in ECS components.
pub type TextureHandle = TextureId;
/// Component for rendering a mesh on an entity.
///
/// Attach this component along with a [`Transform`](crate::Transform) to make an entity
/// renderable. Call [`Frame::render_world`](crate::Frame::render_world) to render all
/// entities with these components.
///
/// # Example
///
/// ```ignore
/// // Untextured colored mesh
/// world.spawn((
/// Transform::new().position(Vec3::Y * 2.0),
/// RenderMesh::new(MeshHandle(cube), Color::RED),
/// ));
///
/// // Textured mesh
/// world.spawn((
/// Transform::new(),
/// RenderMesh::with_texture(MeshHandle(cube), Color::WHITE, TextureHandle(tex)),
/// ));
/// ```