From c9d5bbfe490aa4aab0e9de02b67bf8fee6dca5a2 Mon Sep 17 00:00:00 2001 From: HampusM Date: Sun, 5 May 2024 21:28:53 +0200 Subject: refactor(engine): make Material hold textures --- engine/src/material.rs | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'engine/src/material.rs') diff --git a/engine/src/material.rs b/engine/src/material.rs index c292af4..6839fd1 100644 --- a/engine/src/material.rs +++ b/engine/src/material.rs @@ -1,7 +1,7 @@ use ecs::Component; use crate::color::Color; -use crate::texture::Id as TextureId; +use crate::texture::{Id as TextureId, Texture}; #[derive(Debug, Clone, Component)] pub struct Material @@ -12,6 +12,7 @@ pub struct Material ambient_map: TextureId, diffuse_map: TextureId, specular_map: TextureId, + textures: Vec, shininess: f32, } @@ -53,6 +54,12 @@ impl Material &self.specular_map } + #[must_use] + pub fn textures(&self) -> &[Texture] + { + &self.textures + } + #[must_use] pub fn shininess(&self) -> f32 { @@ -70,6 +77,7 @@ pub struct Builder ambient_map: Option, diffuse_map: Option, specular_map: Option, + textures: Vec, shininess: f32, } @@ -85,6 +93,7 @@ impl Builder ambient_map: None, diffuse_map: None, specular_map: None, + textures: Vec::new(), shininess: 32.0, } } @@ -137,6 +146,14 @@ impl Builder self } + #[must_use] + pub fn textures(mut self, textures: impl IntoIterator) -> Self + { + self.textures = textures.into_iter().collect(); + + self + } + #[must_use] pub fn shininess(mut self, shininess: f32) -> Self { @@ -150,7 +167,7 @@ impl Builder /// # Panics /// Will panic if no ambient map, diffuse map or specular map is set. #[must_use] - pub fn build(&self) -> Material + pub fn build(self) -> Material { Material { ambient: self.ambient.clone(), @@ -159,6 +176,7 @@ impl Builder ambient_map: self.ambient_map.unwrap(), diffuse_map: self.diffuse_map.unwrap(), specular_map: self.specular_map.unwrap(), + textures: self.textures, shininess: self.shininess, } } -- cgit v1.2.3-18-g5258