Unravel Engine C++ Reference
Loading...
Searching...
No Matches
volume_component.cpp
Go to the documentation of this file.
5
6namespace unravel
7{
8
10{
11 entt::meta_factory<volume_mode>{}
12 .type("volume_mode"_hs)
14 entt::attribute{"name", "volume_mode"},
15 entt::attribute{"pretty_name", "Mode"},
16 })
17 .data<volume_mode::local>("local"_hs)
19 entt::attribute{"name", "local"},
20 entt::attribute{"pretty_name", "Local"},
21 entt::attribute{"tooltip", "Volume uses bounds (extents)"},
22 })
23 .data<volume_mode::global>("global"_hs)
25 entt::attribute{"name", "global"},
26 entt::attribute{"pretty_name", "Global"},
27 entt::attribute{"tooltip", "Volume affects camera everywhere (ignores bounds)"},
28 });
29}
30
32{
33 auto local_mode_predicate_entt = entt::property_predicate<bool>([](const entt::meta_any& obj)
34 {
35 auto* data = obj.try_cast<volume_component>();
36 return data && data->mode == volume_mode::local;
37 });
38
39 entt::meta_factory<volume_component>{}
40 .type("volume_component"_hs)
42 entt::attribute{"name", "volume_component"},
43 entt::attribute{"category", "RENDERING"},
44 entt::attribute{"pretty_name", "Volume"},
45 })
46 .func<&component_meta<volume_component>::exists>("component_exists"_hs)
47 .func<&component_meta<volume_component>::add>("component_add"_hs)
48 .func<&component_meta<volume_component>::remove>("component_remove"_hs)
49 .func<&component_meta<volume_component>::save>("component_save"_hs)
50 .func<&component_meta<volume_component>::load>("component_load"_hs)
51 .data<&volume_component::mode>("mode"_hs)
52 .custom<entt::attributes>(entt::attributes{
53 entt::attribute{"name", "mode"},
54 entt::attribute{"pretty_name", "Mode"},
55 entt::attribute{"tooltip", "Local uses bounds, global affects everywhere"},
56 })
57 .data<&volume_component::priority>("priority"_hs)
59 entt::attribute{"name", "priority"},
60 entt::attribute{"pretty_name", "Priority"},
61 entt::attribute{"tooltip", "Higher priority wins when multiple volumes overlap"},
62 })
63 .data<&volume_component::weight>("weight"_hs)
65 entt::attribute{"name", "weight"},
66 entt::attribute{"pretty_name", "Weight"},
67 entt::attribute{"min", 0.0f},
68 entt::attribute{"max", 1.0f},
69 entt::attribute{"step", 0.05f},
70 entt::attribute{"tooltip", "Influence multiplier"},
71 })
72 .data<&volume_component::blend_distance>("blend_distance"_hs)
74 entt::attribute{"name", "blend_distance"},
75 entt::attribute{"pretty_name", "Blend Distance"},
76 entt::attribute{"min", 0.0f},
77 entt::attribute{"tooltip", "Distance outside volume over which contribution ramps from 0 to 1"},
78 entt::attribute{"predicate", local_mode_predicate_entt}
79 })
80 .data<&volume_component::extents>("extents"_hs)
82 entt::attribute{"name", "extents"},
83 entt::attribute{"pretty_name", "Extents"},
84 entt::attribute{"tooltip", "Half-extents for local box bounds"},
85 entt::attribute{"predicate", local_mode_predicate_entt},
86 });
87}
88
90{
91 try_save(ar, ser20::make_nvp("mode", static_cast<std::underlying_type_t<volume_mode>>(obj.mode)));
92 try_save(ar, ser20::make_nvp("priority", obj.priority));
93 try_save(ar, ser20::make_nvp("weight", obj.weight));
94 try_save(ar, ser20::make_nvp("blend_distance", obj.blend_distance));
95 try_save(ar, ser20::make_nvp("extents", obj.extents));
96}
99
101{
102 bool is_global = false;
103 if(try_load(ar, ser20::make_nvp("is_global", is_global)))
104 {
106 }
107 else
108 {
109 std::underlying_type_t<volume_mode> mode_val = 0;
110 try_load(ar, ser20::make_nvp("mode", mode_val));
111 obj.mode = static_cast<volume_mode>(mode_val);
112 }
113 try_load(ar, ser20::make_nvp("priority", obj.priority));
114 try_load(ar, ser20::make_nvp("weight", obj.weight));
115 try_load(ar, ser20::make_nvp("blend_distance", obj.blend_distance));
116 try_load(ar, ser20::make_nvp("extents", obj.extents));
117}
120
121} // namespace unravel
Spatial volume that applies post-processing effects when the camera is inside. Effect settings come f...
volume_mode mode
Volume mode: local uses bounds, global affects camera everywhere.
auto property_predicate(property_predicate_t< T > predicate) -> property_predicate_t< T >
Definition reflection.h:89
attributes::value_type attribute
Definition reflection.h:19
std::map< std::string, meta_any > attributes
Definition reflection.h:18
BinaryInputArchive iarchive_binary_t
simd::JSONOutputArchive oarchive_associative_t
BinaryOutputArchive oarchive_binary_t
simd::JSONInputArchive iarchive_associative_t
#define REFLECT(cls)
Definition reflection.h:149
#define REFLECT_INLINE(cls)
Definition reflection.h:144
#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
bool is_global