glc_objtoworld.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00026
00027 #ifndef GLC_OBJTOWORLD_H_
00028 #define GLC_OBJTOWORLD_H_
00029
00030 #include <QFile>
00031 #include <QString>
00032 #include <QObject>
00033 #include <QHash>
00034 #include <QVector>
00035 #include <QStringList>
00036
00037 #include "../maths/glc_vector3d.h"
00038 #include "../maths/glc_vector2df.h"
00039 #include "../maths/glc_vector3df.h"
00040 #include "../geometry/glc_mesh.h"
00041
00042 #include "../glc_config.h"
00043
00044 enum FaceType
00045 {
00046 notSet,
00047 coordinate,
00048 coordinateAndTexture,
00049 coordinateAndNormal,
00050 coordinateAndTextureAndNormal
00051 };
00052
00053 class GLC_World;
00054 class GLC_ObjMtlLoader;
00055 class QGLContext;
00056
00059
00068
00069 class GLC_LIB_EXPORT GLC_ObjToWorld : public QObject
00070 {
00071 Q_OBJECT
00072
00073 public:
00074
00075 struct ObjVertice
00076 {
00077 ObjVertice()
00078 : m_Values(3)
00079 {
00080 m_Values[0]= 0;
00081 m_Values[1]= 0;
00082 m_Values[2]= 0;
00083 }
00084 ObjVertice(int v1, int v2, int v3)
00085 : m_Values(3)
00086 {
00087 m_Values[0]= v1;
00088 m_Values[1]= v2;
00089 m_Values[2]= v3;
00090 }
00091
00092 QVector<int> m_Values;
00093 };
00094
00095
00096 struct MatOffsetSize
00097 {
00098 MatOffsetSize()
00099 : m_Offset(0)
00100 , m_size(0)
00101 {}
00102 int m_Offset;
00103 int m_size;
00104 };
00105
00106
00107 struct CurrentObjMesh
00108 {
00109 CurrentObjMesh(const QString materialName)
00110 : m_pMesh(new GLC_Mesh())
00111 , m_Positions()
00112 , m_Normals()
00113 , m_Texels()
00114 , m_Index()
00115 , m_pLastOffsetSize(new MatOffsetSize())
00116 , m_Materials()
00117 , m_NextFreeIndex(0)
00118 , m_ObjVerticeIndexMap()
00119 {
00120 m_Materials.insert(materialName, m_pLastOffsetSize);
00121 }
00122 ~CurrentObjMesh()
00123 {
00124 QHash<QString, MatOffsetSize*>::iterator i= m_Materials.begin();
00125 while (m_Materials.constEnd() != i)
00126 {
00127 delete i.value();
00128 ++i;
00129 }
00130 }
00131 GLC_Mesh* m_pMesh;
00132 QList<float> m_Positions;
00133 QList<float> m_Normals;
00134 QList<float> m_Texels;
00136 IndexList m_Index;
00137
00138 MatOffsetSize* m_pLastOffsetSize;
00139
00140 QHash<QString, MatOffsetSize*> m_Materials;
00142 int m_NextFreeIndex;
00144 QHash<ObjVertice, GLuint> m_ObjVerticeIndexMap;
00145 };
00146
00148
00150
00151
00152 public:
00153 GLC_ObjToWorld(const QGLContext*);
00154 virtual ~GLC_ObjToWorld();
00156
00158
00160
00161 public:
00163 GLC_World* CreateWorldFromObj(QFile &file);
00164
00166 inline QStringList listOfAttachedFileName() const{return m_ListOfAttachedFileName;}
00168
00170
00172 private:
00174 QString getMtlLibFileName(QString);
00175
00177 void scanLigne(QString &);
00178
00180 void changeGroup(QString);
00181
00183 QList<float> extract3dVect(QString &);
00184
00186 QList<float> extract2dVect(QString &);
00187
00189 void extractFaceIndex(QString &);
00190
00192 void setCurrentMaterial(QString &line);
00193
00195 void extractVertexIndex(QString ligne, int &Coordinate, int &Normal, int &TextureCoordinate);
00196
00198 void setObjType(QString &);
00199
00201 GLC_Vector3df computeNormal(GLuint, GLuint, GLuint);
00202
00204 void clear();
00205
00207 void mergeLines(QString*, QTextStream*);
00208
00210 void addCurrentObjMeshToWorld();
00211
00212
00213
00215
00217 signals:
00218 void currentQuantum(int);
00219
00221
00223 private:
00225 GLC_World* m_pWorld;
00226
00228 QString m_FileName;
00229
00231 const QGLContext* m_pQGLContext;
00232
00234 GLC_ObjMtlLoader* m_pMtlLoader;
00235
00237 int m_CurrentLineNumber;
00238
00240 CurrentObjMesh* m_pCurrentObjMesh;
00241
00243 FaceType m_FaceType;
00244
00246 QHash<QString, int> m_CurrentMeshMaterials;
00247
00249 QString m_CurrentMaterialName;
00250
00252 QStringList m_ListOfAttachedFileName;
00253
00255 QList<float> m_Positions;
00256
00258 QList<float> m_Normals;
00259
00261 QList<float> m_Texels;
00262 };
00263
00264
00265 inline bool operator==(const GLC_ObjToWorld::ObjVertice& vertice1, const GLC_ObjToWorld::ObjVertice& vertice2)
00266 { return (vertice1.m_Values == vertice2.m_Values);}
00267
00268 inline uint qHash(const GLC_ObjToWorld::ObjVertice& vertice)
00269 { return qHash(QString::number(vertice.m_Values.at(0)) + QString::number(vertice.m_Values.at(1)) + QString::number(vertice.m_Values.at(2)));}
00270
00271
00272 #endif