2020-05-28 01:37:59 +02:00
|
|
|
//! Draw geometry using meshes of triangles.
|
2020-11-10 20:11:23 +01:00
|
|
|
use bytemuck::{Pod, Zeroable};
|
2020-05-28 01:37:59 +02:00
|
|
|
|
2020-05-19 17:15:44 +02:00
|
|
|
/// A set of [`Vertex2D`] and indices representing a list of triangles.
|
|
|
|
|
#[derive(Clone, Debug)]
|
2022-11-14 00:02:42 +01:00
|
|
|
pub struct Mesh2D<T> {
|
2020-05-19 17:15:44 +02:00
|
|
|
/// The vertices of the mesh
|
2022-11-14 00:02:42 +01:00
|
|
|
pub vertices: Vec<T>,
|
|
|
|
|
|
2020-05-19 17:15:44 +02:00
|
|
|
/// The list of vertex indices that defines the triangles of the mesh.
|
2022-10-18 15:18:37 -07:00
|
|
|
///
|
|
|
|
|
/// Therefore, this list should always have a length that is a multiple of 3.
|
2020-05-19 17:15:44 +02:00
|
|
|
pub indices: Vec<u32>,
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-29 10:52:58 -07:00
|
|
|
/// A two-dimensional vertex.
|
2020-11-10 20:11:23 +01:00
|
|
|
#[derive(Copy, Clone, Debug, Zeroable, Pod)]
|
2020-05-19 17:15:44 +02:00
|
|
|
#[repr(C)]
|
|
|
|
|
pub struct Vertex2D {
|
2022-09-29 10:52:58 -07:00
|
|
|
/// The vertex position in 2D space.
|
2020-05-19 17:15:44 +02:00
|
|
|
pub position: [f32; 2],
|
2022-10-06 07:28:05 -07:00
|
|
|
}
|
2022-11-03 05:50:53 +01:00
|
|
|
|
2022-11-14 00:02:42 +01:00
|
|
|
/// A two-dimensional vertex with a color.
|
|
|
|
|
#[derive(Copy, Clone, Debug, Zeroable, Pod)]
|
|
|
|
|
#[repr(C)]
|
|
|
|
|
pub struct ColoredVertex2D {
|
|
|
|
|
/// The vertex position in 2D space.
|
|
|
|
|
pub position: [f32; 2],
|
2022-11-03 05:50:53 +01:00
|
|
|
|
2022-11-14 00:02:42 +01:00
|
|
|
/// The color of the vertex in __linear__ RGBA.
|
|
|
|
|
pub color: [f32; 4],
|
2022-11-03 05:50:53 +01:00
|
|
|
}
|