]> Dogcows Code - chaz/yoink/blob - src/moof/mesh.hh
mesh and other random adjustments
[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 #include <map>
22 #include <vector>
23
24 #include <boost/noncopyable.hpp>
25 #include <boost/shared_ptr.hpp>
26 #include <boost/weak_ptr.hpp>
27
28 #include <moof/entity.hh>
29 #include <moof/image.hh>
30 #include <moof/math.hh>
31 #include <moof/resource.hh>
32
33
34 namespace moof {
35
36
37 class script;
38
39
40 class mesh : public boost::noncopyable, public entity
41 {
42 public:
43
44 explicit mesh(const std::string& path);
45
46 void draw(scalar alpha = SCALAR(0.0)) const;
47
48
49 struct material
50 {
51 material(const std::string& id) :
52 name(id) {}
53
54
55 std::string name;
56
57 vector4 diffuse;
58 vector4 ambient;
59 vector4 emissive;
60 vector4 specular;
61 scalar shininess;
62 };
63
64
65 void set_material(int index) const;
66 void set_material(const material& material) const;
67
68 struct material_group
69 {
70 std::vector<unsigned> triangles;
71 std::vector<vector2> triangles_uv;
72 };
73
74
75 class object;
76 typedef boost::shared_ptr<object> object_ptr;
77 typedef boost::weak_ptr<object> object_weakptr;
78
79 struct object
80 {
81 object(const mesh& m) :
82 mesh(m),
83 texrep(SCALAR(1.0), SCALAR(1.0)) {}
84
85 static object_ptr alloc(const mesh& m)
86 {
87 return object_ptr(new object(m));
88 }
89
90 void draw(scalar alpha = SCALAR(0.0), bool recurse = true) const;
91
92
93 const moof::mesh& mesh;
94
95 std::string name;
96 std::string data;
97 std::string url;
98
99 image_handle texture;
100 vector2 texrep;
101
102 std::vector<vector3> verts;
103 std::vector<material_group> faces;
104
105 std::vector<object_ptr> kids;
106 std::map<std::string,object_ptr> kids_byname;
107 object_weakptr parent;
108 };
109
110
111 object_ptr operator [] (unsigned index) const
112 {
113 return objects_[index];
114 }
115
116
117 /**
118 * Import script bindings for the mesh class.
119 * \param The script.
120 * \param The name of the namespace to import to.
121 */
122 static void import(script& script, const std::string& nspace = "");
123
124
125 private:
126
127 void import(std::istream& stream);
128
129 std::vector<material> materials_;
130 std::vector<object_ptr> objects_;
131 };
132
133 typedef resource_handle<mesh> mesh_handle;
134
135
136 } // namespace moof
137
138 #endif // _MOOF_MESH_HH_
139
This page took 0.040002 seconds and 4 git commands to generate.