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
117
118
119
120
use crate::math::Color;
use crate::textures::Texture;
use std::sync::Arc;
#[derive(Debug, Clone)]
pub struct BasicMaterial {
pub color: Color,
pub wireframe: bool,
pub map: Option<Arc<Texture>>,
pub transparent: bool,
pub opacity: f32,
/// 0=FrontSide (default cull-back), 1=BackSide (cull-front),
/// 2=DoubleSide (no cull). Both 1 and 2 currently route to the
/// no-cull pipeline.
pub side: u32,
/// When true, only shadow darkness is visible (three.js ShadowMaterial).
pub shadow_only: bool,
pub alpha_test: f32,
/// three.js `alphaMap`: its green channel multiplies the opacity, before
/// `alphaTest` (`alphamap_fragment`). Shows only with `transparent` or
/// `alpha_test`, as in three.js.
pub alpha_map: Option<Arc<Texture>>,
/// three.js `envMap`: a cube map reflected (or, under
/// [`CubeMapping::Refraction`](crate::textures::CubeMapping), refracted)
/// and combined with the shaded colour per [`combine`](Self::combine).
pub env_map: Option<Arc<crate::textures::CubeTexture>>,
/// three.js `combine` (default `Multiply`).
pub combine: super::Combine,
/// three.js `reflectivity` (default 1): the environment's weight.
pub reflectivity: f32,
/// three.js `refractionRatio` (default 0.98), for a refraction-mapped
/// `env_map`.
pub refraction_ratio: f32,
/// three.js `envMapRotation` (default zero).
pub env_map_rotation: crate::math::Euler,
/// three.js `lightMap`: baked irradiance added to the indirect light, times
/// [`light_map_intensity`](Self::light_map_intensity).
pub light_map: Option<Arc<Texture>>,
/// three.js `lightMapIntensity` (default 1).
pub light_map_intensity: f32,
/// three.js `specularMap`: its red channel scales the specular term.
pub specular_map: Option<Arc<Texture>>,
/// three.js `polygonOffset` / `polygonOffsetFactor` / `polygonOffsetUnits`:
/// `Some` enables the depth offset (see [`PolygonOffset`](super::PolygonOffset)).
pub polygon_offset: Option<super::PolygonOffset>,
/// three.js `toneMapped` (default `true`): whether the renderer's tone
/// mapping applies to this material's output.
pub tone_mapped: bool,
/// three.js `depthTest` / `depthWrite` / `depthFunc` / `colorWrite`.
pub render_state: super::RenderState,
}
impl Default for BasicMaterial {
fn default() -> Self {
Self {
color: Color::WHITE,
wireframe: false,
map: None,
transparent: false,
opacity: 1.0,
side: 0,
shadow_only: false,
alpha_test: 0.0,
alpha_map: None,
env_map: None,
combine: super::Combine::Multiply,
reflectivity: 1.0,
refraction_ratio: 0.98,
env_map_rotation: crate::math::Euler::default(),
light_map: None,
light_map_intensity: 1.0,
specular_map: None,
polygon_offset: None,
tone_mapped: true,
render_state: super::RenderState::default(),
}
}
}
impl BasicMaterial {
pub fn new(color: Color) -> Self {
Self {
color,
wireframe: false,
map: None,
transparent: false,
opacity: 1.0,
side: 0,
shadow_only: false,
alpha_test: 0.0,
alpha_map: None,
env_map: None,
combine: super::Combine::Multiply,
reflectivity: 1.0,
refraction_ratio: 0.98,
env_map_rotation: crate::math::Euler::default(),
light_map: None,
light_map_intensity: 1.0,
specular_map: None,
polygon_offset: None,
tone_mapped: true,
render_state: super::RenderState::default(),
}
}
pub fn wireframe(mut self, w: bool) -> Self {
self.wireframe = w;
self
}
pub fn with_opacity(mut self, opacity: f32) -> Self {
self.opacity = opacity;
self
}
pub fn with_transparent(mut self, transparent: bool) -> Self {
self.transparent = transparent;
self
}
}