11//! A light in Processing
22//!
33
4- use bevy:: prelude:: * ;
4+ use bevy:: { camera:: visibility:: RenderLayers , prelude:: * } ;
5+
6+ use crate :: { error:: ProcessingError , graphics:: Graphics } ;
57
68pub struct LightPlugin ;
79
@@ -10,26 +12,44 @@ impl Plugin for LightPlugin {
1012}
1113
1214pub fn create_directional (
13- In ( ( px, py, pz, color, illuminance) ) : In < ( f32 , f32 , f32 , Color , f32 ) > ,
15+ In ( ( entity , px, py, pz, color, illuminance) ) : In < ( Entity , f32 , f32 , f32 , Color , f32 ) > ,
1416 mut commands : Commands ,
15- ) -> Entity {
16- commands
17+ graphics : Query < & RenderLayers , With < Graphics > > ,
18+ ) -> Result < Entity , ProcessingError > {
19+ let layer = graphics
20+ . get ( entity)
21+ . map_err ( |_| ProcessingError :: GraphicsNotFound ) ?;
22+ Ok ( commands
1723 . spawn ( (
1824 DirectionalLight {
1925 illuminance,
2026 color,
2127 ..default ( )
2228 } ,
2329 Transform :: from_xyz ( px, py, pz) ,
30+ layer. clone ( ) ,
2431 ) )
25- . id ( )
32+ . id ( ) )
2633}
2734
2835pub fn create_point (
29- In ( ( px, py, pz, color, intensity, range, radius) ) : In < ( f32 , f32 , f32 , Color , f32 , f32 , f32 ) > ,
36+ In ( ( entity, px, py, pz, color, intensity, range, radius) ) : In < (
37+ Entity ,
38+ f32 ,
39+ f32 ,
40+ f32 ,
41+ Color ,
42+ f32 ,
43+ f32 ,
44+ f32 ,
45+ ) > ,
3046 mut commands : Commands ,
31- ) -> Entity {
32- commands
47+ graphics : Query < & RenderLayers , With < Graphics > > ,
48+ ) -> Result < Entity , ProcessingError > {
49+ let layer = graphics
50+ . get ( entity)
51+ . map_err ( |_| ProcessingError :: GraphicsNotFound ) ?;
52+ Ok ( commands
3353 . spawn ( (
3454 PointLight {
3555 intensity,
@@ -39,12 +59,14 @@ pub fn create_point(
3959 ..default ( )
4060 } ,
4161 Transform :: from_xyz ( px, py, pz) ,
62+ layer. clone ( ) ,
4263 ) )
43- . id ( )
64+ . id ( ) )
4465}
4566
4667pub fn create_spot (
47- In ( ( px, py, pz, color, intensity, range, radius, inner_angle, outer_angle) ) : In < (
68+ In ( ( entity, px, py, pz, color, intensity, range, radius, inner_angle, outer_angle) ) : In < (
69+ Entity ,
4870 f32 ,
4971 f32 ,
5072 f32 ,
@@ -56,8 +78,12 @@ pub fn create_spot(
5678 f32 ,
5779 ) > ,
5880 mut commands : Commands ,
59- ) -> Entity {
60- commands
81+ graphics : Query < & RenderLayers , With < Graphics > > ,
82+ ) -> Result < Entity , ProcessingError > {
83+ let layer = graphics
84+ . get ( entity)
85+ . map_err ( |_| ProcessingError :: GraphicsNotFound ) ?;
86+ Ok ( commands
6187 . spawn ( (
6288 SpotLight {
6389 color,
@@ -69,6 +95,7 @@ pub fn create_spot(
6995 ..default ( )
7096 } ,
7197 Transform :: from_xyz ( px, py, pz) ,
98+ layer. clone ( ) ,
7299 ) )
73- . id ( )
100+ . id ( ) )
74101}
0 commit comments