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
use glam::{Mat4, Quat};
use crate::MeshGraph;
impl MeshGraph {
/// Apply a quaternion rotation to the mesh graph (positions and normals).
///
/// After this you should probably call `rebuild_bvh` to update the bounding volume hierarchy.
pub fn apply_quat(&mut self, quat: Quat) {
for pos in self.positions.values_mut() {
*pos = quat * *pos;
}
if let Some(normals) = self.vertex_normals.as_mut() {
for normal in normals.values_mut() {
*normal = quat * *normal;
}
}
}
/// Apply a projection to the mesh graph (positions and normals).
///
/// After this you should probably call `rebuild_bvh` to update the bounding volume hierarchy.
pub fn apply_projection(&mut self, projection: Mat4) {
for pos in self.positions.values_mut() {
*pos = projection.project_point3(*pos);
}
if self.vertex_normals.is_some() {
self.compute_vertex_normals();
}
}
/// Apply a transform matrix to the mesh graph (positions and normals).
///
/// After this you should probably call `rebuild_bvh` to update the bounding volume hierarchy.
pub fn apply_transform(&mut self, transform: Mat4) {
for pos in self.positions.values_mut() {
*pos = transform.transform_point3(*pos);
}
if let Some(normals) = self.vertex_normals.as_mut() {
for normal in normals.values_mut() {
*normal = transform.transform_vector3(*normal);
}
}
}
}