]> Dogcows Code - chaz/yoink/blob - src/moof/mesh.hh
use only triangles; no quads
[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 void set_material(int index) const;
60 void set_material(const material& material) const;
61
62 struct material_group : public drawable
63 {
64 material_group() {}
65
66 void draw(scalar alpha = SCALAR(0.0)) const;
67
68
69 std::vector<unsigned> triangles;
70 std::vector<vector2> triangles_uv;
71 };
72
73
74 class object;
75 typedef boost::shared_ptr<object> object_ptr;
76
77 struct object
78 {
79 object() :
80 texrep(SCALAR(1.0), SCALAR(1.0)) {}
81
82 static object_ptr alloc()
83 {
84 return object_ptr(new object);
85 }
86
87
88 void draw(const mesh& mesh, scalar alpha = SCALAR(0.0)) const;
89
90
91 std::string name;
92 std::string data;
93 std::string url;
94
95 image_handle texture;
96 vector2 texrep;
97
98 std::vector<vector3> verts;
99 std::vector<material_group> faces;
100
101 std::vector<object_ptr> kids;
102 object_ptr parent;
103 };
104
105
106 private:
107
108 void import(std::istream& stream);
109
110 std::vector<material> materials_;
111 std::vector<object_ptr> objects_;
112 };
113
114 typedef resource_handle<mesh> mesh_handle;
115
116
117 } // namespace moof
118
119 #endif // _MOOF_MESH_HH_
120
This page took 0.037861 seconds and 4 git commands to generate.