]> Dogcows Code - chaz/yoink/blobdiff - src/moof/mesh.hh
fixed documentation about where to find licenses
[chaz/yoink] / src / moof / mesh.hh
index cf267fba65d8a437a014301869e24dcf78245d44..5c9c34399f6be0bfd1223da75539463495851fb6 100644 (file)
@@ -1,37 +1,41 @@
 
-/*]  Copyright (c) 2009-2010, Charles McGarvey  [**************************
+/*]  Copyright (c) 2009-2011, Charles McGarvey  [*****************************
 **]  All rights reserved.
 *
-* vi:ts=4 sw=4 tw=75
-*
 * Distributable under the terms and conditions of the 2-clause BSD license;
 * see the file COPYING for a complete text of the license.
 *
-**************************************************************************/
+*****************************************************************************/
 
 #ifndef _MOOF_MESH_HH_
 #define _MOOF_MESH_HH_
 
-/**
- * \file mesh.hh
- * Defines classes for loading and manipulating meshes.
- */
-
 #include <iostream>
+#include <map>
+#include <vector>
 
 #include <boost/noncopyable.hpp>
 #include <boost/shared_ptr.hpp>
+#include <boost/weak_ptr.hpp>
 
-#include <moof/drawable.hh>
+#include <moof/entity.hh>
 #include <moof/image.hh>
 #include <moof/math.hh>
 #include <moof/resource.hh>
 
 
+/**
+ * \file mesh.hh
+ * Defines classes for loading and manipulating meshes.
+ */
+
 namespace moof {
 
 
-class mesh : public boost::noncopyable, public drawable
+// forward declarations
+class script;
+
+class mesh : public boost::noncopyable, public entity
 {
 public:
 
@@ -39,73 +43,82 @@ public:
 
        void draw(scalar alpha = SCALAR(0.0)) const;
 
-
        struct material
        {
                material(const std::string& id) :
                        name(id) {}
 
-
+               scalar          shininess;
                std::string     name;
-
+               vector4         ambient;
                vector4         diffuse;
-               vector3         ambient;
-               vector3         emissive;
-               vector3         specular;
-               scalar          shininess;
+               vector4         emissive;
+               vector4         specular;
        };
 
-
        void set_material(int index) const;
        void set_material(const material& material) const;
 
-       struct material_group : public drawable
+       struct material_group
        {
-               material_group() {}
-
-               void draw(scalar alpha = SCALAR(0.0)) const;
-
-
                std::vector<unsigned>   triangles;
                std::vector<vector2>    triangles_uv;
        };
 
-
        class object;
        typedef boost::shared_ptr<object> object_ptr;
+       typedef boost::weak_ptr<object>   object_weakptr;
 
        struct object
        {
-               object() :
+               object(const mesh& m) :
+                       mesh(m),
                        texrep(SCALAR(1.0), SCALAR(1.0)) {}
 
-               static object_ptr alloc()
+               static object_ptr alloc(const mesh& m)
                {
-                       return object_ptr(new object);
+                       return object_ptr(new object(m));
                }
 
+               void
+               draw(scalar alpha = SCALAR(0.0), bool recurse = true) const;
 
-               void draw(const mesh& mesh, scalar alpha = SCALAR(0.0)) const;
-
+               const moof::mesh&       mesh;
 
-               std::string                                     name;
-               std::string                                     data;
-               std::string                                     url;
+               std::string             name;
+               std::string             data;
+               std::string             url;
 
-               image_handle                            texture;
-               vector2                                         texrep;
+               image_handle            texture;
+               vector2                 texrep;
 
-               std::vector<vector3>            verts;
-               std::vector<material_group>     faces;
+               std::vector<vector3>                    verts;
+               std::vector<material_group>             faces;
 
-               std::vector<object_ptr>         kids;
-               object_ptr                                      parent;
+               std::vector<object_ptr>                 kids;
+               std::map<std::string,object_ptr>        kids_byname;
+               object_weakptr                          parent;
        };
 
+       object_ptr operator [] (unsigned index) const
+       {
+               return objects_[index];
+       }
+
+       /**
+        * Import script bindings for the mesh class.
+        * \param The script.
+        * \param The name of the namespace to import to.
+        */
+       static void import(script& script, const std::string& nspace = "");
 
 private:
 
-       void import(std::istream& stream);
+       void load(std::istream& stream);
+
+       void load_material(std::istream& stream);
+       object_ptr load_object(std::istream& stream, object_ptr parent);
+       void load_surface(std::istream& stream, object_ptr obj);
        
        std::vector<material>   materials_;
        std::vector<object_ptr> objects_;
This page took 0.023778 seconds and 4 git commands to generate.