Updated README.md with build instructions
[hair] / src / mesh.h
1 #ifndef MESH_H_
2 #define MESH_H_
3
4 #include <stdint.h>
5 #include <vector>
6 #include <gmath/gmath.h>
7
8 #define MESH_ALL (0xffffffff)
9
10 enum {
11         MESH_VERTEX = 1,
12         MESH_NORMAL = 2,
13         MESH_TEXCOORDS = 4,
14         MESH_COLOR = 8,
15         MESH_INDEX = 16
16 };
17
18 struct Aabb {
19         Vec3 v0;
20         Vec3 v1;
21 };
22
23 struct Material {
24         Vec3 diffuse;
25         Vec3 specular;
26         float shininess;
27
28         unsigned int tex;
29         bool tex_opaque;
30 };
31
32 class Mesh {
33 private:
34         unsigned int vbo_vertices;
35         unsigned int vbo_normals;
36         unsigned int vbo_texcoords;
37         unsigned int vbo_colors;
38         unsigned int ibo;
39
40         int num_vertices;
41         int num_indices;
42
43 public:
44         Mesh();
45         ~Mesh();
46
47         Aabb bbox;
48         Material mtl;
49
50         std::string name;
51         std::vector<uint16_t> indices;
52         std::vector<Vec3> vertices;
53         std::vector<Vec2> texcoords;
54         std::vector<Vec3> normals;
55         std::vector<Vec3> colors;
56
57         void draw() const;
58         void update_vbo(unsigned int which);
59
60         void calc_bbox();
61 };
62
63 std::vector<Mesh*> load_meshes(const char *fname);
64
65 #endif // MESH_H_