meshtext/types/indexed_mesh_text.rs
1use crate::{error::MeshTextError, BoundingBox, TriangleMesh};
2
3/// Holds the generated mesh data for the given text input.
4///
5/// The triangles use indexed vertices.
6pub struct IndexedMeshText {
7 /// The bounding box of this mesh.
8 pub bbox: BoundingBox,
9
10 /// The indices of this mesh.
11 pub indices: Vec<u32>,
12
13 /// The vertices of this mesh.
14 ///
15 /// Each vertex is composed of three [f32] values in the order _XYZ_.
16 /// If the mesh is flat the third component must be set to zero.
17 pub vertices: Vec<f32>,
18}
19
20impl IndexedMeshText {
21 /// Creates a new [IndexedMeshText].
22 ///
23 /// Arguments:
24 ///
25 /// * `indices`: The indices used to construct a triangle mesh from the supplied `vertices`.
26 /// * `vertices`: The vertices forming the mesh. Each vertex is composed of three [f32]
27 /// values in the order _XYZ_. If the mesh is flat the third component must be set to zero.
28 ///
29 /// Returns:
30 ///
31 /// The new [IndexedMeshText] or a [MeshTextError] if the operation failed.
32 pub fn new(indices: Vec<u32>, vertices: Vec<f32>) -> Result<Self, Box<dyn MeshTextError>> {
33 let bbox = BoundingBox::from_vertices(&vertices)?;
34
35 Ok(Self {
36 bbox,
37 indices,
38 vertices,
39 })
40 }
41}
42
43impl TriangleMesh for IndexedMeshText {
44 fn bbox(&self) -> BoundingBox {
45 self.bbox
46 }
47
48 fn indices(&self) -> Option<Vec<u32>> {
49 Some(self.indices.clone())
50 }
51
52 fn vertices(&self) -> Vec<f32> {
53 self.vertices.clone()
54 }
55}