-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathComponentAnimation.h
More file actions
113 lines (83 loc) · 2.77 KB
/
ComponentAnimation.h
File metadata and controls
113 lines (83 loc) · 2.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#ifndef __COMPONENT_ANIMATION_H__
#define __COMPONENT_ANIMATION_H__
#include "Component.h"
#include <string>
#include "Globals.h"
#include "MathGeoLib\include\MathGeoLib.h"
#include <map>
class GameObject;
struct Channel;
class ComponentMesh;
class ComponentBone;
class ResourceFileAnimation;
struct Animation
{
std::string name;
uint start_frame;
uint end_frame;
float ticks_per_second;
bool loopable = false;
float time = 0.0f;
uint index;
bool Advance(float dt);
void SetFrameRatio(float ratio);
float GetDuration();
};
class ComponentAnimation : public Component
{
//Careful, this could be dangerous, duplicating pointers
//TODO: try some other way
struct Link
{
Link(GameObject* gameObject, Channel* channel) : gameObject(gameObject), channel(channel) {};
GameObject* gameObject;
Channel* channel;
};
public:
ComponentAnimation(GameObject* game_object);
~ComponentAnimation();
//Base component behaviour ------------------
void OnInspector(bool debug);
void Save(Data& file)const;
void Load(Data& conf);
//-------------------------------------------
//Single animation management----------------
void AddAnimation();
void AddAnimation(const char* name, uint init, uint end, float ticksPerSec);
void RemoveAnimation(uint index);
void PlayAnimation(uint index, float blendTime = 0.0f, bool keepBlend = false);
void PlayAnimation(const char* name, float blendTime = 0.0f, bool keepBlend = false);
void LockAnimationRatio(float ratio);
//-------------------------------------------
void LinkAnimation();
const char* GetResourcePath();
void SetResource(ResourceFileAnimation* resource);
bool StartAnimation();
void Update();
private:
void UpdateBonesTransform(const Animation* settings, const Animation* blend, float blendRatio);
float3 GetChannelPosition(Link& link, float currentKey, float3 default, const Animation& settings);
Quat GetChannelRotation(Link& link, float currentKey, Quat default, const Animation& settings);
float3 GetChannelScale(Link& link, float currentKey, float3 default, const Animation& settings);
void ComponentAnimation::CollectMeshesBones(GameObject* gameObject, std::map<std::string, ComponentMesh*>& meshes, std::vector<ComponentBone*>& bones);
void ComponentAnimation::UpdateMeshAnimation(GameObject* gameObject);
void LinkChannels();
void LinkBones();
public:
std::vector<Animation> animations;
Animation* current_animation = nullptr;
//Animation out of blend
Animation* blend_animation = nullptr;
bool playing = false;
bool linked = false;
bool game_started = false;
private:
ResourceFileAnimation* rAnimation;
bool started = false;
float blend_time = 0.0f;
float blend_time_duration = 0.0f;
std::vector<Link> links;
int renaming_animation = -1;
int popup_animation = -1;
};
#endif // !__COMPONENT_LIGHT_H__