a39c70a0651eb8043cd14bbb9ea4e0567bba85d9
[opengl.git] / model.hpp
1 #include <vector>
2 #ifdef __APPLE__
3 #include <GL/glew.h>
4 #else
5 #include <OpenGL/glew.h>
6 #endif
7 #include <glm/glm.hpp>
8 #include <assimp/scene.h>
9 #include <assimp/Importer.hpp>
10 #include "material.hpp"
11
12 class Model {
13
14         struct Mesh {
15                 Mesh(const aiMesh *aiMesh, GLuint progId);
16                 GLuint progId, vao, numIndices;
17                 unsigned int materialIndex;
18         };
19         
20         public:
21                 Model(const std::string &path, GLuint progId);
22                 void draw() const;
23
24                 class Node {
25                         public:
26                                 Node(const aiNode &aiNode, GLuint progId);
27                                 void draw(const std::vector<Mesh> &meshes, const std::vector<Material> &materials, glm::mat4 parentModel) const;
28                                 const std::vector<Node*> &getChildren() const { return children; }
29                                 Node* findNode(const aiNode &aiNode);
30                                 glm::mat4 model = glm::mat4(1);
31                                 const aiNode &ai;
32                         private:
33                                 const GLuint progId;
34
35                                 std::vector<Node*> children;
36                                 std::vector<unsigned int> meshIndices;
37                 };
38                 
39                 Node* getRoot() { return root; }
40                 Node* find(const std::string &name);
41         
42         private:
43                 const GLuint progId;
44                 
45                 std::vector<Mesh> meshes;
46                 Node *root;
47
48                 std::vector<Material> materials;
49
50                 void loadModel(const std::string &path);
51
52                 Assimp::Importer importer;
53 };