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
use crate::mesh::*;
impl Mesh {
pub fn vertex_position(&self, vertex_id: VertexID) -> Vec3 {
self.position(vertex_id)
}
pub fn vertex_normal(&self, vertex_id: VertexID) -> Vec3 {
let mut normal = Vec3::zero();
for halfedge_id in self.vertex_halfedge_iter(vertex_id) {
if let Some(face_id) = self.walker_from_halfedge(halfedge_id).face_id() {
normal += self.face_normal(face_id)
}
}
normal.normalize()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_vertex_normal() {
let mesh = crate::test_utility::subdivided_triangle();
let computed_normal = mesh.vertex_normal(unsafe { VertexID::new(0) });
assert_eq!(0.0, computed_normal.x);
assert_eq!(0.0, computed_normal.y);
assert_eq!(1.0, computed_normal.z);
}
}