From d7675fd0119afe5e9cc872ce8bbb2977a16f0b26 Mon Sep 17 00:00:00 2001 From: HampusM Date: Sat, 18 May 2024 16:22:09 +0200 Subject: refactor(engine): generate vertex builder using the builder macro --- engine/src/vertex.rs | 56 +++------------------------------------------------- 1 file changed, 3 insertions(+), 53 deletions(-) (limited to 'engine/src/vertex.rs') diff --git a/engine/src/vertex.rs b/engine/src/vertex.rs index 456a2a3..897ee97 100644 --- a/engine/src/vertex.rs +++ b/engine/src/vertex.rs @@ -1,7 +1,10 @@ use std::mem::size_of; +use crate::util::builder; use crate::vector::{Vec2, Vec3}; +builder! { +#[builder(name = Builder, derives = (Debug, Default))] #[derive(Debug, Clone, Default)] #[repr(C)] pub struct Vertex @@ -10,59 +13,6 @@ pub struct Vertex texture_coords: Vec2, normal: Vec3, } - -#[derive(Debug, Default)] -pub struct Builder -{ - pos: Option>, - texture_coords: Vec2, - normal: Option>, -} - -impl Builder -{ - #[must_use] - pub fn new() -> Self - { - Self::default() - } - - #[must_use] - pub fn pos(mut self, pos: Vec3) -> Self - { - self.pos = Some(pos); - - self - } - - #[must_use] - pub fn texture_coords(mut self, texture_coords: Vec2) -> Self - { - self.texture_coords = texture_coords; - - self - } - - #[must_use] - pub fn normal(mut self, normal: Vec3) -> Self - { - self.normal = Some(normal); - - self - } - - #[must_use] - pub fn build(self) -> Option - { - let pos = self.pos?; - let normal = self.normal.unwrap_or_default(); - - Some(Vertex { - pos, - texture_coords: self.texture_coords, - normal, - }) - } } impl Vertex -- cgit v1.2.3-18-g5258