forked from processing/libprocessing
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlight.rs
More file actions
86 lines (79 loc) · 2.05 KB
/
light.rs
File metadata and controls
86 lines (79 loc) · 2.05 KB
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
//! A light in Processing
//!
use bevy::{camera::visibility::RenderLayers, prelude::*};
use crate::{error::ProcessingError, graphics::Graphics};
pub struct LightPlugin;
impl Plugin for LightPlugin {
fn build(&self, _app: &mut App) {}
}
pub fn create_directional(
In((entity, color, illuminance)): In<(Entity, Color, f32)>,
mut commands: Commands,
graphics: Query<&RenderLayers, With<Graphics>>,
) -> Result<Entity, ProcessingError> {
let layer = graphics
.get(entity)
.map_err(|_| ProcessingError::GraphicsNotFound)?;
Ok(commands
.spawn((
DirectionalLight {
illuminance,
color,
..default()
},
layer.clone(),
))
.id())
}
pub fn create_point(
In((entity, color, intensity, range, radius)): In<(Entity, Color, f32, f32, f32)>,
mut commands: Commands,
graphics: Query<&RenderLayers, With<Graphics>>,
) -> Result<Entity, ProcessingError> {
let layer = graphics
.get(entity)
.map_err(|_| ProcessingError::GraphicsNotFound)?;
Ok(commands
.spawn((
PointLight {
intensity,
color,
range,
radius,
..default()
},
layer.clone(),
))
.id())
}
pub fn create_spot(
In((entity, color, intensity, range, radius, inner_angle, outer_angle)): In<(
Entity,
Color,
f32,
f32,
f32,
f32,
f32,
)>,
mut commands: Commands,
graphics: Query<&RenderLayers, With<Graphics>>,
) -> Result<Entity, ProcessingError> {
let layer = graphics
.get(entity)
.map_err(|_| ProcessingError::GraphicsNotFound)?;
Ok(commands
.spawn((
SpotLight {
color,
intensity,
range,
radius,
inner_angle,
outer_angle,
..default()
},
layer.clone(),
))
.id())
}