diff options
author | HampusM <hampus@hampusmat.com> | 2024-08-21 19:40:59 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2024-08-21 19:40:59 +0200 |
commit | c3c96f2d7b63d1d7e55f5a9a85da85444089c2a2 (patch) | |
tree | cc241270df8e73d6abf3e7d3747e835a13c10b5e | |
parent | de5c5f54bfd6881d8da07f40cd16f28e40cb886a (diff) |
refactor(engine): make cube vertex indices const variables
-rw-r--r-- | engine/src/mesh/cube.rs | 157 |
1 files changed, 82 insertions, 75 deletions
diff --git a/engine/src/mesh/cube.rs b/engine/src/mesh/cube.rs index ca946bb..7cdf885 100644 --- a/engine/src/mesh/cube.rs +++ b/engine/src/mesh/cube.rs @@ -62,84 +62,10 @@ pub fn create( create_top(&creation_spec, &mut vertices, &vertex_builder_cb); create_bottom(&creation_spec, &mut vertices, &vertex_builder_cb); - let front = [ - // 🮝 - VertexIndex::FrontTopRight, - VertexIndex::FrontBottomRight, - VertexIndex::FrontTopLeft, - // - // 🮟 - VertexIndex::FrontBottomRight, - VertexIndex::FrontBottomLeft, - VertexIndex::FrontTopLeft, - ]; - - let back = [ - // 🮝 - VertexIndex::BackTopRight, - VertexIndex::BackBottomRight, - VertexIndex::BackTopLeft, - // - // 🮟 - VertexIndex::BackBottomRight, - VertexIndex::BackBottomLeft, - VertexIndex::BackTopLeft, - ]; - - let right = [ - // 🮝 - VertexIndex::RightBackTop, - VertexIndex::RightBackBottom, - VertexIndex::RightFrontTop, - // - // 🮟 - VertexIndex::RightBackBottom, - VertexIndex::RightFrontBottom, - VertexIndex::RightFrontTop, - ]; - - let left = [ - // 🮝 - VertexIndex::LeftBackTop, - VertexIndex::LeftBackBottom, - VertexIndex::LeftFrontTop, - // - // 🮟 - VertexIndex::LeftBackBottom, - VertexIndex::LeftFrontBottom, - VertexIndex::LeftFrontTop, - ]; - - let top = [ - // 🮝 - VertexIndex::TopBackRight, - VertexIndex::TopBackLeft, - VertexIndex::TopFrontRight, - // - // 🮟 - VertexIndex::TopBackLeft, - VertexIndex::TopFrontLeft, - VertexIndex::TopFrontRight, - ]; - - let bottom = [ - // 🮝 - VertexIndex::BottomBackRight, - VertexIndex::BottomBackLeft, - VertexIndex::BottomFrontRight, - // - // 🮟 - VertexIndex::BottomBackLeft, - VertexIndex::BottomFrontLeft, - VertexIndex::BottomFrontRight, - ]; - - let indices = [front, back, right, left, top, bottom]; - Mesh::new( vertices.map(Option::unwrap).to_vec(), Some( - indices + VERTEX_INDICES .into_iter() .flatten() .map(|index| index as u32) @@ -693,3 +619,84 @@ fn create_bottom( .build(), ); } + +const VERTEX_INDICES_FRONT: [VertexIndex; 6] = [ + // 🮝 + VertexIndex::FrontTopRight, + VertexIndex::FrontBottomRight, + VertexIndex::FrontTopLeft, + // + // 🮟 + VertexIndex::FrontBottomRight, + VertexIndex::FrontBottomLeft, + VertexIndex::FrontTopLeft, +]; + +const VERTEX_INDICES_BACK: [VertexIndex; 6] = [ + // 🮝 + VertexIndex::BackTopRight, + VertexIndex::BackBottomRight, + VertexIndex::BackTopLeft, + // + // 🮟 + VertexIndex::BackBottomRight, + VertexIndex::BackBottomLeft, + VertexIndex::BackTopLeft, +]; + +const VERTEX_INDICES_RIGHT: [VertexIndex; 6] = [ + // 🮝 + VertexIndex::RightBackTop, + VertexIndex::RightBackBottom, + VertexIndex::RightFrontTop, + // + // 🮟 + VertexIndex::RightBackBottom, + VertexIndex::RightFrontBottom, + VertexIndex::RightFrontTop, +]; + +const VERTEX_INDICES_LEFT: [VertexIndex; 6] = [ + // 🮝 + VertexIndex::LeftBackTop, + VertexIndex::LeftBackBottom, + VertexIndex::LeftFrontTop, + // + // 🮟 + VertexIndex::LeftBackBottom, + VertexIndex::LeftFrontBottom, + VertexIndex::LeftFrontTop, +]; + +const VERTEX_INDICES_TOP: [VertexIndex; 6] = [ + // 🮝 + VertexIndex::TopBackRight, + VertexIndex::TopBackLeft, + VertexIndex::TopFrontRight, + // + // 🮟 + VertexIndex::TopBackLeft, + VertexIndex::TopFrontLeft, + VertexIndex::TopFrontRight, +]; + +const VERTEX_INDICES_BOTTOM: [VertexIndex; 6] = [ + // 🮝 + VertexIndex::BottomBackRight, + VertexIndex::BottomBackLeft, + VertexIndex::BottomFrontRight, + // + // 🮟 + VertexIndex::BottomBackLeft, + VertexIndex::BottomFrontLeft, + VertexIndex::BottomFrontRight, +]; + +const VERTEX_INDICES: [[VertexIndex; 6]; 6] = [ + VERTEX_INDICES_FRONT, + VERTEX_INDICES_BACK, + VERTEX_INDICES_RIGHT, + VERTEX_INDICES_LEFT, + VERTEX_INDICES_TOP, + VERTEX_INDICES_BOTTOM, +]; |