1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
use crate::texture::Id as TextureId;
#[derive(Debug, Clone)]
pub struct Material
{
ambient_map: TextureId,
diffuse_map: TextureId,
specular_map: TextureId,
shininess: f32,
}
impl Material
{
#[must_use]
pub fn ambient_map(&self) -> &TextureId
{
&self.ambient_map
}
#[must_use]
pub fn diffuse_map(&self) -> &TextureId
{
&self.diffuse_map
}
#[must_use]
pub fn specular_map(&self) -> &TextureId
{
&self.specular_map
}
#[must_use]
pub fn shininess(&self) -> f32
{
self.shininess
}
}
/// [`Material`] builder.
#[derive(Debug, Clone)]
pub struct Builder
{
ambient_map: Option<TextureId>,
diffuse_map: Option<TextureId>,
specular_map: Option<TextureId>,
shininess: f32,
}
impl Builder
{
#[must_use]
pub fn new() -> Self
{
Self {
ambient_map: None,
diffuse_map: None,
specular_map: None,
shininess: 32.0,
}
}
#[must_use]
pub fn ambient_map(mut self, ambient_map: TextureId) -> Self
{
self.ambient_map = Some(ambient_map);
self
}
#[must_use]
pub fn diffuse_map(mut self, diffuse_map: TextureId) -> Self
{
self.diffuse_map = Some(diffuse_map);
self
}
#[must_use]
pub fn specular_map(mut self, specular_map: TextureId) -> Self
{
self.specular_map = Some(specular_map);
self
}
#[must_use]
pub fn shininess(mut self, shininess: f32) -> Self
{
self.shininess = shininess;
self
}
/// Builds a new [`Material`].
///
/// # Panics
/// Will panic if no ambient map, diffuse map or specular map is set.
#[must_use]
pub fn build(&self) -> Material
{
Material {
ambient_map: self.ambient_map.unwrap(),
diffuse_map: self.diffuse_map.unwrap(),
specular_map: self.specular_map.unwrap(),
shininess: self.shininess,
}
}
}
impl Default for Builder
{
fn default() -> Self
{
Self::new()
}
}
|