vkmEngine 1.0.0
A C++ game engine · vkmengine.com
Loading...
Searching...
No Matches
skeletal_animation_system.h
1#pragma once
2
3#include <cstdint>
4#include <vector>
5
6#include "core/system.h"
7#include "debug/fault_latch.h"
8#include "ecs/component/animation/animator.h"
9#include "ecs/entity.h"
10#include "system/animation/pose_buffer.h"
11#include "system/animation/ragdoll_pose.h"
12#include "system/animation/pose_evaluator.h"
13
14namespace Vkm::Engine {
15
16struct Ragdoll;
17
18class ResourceManager;
19class Scene;
21struct SkeletonAsset;
22
34class SkeletalAnimationSystem : public System {
35 public:
36 SkeletalAnimationSystem() = default;
37 ~SkeletalAnimationSystem() override = default;
38
39 SkeletalAnimationSystem(const SkeletalAnimationSystem& other) = delete;
40 SkeletalAnimationSystem& operator=(const SkeletalAnimationSystem& other) = delete;
41
42 SkeletalAnimationSystem(SkeletalAnimationSystem && other) = delete;
43 SkeletalAnimationSystem& operator=(SkeletalAnimationSystem && other) = delete;
44
45 public:
46 void update(FrameContext& ctx) override;
47 void fixedUpdate(FrameContext& ctx) override;
48
49 private:
56 struct RigWork {
57 uint32_t animatorIndex = 0;
58 uint32_t entityIndex = 0;
59 uint32_t slice = 0;
60
61 const SkeletonAsset* skeleton = nullptr;
62
66 const Ragdoll* ragdoll = nullptr;
67 uint32_t firstBody = 0;
68 glm::mat4 rigWorld = glm::mat4(1.0f);
69
70 const AnimationClipAsset* clip = nullptr;
71 const AnimationClipAsset* fadeClip = nullptr;
72
76 PlaybackStep step;
77 };
78
88 void run(FrameContext& ctx, float step, bool announceMarkers);
89
96 void poseRigs(FrameContext& ctx, float step);
97
106 bool isPoseable(const SkeletonAsset& skeleton);
107
119 const AnimationClipAsset* resolveClip(
120 const ResourceManager& resources,
121 const AnimationClipHandle& handle,
122 const SkeletonAsset& skeleton
123 );
124
137 void stampDescendants(
138 Scene& scene,
139 const ResourceManager& resources,
140 EntityId entity,
141 const RigWork& work,
142 uint32_t depth
143 );
144
150 void publishMarkers(FrameContext& ctx);
151
165 void checkSkinnedMesh(
166 const Scene& scene,
167 const ResourceManager& resources,
168 EntityId entity,
169 const SkeletonAsset& skeleton,
170 bool onRig
171 );
172
173 private:
174 PoseBuffer m_poses;
175 std::vector<RigWork> m_work;
176
178 std::vector<RagdollBodyPose> m_ragdollBodies;
179
180 uint64_t m_epoch = 0;
181
182 FaultLatch m_badSkeleton;
183 FaultLatch m_badClip;
184 FaultLatch m_clipMismatch;
185 FaultLatch m_rigMismatch;
186 FaultLatch m_meshOffset;
187};
188
189} // namespace Vkm::Engine
Names a recurring fault once per gap rather than once a frame.
Definition fault_latch.h:11
Every rig's pose for one frame, published on FrameContext::poses.
Definition pose_buffer.h:47
Open type-erased resource registry with typed handles and generational lifetimes.
Definition resource_manager.h:46
Central registry managing entities and an open set of component types.
Definition scene.h:29
void fixedUpdate(FrameContext &ctx) override
Execute this system at the fixed simulation rate.
void update(FrameContext &ctx) override
Execute this system for the current frame.
A baked animation: every bone's keys, in six flat arrays.
Definition animation_clip_asset.h:50
Names one entity of one Scene, for as long as that slot holds it.
Definition entity.h:23
Per-frame state bundle passed to every system.
Definition system.h:55
The sweep a playback head made this frame.
Definition pose_evaluator.h:43
Turns a rig over to physics, and back.
Definition ragdoll.h:49
A rig: a flat, parent-before-child bone array plus its bind pose.
Definition skeleton_asset.h:33