Unravel Engine C++ Reference
Loading...
Searching...
No Matches
light_component.cpp
Go to the documentation of this file.
1#include "light_component.hpp"
2
6
9
10namespace unravel
11{
13{
14 entt::meta_factory<light_component>{}
15 .type("light_component"_hs)
17 entt::attribute{"name", "light_component"},
18 entt::attribute{"category", "LIGHTING"},
19 entt::attribute{"pretty_name", "Light"},
20 })
21 .func<&component_meta<light_component>::exists>("component_exists"_hs)
22 .func<&component_meta<light_component>::add>("component_add"_hs)
23 .func<&component_meta<light_component>::save>("component_save"_hs)
24 .func<&component_meta<light_component>::load>("component_load"_hs)
25 .func<&component_meta<light_component>::remove>("component_remove"_hs)
27 .custom<entt::attributes>(entt::attributes{
28 entt::attribute{"name", "light"},
29 entt::attribute{"pretty_name", "Light"},
30 });
31}
32
34{
35 try_save(ar, ser20::make_nvp("light", obj.get_light()));
36}
39
41{
42 light l;
43 try_load(ar, ser20::make_nvp("light", l));
44 obj.set_light(l);
45}
48
50{
51 auto skybox_predicate_entt = entt::property_predicate([](const entt::meta_any& obj)
52 {
53 auto data = obj.try_cast<skylight_component>();
55 });
56
57
58 auto dynamic_sky_predicate_entt = entt::property_predicate([](const entt::meta_any& obj)
59 {
60 auto data = obj.try_cast<skylight_component>();
62 });
63
64 // Register skylight_component::sky_mode enum with entt
65 entt::meta_factory<skylight_component::sky_mode>{}
66 .type("sky_mode"_hs)
68 entt::attribute{"name", "sky_mode"},
69 entt::attribute{"pretty_name", "Sky Mode"},
70 })
71 .data<skylight_component::sky_mode::standard>("standard"_hs)
73 entt::attribute{"name", "standard"},
74 entt::attribute{"pretty_name", "Standard"},
75 })
76 .data<skylight_component::sky_mode::perez>("perez"_hs)
78 entt::attribute{"name", "perez"},
79 entt::attribute{"pretty_name", "Perez"},
80 })
81 .data<skylight_component::sky_mode::skybox>("skybox"_hs)
83 entt::attribute{"name", "skybox"},
84 entt::attribute{"pretty_name", "Skybox"},
85 });
86
87 // Register skylight_component class with entt
88 entt::meta_factory<skylight_component>{}
89 .type("skylight_component"_hs)
91 entt::attribute{"name", "skylight_component"},
92 entt::attribute{"category", "LIGHTING"},
93 entt::attribute{"pretty_name", "Skylight"},
94 })
95 .func<&component_meta<skylight_component>::exists>("component_exists"_hs)
96 .func<&component_meta<skylight_component>::add>("component_add"_hs)
97 .func<&component_meta<skylight_component>::save>("component_save"_hs)
98 .func<&component_meta<skylight_component>::load>("component_load"_hs)
99 .func<&component_meta<skylight_component>::remove>("component_remove"_hs)
101 .custom<entt::attributes>(entt::attributes{
102 entt::attribute{"name", "mode"},
103 entt::attribute{"pretty_name", "Mode"},
104 })
105 .data<&skylight_component::set_turbidity, &skylight_component::get_turbidity>("turbidity"_hs)
107 entt::attribute{"name", "turbidity"},
108 entt::attribute{"pretty_name", "Turbidity"},
109 entt::attribute{"min", 1.9f},
110 entt::attribute{"max", 10.0f},
111 entt::attribute{"tooltip", "Adjusts the clarity of the atmosphere. Lower values (1.9) result in a clear, blue sky, while higher values (up to 10) create a hazy, diffused appearance with more scattering of light.."},
112 entt::attribute{"predicate", dynamic_sky_predicate_entt},
113 })
114 .data<&skylight_component::set_cubemap, &skylight_component::get_cubemap>("cubemap"_hs)
116 entt::attribute{"name", "cubemap"},
117 entt::attribute{"pretty_name", "Cubemap"},
118 entt::attribute{"predicate", skybox_predicate_entt},
119 });
120}
121
123{
124 try_save(ar, ser20::make_nvp("mode", obj.get_mode()));
125 try_save(ar, ser20::make_nvp("turbidity", obj.get_turbidity()));
126 try_save(ar, ser20::make_nvp("cubemap", obj.get_cubemap()));
127}
130
132{
134 if(try_load(ar, ser20::make_nvp("mode", mode)))
135 {
136 obj.set_mode(mode);
137 }
138
139 float turbidity{};
140 if(try_load(ar, ser20::make_nvp("turbidity", turbidity)))
141 {
142 obj.set_turbidity(turbidity);
143 }
144
146 if(try_load(ar, ser20::make_nvp("cubemap", cubemap)))
147 {
148 obj.set_cubemap(cubemap);
149 }
150}
153} // namespace unravel
Class that contains core light data, used for rendering and other purposes.
void set_light(const light &l)
Sets the light object.
auto get_light() const -> const light &
Gets the light object.
Class that contains sky light data.
void set_mode(const sky_mode &mode)
Sets the sky mode.
auto get_mode() const noexcept -> const sky_mode &
Gets the current sky mode.
sky_mode
Enumeration for sky modes.
attributes::value_type attribute
Definition reflection.h:19
std::map< std::string, meta_any > attributes
Definition reflection.h:18
auto property_predicate(property_predicate_t predicate) -> property_predicate_t
BinaryInputArchive iarchive_binary_t
simd::JSONOutputArchive oarchive_associative_t
BinaryOutputArchive oarchive_binary_t
simd::JSONInputArchive iarchive_associative_t
#define REFLECT(cls)
Definition reflection.h:133
#define SAVE_INSTANTIATE(cls, Archive)
#define LOAD(cls)
auto try_save(Archive &ar, ser20::NameValuePair< T > &&t, const hpp::source_location &loc=hpp::source_location::current()) -> bool
#define LOAD_INSTANTIATE(cls, Archive)
#define SAVE(cls)
auto try_load(Archive &ar, ser20::NameValuePair< T > &&t, const hpp::source_location &loc=hpp::source_location::current()) -> bool
Represents a handle to an asset, providing access and management functions.
Struct representing a light.
Definition light.h:87