-
Notifications
You must be signed in to change notification settings - Fork 0
/
Model.h
61 lines (48 loc) · 1.7 KB
/
Model.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
#ifndef MODEL_CLASS_H
#define MODEL_CLASS_H
#include<json/json.h>
#include"Mesh.h"
using json = nlohmann::json;
class Model
{
public:
// Loads in a model from a file and stores tha information in 'data', 'JSON', and 'file'
Model(const char* file);
void Draw(Shader& shader, Camera& camera);
private:
// Variables for easy access
const char* file;
std::vector<unsigned char> data;
json JSON;
// All the meshes and transformations
std::vector<Mesh> meshes;
std::vector<glm::vec3> translationsMeshes;
std::vector<glm::quat> rotationsMeshes;
std::vector<glm::vec3> scalesMeshes;
std::vector<glm::mat4> matricesMeshes;
// Prevents textures from being loaded twice
std::vector<std::string> loadedTexName;
std::vector<Texture> loadedTex;
// Loads a single mesh by its index
void loadMesh(unsigned int indMesh);
// Traverses a node recursively, so it essentially traverses all connected nodes
void traverseNode(unsigned int nextNode, glm::mat4 matrix = glm::mat4(1.0f));
// Gets the binary data from a file
std::vector<unsigned char> getData();
// Interprets the binary data into floats, indices, and textures
std::vector<float> getFloats(json accessor);
std::vector<GLuint> getIndices(json accessor);
std::vector<Texture> getTextures();
// Assembles all the floats into vertices
std::vector<Vertex> assembleVertices
(
std::vector<glm::vec3> positions,
std::vector<glm::vec3> normals,
std::vector<glm::vec2> texUVs
);
// Helps with the assembly from above by grouping floats
std::vector<glm::vec2> groupFloatsVec2(std::vector<float> floatVec);
std::vector<glm::vec3> groupFloatsVec3(std::vector<float> floatVec);
std::vector<glm::vec4> groupFloatsVec4(std::vector<float> floatVec);
};
#endif