From 33f7772ddddf2a1c2bfefc50ef39f123df8af3e4 Mon Sep 17 00:00:00 2001 From: HampusM Date: Wed, 24 Apr 2024 20:43:18 +0200 Subject: feat(engine): add colors to materials --- engine/src/material.rs | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) (limited to 'engine/src/material.rs') diff --git a/engine/src/material.rs b/engine/src/material.rs index 7d8c5db..c292af4 100644 --- a/engine/src/material.rs +++ b/engine/src/material.rs @@ -1,10 +1,14 @@ use ecs::Component; +use crate::color::Color; use crate::texture::Id as TextureId; #[derive(Debug, Clone, Component)] pub struct Material { + ambient: Option>, + diffuse: Option>, + specular: Option>, ambient_map: TextureId, diffuse_map: TextureId, specular_map: TextureId, @@ -13,6 +17,24 @@ pub struct Material impl Material { + #[must_use] + pub fn ambient(&self) -> Option<&Color> + { + self.ambient.as_ref() + } + + #[must_use] + pub fn diffuse(&self) -> Option<&Color> + { + self.diffuse.as_ref() + } + + #[must_use] + pub fn specular(&self) -> Option<&Color> + { + self.specular.as_ref() + } + #[must_use] pub fn ambient_map(&self) -> &TextureId { @@ -42,6 +64,9 @@ impl Material #[derive(Debug, Clone)] pub struct Builder { + ambient: Option>, + diffuse: Option>, + specular: Option>, ambient_map: Option, diffuse_map: Option, specular_map: Option, @@ -54,6 +79,9 @@ impl Builder pub fn new() -> Self { Self { + ambient: None, + diffuse: None, + specular: None, ambient_map: None, diffuse_map: None, specular_map: None, @@ -61,6 +89,30 @@ impl Builder } } + #[must_use] + pub fn ambient(mut self, ambient: Color) -> Self + { + self.ambient = Some(ambient); + + self + } + + #[must_use] + pub fn diffuse(mut self, diffuse: Color) -> Self + { + self.diffuse = Some(diffuse); + + self + } + + #[must_use] + pub fn specular(mut self, specular: Color) -> Self + { + self.specular = Some(specular); + + self + } + #[must_use] pub fn ambient_map(mut self, ambient_map: TextureId) -> Self { @@ -101,6 +153,9 @@ impl Builder pub fn build(&self) -> Material { Material { + ambient: self.ambient.clone(), + diffuse: self.diffuse.clone(), + specular: self.specular.clone(), ambient_map: self.ambient_map.unwrap(), diffuse_map: self.diffuse_map.unwrap(), specular_map: self.specular_map.unwrap(), -- cgit v1.2.3-18-g5258