98c630e83306e36c72053760629eba52d52970e4
[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
11 class Model {
12
13         struct Mesh {
14                 Mesh(const aiMesh *aiMesh, GLuint progId);
15                 GLuint vao;
16                 GLuint numIndices;
17         };
18         
19         public:
20                 Model(const std::string &path, GLuint progId);
21                 void draw() const;
22
23                 class Node {
24                         public:
25                                 Node(const aiNode &aiNode, GLuint progId);
26                                 void draw(const std::vector<Mesh> &meshes, glm::mat4 parentModel) const;
27                                 const std::vector<Node*> &getChildren() const { return children; }
28                                 Node* findNode(const aiNode &aiNode);
29                                 glm::mat4 model = glm::mat4(1);
30                                 const aiNode &ai;
31                         private:
32                                 const GLuint progId;
33
34                                 std::vector<Node*> children;
35                                 std::vector<unsigned int> meshIndices;
36                 };
37                 
38                 Node* getRoot() { return root; }
39                 Node* find(const std::string &name);
40         
41         private:
42                 const GLuint progId;
43                 
44                 std::vector<Mesh> meshes;
45                 Node *root;
46                 void loadModel(const std::string &path);
47
48                 Assimp::Importer importer;
49 };