Cogs.Core
AnimationSystem.h
1#pragma once
2
3#include "Components/Core/AnimationComponent.h"
4
5#include "Systems/ComponentSystem.h"
6
7#include "Resources/Animation.h"
8#include "Resources/Skeleton.h"
9
10namespace Cogs
11{
12 namespace Core
13 {
14 // Misc notes:
15 // - If a mesh has the MeshFlags::Skinned set, the AnimationData::pose is pulled from
16 // the animation component of the entity that is drawing the mesh, and uploaded to
17 // the "AnimationBuffer" . This is an array of kMaxBones (=256).
18 // - AnimationData::pose is updated in the end of AnimationSystem::update, and the mesh's
19 // poseIndexes are used to pull particular absolute bone matrices from the skeleton
20 // on AnimationData::skeleton. If the animation component has a master animation component,
21 // the skeleton of the master is used instead.
22 // - AnimationComponent::clipIndex specifices which of the clips in AnimationComponent::animation
23 // that is used.
24 // - Each clip has a set of track, where AnimationTrack::boneIndex specifies which bone in
25 // AnimationData::skeleton that the clip should animate. This is a copy of the skeleton
26 // - Position/scale/rotation of each track is animated, and the corresponding bone's relative
27 // matrix gets updated.
28 // - Bone::pos, Bone::scale, and Bone::rot is only used as default value for track evaluations,
29 // which is only used when track has no keyframes. They are not updated when animating.
30 // Bone::relative is usually used as authority.
31
32
34 {
35 std::unique_ptr<Skeleton> skeleton;
36 std::unique_ptr<PoseData> pose;
37
38 Entity * root = nullptr;
39 std::vector<ComponentModel::ComponentHandle> transformCache;
40
41 AnimationCache cache;
42 };
43
44 class AnimationSystem : public ComponentSystemWithDataPool<AnimationComponent, AnimationData>
45 {
46 public:
47 AnimationSystem(Memory::Allocator * allocator, SizeType capacity) : ComponentSystemWithDataPool(allocator, capacity) {}
48
49 void update(AnimationComponent & animationComponent, float globalTime);
50 void update(Context * context);
51 };
52 }
53}
Container for components, providing composition of dynamic entities.
Definition: Entity.h:18
Context * context
Pointer to the Context instance the system lives in.
void update()
Updates the system state to that of the current frame.
Component system with parallel data per component stored in a pool similar to how the components them...
A Context instance contains all the services, systems and runtime components needed to use Cogs.
Definition: Context.h:83
Base allocator implementation.
Definition: Allocator.h:30
Contains all Cogs related functionality.
Definition: FieldSetter.h:23
ComponentIndex SizeType
Type used to track the size of pools.
Definition: Component.h:19
Component handling animation of multiple Poses of an Animation Resource.