diff options
-rw-r--r-- | engine/src/file_format/wavefront/obj.rs | 4 | ||||
-rw-r--r-- | engine/src/vertex.rs | 56 |
2 files changed, 5 insertions, 55 deletions
diff --git a/engine/src/file_format/wavefront/obj.rs b/engine/src/file_format/wavefront/obj.rs index 6367ead..97e0110 100644 --- a/engine/src/file_format/wavefront/obj.rs +++ b/engine/src/file_format/wavefront/obj.rs @@ -297,7 +297,7 @@ impl FaceVertex /// Tries to convert this face vertex into a [`Vertex`]. pub fn to_vertex(&self, obj: &Obj) -> Result<Vertex, Error> { - let mut vertex_builder = VertexBuilder::new(); + let mut vertex_builder = VertexBuilder::default(); let vertex_pos = *obj.vertex_positions.get(self.position as usize - 1).ok_or( Error::FaceVertexPositionNotFound { vertex_pos_index: self.position }, @@ -327,7 +327,7 @@ impl FaceVertex vertex_builder = vertex_builder.normal(vertex_normal); } - Ok(vertex_builder.build().unwrap()) + Ok(vertex_builder.build()) } } 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<f32>, normal: Vec3<f32>, } - -#[derive(Debug, Default)] -pub struct Builder -{ - pos: Option<Vec3<f32>>, - texture_coords: Vec2<f32>, - normal: Option<Vec3<f32>>, -} - -impl Builder -{ - #[must_use] - pub fn new() -> Self - { - Self::default() - } - - #[must_use] - pub fn pos(mut self, pos: Vec3<f32>) -> Self - { - self.pos = Some(pos); - - self - } - - #[must_use] - pub fn texture_coords(mut self, texture_coords: Vec2<f32>) -> Self - { - self.texture_coords = texture_coords; - - self - } - - #[must_use] - pub fn normal(mut self, normal: Vec3<f32>) -> Self - { - self.normal = Some(normal); - - self - } - - #[must_use] - pub fn build(self) -> Option<Vertex> - { - let pos = self.pos?; - let normal = self.normal.unwrap_or_default(); - - Some(Vertex { - pos, - texture_coords: self.texture_coords, - normal, - }) - } } impl Vertex |