-
Notifications
You must be signed in to change notification settings - Fork 0
/
MD5Model.h
109 lines (93 loc) · 3.13 KB
/
MD5Model.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
#ifndef MD5MODEL_H_INCLUDED
#define MD5MODEL_H_INCLUDED
#include "OpenGL.h"
#include "Shader.h"
#include "math/Matrix4D.h"
#include "math/Vector2D.h"
#include "math/Vector3D.h"
#include "math/Quaternion.h"
#include "MD5Animation.h"
namespace ST
{
class MD5Model
{
public:
struct Joint
{
std::string name;
int parentID;
Math::Vector3D pos;
Math::Quaternion orient;
};
typedef std::vector<Joint> JointList;
MD5Model();
virtual ~MD5Model();
void Load(const std::string& fileName, const Shader& shader);
void LoadAnim(const std::string& fileName);
void Draw( bool draw_skeleton );
void Update(float deltaTimeSec);
void AffectJoint();
Joint& GetJoint(size_t i);
JointList& GetSkeleton();
const Math::Matrix4D& GetModelTrans() const;
protected:
typedef std::vector<Math::Vector3D> PositionBuffer;
typedef std::vector<Math::Vector3D> NormalBuffer;
typedef std::vector<Math::Vector2D> Tex2DBuffer;
typedef std::vector<GLuint> IndexBuffer;
struct Vertex
{
Math::Vector3D pos;
Math::Vector3D normal;
Math::Vector2D tex;
int startWeight;
int weightCount;
};
typedef std::vector<Vertex> VertexList;
struct Weight
{
int jointID;
float bias;
Math::Vector3D pos;
};
typedef std::vector<Weight> WeightList;
struct Mesh
{
// Name of the TGA file that is in the same
// folder as the mesh being loaded.
std::string shader;
// Vertices in bind-pose.
VertexList verts;
WeightList weights;
// TexID for material.
GLuint texID;
GLuint vbo[3]; // Buffer for vertex attributes and indices.
GLuint vao; // Vertex Array Object.
// Buffers used for rendering.
PositionBuffer positionBuffer;
NormalBuffer normalBuffer;
Tex2DBuffer tex2DBuffer;
IndexBuffer indexBuffer;
};
typedef std::vector<Mesh> MeshList;
private:
void removeQuotes(std::string& str);
void prepareMesh(Mesh& mesh);
void prepareMesh(Mesh& mesh, const MD5Animation::Skeleton& skeleton);
void prepareNormals(Mesh& mesh);
void loadModelInVideomemory();
void reloadModel();
bool checkAnimation(const MD5Animation& anim) const;
void printJoints();
private:
const Shader* shader;
MeshList meshes; // Meshes that make up the whole.
JointList joints; // Joints are the same for all meshes.
Math::Matrix4D model; // Model transformation.
MD5Animation animation; // Single animation for the model.
bool hasAnimation;
GLint posLocation; // Position location in shader.
GLint normLocation; // Position location in shader.
};
}
#endif // MD5MODEL_H_INCLUDED