summaryrefslogtreecommitdiff
path: root/engine/src/material.rs
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2024-05-05 22:10:57 +0200
committerHampusM <hampus@hampusmat.com>2024-05-05 22:11:06 +0200
commit5013c63cf727eaa94c30f2680163a9f868aafb6e (patch)
treea882ccf5cb5ee2cc7420182f0f013bfb23ffd57f /engine/src/material.rs
parent81bba9fb007333c54006be9172e090c38c45d110 (diff)
feat(engine): make material textures optional
Diffstat (limited to 'engine/src/material.rs')
-rw-r--r--engine/src/material.rs41
1 files changed, 37 insertions, 4 deletions
diff --git a/engine/src/material.rs b/engine/src/material.rs
index 6839fd1..69fe970 100644
--- a/engine/src/material.rs
+++ b/engine/src/material.rs
@@ -1,6 +1,7 @@
use ecs::Component;
use crate::color::Color;
+use crate::data_types::dimens::Dimens;
use crate::texture::{Id as TextureId, Texture};
#[derive(Debug, Clone, Component)]
@@ -167,15 +168,42 @@ 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(mut self) -> Material
{
+ let ambient_map = self.ambient_map.unwrap_or_else(|| {
+ let texture = create_1x1_white_texture();
+ let texture_id = texture.id();
+
+ self.textures.push(texture);
+
+ texture_id
+ });
+
+ let diffuse_map = self.diffuse_map.unwrap_or_else(|| {
+ let texture = create_1x1_white_texture();
+ let texture_id = texture.id();
+
+ self.textures.push(texture);
+
+ texture_id
+ });
+
+ let specular_map = self.specular_map.unwrap_or_else(|| {
+ let texture = create_1x1_white_texture();
+ let texture_id = texture.id();
+
+ self.textures.push(texture);
+
+ texture_id
+ });
+
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(),
+ ambient_map,
+ diffuse_map,
+ specular_map,
textures: self.textures,
shininess: self.shininess,
}
@@ -189,3 +217,8 @@ impl Default for Builder
Self::new()
}
}
+
+fn create_1x1_white_texture() -> Texture
+{
+ Texture::new_from_color(&Dimens { width: 1, height: 1 }, &Color::WHITE_U8)
+}