-
Notifications
You must be signed in to change notification settings - Fork 0
/
MFile.h
141 lines (93 loc) · 3.83 KB
/
MFile.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
#ifndef MFILE_H
#define MFILE_H
#include <iostream>
#include <vector>
#include <map>
#include <fstream>
#include <QString>
#include "glm/glm.hpp"
/******************************************************************************
* Declaration for index struct *
******************************************************************************/
struct MIndex {
size_t x = 0, y = 0, z = 0;
};
/******************************************************************************
* Declaration for vertex struct *
******************************************************************************/
struct MVertex {
glm::vec3 position;
glm::vec3 normal;
glm::vec2 tex_coord;
glm::vec3 tangent;
int vertex_index;
// Skinning
glm::vec4 bone_indicies;
glm::vec4 bone_weights;
};
/******************************************************************************
* Declaration for bone struct *
******************************************************************************/
struct MBone {
int parent_index;
glm::mat4 matrix;
glm::mat4 bind_matrix;
std::string name;
};
/******************************************************************************
* Declaration for animation data *
******************************************************************************/
enum MAnimationTweening {
MAnimationTweeningNormal
};
struct MAnimationKeyFrame {
MAnimationTweening tweener;
float time = 0.0;
glm::mat4 matrix;
};
/******************************************************************************
* Declaration for tokens *
******************************************************************************/
#define END_OF_FILE_TOKEN 0x00
#define COLLISION_TOKEN 0x01
#define SKINNED_TOKEN 0x02
#define NEW_MATERIAL_TOKEN 0xFF
/******************************************************************************
* Declaration for material struct *
******************************************************************************/
struct MMaterial {
std::string material_domain_name;
std::string material_path;
};
/******************************************************************************
* Declaration for generic file *
******************************************************************************/
class MFile {
public:
virtual ~MFile() {}
int getMaterialCount();
MMaterial* getMaterial(int material);
MFile* collision_model = nullptr;
virtual void loadFile(const QString& path) = 0;
virtual void saveFile(const QString& path);
virtual void saveAnimation(const QString& path);
const std::vector<std::vector<MAnimationKeyFrame>> getAnimation() { return animation; }
protected:
size_t getVertexIndex(glm::vec3& _position, glm::vec3& _normal, glm::vec2& _tex_coord);
size_t getVertexIndex(glm::vec3& _position, glm::vec3& _normal, glm::vec2& _tex_coord, glm::vec4& _bone_indicies, glm::vec4& _bone_weights);
void calculateTangent(MIndex& index);
void finalizeTangents();
int findBoneNamed(const std::string& name);
std::map<size_t, MVertex> vertices;
unsigned int total_face_count = 0;
std::vector<MMaterial> materials;
glm::vec3 mins, maxes;
std::vector<std::vector<MIndex>> indicies;
// Data for skinning
bool skinned = false;
std::vector<std::string> bone_names;
std::vector<MBone> bones;
glm::mat4 global_bind_pos;
std::vector<std::vector<MAnimationKeyFrame>> animation;
};
#endif // MFILE_H