From b0315b7ebc16fcbae6c3098db6c824f9057d2a71 Mon Sep 17 00:00:00 2001 From: HampusM Date: Mon, 20 Nov 2023 22:00:34 +0100 Subject: feat(engine): add materials --- engine/src/object.rs | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) (limited to 'engine/src/object.rs') diff --git a/engine/src/object.rs b/engine/src/object.rs index 3827763..6749124 100644 --- a/engine/src/object.rs +++ b/engine/src/object.rs @@ -2,6 +2,7 @@ use std::fs::read_to_string; use std::io::Error as IoError; use std::path::{Path, PathBuf}; +use crate::material::{Builder as MaterialBuilder, Material}; use crate::opengl::shader::{ Error as ShaderError, Kind as ShaderKind, @@ -28,6 +29,7 @@ pub struct Object renderable: Renderable, transform: Transform, texture: Option, + material: Material, } impl Object @@ -62,6 +64,12 @@ impl Object self.texture.as_ref() } + #[must_use] + pub fn material(&self) -> &Material + { + &self.material + } + pub(crate) fn renderable(&self) -> &Renderable { &self.renderable @@ -74,12 +82,13 @@ impl Object } /// Object builder. -#[derive(Debug, Default)] +#[derive(Debug)] pub struct Builder { vertices: Vec, indices: Option>, texture: Option, + material: Material, } impl Builder @@ -88,7 +97,12 @@ impl Builder #[must_use] pub fn new() -> Self { - Self::default() + Self { + vertices: Vec::new(), + indices: None, + texture: None, + material: MaterialBuilder::new().build(), + } } #[must_use] @@ -115,6 +129,14 @@ impl Builder self } + #[must_use] + pub fn material(mut self, material: Material) -> Self + { + self.material = material; + + self + } + /// Builds a new [`Object`]. /// /// # Errors @@ -212,6 +234,7 @@ impl Builder renderable, transform, texture: self.texture, + material: self.material, }) } @@ -226,6 +249,14 @@ impl Builder } } +impl Default for Builder +{ + fn default() -> Self + { + Self::new() + } +} + /// Object error #[derive(Debug, thiserror::Error)] pub enum Error -- cgit v1.2.3-18-g5258