Add specular component
[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 #include "program.hpp"
12 #include "skybox.hpp"
13
14 class Model {
15
16         struct Mesh {
17                 Mesh(const aiMesh *aiMesh, GLuint progId);
18                 GLuint progId, vao, numIndices;
19                 unsigned int materialIndex;
20         };
21         
22         public:
23                 Model(const std::string &path, Program p, Skybox s);
24                 void draw() const;
25
26                 class Node {
27                         public:
28                                 Node(const aiNode &aiNode, GLuint progId);
29                                 void draw(const std::vector<Mesh> &meshes, const std::vector<Material> &materials, const Skybox s, glm::mat4 parentModel) const;
30                                 const std::vector<Node*> &getChildren() const { return children; }
31                                 Node* findNode(const aiNode &aiNode);
32                                 glm::mat4 model = glm::mat4(1);
33                                 const aiNode &ai;
34                         private:
35                                 const GLuint progId;
36
37                                 std::vector<Node*> children;
38                                 std::vector<unsigned int> meshIndices;
39                 };
40                 
41                 Node* getRoot() { return root; }
42                 Node* find(const std::string &name);
43         
44         private:
45                 const Program program;
46                 const Skybox skybox;
47                 
48                 std::vector<Mesh> meshes;
49                 Node *root;
50
51                 std::vector<Material> materials;
52
53                 void loadModel(const std::string &path);
54
55                 Assimp::Importer importer;
56 };