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
use crate::math::Color;
/// Flat-color line material. Mirrors three.js's `LineBasicMaterial`.
#[derive(Debug, Clone, Copy)]
pub struct LineBasicMaterial {
pub color: Color,
pub opacity: f32,
/// three.js `alphaTest`: fragments whose alpha (opacity × map alpha) is
/// below this are discarded. 0 (the default) keeps every fragment.
pub alpha_test: f32,
/// three.js `transparent`. `Some` is three.js's flag as given — `false`
/// draws opaquely whatever the opacity. `None` (the default) blends when
/// `opacity < 1`, the rule this crate used before it had the flag.
pub transparent: Option<bool>,
pub line_width: f32,
pub dashed: bool,
pub dash_scale: f32,
pub dash_size: f32,
pub gap_size: f32,
/// 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`.
/// `depth_test: false` draws the line over the depth buffer (an x-ray
/// or overlay stroke).
pub render_state: super::RenderState,
}
impl Default for LineBasicMaterial {
fn default() -> Self {
Self {
color: Color::WHITE,
opacity: 1.0,
alpha_test: 0.0,
transparent: None,
line_width: 1.0,
dashed: false,
dash_scale: 1.0,
dash_size: 0.0,
gap_size: 0.0,
tone_mapped: true,
render_state: super::RenderState::default(),
}
}
}
impl LineBasicMaterial {
pub fn new(color: Color) -> Self {
Self {
color,
..Default::default()
}
}
/// Draw through occluders (active highlights, HUD strokes): three.js
/// `depthTest`. Draws in order like any other, so an overlay wants a
/// later `render_order` than what it overlays.
pub fn with_depth_test(mut self, enabled: bool) -> Self {
self.render_state.depth_test = enabled;
self
}
}