00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef FLUX_OBJ_PRIMITIVE_IO
00018 #define FLUX_OBJ_PRIMITIVE_IO
00019
00020 #include "PrimitiveIO.h"
00021 #include <vector>
00022
00023 namespace Fluxus
00024 {
00025
00026 class OBJPrimitiveIO : public PrimitiveIO
00027 {
00028 public:
00029 OBJPrimitiveIO();
00030 virtual ~OBJPrimitiveIO();
00031 virtual Primitive *FormatRead(const std::string &filename);
00032 virtual bool FormatWrite(const std::string &filename, const Primitive *ob);
00033
00034 private:
00035 class Indices
00036 {
00037 public:
00038 Indices() : Position(0), Texture(0), Normal(0) {}
00039
00040 bool operator==(const Indices &other) const
00041 {
00042 return Position==other.Position &&
00043 Texture==other.Texture &&
00044 Normal==other.Normal;
00045 }
00046
00047 unsigned int Position;
00048 unsigned int Texture;
00049 unsigned int Normal;
00050 };
00051
00052 struct Face
00053 {
00054 vector<Indices> Index;
00055 };
00056
00057 unsigned int TokeniseLine(unsigned int pos, vector<string> &output);
00058 void TokeniseIndices(const string &str, vector<string> &output);
00059 void ReadVectors(const std::string &code, std::vector<dVector> &output);
00060 void ReadIndices(std::vector<Face> &output);
00061 vector<Indices> RemoveDuplicateIndices();
00062 void ReorderData(const vector<Indices> &unique);
00063 void UnifyIndices(const vector<Indices> &unique);
00064 Primitive *MakePrimitive();
00065
00066 void WriteVertices(const std::string &pdataname, const std::string &objname, const Primitive *ob, FILE *file);
00067 void WriteIndices(const Primitive *ob, FILE *file);
00068
00069 unsigned int m_DataSize;
00070 char *m_Data;
00071
00072 vector<Face> m_Faces;
00073 vector<dVector> m_Position;
00074 vector<dVector> m_Texture;
00075 vector<dVector> m_Normal;
00076 vector<unsigned int> m_Indices;
00077 };
00078
00079 }
00080
00081 #endif