SleakEngine 1.0.0
C++23 multi-backend game engine
Loading...
Searching...
No Matches
AnimationClip.hpp
Go to the documentation of this file.
1#ifndef _ANIMATIONCLIP_HPP_
2#define _ANIMATIONCLIP_HPP_
3
4#include <Core/OSDef.hpp>
5#include <Math/Vector.hpp>
6#include <Math/Quaternion.hpp>
7#include <string>
8#include <vector>
9#include <unordered_map>
10
11namespace Sleak {
12
13 /// A single timed sample of a value, used as a control point for interpolation.
14 /// @ingroup animation
15 template<typename T>
16 struct Keyframe {
17 float time;
19 };
20
21 /// Position/rotation/scale keyframe tracks for one bone or scene node.
22 /// @ingroup animation
24 std::string boneName;
25 int boneId = -1;
26 std::vector<Keyframe<Math::Vector3D>> positionKeys;
27 std::vector<Keyframe<Math::Quaternion>> rotationKeys;
28 std::vector<Keyframe<Math::Vector3D>> scaleKeys;
29 };
30
31 /// A named set of per-bone keyframe channels sampled by AnimatorComponent.
32 /// @ingroup animation
33 class ENGINE_API AnimationClip {
34 public:
35 std::string name;
36 float duration = 0.0f; // in ticks
37 float ticksPerSecond = 25.0f; // ticks per second
38 std::vector<AnimationChannel> channels;
39
40 float GetDurationInSeconds() const {
41 return (ticksPerSecond > 0.0f) ? duration / ticksPerSecond : 0.0f;
42 }
43
44 /// O(1) channel lookup by bone name; requires BuildLookup() to have run.
45 const AnimationChannel* FindChannel(const std::string& boneName) const {
46 auto it = m_channelLookup.find(boneName);
47 return (it != m_channelLookup.end()) ? &channels[it->second] : nullptr;
48 }
49
50 // Call after all channels have been added
51 void BuildLookup() {
52 m_channelLookup.clear();
53 for (size_t i = 0; i < channels.size(); ++i) {
54 m_channelLookup[channels[i].boneName] = static_cast<int>(i);
55 }
56 }
57
58 private:
59 std::unordered_map<std::string, int> m_channelLookup;
60 };
61
62} // namespace Sleak
63
64#endif // _ANIMATIONCLIP_HPP_
const AnimationChannel * FindChannel(const std::string &boneName) const
O(1) channel lookup by bone name; requires BuildLookup() to have run.
float GetDurationInSeconds() const
std::vector< AnimationChannel > channels
Root namespace for everything the engine exposes.
Definition Camera.hpp:10
std::vector< Keyframe< Math::Quaternion > > rotationKeys
std::vector< Keyframe< Math::Vector3D > > positionKeys
std::vector< Keyframe< Math::Vector3D > > scaleKeys