honeycomb_render/capture/
ecs_data.rs

1use bevy::prelude::*;
2use bevy::utils::HashMap;
3use honeycomb_core::cmap::{DartIdType, EdgeIdType, FaceIdType, VertexIdType, VolumeIdType};
4
5// --- shared data
6
7/// Collection of a map's vertices.
8#[derive(Resource)]
9pub struct MapVertices(pub Vec<Vec3>);
10
11/// Collection of normals, organized per faces of a map.
12#[derive(Resource)]
13pub struct FaceNormals(pub HashMap<FaceIdType, Vec<Vec3>>);
14
15// --- bundles
16
17/// Bundle used to create entities modeling dart heads.
18#[derive(Bundle, Clone)]
19pub struct DartHeadBundle {
20    pub(crate) capture_id: CaptureId,
21    id: DartId,
22    vertex_id: VertexId,
23    edge_id: EdgeId,
24    pub(crate) face_id: FaceId,
25    pub(crate) dart_head: DartHead,
26}
27
28impl DartHeadBundle {
29    /// Constructor.
30    #[must_use = "Object unused after construction"]
31    pub fn new(
32        capture_id: usize,
33        id: DartIdType,
34        vertex_id: VertexIdType,
35        edge_id: EdgeIdType,
36        face_id: FaceIdType,
37        vertices: (usize, usize),
38        normals: (usize, usize),
39    ) -> Self {
40        Self {
41            capture_id: CaptureId(capture_id),
42            id: DartId(id),
43            vertex_id: VertexId(vertex_id),
44            edge_id: EdgeId(edge_id),
45            face_id: FaceId(face_id),
46            dart_head: DartHead { vertices, normals },
47        }
48    }
49}
50
51/// Bundle used to create entities modeling dart bodies.
52#[derive(Bundle, Clone)]
53pub struct DartBodyBundle {
54    pub(crate) capture_id: CaptureId,
55    id: DartId,
56    vertex_id: VertexId,
57    edge_id: EdgeId,
58    pub(crate) face_id: FaceId,
59    pub(crate) dart_body: DartBody,
60}
61
62impl DartBodyBundle {
63    /// Constructor.
64    #[must_use = "Object unused after construction"]
65    pub fn new(
66        capture_id: usize,
67        id: DartIdType,
68        vertex_id: VertexIdType,
69        edge_id: EdgeIdType,
70        face_id: FaceIdType,
71        vertices: (usize, usize),
72        normals: (usize, usize),
73    ) -> Self {
74        Self {
75            capture_id: CaptureId(capture_id),
76            id: DartId(id),
77            vertex_id: VertexId(vertex_id),
78            edge_id: EdgeId(edge_id),
79            face_id: FaceId(face_id),
80            dart_body: DartBody { vertices, normals },
81        }
82    }
83}
84
85/// Bundle used to create entities modeling vertices.
86#[derive(Bundle, Clone)]
87pub struct VertexBundle {
88    pub(crate) capture_id: CaptureId,
89    id: VertexId,
90    pub(crate) vertex: Vertex,
91}
92
93impl VertexBundle {
94    /// Constructor.
95    #[must_use = "Object unused after construction"]
96    pub fn new(capture_id: usize, id: VertexIdType, vertex: usize) -> Self {
97        Self {
98            capture_id: CaptureId(capture_id),
99            id: VertexId(id),
100            vertex: Vertex(vertex),
101        }
102    }
103}
104
105/// Bundle used to create entities modeling edges.
106#[derive(Bundle, Clone)]
107pub struct EdgeBundle {
108    pub(crate) capture_id: CaptureId,
109    id: EdgeId,
110    pub(crate) edge: Edge,
111}
112
113impl EdgeBundle {
114    /// Constructor.
115    #[must_use = "Object unused after construction"]
116    pub fn new(capture_id: usize, id: EdgeIdType, vertices: (usize, usize)) -> Self {
117        Self {
118            capture_id: CaptureId(capture_id),
119            id: EdgeId(id),
120            edge: Edge(vertices.0, vertices.1),
121        }
122    }
123}
124
125/// Bundle used to create entities modeling faces.
126#[derive(Bundle, Clone)]
127pub struct FaceBundle {
128    pub(crate) capture_id: CaptureId,
129    pub(crate) id: FaceId,
130    pub(crate) face: Face,
131}
132
133impl FaceBundle {
134    /// Constructor.
135    #[must_use = "Object unused after construction"]
136    pub fn new(capture_id: usize, id: FaceIdType, vertices: Vec<usize>) -> Self {
137        Self {
138            capture_id: CaptureId(capture_id),
139            id: FaceId(id),
140            face: Face(vertices),
141        }
142    }
143}
144
145// --- individual components
146
147/// Capture ID component.
148#[derive(Component, Clone, PartialEq, Eq)]
149pub struct CaptureId(pub usize);
150
151/// Dart ID component.
152#[derive(Component, Clone)]
153pub struct DartId(pub DartIdType);
154
155/// Vertex ID component.
156#[derive(Component, Clone)]
157pub struct VertexId(pub VertexIdType);
158
159/// Edge ID component.
160#[derive(Component, Clone)]
161pub struct EdgeId(pub EdgeIdType);
162
163/// Face ID component.
164#[derive(Component, Clone)]
165pub struct FaceId(pub FaceIdType);
166
167/// Volume ID component.
168#[derive(Component, Clone)]
169pub struct VolumeId(pub VolumeIdType);
170
171/// Dart head component.
172#[derive(Component, Clone)]
173pub struct DartHead {
174    pub(crate) vertices: (usize, usize), // (v0_id, v1_id); we need both for rotation computations
175    pub(crate) normals: (usize, usize),  // vertex normals (for shrink ops)
176}
177
178/// Dart body component.
179#[derive(Component, Clone)]
180pub struct DartBody {
181    pub(crate) vertices: (usize, usize), // (v0_id, v1_id)
182    pub(crate) normals: (usize, usize),  // vertex normals (for shrink ops)
183}
184
185/// Beta component.
186#[derive(Component, Clone)]
187pub struct Beta(pub u8, pub usize, pub usize); // beta id, v0_id, v1_id ?
188
189/// Vertex component.
190#[derive(Component, Clone)]
191pub struct Vertex(pub usize); // map id, vid
192
193/// Edge component.
194#[derive(Component, Clone)]
195pub struct Edge(pub usize, pub usize); // v0_id, v1_id
196
197/// Face component.
198#[derive(Component, Clone)]
199pub struct Face(pub Vec<usize>); // vertex list
200
201/// Volume component.
202#[derive(Component, Clone)]
203pub struct Volume;