Unravel Engine C++ Reference
Loading...
Searching...
No Matches
camera_component.cpp
Go to the documentation of this file.
2
5
8
9namespace unravel
10{
12{
13 auto is_ortho_predicate = entt::property_predicate(
14 [](const entt::meta_any& i)
15 {
16 return i.try_cast<camera_component>()->get_projection_mode() == projection_mode::orthographic;
17 });
18
19 auto is_perspective_predicate = entt::property_predicate(
20 [](const entt::meta_any& i)
21 {
22 return i.try_cast<camera_component>()->get_projection_mode() == projection_mode::perspective;
23 });
24
25 entt::meta_factory<camera_component>{}
26 .type("camera_component"_hs)
28 entt::attribute{"name", "camera_component"},
29 entt::attribute{"category", "RENDERING"},
30 entt::attribute{"pretty_name", "Camera"},
31 })
32 .func<&component_meta<camera_component>::exists>("component_exists"_hs)
33 .func<&component_meta<camera_component>::add>("component_add"_hs)
34 .func<&component_meta<camera_component>::save>("component_save"_hs)
35 .func<&component_meta<camera_component>::load>("component_load"_hs)
36 .func<&component_meta<camera_component>::remove>("component_remove"_hs)
38 .custom<entt::attributes>(entt::attributes{
39 entt::attribute{"name", "projection_mode"},
40 entt::attribute{"pretty_name", "Projection Mode"},
41 })
42 .data<&camera_component::set_fov, &camera_component::get_fov>("field_of_view"_hs)
44 entt::attribute{"name", "field_of_view"},
45 entt::attribute{"pretty_name", "Field Of View"},
46 entt::attribute{"min", 5.0f},
47 entt::attribute{"max", 150.0f},
48 entt::attribute{"predicate", is_perspective_predicate},
49 })
50 .data<&camera_component::set_ortho_size, &camera_component::get_ortho_size>("orthographic_size"_hs)
52 entt::attribute{"name", "orthographic_size"},
53 entt::attribute{"pretty_name", "Orthographic Size"},
54 entt::attribute{"min", 0.1f},
55 entt::attribute{"tooltip", "This is half of the vertical size of the viewing volume.\nHorizontal viewing size varies depending on viewport's aspect ratio.\nOrthographic size is ignored when camera is not orthographic."},
56 entt::attribute{"predicate", is_ortho_predicate},
57 })
58 .data<nullptr, &camera_component::get_ppu>("pixels_per_unit"_hs)
60 entt::attribute{"name", "pixels_per_unit"},
61 entt::attribute{"pretty_name", "Pixels Per Unit"},
62 entt::attribute{"tooltip", "Pixels per unit only usable in orthographic mode."},
63 })
64 .data<nullptr, &camera_component::get_viewport_size>("viewport_size"_hs)
66 entt::attribute{"name", "viewport_size"},
67 entt::attribute{"pretty_name", "Viewport Size"},
68 })
69 .data<&camera_component::set_near_clip, &camera_component::get_near_clip>("near_clip_distance"_hs)
71 entt::attribute{"name", "near_clip_distance"},
72 entt::attribute{"pretty_name", "Near Clip"},
73 entt::attribute{"min", 0.1f},
74 })
75 .data<&camera_component::set_far_clip, &camera_component::get_far_clip>("far_clip_distance"_hs)
77 entt::attribute{"name", "far_clip_distance"},
78 entt::attribute{"pretty_name", "Far Clip"},
79 })
80 .data<&camera_component::set_render_include_mask, &camera_component::get_render_include_mask>("include_layers"_hs)
82 entt::attribute{"name", "include_layers"},
83 entt::attribute{"pretty_name", "Include Layers"},
84 entt::attribute{"tooltip", "Layers to include when rendering."},
85 })
86 .data<&camera_component::set_render_exclude_mask, &camera_component::get_render_exclude_mask>("exclude_layers"_hs)
88 entt::attribute{"name", "exclude_layers"},
89 entt::attribute{"pretty_name", "Exclude Layers"},
90 entt::attribute{"tooltip", "Layers to exclude when rendering."},
91 })
92 .data<nullptr, &camera_component::get_render_mask>("render_layers"_hs)
94 entt::attribute{"name", "render_layers"},
95 entt::attribute{"pretty_name", "Render Layers"},
96 entt::attribute{"tooltip", "Layers (Include - Exclude) used when rendering."},
97 });
98}
99
101{
102 try_save(ar, ser20::make_nvp("camera", obj.get_camera()));
103 try_save(ar, ser20::make_nvp("render_include_layers", obj.get_render_include_mask()));
104 try_save(ar, ser20::make_nvp("render_exclude_layers", obj.get_render_exclude_mask()));
105}
108
110{
111 try_load(ar, ser20::make_nvp("camera", obj.get_camera()));
112
113 layer_mask render_include_layers{layer_reserved::everything_layer};
114 if(try_load(ar, ser20::make_nvp("render_include_layers", render_include_layers)))
115 {
116 obj.set_render_include_mask(render_include_layers);
117 }
118
119 layer_mask render_exclude_layers{layer_reserved::nothing_layer};
120 if(try_load(ar, ser20::make_nvp("render_exclude_layers", render_exclude_layers)))
121 {
122 obj.set_render_exclude_mask(render_exclude_layers);
123 }
124}
127} // namespace unravel
Class that contains core camera data, used for rendering and other purposes.
auto get_projection_mode() const -> projection_mode
Gets the projection mode.
void set_projection_mode(projection_mode mode)
Sets the projection mode.
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
@ everything_layer
Definition layer_mask.h:16
@ nothing_layer
Definition layer_mask.h:13
#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