summaryrefslogtreecommitdiff
path: root/engine/src/material.rs
diff options
context:
space:
mode:
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)
+}