Convert Vertex into struct

This commit is contained in:
Hanno Braun 2024-11-05 18:01:30 +01:00
parent 94e157bbf0
commit 9b4ae17a13
4 changed files with 9 additions and 5 deletions

View File

@ -7,7 +7,7 @@ pub fn export(mesh: &Mesh) -> anyhow::Result<()> {
.vertices()
.iter()
.copied()
.map(|vertex| vertex.map(Into::into))
.map(|vertex| vertex.point.map(Into::into))
.map(|[x, y, z]| threemf::model::Vertex { x, y, z })
.collect();

View File

@ -22,6 +22,10 @@ impl Mesh {
}
}
pub type Vertex = [f32; 3];
#[derive(Clone, Copy)]
pub struct Vertex {
pub point: [f32; 3],
}
pub type Index = u32;
pub type Triangle = [Index; 3];

View File

@ -1,4 +1,4 @@
use crate::geometry::Mesh;
use crate::geometry::{Mesh, Vertex};
pub fn model() -> anyhow::Result<Mesh> {
let mut mesh = Mesh::default();
@ -13,7 +13,7 @@ pub fn model() -> anyhow::Result<Mesh> {
[-0.5, 0.5, 0.5], // 6
[0.5, 0.5, 0.5], // 7
]
.map(|vertex| mesh.push_vertex(vertex));
.map(|vertex| mesh.push_vertex(Vertex { point: vertex }));
[
[0, 4, 6], // left

View File

@ -193,7 +193,7 @@ impl Renderer {
for triangle in mesh.triangles() {
let triangle = triangle
.map(|index| Vec3::from(mesh.vertices()[index as usize]));
.map(|index| Vec3::from(mesh.vertices()[index as usize].point));
let normal = {
let [a, b, c] = triangle;