Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2011-08-25 22:04:42 +0000
committerStijn Buys <ingar@osirion.org>2011-08-25 22:04:42 +0000
commit431421c7e626b50186fc54542db3967cde844a66 (patch)
tree31eddc445b1227e77e12f628305e9dacb3f81c39 /src/model/objfile.h
parentbdd1e564921d7001c218d1e7bcde925057f9b3dc (diff)
OBJ model support, by Thorn
Diffstat (limited to 'src/model/objfile.h')
-rw-r--r--src/model/objfile.h113
1 files changed, 113 insertions, 0 deletions
diff --git a/src/model/objfile.h b/src/model/objfile.h
new file mode 100644
index 0000000..4e7f0c7
--- /dev/null
+++ b/src/model/objfile.h
@@ -0,0 +1,113 @@
+/*
+ model/objfile.h
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2
+*/
+
+/* http://www.royriggs.com/obj.html
+ http://en.wikipedia.org/wiki/Wavefront_.obj_file */
+
+#ifndef __INCLUDED_MODEL_OBJFILE_H__
+#define __INCLUDED_MODEL_OBJFILE_H__
+
+#include "math/vector3f.h"
+#include "model/model.h"
+#include "model/material.h"
+#include "model/fragment.h"
+#include "model/triangle.h"
+#include "model/quad.h"
+#include "filesystem/filestream.h"
+
+#include <string>
+#include <map>
+#include <vector>
+#include <utility>
+
+namespace model
+{
+
+/// class to parse the .obj file structure and load geometry data into a model
+class OBJFile
+{
+public:
+ /**
+ * @brief load a .obj file into a Model
+ * @param name name of the model to be loaded, without .obj extension or models/ prefix
+ * If the file can not be read, load() returns the NULL-pointer
+ */
+ static Model *load(std::string const &name);
+
+private:
+
+ /**
+ * @brief type definition for a list of materials in the ASE file
+ */
+ typedef std::map<size_t, Material *> MaterialList;
+
+ /**
+ * @brief type definition for a list of vertices
+ */
+ typedef std::map<size_t, math::Vector3f *> VertexList;
+ typedef std::map<size_t, math::Vector3f *> NormalList;
+ typedef std::map<size_t, math::Vector2f *> UVList;
+
+ /**
+ * @brief type definition for a list of faces
+ */
+ typedef std::list<std::pair<size_t, Triangle *> > TriList;
+ typedef std::list<std::pair<size_t, Quad *> > QuadList;
+
+ OBJFile(std::string const &name);
+ ~OBJFile();
+
+ /**
+ * @brief read the .obj file
+ */
+ bool read();
+
+ /**
+ * @brief parse a line in the .obj file.
+ */
+ void readline(std::string const &line);
+
+ inline const std::string &name() const {
+ return objfile_name;
+ }
+
+ inline bool is_open() {
+ return objfile_ifs.is_open();
+ }
+
+ inline size_t vertexcount() const {
+ return obj_vertexlist.size();
+ }
+
+ inline FragmentGroup *fragmentgroup() {
+ return obj_fragmentgroup;
+ }
+
+ inline const math::BoundingBox3f & box() const {
+ return obj_box;
+ }
+
+ std::string objfile_name;
+
+ filesystem::IFileStream objfile_ifs;
+
+ MaterialList obj_materiallist;
+ VertexList obj_vertexlist;
+ UVList obj_uvlist;
+ NormalList obj_normallist;
+ TriList obj_trilist;
+ QuadList obj_quadlist;
+
+ math::BoundingBox3f obj_box;
+
+ FragmentGroup *obj_fragmentgroup;
+
+ size_t obj_normalcount;
+};
+
+} // namespace model
+
+#endif // __INCLUDED_MODEL_OBJFILE_H__