vkmEngine 1.0.0
A C++ game engine · vkmengine.com
Loading...
Searching...
No Matches
animator.h
1#pragma once
2
3#include <cstdint>
4#include <vector>
5
6#include <glm/glm.hpp>
7#include <glm/gtc/quaternion.hpp>
8
9#include "core/reflect.h"
10
11#include "resource/asset/animation_clip_asset.h"
12#include "resource/asset/skeleton_asset.h"
13
14namespace Vkm::Engine {
15
28struct BoneAdjust {
29 int32_t bone = -1;
30 glm::quat rotation{1.0f, 0.0f, 0.0f, 0.0f};
31 glm::vec3 offset{0.0f};
32 float scale = 1.0f;
33 bool absolute = false;
34};
35
45struct Animator {
46 SkeletonHandle skeleton;
47 AnimationClipHandle clip;
48
54 float time = 0.0f;
55 float speed = 1.0f;
61 bool looping = true;
62
69 bool playOnStart = true;
70
72 bool playing = false;
73
75 bool started = false;
76
77 AnimationClipHandle fadeFrom;
78 float fadeTime = 0.0f;
79 float fadeRemaining = 0.0f;
80 float fadeDuration = 0.0f;
81
85 bool fadeLooping = true;
86
94 std::vector<BoneAdjust> adjust;
95
107 static void crossFadeTo(Animator& animator, AnimationClipHandle clip, float seconds, bool looping);
108};
109
110} // namespace Vkm::Engine
111
112VKM_REFLECT_BEGIN(::Vkm::Engine::Animator)
113 VKM_F(skeleton)
114 VKM_F(clip)
115 VKM_F(speed)
116 VKM_F(playOnStart)
117 VKM_F(looping)
118VKM_REFLECT_END()
What drives a rig: the skeleton, the clip playing on it, and the playback position.
Definition animator.h:45
float fadeRemaining
Simulation seconds of blend left.
Definition animator.h:79
bool started
Whether playOnStart has been honoured this session. Session state.
Definition animator.h:75
std::vector< BoneAdjust > adjust
Per-bone additions on top of the clip; session state.
Definition animator.h:94
float fadeTime
Its own playback head; it keeps playing while it fades.
Definition animator.h:78
float fadeDuration
fadeRemaining's start; the weight divides by it.
Definition animator.h:80
float speed
Multiplies the simulation delta.
Definition animator.h:55
SkeletonHandle skeleton
The rig posed; nothing is posed without it.
Definition animator.h:46
bool fadeLooping
Whether the outgoing clip wraps while it fades out; parked here by crossFadeTo.
Definition animator.h:85
bool playing
Session state.
Definition animator.h:72
bool playOnStart
Start playing on the first frame the simulation runs.
Definition animator.h:69
AnimationClipHandle clip
Clip playing on it; empty holds the bind pose.
Definition animator.h:47
static void crossFadeTo(Animator &animator, AnimationClipHandle clip, float seconds, bool looping)
Start playing clip, blending out of whatever is playing now.
float time
Playback head in seconds; session state, not serialized.
Definition animator.h:54
bool looping
Whether the clip in clip wraps at its end or stops there.
Definition animator.h:61
AnimationClipHandle fadeFrom
Clip being left; empty when nothing is fading.
Definition animator.h:77
What a behavior adds to one bone on top of the clip, this frame.
Definition animator.h:28
int32_t bone
Into the rig's bones; out of range adjusts nothing.
Definition animator.h:29
glm::vec3 offset
Model space, added to the bone's origin.
Definition animator.h:31
glm::quat rotation
Model space, about the bone's origin.
Definition animator.h:30
bool absolute
True: rotation replaces the clip's orientation.
Definition animator.h:33
float scale
Multiplies the bone's scale; children inherit.
Definition animator.h:32