Skip to main content

eldiron_shared/
effectwrapper.rs

1use rusterix::{Light, LightType};
2use theframework::prelude::*;
3
4#[derive(Clone)]
5pub enum EffectWrapper {
6    RusterixLight(Light),
7}
8
9use EffectWrapper::*;
10
11impl EffectWrapper {
12    pub fn name(&self) -> String {
13        match self {
14            RusterixLight(light) => match light.light_type {
15                LightType::Area => "Area Light".into(),
16                LightType::Daylight => "Daylight".into(),
17                _ => "Point Light".into(),
18            },
19        }
20    }
21    pub fn icon(&self) -> String {
22        match self {
23            RusterixLight(_) => "light_on".into(),
24        }
25    }
26
27    /// Create the light ui for an Rusterix Light source
28    pub fn create_light_ui(light: &Light) -> TheNodeUI {
29        let mut nodeui = TheNodeUI::default();
30
31        #[allow(clippy::single_match)]
32        match light.light_type {
33            LightType::Point => {
34                let item = TheNodeUIItem::ColorPicker(
35                    "lightColor".into(),
36                    "".into(),
37                    "Set the color of the light".into(),
38                    TheColor::from(light.get_color()),
39                    false,
40                );
41                nodeui.add_item(item);
42
43                let item = TheNodeUIItem::FloatEditSlider(
44                    "lightIntensity".into(),
45                    "Intensity".into(),
46                    "Set the intensity of the light.".into(),
47                    light.get_intensity(),
48                    0.0..=4.0,
49                    false,
50                );
51                nodeui.add_item(item);
52
53                let item = TheNodeUIItem::FloatEditSlider(
54                    "lightStartDistance".into(),
55                    "Fade Start".into(),
56                    "Set the distance the light starts to fade.".into(),
57                    light.get_start_distance(),
58                    0.0..=100.0,
59                    false,
60                );
61                nodeui.add_item(item);
62
63                let item = TheNodeUIItem::FloatEditSlider(
64                    "lightEndDistance".into(),
65                    "Fade End".into(),
66                    "Set the distance the light fade ends.".into(),
67                    light.get_end_distance(),
68                    0.0..=100.0,
69                    false,
70                );
71                nodeui.add_item(item);
72                /*
73                let item = TheNodeUIItem::Selector(
74                    "lightType".into(),
75                    "Type".into(),
76                    "Select the type of light.".into(),
77                    vec!["Yes".to_string(), "No".to_string()],
78                    properties.get_int_default("light_type", 0),
79                );
80                nodeui.add_item(item);*/
81            }
82            LightType::Area => {
83                let item = TheNodeUIItem::ColorPicker(
84                    "lightColor".into(),
85                    "".into(),
86                    "Set the color of the light".into(),
87                    TheColor::from(light.get_color()),
88                    false,
89                );
90                nodeui.add_item(item);
91
92                let item = TheNodeUIItem::FloatEditSlider(
93                    "lightIntensity".into(),
94                    "Intensity".into(),
95                    "Set the intensity of the light.".into(),
96                    light.get_intensity(),
97                    0.0..=4.0,
98                    false,
99                );
100                nodeui.add_item(item);
101
102                let item = TheNodeUIItem::FloatEditSlider(
103                    "lightStartDistance".into(),
104                    "Fade Start".into(),
105                    "Set the distance the light starts to fade.".into(),
106                    light.get_start_distance(),
107                    0.0..=100.0,
108                    false,
109                );
110                nodeui.add_item(item);
111
112                let item = TheNodeUIItem::FloatEditSlider(
113                    "lightEndDistance".into(),
114                    "Fade End".into(),
115                    "Set the distance the light fade ends.".into(),
116                    light.get_end_distance(),
117                    0.0..=100.0,
118                    false,
119                );
120                nodeui.add_item(item);
121                /*
122                let item = TheNodeUIItem::Selector(
123                    "lightType".into(),
124                    "Type".into(),
125                    "Select the type of light.".into(),
126                    vec!["Yes".to_string(), "No".to_string()],
127                    properties.get_int_default("light_type", 0),
128                );
129                nodeui.add_item(item);*/
130            }
131            _ => {}
132        }
133
134        nodeui
135    }
136
137    pub fn to_light(&self, position: Vec2<f32>) -> Option<Light> {
138        match self {
139            RusterixLight(light) => {
140                let mut l = light.clone();
141                l.set_position(Vec3::new(position.x, 0.0, position.y));
142                Some(l)
143            }
144        }
145    }
146}