-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathMeshController.h
82 lines (62 loc) · 1.77 KB
/
MeshController.h
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
#pragma once
#include <chrono>
#include <vector>
#include "RenderSkin.h"
#include "Animation.h"
using std::string;
using std::vector;
using std::chrono::system_clock;
namespace happy
{
using StencilMask = uint8_t;
class RenderQueue_Root;
struct SkinRenderItem
{
RenderSkin m_Skin;
bb::vec4 m_Color;
StencilMask m_Groups;
unsigned m_AnimationCount;
bb::vec2 m_PreviousBlendFrame;
bb::vec2 m_PreviousBlendAnimation;
ID3D11Buffer* m_PreviousFrames[4];
bb::mat4 m_PreviousWorld;
bb::vec2 m_CurrentBlendFrame;
bb::vec2 m_CurrentBlendAnimation;
ID3D11Buffer* m_CurrentFrames[4];
bb::mat4 m_CurrentWorld;
};
class MeshController
{
public:
void setMesh(shared_ptr<RenderMesh> mesh);
void setRenderGroups(StencilMask &groups);
void setAlpha(float alpha);
void setColor(bb::vec4 color);
int addAnimation(string name, Animation animation, system_clock::time_point start);
int getAnimationIndex(string name);
void setAnimationTimer(int id, system_clock::time_point start, system_clock::duration offset);
void setAnimationBlend(int id, float blend, system_clock::time_point start, float duration = 0);
void setAnimationSpeed(int id, float multiplier);
void resetAllAnimationBlends(system_clock::time_point start, float duration = 0);
bb::mat4 &worldMatrix();
void update(system_clock::time_point time);
void render(RenderQueue_Root &queue) const;
private:
struct anim_state
{
Animation m_Anim;
string m_Name;
system_clock::time_point m_Timer;
system_clock::time_point m_Blender;
float m_SpeedMultiplier;
float m_BlendSource;
float m_BlendTarget;
float m_BlendDuration;
bool m_Looped;
};
shared_ptr<RenderMesh> m_Mesh;
bool m_Static = false;
SkinRenderItem m_RenderItem;
vector<anim_state> m_States;
};
}