00001
00010 #ifndef __OBJ_LOADER_HPP_INCLUDE_GUARD__
00011 #define __OBJ_LOADER_HPP_INCLUDE_GUARD__
00012
00013 #include <iostream>
00014 #include <fstream>
00015 #include <vector>
00016 #include "../gbLib/include/gbException.hpp"
00017
00025 class OBJ_Mesh {
00026 public:
00029 struct Face {
00030 int vert1, vert2, vert3;
00031 int normal1, normal2, normal3;
00032 int texture1, texture2, texture3;
00033 int smoothing_group;
00034 };
00035 private:
00036 std::vector<double> m_geometry;
00037 std::vector<double> m_normals;
00038 std::vector<double> m_texcoords;
00039 std::vector<Face> m_faces;
00040 char* m_name;
00041 public:
00046 OBJ_Mesh(char const* name);
00049 ~OBJ_Mesh();
00053 OBJ_Mesh(OBJ_Mesh const&);
00058 void SetName(char const* name);
00062 void SetGeometry(std::vector<double> const& data);
00067 template<typename T>
00068 void SetGeometry(T const* data, int n_data);
00073 template<typename T>
00074 void AddGeometry(T const* data, int n_data);
00078 void SetNormals(std::vector<double> const& data);
00083 template<typename T>
00084 void SetNormals(T const* data, int n_data);
00089 template<typename T>
00090 void AddNormals(T const* data, int n_data);
00094 void SetTextureData(std::vector<double> const& data);
00099 template<typename T>
00100 void SetTextureData(T const* data, int n_data);
00105 template<typename T>
00106 void AddTextureData(T const* data, int n_data);
00110 void SetFaceData(std::vector<Face> const& data);
00115 void SetFaceData(Face const* data, int n_data);
00120 void AddFaceData(Face const* data, int n_data);
00123 void ClearGeometry();
00126 void ClearNormals();
00129 void ClearTextureData();
00132 void ClearFaceData();
00136 char const* GetName() const;
00140 int GetNVertices() const;
00144 int GetNFaces() const;
00148 int GetNNormals() const;
00152 int GetNTexture() const;
00159 template<typename T>
00160 void GetMeshGeometryUnindexed(T* mesh_geometry, T* mesh_normals, T* mesh_texture, T scale) const;
00168 template<typename T>
00169 void GetMeshGeometry(T* mesh_geometry, T* mesh_normals, T* mesh_texture, Face* mesh_faces, T scale) const;
00174 double const* GetVertexX(int index) const;
00179 double const* GetVertexY(int index) const;
00184 double const* GetVertexZ(int index) const;
00189 double const* GetNormalX(int index) const;
00194 double const* GetNormalY(int index) const;
00199 double const* GetNormalZ(int index) const;
00204 double const* GetTextureX(int index) const;
00209 double const* GetTextureY(int index) const;
00214 double const* GetTextureZ(int index) const;
00219 Face const* GetFace(int index) const;
00220 private:
00221 OBJ_Mesh& operator=(OBJ_Mesh const&);
00222 };
00223
00224 #include "../src/obj_loader.impl.hpp"
00225
00228 class OBJ_FileLoader {
00229 private:
00230 std::vector<OBJ_Mesh*> m_MeshList;
00231 public:
00234 OBJ_FileLoader();
00239 OBJ_FileLoader(const char* fname);
00242 ~OBJ_FileLoader();
00246 int GetNMeshes() const;
00251 OBJ_Mesh const* GetMesh(int index) const;
00256 void AddMesh(OBJ_Mesh const& mesh);
00261 void WriteFile(char const* fname) const;
00262 private:
00268 void ReadFile(std::ifstream& f);
00269 };
00270
00271 #endif