use crate::color::Color; #[derive(Debug, Clone)] pub struct Material { ambient: Color, diffuse: Color, specular: Color, shininess: f32, } impl Material { #[must_use] pub fn ambient(&self) -> &Color { &self.ambient } #[must_use] pub fn diffuse(&self) -> &Color { &self.diffuse } #[must_use] pub fn specular(&self) -> &Color { &self.specular } #[must_use] pub fn shininess(&self) -> f32 { self.shininess } } /// [`Material`] builder. #[derive(Debug, Clone)] pub struct Builder { ambient: Color, diffuse: Color, specular: Color, shininess: f32, } impl Builder { #[must_use] pub fn new() -> Self { Self { ambient: 0.2.into(), diffuse: 0.5.into(), specular: 1.0.into(), shininess: 32.0, } } #[must_use] pub fn ambient(mut self, ambient: Color) -> Self { self.ambient = ambient; self } #[must_use] pub fn diffuse(mut self, diffuse: Color) -> Self { self.diffuse = diffuse; self } #[must_use] pub fn specular(mut self, specular: Color) -> Self { self.specular = specular; self } #[must_use] pub fn shininess(mut self, shininess: f32) -> Self { self.shininess = shininess; self } /// Builds a new [`Material`]. #[must_use] pub fn build(&self) -> Material { Material { ambient: self.ambient.clone(), diffuse: self.diffuse.clone(), specular: self.specular.clone(), shininess: self.shininess, } } } impl Default for Builder { fn default() -> Self { Self::new() } }