/
current_plan_rendering.rs
63 lines (58 loc) · 2.38 KB
/
current_plan_rendering.rs
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
use kay::{Recipient, Fate, ActorSystem};
use descartes::{Band, Path};
use monet::{Thing, Instance};
use ::core::geometry::band_to_thing;
use super::{CurrentPlan, RoadStroke};
use monet::SetupInScene;
impl Recipient<SetupInScene> for CurrentPlan {
fn receive(&mut self, _msg: &SetupInScene) -> Fate {
self.create_interactables();
Fate::Live
}
}
use monet::RenderToScene;
use monet::UpdateThing;
impl Recipient<RenderToScene> for CurrentPlan {
fn receive(&mut self, msg: &RenderToScene) -> Fate {match *msg{
RenderToScene{renderer_id, scene_id} => {
if self.ui_state.dirty {
let thing : Thing = self.current_plan_result_delta.new_inbetween_strokes.values()
.filter(|stroke| stroke.nodes.len() > 1)
.map(RoadStroke::preview_thing)
.sum();
renderer_id << UpdateThing{
scene_id: scene_id,
thing_id: 500,
thing: thing,
instance: Instance::with_color([0.3, 0.3, 0.5])
};
let intersections_thing : Thing = self.current_plan_result_delta.new_intersections.values()
.filter(|i| i.shape.segments().len() > 0)
.map(|i| band_to_thing(&Band::new(i.shape.clone(), 0.4), 0.5))
.sum();
renderer_id << UpdateThing{
scene_id: scene_id,
thing_id: 501,
thing: intersections_thing,
instance: Instance::with_color([0.0, 0.0, 1.0])
};
let connecting_strokes_thing : Thing = self.current_plan_result_delta.new_intersections.values()
.filter(|i| !i.strokes.is_empty())
.map(|i| -> Thing {i.strokes.iter().map(RoadStroke::preview_thing).sum()})
.sum();
renderer_id << UpdateThing{
scene_id: scene_id,
thing_id: 502,
thing: connecting_strokes_thing,
instance: Instance::with_color([0.5, 0.5, 1.0])
};
self.ui_state.dirty = false;
}
Fate::Live
}
}}
}
pub fn setup(system: &mut ActorSystem) {
system.add_inbox::<SetupInScene, CurrentPlan>();
system.add_inbox::<RenderToScene, CurrentPlan>();
}