rev |
line source |
nuclear@6
|
1 #ifndef MESH_H_
|
nuclear@6
|
2 #define MESH_H_
|
nuclear@6
|
3
|
nuclear@23
|
4 #include <stdio.h>
|
nuclear@6
|
5 #include <vector>
|
nuclear@24
|
6 #include <list>
|
nuclear@45
|
7 #include "common.h"
|
nuclear@6
|
8
|
nuclear@6
|
9 struct Vertex {
|
nuclear@9
|
10 float pos[4];
|
nuclear@9
|
11 float normal[4];
|
nuclear@12
|
12 float tex[4];
|
nuclear@12
|
13 float padding[4];
|
nuclear@6
|
14 };
|
nuclear@6
|
15
|
nuclear@6
|
16 struct Face {
|
nuclear@6
|
17 Vertex v[3];
|
nuclear@9
|
18 float normal[4];
|
nuclear@6
|
19 int matid;
|
nuclear@12
|
20 int padding[3];
|
John@15
|
21
|
John@15
|
22 bool operator ==(const Face &f) const;
|
nuclear@6
|
23 };
|
nuclear@6
|
24
|
nuclear@6
|
25 struct Material {
|
nuclear@9
|
26 float kd[4], ks[4];
|
nuclear@6
|
27 float kr, kt;
|
nuclear@6
|
28 float spow;
|
nuclear@12
|
29 float padding;
|
nuclear@6
|
30 };
|
nuclear@6
|
31
|
nuclear@6
|
32 struct Mesh {
|
nuclear@6
|
33 std::vector<Face> faces;
|
nuclear@6
|
34 int matid;
|
nuclear@6
|
35 };
|
nuclear@6
|
36
|
nuclear@25
|
37 class AABBox {
|
nuclear@25
|
38 public:
|
nuclear@25
|
39 float min[4], max[4];
|
nuclear@25
|
40
|
nuclear@25
|
41 float calc_surface_area() const;
|
nuclear@25
|
42 };
|
nuclear@25
|
43
|
nuclear@22
|
44 struct KDNode {
|
nuclear@37
|
45 int axis;
|
nuclear@25
|
46 AABBox aabb;
|
nuclear@26
|
47 float cost;
|
nuclear@24
|
48
|
nuclear@24
|
49 KDNode *left, *right;
|
nuclear@32
|
50 std::vector<int> face_idx;
|
nuclear@26
|
51
|
nuclear@26
|
52 KDNode();
|
nuclear@23
|
53 };
|
nuclear@22
|
54
|
nuclear@24
|
55 struct KDNodeGPU {
|
nuclear@28
|
56 AABBox aabb;
|
nuclear@43
|
57 int face_idx[MAX_NODE_FACES];
|
nuclear@28
|
58 int num_faces;
|
nuclear@35
|
59 int left, right;
|
nuclear@35
|
60 int padding;
|
nuclear@24
|
61 };
|
nuclear@24
|
62
|
nuclear@24
|
63
|
nuclear@6
|
64 class Scene {
|
nuclear@24
|
65 private:
|
nuclear@24
|
66 mutable Face *facebuf;
|
nuclear@24
|
67 mutable int num_faces;
|
nuclear@24
|
68
|
nuclear@28
|
69 mutable KDNodeGPU *kdbuf;
|
nuclear@28
|
70
|
nuclear@6
|
71 public:
|
nuclear@6
|
72 std::vector<Mesh*> meshes;
|
nuclear@6
|
73 std::vector<Material> matlib;
|
nuclear@24
|
74 KDNode *kdtree;
|
nuclear@24
|
75
|
nuclear@24
|
76 Scene();
|
nuclear@24
|
77 ~Scene();
|
nuclear@6
|
78
|
nuclear@13
|
79 bool add_mesh(Mesh *m);
|
John@14
|
80 int get_num_meshes() const;
|
nuclear@35
|
81 int get_num_faces() const;
|
John@14
|
82 int get_num_materials() const;
|
nuclear@35
|
83 int get_num_kdnodes() const;
|
nuclear@13
|
84
|
John@14
|
85 Material *get_materials();
|
John@14
|
86 const Material *get_materials() const;
|
nuclear@13
|
87
|
nuclear@6
|
88 bool load(const char *fname);
|
nuclear@6
|
89 bool load(FILE *fp);
|
nuclear@22
|
90
|
nuclear@24
|
91 const Face *get_face_buffer() const;
|
nuclear@28
|
92 const KDNodeGPU *get_kdtree_buffer() const;
|
nuclear@27
|
93
|
nuclear@27
|
94 void draw_kdtree() const;
|
nuclear@27
|
95 bool build_kdtree();
|
nuclear@6
|
96 };
|
nuclear@6
|
97
|
nuclear@26
|
98 enum {
|
nuclear@26
|
99 ACCEL_PARAM_MAX_TREE_DEPTH,
|
nuclear@26
|
100 ACCEL_PARAM_MAX_NODE_ITEMS,
|
nuclear@26
|
101 ACCEL_PARAM_COST_TRAVERSE,
|
nuclear@26
|
102 ACCEL_PARAM_COST_INTERSECT,
|
nuclear@26
|
103
|
nuclear@26
|
104 NUM_ACCEL_PARAMS
|
nuclear@26
|
105 };
|
nuclear@26
|
106
|
nuclear@26
|
107 void set_accel_param(int p, int v);
|
nuclear@26
|
108
|
nuclear@28
|
109 int kdtree_depth(const KDNode *tree);
|
nuclear@28
|
110 int kdtree_nodes(const KDNode *tree);
|
nuclear@28
|
111
|
nuclear@32
|
112 bool kdtree_dump(const KDNode *tree, const char *fname);
|
nuclear@32
|
113 KDNode *kdtree_restore(const char *fname);
|
nuclear@32
|
114
|
nuclear@6
|
115 #endif /* MESH_H_ */
|