sgltk 0.6
Simple OpenGL Tool Kit
Loading...
Searching...
No Matches
model.h
1#ifndef __MODEL_H__
2#define __MODEL_H__
3
4#include "app.h"
5#include "mesh.h"
6#include "camera.h"
7#include "shader.h"
8#include "image.h"
9#include "texture.h"
10
11namespace sgltk {
12
13#ifdef HAVE_ASSIMP_H
14
15#ifndef BONES_PER_VERTEX
16 #define BONES_PER_VERTEX 4
17#endif
18
19
24class Model {
25 static std::vector<std::string> paths;
26 Assimp::Importer importer;
27 const aiScene *scene;
28 Shader *shader;
29
30 int model_matrix_buf;
31 int normal_matrix_buf;
32
33 glm::mat4 *view_matrix;
34 glm::mat4 *projection_matrix;
35
36 std::string position_name;
37 std::string normal_name;
38 std::string tangent_name;
39 std::string color_name;
40 std::string texture_coordinates_name;
41 std::string bone_ids_name;
42 std::string bone_weights_name;
43 std::string bone_array_name;
44
45 std::vector<glm::mat4> bone_offsets;
46
47 double ticks_per_second;
48 glm::mat4 glob_inv_transf;
49
50 void set_vertex_attribute(std::unique_ptr<Mesh>& mesh);
51 void traverse_scene_nodes(aiNode *start_node, aiMatrix4x4 *parent_trafo);
52 void traverse_animation_nodes(float time, aiNode *node, glm::mat4 parent_transformation);
53
54 std::unique_ptr<Mesh> create_mesh(unsigned int index);
55 void compute_bounding_box();
56
57 static aiVector3D interpolate_scaling(float time, aiNodeAnim *node);
58 static aiVector3D interpolate_translation(float time, aiNodeAnim *node);
59 static aiQuaternion interpolate_rotation(float time, aiNodeAnim *node);
60 static glm::mat4 ai_to_glm_mat4(const aiMatrix4x4& in);
61
62 public:
66 glm::mat4 model_matrix;
70 std::vector<glm::vec3> bounding_box;
74 std::vector<std::unique_ptr<Mesh> > meshes;
78 std::vector<glm::mat4> bones;
85 std::map<std::string, unsigned int> bone_map;
92 std::map<std::string, unsigned int> mesh_map;
93
94 EXPORT Model();
95 EXPORT ~Model();
96
103 EXPORT static void add_path(std::string path);
104
114 EXPORT bool load(const std::string& filename);
119 EXPORT void setup_shader(Shader *shader);
127 EXPORT bool setup_camera(glm::mat4 *view_matrix,
128 glm::mat4 *projection_matrix);
135 EXPORT bool setup_camera(Camera *camera);
141 EXPORT void set_position_name(const std::string& name);
147 EXPORT void set_normal_name(const std::string& name);
153 EXPORT void set_tangent_name(const std::string& name);
159 EXPORT void set_color_name(const std::string& name);
165 EXPORT void set_texture_coordinates_name(const std::string& name);
171 EXPORT void set_bone_ids_name(const std::string& name);
177 EXPORT void set_bone_weights_name(const std::string& name);
183 EXPORT void set_bone_array_name(const std::string& name);
188 EXPORT void set_animation_speed(double speed);
195 EXPORT void attach_texture(const std::string& name,
196 const Texture& texture,
197 unsigned int index = 0);
204 EXPORT void set_texture_parameter(GLenum name, int parameter);
211 EXPORT void set_texture_parameter(GLenum name, float parameter);
218 EXPORT bool animate(float time);
227 EXPORT void setup_instanced_matrix(const std::vector<glm::mat4>& model_matrix,
228 GLenum usage = GL_STATIC_DRAW);
234 EXPORT void set_instanced_matrix_attributes(void);
240 EXPORT void draw(const glm::mat4 *model_matrix = nullptr);
245 EXPORT void draw_instanced(unsigned int num_instances);
246 };
247
248#endif //HAVE_ASSIMP_H
249
250}
251
252#endif //__MODEL_H__