Unravel Engine C++ Reference
Loading...
Searching...
No Matches
animation_component.cpp
Go to the documentation of this file.
6
7namespace unravel
8{
9
11{
12 entt::meta_factory<animation_retargeting_mode>{}
13 .type("animation_retargeting_mode"_hs)
15 entt::attribute{"name", "animation_retargeting_mode"},
16 entt::attribute{"pretty_name", "Animation Retargeting Mode"},
17 })
18 .data<animation_retargeting_mode::index_based>("index_based"_hs)
20 entt::attribute{"name", "index_based"},
21 entt::attribute{"pretty_name", "Index Based"},
22 })
23 .data<animation_retargeting_mode::name_based>("name_based"_hs)
25 entt::attribute{"name", "name_based"},
26 entt::attribute{"pretty_name", "Name Based"},
27 });
28}
29
31{
32 entt::meta_factory<animation_component::culling_mode>{}
33 .type("culling_mode"_hs)
35 entt::attribute{"name", "culling_mode"},
36 entt::attribute{"pretty_name", "Culling Mode"},
37 })
38 .data<animation_component::culling_mode::always_animate>("always_animate"_hs)
40 entt::attribute{"name", "always_animate"},
41 entt::attribute{"pretty_name", "Always Animate"},
42 })
43 .data<animation_component::culling_mode::renderer_based>("renderer_based"_hs)
45 entt::attribute{"name", "renderer_based"},
46 entt::attribute{"pretty_name", "Renderer Based"},
47 });
48
49 // Register animation_component class with entt
50 entt::meta_factory<animation_component>{}
51 .type("animation_component"_hs)
53 entt::attribute{"name", "animation_component"},
54 entt::attribute{"category", "ANIMATION"},
55 entt::attribute{"pretty_name", "Animation"},
56 })
57 .func<&component_meta<animation_component>::exists>("component_exists"_hs)
58 .func<&component_meta<animation_component>::add>("component_add"_hs)
59 .func<&component_meta<animation_component>::save>("component_save"_hs)
60 .func<&component_meta<animation_component>::load>("component_load"_hs)
61 .func<&component_meta<animation_component>::remove>("component_remove"_hs)
63 .custom<entt::attributes>(entt::attributes{
64 entt::attribute{"name", "animation"},
65 entt::attribute{"pretty_name", "Animation"},
66 })
67 .data<&animation_component::set_autoplay, &animation_component::get_autoplay>("auto_play"_hs)
69 entt::attribute{"name", "auto_play"},
70 entt::attribute{"pretty_name", "Auto Play"},
71 entt::attribute{"tooltip", "Controls whether the animation should auto start."},
72 })
73 .data<&animation_component::set_culling_mode, &animation_component::get_culling_mode>("culling_mode"_hs)
75 entt::attribute{"name", "culling_mode"},
76 entt::attribute{"pretty_name", "Culling Mode"},
77 entt::attribute{"tooltip", "Controls how the animation logic should be culled."},
78 })
79 .data<&animation_component::set_apply_root_motion, &animation_component::get_apply_root_motion>("apply_root_motion"_hs)
81 entt::attribute{"name", "apply_root_motion"},
82 entt::attribute{"pretty_name", "Apply Root Motion"},
83 })
84 .data<&animation_component::set_speed, &animation_component::get_speed>("speed"_hs)
86 entt::attribute{"name", "speed"},
87 entt::attribute{"pretty_name", "Speed"},
88 entt::attribute{"tooltip", "Controls the playback speed of the animation. 1.0 = normal speed, 2.0 = double speed, 0.5 = half speed."},
89 entt::attribute{"min", 0.0f},
90 entt::attribute{"max", 10.0f},
91 })
92 .data<&animation_component::set_retargeting_mode, &animation_component::get_retargeting_mode>("retargeting_mode"_hs)
94 entt::attribute{"name", "retargeting_mode"},
95 entt::attribute{"pretty_name", "Retargeting Mode"},
96 entt::attribute{"tooltip", "Bone matching mode: index-based (fast, requires exact match) or name-based (flexible, works with different skeletons)"},
97 });
98}
99
101{
102 try_save(ar, ser20::make_nvp("animation", obj.get_animation()));
103 try_save(ar, ser20::make_nvp("auto_play", obj.get_autoplay()));
104 try_save(ar, ser20::make_nvp("culling_mode", obj.get_culling_mode()));
105 try_save(ar, ser20::make_nvp("apply_root_motion", obj.get_apply_root_motion()));
106 try_save(ar, ser20::make_nvp("speed", obj.get_speed()));
107 try_save(ar, ser20::make_nvp("retargeting_mode", obj.get_retargeting_mode()));
108}
111
113{
115 if(try_load(ar, ser20::make_nvp("animation", animation)))
116 {
117 obj.set_animation(animation);
118 }
119
120 bool auto_play{};
121 if(try_load(ar, ser20::make_nvp("auto_play", auto_play)))
122 {
123 obj.set_autoplay(auto_play);
124 }
125
127 if(try_load(ar, ser20::make_nvp("culling_mode", culling_mode)))
128 {
129 obj.set_culling_mode(culling_mode);
130 }
131
132 bool apply_root_motion{};
133 if(try_load(ar, ser20::make_nvp("apply_root_motion", apply_root_motion)))
134 {
135 obj.set_apply_root_motion(apply_root_motion);
136 }
137
138 float speed{1.0f};
139 if(try_load(ar, ser20::make_nvp("speed", speed)))
140 {
141 obj.set_speed(speed);
142 }
143
145 if(try_load(ar, ser20::make_nvp("retargeting_mode", retargeting_mode)))
146 {
147 obj.set_retargeting_mode(retargeting_mode);
148 }
149}
152
153} // namespace unravel
auto get_animation() const -> const asset_handle< animation_clip > &
void set_animation(const asset_handle< animation_clip > &animation)
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
animation_retargeting_mode
Animation retargeting mode for bone matching.
@ name_based
Flexible, works with different skeletons (uses cached hash map)
#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
Thread-safe handle to an asset.