SleakEngine
0.1.0
C++23 multi-backend game engine
Toggle main menu visibility
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
11
namespace
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
;
18
T
value
;
19
};
20
21
/// Position/rotation/scale keyframe tracks for one bone or scene node.
22
/// @ingroup animation
23
struct
AnimationChannel
{
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_
OSDef.hpp
Quaternion.hpp
Vector.hpp
Sleak::AnimationClip
Definition
AnimationClip.hpp:33
Sleak::AnimationClip::FindChannel
const AnimationChannel * FindChannel(const std::string &boneName) const
O(1) channel lookup by bone name; requires BuildLookup() to have run.
Definition
AnimationClip.hpp:45
Sleak::AnimationClip::ticksPerSecond
float ticksPerSecond
Definition
AnimationClip.hpp:37
Sleak::AnimationClip::GetDurationInSeconds
float GetDurationInSeconds() const
Definition
AnimationClip.hpp:40
Sleak::AnimationClip::duration
float duration
Definition
AnimationClip.hpp:36
Sleak::AnimationClip::name
std::string name
Definition
AnimationClip.hpp:35
Sleak::AnimationClip::BuildLookup
void BuildLookup()
Definition
AnimationClip.hpp:51
Sleak::AnimationClip::channels
std::vector< AnimationChannel > channels
Definition
AnimationClip.hpp:38
Sleak
Root namespace for everything the engine exposes.
Definition
Camera.hpp:10
Sleak::AnimationChannel
Definition
AnimationClip.hpp:23
Sleak::AnimationChannel::boneId
int boneId
Definition
AnimationClip.hpp:25
Sleak::AnimationChannel::boneName
std::string boneName
Definition
AnimationClip.hpp:24
Sleak::AnimationChannel::rotationKeys
std::vector< Keyframe< Math::Quaternion > > rotationKeys
Definition
AnimationClip.hpp:27
Sleak::AnimationChannel::positionKeys
std::vector< Keyframe< Math::Vector3D > > positionKeys
Definition
AnimationClip.hpp:26
Sleak::AnimationChannel::scaleKeys
std::vector< Keyframe< Math::Vector3D > > scaleKeys
Definition
AnimationClip.hpp:28
Sleak::Keyframe
Definition
AnimationClip.hpp:16
Sleak::Keyframe::value
T value
Definition
AnimationClip.hpp:18
Sleak::Keyframe::time
float time
Definition
AnimationClip.hpp:17
include
public
Runtime
AnimationClip.hpp
Generated on
for SleakEngine by
1.18.0