summaryrefslogtreecommitdiff
path: root/engine/src/object.rs
diff options
context:
space:
mode:
Diffstat (limited to 'engine/src/object.rs')
-rw-r--r--engine/src/object.rs35
1 files changed, 33 insertions, 2 deletions
diff --git a/engine/src/object.rs b/engine/src/object.rs
index 3827763..6749124 100644
--- a/engine/src/object.rs
+++ b/engine/src/object.rs
@@ -2,6 +2,7 @@ use std::fs::read_to_string;
use std::io::Error as IoError;
use std::path::{Path, PathBuf};
+use crate::material::{Builder as MaterialBuilder, Material};
use crate::opengl::shader::{
Error as ShaderError,
Kind as ShaderKind,
@@ -28,6 +29,7 @@ pub struct Object
renderable: Renderable,
transform: Transform,
texture: Option<Texture>,
+ material: Material,
}
impl Object
@@ -62,6 +64,12 @@ impl Object
self.texture.as_ref()
}
+ #[must_use]
+ pub fn material(&self) -> &Material
+ {
+ &self.material
+ }
+
pub(crate) fn renderable(&self) -> &Renderable
{
&self.renderable
@@ -74,12 +82,13 @@ impl Object
}
/// Object builder.
-#[derive(Debug, Default)]
+#[derive(Debug)]
pub struct Builder
{
vertices: Vec<Vertex>,
indices: Option<Vec<u32>>,
texture: Option<Texture>,
+ material: Material,
}
impl Builder
@@ -88,7 +97,12 @@ impl Builder
#[must_use]
pub fn new() -> Self
{
- Self::default()
+ Self {
+ vertices: Vec::new(),
+ indices: None,
+ texture: None,
+ material: MaterialBuilder::new().build(),
+ }
}
#[must_use]
@@ -115,6 +129,14 @@ impl Builder
self
}
+ #[must_use]
+ pub fn material(mut self, material: Material) -> Self
+ {
+ self.material = material;
+
+ self
+ }
+
/// Builds a new [`Object`].
///
/// # Errors
@@ -212,6 +234,7 @@ impl Builder
renderable,
transform,
texture: self.texture,
+ material: self.material,
})
}
@@ -226,6 +249,14 @@ impl Builder
}
}
+impl Default for Builder
+{
+ fn default() -> Self
+ {
+ Self::new()
+ }
+}
+
/// Object error
#[derive(Debug, thiserror::Error)]
pub enum Error