]> Dogcows Code - chaz/yoink/blob - src/moof/mesh.hh
fixed documentation about where to find licenses
[chaz/yoink] / src / moof / mesh.hh
1
2 /*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
3 **] All rights reserved.
4 *
5 * Distributable under the terms and conditions of the 2-clause BSD license;
6 * see the file COPYING for a complete text of the license.
7 *
8 *****************************************************************************/
9
10 #ifndef _MOOF_MESH_HH_
11 #define _MOOF_MESH_HH_
12
13 #include <iostream>
14 #include <map>
15 #include <vector>
16
17 #include <boost/noncopyable.hpp>
18 #include <boost/shared_ptr.hpp>
19 #include <boost/weak_ptr.hpp>
20
21 #include <moof/entity.hh>
22 #include <moof/image.hh>
23 #include <moof/math.hh>
24 #include <moof/resource.hh>
25
26
27 /**
28 * \file mesh.hh
29 * Defines classes for loading and manipulating meshes.
30 */
31
32 namespace moof {
33
34
35 // forward declarations
36 class script;
37
38 class mesh : public boost::noncopyable, public entity
39 {
40 public:
41
42 explicit mesh(const std::string& path);
43
44 void draw(scalar alpha = SCALAR(0.0)) const;
45
46 struct material
47 {
48 material(const std::string& id) :
49 name(id) {}
50
51 scalar shininess;
52 std::string name;
53 vector4 ambient;
54 vector4 diffuse;
55 vector4 emissive;
56 vector4 specular;
57 };
58
59 void set_material(int index) const;
60 void set_material(const material& material) const;
61
62 struct material_group
63 {
64 std::vector<unsigned> triangles;
65 std::vector<vector2> triangles_uv;
66 };
67
68 class object;
69 typedef boost::shared_ptr<object> object_ptr;
70 typedef boost::weak_ptr<object> object_weakptr;
71
72 struct object
73 {
74 object(const mesh& m) :
75 mesh(m),
76 texrep(SCALAR(1.0), SCALAR(1.0)) {}
77
78 static object_ptr alloc(const mesh& m)
79 {
80 return object_ptr(new object(m));
81 }
82
83 void
84 draw(scalar alpha = SCALAR(0.0), bool recurse = true) const;
85
86 const moof::mesh& mesh;
87
88 std::string name;
89 std::string data;
90 std::string url;
91
92 image_handle texture;
93 vector2 texrep;
94
95 std::vector<vector3> verts;
96 std::vector<material_group> faces;
97
98 std::vector<object_ptr> kids;
99 std::map<std::string,object_ptr> kids_byname;
100 object_weakptr parent;
101 };
102
103 object_ptr operator [] (unsigned index) const
104 {
105 return objects_[index];
106 }
107
108 /**
109 * Import script bindings for the mesh class.
110 * \param The script.
111 * \param The name of the namespace to import to.
112 */
113 static void import(script& script, const std::string& nspace = "");
114
115 private:
116
117 void load(std::istream& stream);
118
119 void load_material(std::istream& stream);
120 object_ptr load_object(std::istream& stream, object_ptr parent);
121 void load_surface(std::istream& stream, object_ptr obj);
122
123 std::vector<material> materials_;
124 std::vector<object_ptr> objects_;
125 };
126
127 typedef resource_handle<mesh> mesh_handle;
128
129
130 } // namespace moof
131
132 #endif // _MOOF_MESH_HH_
133
This page took 0.041017 seconds and 5 git commands to generate.