1400cdd2f920680cb2b2b06a9046807a581dc37a
[chaz/yoink] / src / moof / mesh.hh
1
2 /*] Copyright (c) 2009-2010, Charles McGarvey [**************************
3 **] All rights reserved.
4 *
5 * vi:ts=4 sw=4 tw=75
6 *
7 * Distributable under the terms and conditions of the 2-clause BSD license;
8 * see the file COPYING for a complete text of the license.
9 *
10 **************************************************************************/
11
12 #ifndef _MOOF_MESH_HH_
13 #define _MOOF_MESH_HH_
14
15 /**
16 * \file mesh.hh
17 * Defines classes for loading and manipulating meshes.
18 */
19
20 #include <iostream>
21
22 #include <boost/noncopyable.hpp>
23 #include <boost/shared_ptr.hpp>
24
25 #include <moof/drawable.hh>
26 #include <moof/image.hh>
27 #include <moof/math.hh>
28 #include <moof/resource.hh>
29
30
31 namespace moof {
32
33
34 class mesh : public boost::noncopyable, public drawable
35 {
36 public:
37
38 explicit mesh(const std::string& path);
39
40 void draw(scalar alpha = SCALAR(0.0)) const;
41
42
43 struct material
44 {
45 material(const std::string& id) :
46 name(id) {}
47
48
49 std::string name;
50
51 vector4 diffuse;
52 vector3 ambient;
53 vector3 emissive;
54 vector3 specular;
55 scalar shininess;
56 };
57
58
59 //typedef vector3 triangle[3];
60 //typedef vector2 triangle_uv[3];
61 //typedef vector3 quad[4];
62 //typedef vector2 quad_uv[4];
63
64 //struct triangle
65 //{
66 //vector3 verts[3];
67 //vector3& operator [] (int i) { return verts[i]; }
68 //const vector3& operator [] (int i) const { return verts[i]; }
69 //};
70
71 //struct triangle_uv
72 //{
73 //vector2 verts[3];
74 //vector2& operator [] (int i) { return verts[i]; }
75 //const vector2& operator [] (int i) const { return verts[i]; }
76 //};
77
78
79 //struct quad
80 //{
81 //vector3 verts[4];
82 //vector3& operator [] (int i) { return verts[i]; }
83 //const vector3& operator [] (int i) const { return verts[i]; }
84 //};
85
86
87 //struct quad_uv
88 //{
89 //vector2 verts[4];
90 //vector2& operator [] (int i) { return verts[i]; }
91 //const vector2& operator [] (int i) const { return verts[i]; }
92 //};
93
94
95 void set_material(int index) const;
96 void set_material(const material& material) const;
97
98 struct material_group : public drawable
99 {
100 material_group() {}
101
102 std::vector<unsigned> triangles;
103 std::vector<vector2> triangles_uv;
104
105 std::vector<unsigned> quads;
106 std::vector<vector2> quads_uv;
107
108
109 void draw(scalar alpha = SCALAR(0.0)) const;
110 };
111
112
113 class object;
114 typedef boost::shared_ptr<object> object_ptr;
115
116 struct object
117 {
118 object() :
119 texrep(SCALAR(1.0), SCALAR(1.0)) {}
120
121 static object_ptr alloc()
122 {
123 return object_ptr(new object);
124 }
125
126
127 void draw(const mesh& mesh, scalar alpha = SCALAR(0.0)) const;
128
129
130 std::string name;
131 std::string data;
132 std::string url;
133
134 image_handle texture;
135 vector2 texrep;
136
137 std::vector<vector3> verts;
138 std::vector<material_group> faces;
139
140 std::vector<object_ptr> kids;
141 object_ptr parent;
142 };
143
144
145 private:
146
147 void import(std::istream& stream);
148
149 std::vector<material> materials_;
150 std::vector<object_ptr> objects_;
151 };
152
153 typedef resource_handle<mesh> mesh_handle;
154
155
156 } // namespace moof
157
158 #endif // _MOOF_MESH_HH_
159
This page took 0.034984 seconds and 3 git commands to generate.