glc_colladatoworld.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
00025
00026 #ifndef GLC_COLLADATOWORLD_H_
00027 #define GLC_COLLADATOWORLD_H_
00028
00029 #include <QObject>
00030 #include <QString>
00031 #include <QFile>
00032 #include <QXmlStreamReader>
00033 #include <QHash>
00034 #include <QColor>
00035
00036 #include "../shading/glc_material.h"
00037 #include "../geometry/glc_mesh.h"
00038 #include "../sceneGraph/glc_structoccurence.h"
00039
00040 #include "../glc_config.h"
00041
00042 class GLC_World;
00043 class QGLContext;
00044
00047
00048
00049 class GLC_LIB_EXPORT GLC_ColladaToWorld : public QObject
00050 {
00051 private:
00052 Q_OBJECT
00053
00054
00055 enum Semantic
00056 {
00057 VERTEX= 0,
00058 NORMAL= 1,
00059 TEXCOORD= 2
00060 };
00061
00062
00063 struct InputData
00064 {
00065 int m_Offset;
00066 QString m_Source;
00067 Semantic m_Semantic;
00068 };
00069 public:
00070
00071 struct ColladaVertice
00072 {
00073 ColladaVertice()
00074 : m_Values(3)
00075 {
00076 m_Values[0]= 0;
00077 m_Values[1]= 0;
00078 m_Values[2]= 0;
00079 }
00080
00081 QVector<int> m_Values;
00082 };
00083 private:
00084
00085
00086 struct MatOffsetSize
00087 {
00088 int m_Offset;
00089 int m_size;
00090 };
00091
00092 struct MeshInfo
00093 {
00094 MeshInfo()
00095 : m_pMesh(NULL)
00096 , m_Datas(3)
00097 , m_Mapping()
00098 , m_Index()
00099 , m_FreeIndex(0)
00100 {}
00101
00102 ~MeshInfo() {delete m_pMesh;}
00103
00104 GLC_Mesh* m_pMesh;
00105
00106 QVector<QList<float> > m_Datas;
00107
00108 QHash<ColladaVertice, GLuint> m_Mapping;
00109
00110 IndexList m_Index;
00111
00112 GLuint m_FreeIndex;
00113
00114 QHash<QString, MatOffsetSize> m_Materials;
00115 };
00116
00117
00118 struct ColladaNode
00119 {
00120 ColladaNode(const QString id, ColladaNode* pParent)
00121 : m_Id(id)
00122 , m_Matrix()
00123 , m_InstanceGeometryIDs()
00124 , m_InstanceOffNodeIds()
00125 , m_ChildNodes()
00126 , m_pParent(pParent)
00127 {}
00128
00129
00130 QString m_Id;
00131
00132 GLC_Matrix4x4 m_Matrix;
00133
00134 QList<QString> m_InstanceGeometryIDs;
00135
00136 QList<QString> m_InstanceOffNodeIds;
00137
00138 QList<ColladaNode*> m_ChildNodes;
00139
00140 ColladaNode* m_pParent;
00141 };
00142
00143 typedef QHash<const QString, GLC_Material*> MaterialHash;
00144 typedef QHash<const QString, QList<float> > BulkDataHash;
00146
00148
00149 public:
00151 GLC_ColladaToWorld(const QGLContext*);
00152
00154 virtual ~GLC_ColladaToWorld();
00156
00158
00160
00161 public:
00163 GLC_World* CreateWorldFromCollada(QFile &);
00164
00166 inline QStringList listOfAttachedFileName() const
00167 {return m_ListOfAttachedFileName.toList();}
00168
00170
00172
00174 signals:
00175 void currentQuantum(int);
00176
00178
00180
00181 private:
00183 void goToElement(const QString&);
00184
00186 void goToEndElement(const QString&);
00187
00188
00189 QString getContent(const QString&);
00190
00192 QString readAttribute(const QString&, bool required= false);
00193
00196 void checkForXmlError(const QString&);
00197
00199 void throwException(const QString&);
00200
00202 inline bool endElementNotReached(const QString& element)
00203 {return !m_pStreamReader->atEnd() && !(m_pStreamReader->isEndElement() && (m_pStreamReader->name() == element));}
00204
00206 inline bool startElementNotReached(const QString& element)
00207 {return !m_pStreamReader->atEnd() && !(m_pStreamReader->isStartElement() && (m_pStreamReader->name() == element));}
00208
00210 void clear();
00211
00213 void loadLibraryImage();
00214
00216 void loadImage();
00217
00219 void loadLibraryMaterials();
00220
00222 void loadMaterial();
00223
00225 void loadLibraryEffects();
00226
00228 void loadEffect();
00229
00231 void loadProfileCommon();
00232
00234 void loadNewParam();
00235
00237 void loadSurface(const QString&);
00238
00240 void loadSampler2D(const QString&);
00241
00243 void loadTechnique();
00244
00246 void loadMaterialTechnique(const QString&);
00247
00249 void loadCommonColorOrTexture(const QString&);
00250
00252 void loadTransparent();
00253
00255 void loadTransparency(const QString&);
00256
00258 void loadShininess(const QString&);
00259
00261 QColor readXmlColor();
00262
00264 void loadLibraryGeometries();
00265
00267 void loadGeometry();
00268
00270 void loadMesh();
00271
00273 void loadVertexBulkData();
00274
00276 void loadVertices();
00277
00279 void loadPolylist();
00280
00282 void loadPolygons();
00283
00285 void addPolylistToCurrentMesh(const QList<InputData>&, const QList<int>&, const QList<int>&, const QString&);
00286
00288 void computeNormalOfCurrentPrimitiveOfCurrentMesh(int offset);
00289
00291 void loadTriangles();
00292
00294 void addTrianglesToCurrentMesh(const QList<InputData>&, const QList<int>&, const QString&);
00295
00297 void loadLibraryNodes();
00298
00300 void loadLibraryContollers();
00301
00303 void loadVisualScenes();
00304
00306 void loadInstanceGeometry(ColladaNode*);
00307
00309 void loadInstanceNode(ColladaNode*);
00310
00312 void loadInstanceController(ColladaNode*);
00313
00315 void loadController();
00316
00318 ColladaNode* loadNode(ColladaNode*);
00319
00321 void translateNode(ColladaNode*);
00322
00324 void scaleNode(ColladaNode*);
00325
00327 void rotateNode(ColladaNode*);
00328
00330 void composeMatrixNode(ColladaNode*);
00331
00333 void loadScene();
00334
00336 void linkTexturesToMaterials();
00337
00339 void createMesh();
00340
00342 void createSceneGraph();
00343
00345 GLC_StructOccurence* createOccurenceFromNode(ColladaNode*);
00346
00348 void updateProgressBar();
00349
00350
00351
00353
00354
00356 private:
00358 GLC_World* m_pWorld;
00359
00361 const QGLContext* m_pQGLContext;
00362
00364 QXmlStreamReader* m_pStreamReader;
00365
00367 QString m_FileName;
00368
00370 QFile* m_pFile;
00371
00373 QHash<QString, QString> m_ImageFileHash;
00374
00376 QHash<QString, QString> m_MaterialLibHash;
00377
00379 QHash<QString, QString> m_SurfaceImageHash;
00380
00382 QHash<QString, QString> m_Sampler2DSurfaceHash;
00383
00385 MaterialHash m_MaterialEffectHash;
00386
00388 GLC_Material* m_pCurrentMaterial;
00389
00391 MaterialHash m_TextureToMaterialHash;
00392
00394 BulkDataHash m_BulkDataHash;
00395
00397 QHash<QString, QString> m_VerticesSourceHash;
00398
00400 MeshInfo* m_pMeshInfo;
00401
00403 QHash<const QString, MeshInfo*> m_GeometryHash;
00404
00406 QHash<const QString, ColladaNode*> m_ColladaNodeHash;
00407
00409 QList<ColladaNode*> m_TopLevelColladaNode;
00410
00412 QHash<const QString, QString> m_MaterialInstanceMap;
00413
00415 QHash<const QString, GLC_3DRep*> m_3DRepHash;
00416
00418 QHash<const QString, GLC_StructInstance*> m_StructInstanceHash;
00419
00421 QString m_CurrentId;
00422
00424 qint64 m_FileSize;
00425
00427 int m_CurrentOffset;
00428
00430 QSet<QString> m_ListOfAttachedFileName;
00431
00433 bool m_TransparentIsRgbZero;
00434
00435
00436 };
00437
00438
00439 inline bool operator==(const GLC_ColladaToWorld::ColladaVertice& vertice1, const GLC_ColladaToWorld::ColladaVertice& vertice2)
00440 { return (vertice1.m_Values == vertice2.m_Values);}
00441
00442 inline uint qHash(const GLC_ColladaToWorld::ColladaVertice& vertice)
00443 { return qHash(QString::number(vertice.m_Values.at(0)) + QString::number(vertice.m_Values.at(1)) + QString::number(vertice.m_Values.at(2)));}
00444
00445 #endif