NSUNI/NSLAR Library a250670
Loading...
Searching...
No Matches
animation.hpp
Go to the documentation of this file.
1
13#pragma once
14
16#include "NNL/common/io.hpp"
18
19namespace nnl {
30namespace animation {
36
43struct KeyFrame {
47 glm::vec3 value{0.0f};
50};
51
61 std::vector<KeyFrame> scale_keys;
62 std::vector<KeyFrame> rotation_keys;
63 std::vector<KeyFrame> translation_keys;
64};
65
70struct Animation {
73 std::vector<BoneAnimation> animation_channels;
77};
78
93 bool move_with_root = false;
95 std::vector<Animation> animations;
96};
97
112std::vector<SAnimation> Convert(const AnimationContainer& animations);
121 bool unbake = true;
122};
123
137AnimationContainer Convert(std::vector<SAnimation>&& sanimations, const ConvertParam& anim_params = {},
138 bool move_with_root = false);
139
140AnimationContainer Convert(std::vector<SAnimation>&& sanimations, const std::vector<ConvertParam>& anim_params,
141 bool move_with_root = false);
142
154bool IsOfType(BufferView buffer);
155
156bool IsOfType(const std::filesystem::path& path);
157
158bool IsOfType(Reader& f);
159
173
174AnimationContainer Import(const std::filesystem::path& path);
175
185[[nodiscard]] Buffer Export(const AnimationContainer& animation_container);
186
187void Export(const AnimationContainer& animation_container, const std::filesystem::path& path);
188
189void Export(const AnimationContainer& animation_container, Writer& f); // Main
191
197
208
221Animation Convert(SAnimation&& sanimation, const ConvertParam& anim_param = {}); // Auxiliary
223
224namespace raw {
238
244constexpr u32 kMagicBytes = 0x86'00'00'01;
245
246NNL_PACK(struct RHeader {
247 u32 magic_bytes = kMagicBytes; // 0x0
248 u16 num_animations = 0; // 0x4
249 u16 num_bones_per_animation = 0; // 0x6
250 u16 move_with_root = 0; // 0x8
251 u16 padding = 0; // 0xA
252 u32 offset_duration_table = 0; // 0xC
253 u32 offset_keyframe_table = 0; // 0x10
254 u32 offset_rotation_table = 0; // 0x14
255 u32 offset_scale_traslation_table = 0; // 0x18
256});
257
258static_assert(sizeof(RHeader) == 0x1C);
259
260NNL_PACK(struct RBoneAnimation {
261 u32 index_keyframe_scale = 0; // 0x0 index to keyframe table
262 u32 index_keyframe_translation = 0; // 0x8
263 u32 index_keyframe_rotation = 0; // 0x4
264 u32 index_scale_table = 0; // 0xC
265 u32 index_rotation_table = 0; // 0x10
266 u32 index_translation_table = 0; // 0x14 uses the same table as scale values
267 u16 num_scale_transforms = 0; // 0x18 how many subsequent keys to play
268 u16 num_rotation_transforms = 0; // 0x1A even if 0, the value at the index is still used
269 u16 num_translation_transforms = 0; // 0x1C
270 u16 padding = 0; // padding
271});
272
273static_assert(sizeof(RBoneAnimation) == 0x20);
274
275struct RAnimationContainer {
276 RHeader header;
277 std::vector<RBoneAnimation> bone_animations;
278 std::vector<Vec3<f32>> scale_translation_table;
279 std::vector<Vec3<i16>> rotation_table; // normalized ints
280 std::vector<u16> keyframe_table;
281 std::vector<u16> duration_table;
282};
283
284AnimationContainer Convert(const RAnimationContainer& ranimation_container);
285
286RAnimationContainer Parse(Reader& f);
288} // namespace raw
289} // namespace animation
290
291} // namespace nnl
Contains macros and definitions for fixed-width types.
std::vector< KeyFrame > rotation_keys
Rotation keys.
Definition animation.hpp:62
std::vector< Animation > animations
Collection of animations.
Definition animation.hpp:95
bool move_with_root
Definition animation.hpp:93
std::vector< KeyFrame > scale_keys
Scale keys.
Definition animation.hpp:61
bool unbake
Remove keyframes that are duplicate or can be derived via interpolation.
Definition animation.hpp:121
std::vector< BoneAnimation > animation_channels
Definition animation.hpp:73
std::vector< KeyFrame > translation_keys
Translation keys.
Definition animation.hpp:63
u16 time_tick
Definition animation.hpp:44
glm::vec3 value
Definition animation.hpp:47
u16 duration_ticks
Definition animation.hpp:71
Holds a collection of skeletal animations.
Definition animation.hpp:92
Represents a keyframe in an animation.
Definition animation.hpp:43
Parameters for converting animations to the in-game format.
Definition animation.hpp:120
Represents the transformations of a bone during an animation.
Definition animation.hpp:60
Represents a single skeletal animation.
Definition animation.hpp:70
std::vector< SAnimation > Convert(const AnimationContainer &animations)
Converts multiple in-game animations to a simpler format.
bool IsOfType(BufferView buffer)
Tests if the provided file is an animation container.
Buffer Export(const AnimationContainer &animation_container)
Exports animations to a binary file format.
AnimationContainer Import(BufferView buffer)
Imports animations from a binary file.
constexpr u32 kMagicBytes
Magic bytes used to identify the animation format.
Definition animation.hpp:244
std::uint16_t u16
16-bit unsigned integer
Definition fixed_type.hpp:62
std::uint32_t u32
32-bit unsigned integer
Definition fixed_type.hpp:60
#define NNL_PACK(...)
A structure packing directive.
Definition fixed_type.hpp:41
Reader implementation for read-only memory buffers.
Definition io.hpp:598
Abstract class for writing data.
Definition io.hpp:136
Abstract class for reading data.
Definition io.hpp:78
std::vector< u8 > Buffer
A type alias for std::vector<u8> that denotes a raw, contiguous memory region that may be interpreted...
Definition io.hpp:40
Represents a skeletal animation.
Definition sanimation.hpp:97
Provides classes for reading and writing binary data to and from various sources.
Contains functions and structures for working with in-game skeletal animations.
Definition animation.hpp:30
Definition exception.hpp:56
Provides data structures for representing various animation types and their essential components.