For a face, use vertex array instead of a tuple

This commit is contained in:
numzero 2024-11-20 21:18:50 +03:00
parent c1b505356c
commit 8f1ade85a6
2 changed files with 9 additions and 9 deletions

View File

@ -37,10 +37,10 @@ pub struct Mesh {
} }
impl Mesh { impl Mesh {
pub fn new_list(device: &wgpu::Device, attrs: Attrs, tris: Vec<(Vec3, Vec3, Vec3)>) -> Self { pub fn new_list(device: &wgpu::Device, attrs: Attrs, tris: Vec<[Vec3; 3]>) -> Self {
let data: Vec<Vertex> = tris let data: Vec<Vertex> = tris
.into_iter() .into_iter()
.flat_map(|(a, b, c)| { .flat_map(|[a, b, c]| {
let n = (b - a).cross(c - a).normalize(); let n = (b - a).cross(c - a).normalize();
[ [
Vertex { Vertex {

View File

@ -17,7 +17,7 @@ pub struct FancyLine {
pub pts: Vec<Ray>, pub pts: Vec<Ray>,
} }
pub type Face = (Vec3, Vec3, Vec3); pub type Face = [Vec3; 3];
pub enum Mesh { pub enum Mesh {
List(Vec<Face>), List(Vec<Face>),
@ -166,12 +166,12 @@ impl Renderable for Tube {
let inner = (0..sides).flat_map(|k| { let inner = (0..sides).flat_map(|k| {
let a = r1 * dir(k); let a = r1 * dir(k);
let b = r1 * dir(k + 1); let b = r1 * dir(k + 1);
[(a - side, b - side, a + side), (b - side, b + side, a + side)] [[a - side, b - side, a + side], [b - side, b + side, a + side]]
}); });
let outer = (0..sides).flat_map(|k| { let outer = (0..sides).flat_map(|k| {
let a = r2 * dir(k); let a = r2 * dir(k);
let b = r2 * dir(k + 1); let b = r2 * dir(k + 1);
[(a - side, b - side, a + side), (b - side, b + side, a + side)] [[a - side, b - side, a + side], [b - side, b + side, a + side]]
}); });
let cap = (0..sides).flat_map(|k| { let cap = (0..sides).flat_map(|k| {
let a = r1 * dir(k); let a = r1 * dir(k);
@ -179,10 +179,10 @@ impl Renderable for Tube {
let c = r2 * dir(k + 1); let c = r2 * dir(k + 1);
let d = r2 * dir(k); let d = r2 * dir(k);
[ [
(a - side, b - side, c - side), [a - side, b - side, c - side],
(a - side, c - side, d - side), [a - side, c - side, d - side],
(a + side, b + side, c + side), [a + side, b + side, c + side],
(a + side, c + side, d + side), [a + side, c + side, d + side],
] ]
}); });
chain!(inner, outer, cap).collect() chain!(inner, outer, cap).collect()