Unravel Engine C++ Reference
Loading...
Searching...
No Matches
animation.cpp
Go to the documentation of this file.
1#include "animation.hpp"
4
5#include <fstream>
8
9namespace unravel
10{
11
13{
14 entt::meta_factory<root_motion_params>{}
15 .type("root_motion_params"_hs)
17 entt::attribute{"name", "root_motion_params"},
18 entt::attribute{"pretty_name", "Root Motion Params"},
19 })
20 .data<&root_motion_params::keep_position_y>("keep_position_y"_hs)
22 entt::attribute{"name", "keep_position_y"},
23 entt::attribute{"pretty_name", "Keep Position Y"},
24 entt::attribute{"tooltip", "Root position t components are not affected by animation."},
25 })
26 .data<&root_motion_params::keep_position_xz>("keep_position_xz"_hs)
28 entt::attribute{"name", "keep_position_xz"},
29 entt::attribute{"pretty_name", "Keep Position XZ"},
30 entt::attribute{"tooltip", "Root position x,z components are not affected by animation."},
31 })
32 .data<&root_motion_params::keep_rotation>("keep_rotation"_hs)
34 entt::attribute{"name", "keep_rotation"},
35 entt::attribute{"pretty_name", "Keep Rotation"},
36 entt::attribute{"tooltip", "Root rotation is not affected by animaation."},
37 })
38 .data<&root_motion_params::keep_in_place>("keep_in_place"_hs)
40 entt::attribute{"name", "keep_in_place"},
41 entt::attribute{"pretty_name", "Keep In Place"},
42 entt::attribute{"tooltip", "Keep the animation in place even if it has root motion in it."},
43 })
44 .data<nullptr, &root_motion_params::position_node_name>("position_node_name"_hs)
46 entt::attribute{"name", "position_node_name"},
47 entt::attribute{"pretty_name", "Root Motion Position Node"},
48 entt::attribute{"tooltip", "Transform node that will be used for root motion."},
49 })
50 .data<nullptr, &root_motion_params::rotation_node_name>("rotation_node_name"_hs)
52 entt::attribute{"name", "rotation_node_name"},
53 entt::attribute{"pretty_name", "Root Motion Rotation Node"},
54 entt::attribute{"tooltip", "Rotation node that will be used for root motion."},
55 });
56}
57
59{
60 try_serialize(ar, ser20::make_nvp("keep_position_y", obj.keep_position_y));
61 try_serialize(ar, ser20::make_nvp("keep_position_xz", obj.keep_position_xz));
62 try_serialize(ar, ser20::make_nvp("keep_rotation", obj.keep_rotation));
63 try_serialize(ar, ser20::make_nvp("keep_in_place", obj.keep_in_place));
64
65 try_serialize(ar, ser20::make_nvp("position_node_name", obj.position_node_name));
66 try_serialize(ar, ser20::make_nvp("position_node_index", obj.position_node_index));
67 try_serialize(ar, ser20::make_nvp("rotation_node_name", obj.rotation_node_name));
68 try_serialize(ar, ser20::make_nvp("rotation_node_index", obj.rotation_node_index));
69
70}
73
75{
76 // Register animation_channel with entt
77 entt::meta_factory<animation_channel>{}
78 .type("animation_channel"_hs)
80 entt::attribute{"name", "animation_channel"},
81 entt::attribute{"pretty_name", "Animation Channel"},
82 })
83 .data<nullptr, &animation_channel::node_name>("node_name"_hs)
85 entt::attribute{"name", "node_name"},
86 entt::attribute{"pretty_name", "Name"},
87 })
88 .data<nullptr, &animation_channel::get_position_keys_count>("position_keys_count"_hs)
90 entt::attribute{"name", "position_keys_count"},
91 entt::attribute{"pretty_name", "Positions"},
92 })
93 .data<nullptr, &animation_channel::get_rotation_keys_count>("rotation_keys_count"_hs)
95 entt::attribute{"name", "rotation_keys_count"},
96 entt::attribute{"pretty_name", "Rotations"},
97 })
98 .data<nullptr, &animation_channel::get_position_keys_count>("scaling_keys_count"_hs)
100 entt::attribute{"name", "scaling_keys_count"},
101 entt::attribute{"pretty_name", "Scalings"},
102 });
103}
104
106{
107 entt::meta_factory<animation_clip>{}
108 .type("animation"_hs)
110 entt::attribute{"name", "animation"},
111 entt::attribute{"pretty_name", "Animation"},
112 })
113 .data<nullptr, &animation_clip::name>("name"_hs)
115 entt::attribute{"name", "name"},
116 entt::attribute{"pretty_name", "Name"},
117 })
118 .data<nullptr, &animation_clip::duration>("duration"_hs)
120 entt::attribute{"name", "duration"},
121 entt::attribute{"pretty_name", "Duration"},
122 })
123 .data<nullptr, &animation_clip::root_motion>("root_motion"_hs)
125 entt::attribute{"name", "root_motion"},
126 entt::attribute{"pretty_name", "Root Motion"},
127 })
128 .data<nullptr, &animation_clip::channels>("channels"_hs)
130 entt::attribute{"name", "channels"},
131 entt::attribute{"pretty_name", "Channels"},
132 });
133}
134
136{
137 try_save(ar, ser20::make_nvp("node_name", obj.node_name));
138 try_save(ar, ser20::make_nvp("node_index", obj.node_index));
139 try_save(ar, ser20::make_nvp("position_keys", obj.position_keys));
140 try_save(ar, ser20::make_nvp("rotation_keys", obj.rotation_keys));
141 try_save(ar, ser20::make_nvp("scaling_keys", obj.scaling_keys));
142}
145
147{
148 try_load(ar, ser20::make_nvp("node_name", obj.node_name));
149 try_load(ar, ser20::make_nvp("node_index", obj.node_index));
150 try_load(ar, ser20::make_nvp("position_keys", obj.position_keys));
151 try_load(ar, ser20::make_nvp("rotation_keys", obj.rotation_keys));
152 try_load(ar, ser20::make_nvp("scaling_keys", obj.scaling_keys));
153}
156
158{
159 try_save(ar, ser20::make_nvp("name", obj.name));
160 try_save(ar, ser20::make_nvp("duration", obj.duration));
161 try_save(ar, ser20::make_nvp("channels", obj.channels));
162 try_save(ar, ser20::make_nvp("root_motion", obj.root_motion));
163}
166
168{
169 try_load(ar, ser20::make_nvp("name", obj.name));
170 try_load(ar, ser20::make_nvp("duration", obj.duration));
171 try_load(ar, ser20::make_nvp("channels", obj.channels));
172 try_load(ar, ser20::make_nvp("root_motion", obj.root_motion));
173}
176
177void save_to_file(const std::string& absolute_path, const animation_clip& obj)
178{
179 std::ofstream stream(absolute_path);
180 if(stream.good())
181 {
182 auto ar = ser20::create_oarchive_associative(stream);
183 try_save(ar, ser20::make_nvp("animation", obj));
184 }
185}
186
187void save_to_file_bin(const std::string& absolute_path, const animation_clip& obj)
188{
189 std::ofstream stream(absolute_path, std::ios::binary);
190 if(stream.good())
191 {
192 ser20::oarchive_binary_t ar(stream);
193 try_save(ar, ser20::make_nvp("animation", obj));
194 }
195}
196
197void load_from_file(const std::string& absolute_path, animation_clip& obj)
198{
199 std::ifstream stream(absolute_path);
200 if(stream.good())
201 {
202 auto ar = ser20::create_iarchive_associative(stream);
203 try_load(ar, ser20::make_nvp("animation", obj));
204 }
205}
206
207void load_from_file_bin(const std::string& absolute_path, animation_clip& obj)
208{
209 std::ifstream stream(absolute_path, std::ios::binary);
210 if(stream.good())
211 {
212 ser20::iarchive_binary_t ar(stream);
213 try_load(ar, ser20::make_nvp("animation", obj));
214 }
215}
216} // namespace unravel
attributes::value_type attribute
Definition reflection.h:19
std::map< std::string, meta_any > attributes
Definition reflection.h:18
auto create_oarchive_associative(std::ostream &stream)
BinaryInputArchive iarchive_binary_t
auto create_iarchive_associative(std::istream &stream)
simd::JSONOutputArchive oarchive_associative_t
BinaryOutputArchive oarchive_binary_t
simd::JSONInputArchive iarchive_associative_t
void save_to_file_bin(const std::string &absolute_path, const animation_clip &obj)
void load_from_file(const std::string &absolute_path, animation_clip &obj)
void save_to_file(const std::string &absolute_path, const animation_clip &obj)
void load_from_file_bin(const std::string &absolute_path, animation_clip &obj)
#define REFLECT(cls)
Definition reflection.h:133
#define SAVE_INSTANTIATE(cls, Archive)
#define LOAD(cls)
auto try_serialize(Archive &ar, ser20::NameValuePair< T > &&t, const hpp::source_location &loc=hpp::source_location::current()) -> bool
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 SERIALIZE(cls)
#define SAVE(cls)
#define SERIALIZE_INSTANTIATE(cls, Archive)
auto try_load(Archive &ar, ser20::NameValuePair< T > &&t, const hpp::source_location &loc=hpp::source_location::current()) -> bool
Struct representing a node animation.
Definition animation.h:19
Struct representing an animation.
Definition animation.h:99