/* 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 #include #include #include 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 MaterialList; /** * @brief type definition for a list of vertices */ typedef std::map VertexList; typedef std::map NormalList; typedef std::map UVList; /** * @brief type definition for a list of faces */ typedef std::list > TriList; typedef std::list > 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; } math::Vector3f *find_vertex(size_t index); math::Vector3f *find_normal(size_t index); math::Vector2f *find_uv(size_t index); 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__