diff options
author | HampusM <hampus@hampusmat.com> | 2024-04-24 20:43:18 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2024-04-24 20:43:18 +0200 |
commit | 33f7772ddddf2a1c2bfefc50ef39f123df8af3e4 (patch) | |
tree | c142293d3ebdcbbaf36220fb073873c95575de9d /engine/src/material.rs | |
parent | d06be3fdaf66eb38e6c54fe2b7407d25692f8edc (diff) |
feat(engine): add colors to materials
Diffstat (limited to 'engine/src/material.rs')
-rw-r--r-- | engine/src/material.rs | 55 |
1 files changed, 55 insertions, 0 deletions
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<Color<f32>>, + diffuse: Option<Color<f32>>, + specular: Option<Color<f32>>, ambient_map: TextureId, diffuse_map: TextureId, specular_map: TextureId, @@ -14,6 +18,24 @@ pub struct Material impl Material { #[must_use] + pub fn ambient(&self) -> Option<&Color<f32>> + { + self.ambient.as_ref() + } + + #[must_use] + pub fn diffuse(&self) -> Option<&Color<f32>> + { + self.diffuse.as_ref() + } + + #[must_use] + pub fn specular(&self) -> Option<&Color<f32>> + { + self.specular.as_ref() + } + + #[must_use] pub fn ambient_map(&self) -> &TextureId { &self.ambient_map @@ -42,6 +64,9 @@ impl Material #[derive(Debug, Clone)] pub struct Builder { + ambient: Option<Color<f32>>, + diffuse: Option<Color<f32>>, + specular: Option<Color<f32>>, ambient_map: Option<TextureId>, diffuse_map: Option<TextureId>, specular_map: Option<TextureId>, @@ -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, @@ -62,6 +90,30 @@ impl Builder } #[must_use] + pub fn ambient(mut self, ambient: Color<f32>) -> Self + { + self.ambient = Some(ambient); + + self + } + + #[must_use] + pub fn diffuse(mut self, diffuse: Color<f32>) -> Self + { + self.diffuse = Some(diffuse); + + self + } + + #[must_use] + pub fn specular(mut self, specular: Color<f32>) -> Self + { + self.specular = Some(specular); + + self + } + + #[must_use] pub fn ambient_map(mut self, ambient_map: TextureId) -> Self { self.ambient_map = Some(ambient_map); @@ -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(), |