Define triangles by referring to meshes

This commit is contained in:
Hanno Braun 2024-11-06 20:36:50 +01:00
parent 7051d681ca
commit aff4f5898b
2 changed files with 27 additions and 24 deletions

View File

@ -58,6 +58,10 @@ impl<'r, T> OperationResult<'r, T> {
results: self.results.push_right(vertex), results: self.results.push_right(vertex),
} }
} }
pub fn results(self) -> T {
self.results
}
} }
#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)] #[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)]

View File

@ -3,33 +3,32 @@ use crate::geometry::Operations;
pub fn model() -> anyhow::Result<Operations> { pub fn model() -> anyhow::Result<Operations> {
let mut mesh = Operations::default(); let mut mesh = Operations::default();
mesh.vertex([-0.5, -0.5, -0.5]) // 0 let (a, b, c, d, e, f, g, h) = mesh
.vertex([0.5, -0.5, -0.5]) // 1 .vertex([-0.5, -0.5, -0.5])
.vertex([-0.5, 0.5, -0.5]) // 2 .vertex([0.5, -0.5, -0.5])
.vertex([0.5, 0.5, -0.5]) // 3 .vertex([-0.5, 0.5, -0.5])
.vertex([-0.5, -0.5, 0.5]) // 4 .vertex([0.5, 0.5, -0.5])
.vertex([0.5, -0.5, 0.5]) // 5 .vertex([-0.5, -0.5, 0.5])
.vertex([-0.5, 0.5, 0.5]) // 6 .vertex([0.5, -0.5, 0.5])
.vertex([0.5, 0.5, 0.5]); // 7 .vertex([-0.5, 0.5, 0.5])
.vertex([0.5, 0.5, 0.5])
.results();
[ [
[0, 4, 6], // left [a, e, g], // left
[0, 6, 2], [a, g, c],
[1, 3, 7], // right [b, d, h], // right
[1, 7, 5], [b, h, f],
[0, 1, 5], // front [a, b, f], // front
[0, 5, 4], [a, f, e],
[2, 7, 3], // back [c, h, d], // back
[2, 6, 7], [c, g, h],
[0, 2, 1], // bottom [a, c, b], // bottom
[1, 2, 3], [b, c, d],
[4, 5, 7], // top [e, f, h], // top
[4, 7, 6], [e, h, g],
] ]
.map(|triangle| { .map(|triangle| mesh.triangle(triangle));
let triangle = triangle.map(|index| mesh.vertices[index]);
mesh.triangle(triangle)
});
Ok(mesh) Ok(mesh)
} }