-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSkeleton.h
162 lines (122 loc) · 2.91 KB
/
Skeleton.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
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#ifndef __SKELETON__
#define __SKELETON__
#include "PreHeader.h"
#include "RenderableThing.h"
#include "Vertice.h"
#include "Utility.h"
using VERTICE::PosNormalTexTan;
struct VertexInfo
{
int StartWeight;
int WeightCount;
};
struct Joint
{
string name;
int parentID;
XMFLOAT3 pos;
XMFLOAT4 orientation;
};
struct Weight
{
int jointID;
float bias;
XMFLOAT3 pos;
XMFLOAT3 normal;
};
struct BoundingBox
{
XMFLOAT3 min;
XMFLOAT3 max;
};
struct FrameData
{
int frameID;
vector<float> frameData;
};
struct AnimJointInfo
{
string name;
int parentID;
int flags;
int startIndex;
};
struct ModelAnimation
{
int numFrames;
int numJoints;
int frameRate;
int numAnimatedComponents;
float frameTime;
float totalAnimTime;
float currAnimTime;
vector<AnimJointInfo> jointInfo;
vector<BoundingBox> frameBounds;
vector<Joint> baseFrameJoints;
vector<FrameData> frameData;
vector<vector<Joint>> frameSkeleton;
};
class Skeleton : public RenderableThing
{
public:
struct SubMesh
{
vector<PosNormalTexTan> vertices;
vector<VertexInfo> vertInfos;
vector<DWORD> indices;
vector<Weight> weights;
vector<XMFLOAT3> positions;
ID3D11ShaderResourceView *texture;
ID3D11Buffer *verticesBuffer; //顶点缓冲
ID3D11Buffer *indicesBuffer; //索引缓冲
ID3D11Buffer *shadowMapVerticesBuffer; //阴影贴图顶点缓冲
SubMesh()
{
texture = NULL;
verticesBuffer = NULL;
indicesBuffer = NULL;
shadowMapVerticesBuffer = NULL;
}
~SubMesh()
{
texture = NULL;
verticesBuffer = NULL;
indicesBuffer = NULL;
shadowMapVerticesBuffer = NULL;
}
};
private:
vector<Joint> joints; //关节数组
vector<SubMesh> meshs; //网格信息
vector<ModelAnimation> animations; //动画数组
public:
Skeleton()
{
type = SKELETON;
};
virtual ~Skeleton();
//载入模型文件
BOOL LoadSkeleton(const string &path, const string &fileName);
//载入动画文件
BOOL LoadAnimation(const string &path, const string &fileName);
//释放资源
void Release();
//获取网格信息
const vector<SubMesh>& GetMeshes() const;
void PlayAnimation(float time, int animation);
virtual void Update(float time);
private:
void InQuots(ifstream& , string& );
void ParserJoints(ifstream&, int);
void ParserMesh(ifstream& , const string & );
void BuildPosition(SubMesh & );
void BuildNormal(SubMesh & , int );
BOOL ParserHierarchy(ifstream& , ModelAnimation& );
void ParserBoundingBox(ifstream& , ModelAnimation& );
void ParserBaseFrame(ifstream& , ModelAnimation& );
void LoadAndBuildFrames(ifstream& , ModelAnimation& );
//初始化缓冲区
BOOL InitBuffers();
void AssembleShadowMapVertices();
};
#endif