meshtext/util/
text_mesh.rs

1use glam::{Vec2, Vec3A};
2
3use crate::{BoundingBox, IndexedMeshText, MeshText};
4
5use super::{glam_vecs_to_raw, glam_vecs_to_raw_2d};
6
7/// Generates a [MeshText] from the internal data representation.
8///
9/// It is a bit unfortunate, that this is needed, because it adds the
10/// main bulk of execution time when loading from the cache.
11///
12/// Arguments:
13///
14/// * `data`: The internal data from the cache or freshly generated.
15///
16/// Returns:
17///
18/// The corresponding [MeshText].
19pub(crate) fn text_mesh_from_data(data: (Vec<Vec3A>, BoundingBox)) -> MeshText {
20    MeshText {
21        bbox: data.1,
22        vertices: glam_vecs_to_raw(&data.0),
23    }
24}
25
26/// Generates a two-dimensional [MeshText] from the internal data representation.
27///
28/// It is a bit unfortunate, that this is needed, because it adds the
29/// main bulk of execution time when loading from the cache.
30///
31/// Arguments:
32///
33/// * `data`: The internal data from the cache or freshly generated.
34///
35/// Returns:
36///
37/// The corresponding [MeshText].
38pub(crate) fn text_mesh_from_data_2d(data: (Vec<Vec2>, BoundingBox)) -> MeshText {
39    MeshText {
40        bbox: data.1,
41        vertices: glam_vecs_to_raw_2d(&data.0),
42    }
43}
44
45/// Generates a [IndexedMeshText] from the internal data representation.
46///
47/// This variant handles indexed meshes.
48///
49/// It is a bit unfortunate, that this is needed, because it adds the
50/// main bulk of execution time when loading from the cache.
51///
52/// Arguments:
53///
54/// * `data`: The internal data from the cache or freshly generated.
55///
56/// Returns:
57///
58/// The corresponding [IndexedMeshText].
59pub(crate) fn text_mesh_from_data_indexed(
60    data: (Vec<u32>, Vec<Vec3A>, BoundingBox),
61) -> IndexedMeshText {
62    IndexedMeshText {
63        bbox: data.2,
64        indices: data.0,
65        vertices: glam_vecs_to_raw(&data.1),
66    }
67}
68
69/// Generates a two-dimensional [IndexedMeshText] from the
70/// internal data representation.
71///
72/// This variant handles indexed meshes.
73///
74/// It is a bit unfortunate, that this is needed, because it adds the
75/// main bulk of execution time when loading from the cache.
76///
77/// Arguments:
78///
79/// * `data`: The internal data from the cache or freshly generated.
80///
81/// Returns:
82///
83/// The corresponding [IndexedMeshText].
84pub(crate) fn text_mesh_from_data_indexed_2d(
85    data: (Vec<u32>, Vec<Vec2>, BoundingBox),
86) -> IndexedMeshText {
87    IndexedMeshText {
88        bbox: data.2,
89        indices: data.0,
90        vertices: glam_vecs_to_raw_2d(&data.1),
91    }
92}