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
00023
00024 #ifndef GLC_COLLADATOWORLD_H_
00025 #define GLC_COLLADATOWORLD_H_
00026
00027 #include <QObject>
00028 #include <QString>
00029 #include <QFile>
00030 #include <QXmlStreamReader>
00031 #include <QHash>
00032 #include <QColor>
00033
00034 #include "../shading/glc_material.h"
00035 #include "../geometry/glc_mesh.h"
00036 #include "../sceneGraph/glc_structoccurence.h"
00037
00038 #include "../glc_config.h"
00039
00040 class GLC_World;
00041 class QGLContext;
00042
00045
00046
00047 class GLC_LIB_EXPORT GLC_ColladaToWorld : public QObject
00048 {
00049 private:
00050 Q_OBJECT
00051
00052
00053 enum Semantic
00054 {
00055 VERTEX= 0,
00056 NORMAL= 1,
00057 TEXCOORD= 2
00058 };
00059
00060
00061 struct InputData
00062 {
00063 int m_Offset;
00064 QString m_Source;
00065 Semantic m_Semantic;
00066 };
00067 public:
00068
00069 struct ColladaVertice
00070 {
00071 ColladaVertice()
00072 : m_Values(3)
00073 {
00074 m_Values[0]= 0;
00075 m_Values[1]= 0;
00076 m_Values[2]= 0;
00077 }
00078
00079 QVector<int> m_Values;
00080 };
00081 private:
00082
00083
00084 struct MatOffsetSize
00085 {
00086 int m_Offset;
00087 int m_size;
00088 };
00089
00090
00091 struct Accessor
00092 {
00093 Accessor()
00094 : m_Count(0)
00095 , m_Offset(0)
00096 , m_Stride(1)
00097 {}
00098 unsigned int m_Count;
00099 unsigned int m_Offset;
00100 unsigned int m_Stride;
00101 };
00102
00103
00104 struct MeshInfo
00105 {
00106 MeshInfo()
00107 : m_pMesh(NULL)
00108 , m_Datas(3)
00109 , m_Mapping()
00110 , m_Index()
00111 , m_FreeIndex(0)
00112 {}
00113
00114 ~MeshInfo() {delete m_pMesh;}
00115
00116 GLC_Mesh* m_pMesh;
00117
00118 QVector<QList<float> > m_Datas;
00119
00120 QHash<ColladaVertice, GLuint> m_Mapping;
00121
00122 IndexList m_Index;
00123
00124 GLuint m_FreeIndex;
00125
00126 QHash<QString, MatOffsetSize> m_Materials;
00127 };
00128
00129
00130 struct ColladaNode
00131 {
00132 ColladaNode(const QString id, ColladaNode* pParent)
00133 : m_Id(id)
00134 , m_Matrix()
00135 , m_InstanceGeometryIDs()
00136 , m_InstanceOffNodeIds()
00137 , m_ChildNodes()
00138 , m_pParent(pParent)
00139 {}
00140
00141
00142 QString m_Id;
00143
00144 GLC_Matrix4x4 m_Matrix;
00145
00146 QList<QString> m_InstanceGeometryIDs;
00147
00148 QList<QString> m_InstanceOffNodeIds;
00149
00150 QList<ColladaNode*> m_ChildNodes;
00151
00152 ColladaNode* m_pParent;
00153 };
00154
00155 typedef QHash<const QString, GLC_Material*> MaterialHash;
00156 typedef QHash<const QString, QList<float> > BulkDataHash;
00157 typedef QHash<const QString, Accessor> DataAccessorHash;
00159
00161
00162 public:
00164 GLC_ColladaToWorld();
00165
00167 virtual ~GLC_ColladaToWorld();
00169
00171
00173
00174 public:
00176 GLC_World* CreateWorldFromCollada(QFile &);
00177
00179 inline QStringList listOfAttachedFileName() const
00180 {return m_ListOfAttachedFileName.toList();}
00181
00183
00185
00187 signals:
00188 void currentQuantum(int);
00189
00191
00193
00194 private:
00196 void goToElement(const QString&);
00197
00199 void goToEndElement(const QString&);
00200
00201
00202 QString getContent(const QString&);
00203
00205 QString readAttribute(const QString&, bool required= false);
00206
00209 void checkForXmlError(const QString&);
00210
00212 void throwException(const QString&);
00213
00215 void clear();
00216
00218 void loadLibraryImage();
00219
00221 void loadImage();
00222
00224 void loadLibraryMaterials();
00225
00227 void loadMaterial();
00228
00230 void loadLibraryEffects();
00231
00233 void loadEffect();
00234
00236 void loadProfileCommon();
00237
00239 void loadNewParam();
00240
00242 void loadSurface(const QString&);
00243
00245 void loadSampler2D(const QString&);
00246
00248 void loadTechnique();
00249
00251 void loadMaterialTechnique(const QString&);
00252
00254 void loadCommonColorOrTexture(const QString&);
00255
00257 void loadTransparent();
00258
00260 void loadTransparency(const QString&);
00261
00263 void loadShininess(const QString&);
00264
00266 QColor readXmlColor();
00267
00269 void loadLibraryGeometries();
00270
00272 void loadGeometry();
00273
00275 void loadMesh();
00276
00278 void loadVertexBulkData();
00279
00281 void loadTechniqueCommon();
00282
00284 void loadAccessor();
00285
00287 void loadVertices();
00288
00290 void loadPolylist();
00291
00293 void loadPolygons();
00294
00296 void addPolylistToCurrentMesh(const QList<InputData>&, const QList<int>&, const QList<int>&, const QString&);
00297
00299 void computeNormalOfCurrentPrimitiveOfCurrentMesh(int offset);
00300
00302 void loadTriangles();
00303
00305 void addTrianglesToCurrentMesh(const QList<InputData>&, const QList<int>&, const QString&);
00306
00308 void loadLibraryNodes();
00309
00311 void loadLibraryContollers();
00312
00314 void loadVisualScenes();
00315
00317 void loadInstanceGeometry(ColladaNode*);
00318
00320 void loadInstanceNode(ColladaNode*);
00321
00323 void loadInstanceController(ColladaNode*);
00324
00326 void loadController();
00327
00329 ColladaNode* loadNode(ColladaNode*);
00330
00332 void translateNode(ColladaNode*);
00333
00335 void scaleNode(ColladaNode*);
00336
00338 void rotateNode(ColladaNode*);
00339
00341 void composeMatrixNode(ColladaNode*);
00342
00344 void loadScene();
00345
00347 void linkTexturesToMaterials();
00348
00350 void createMesh();
00351
00353 void createSceneGraph();
00354
00356 GLC_StructOccurence* createOccurenceFromNode(ColladaNode*);
00357
00359 void updateProgressBar();
00360
00361
00362
00364
00365
00367 private:
00369 GLC_World* m_pWorld;
00370
00372 QXmlStreamReader* m_pStreamReader;
00373
00375 QString m_FileName;
00376
00378 QFile* m_pFile;
00379
00381 QHash<QString, QString> m_ImageFileHash;
00382
00384 QHash<QString, QString> m_MaterialLibHash;
00385
00387 QHash<QString, QString> m_SurfaceImageHash;
00388
00390 QHash<QString, QString> m_Sampler2DSurfaceHash;
00391
00393 MaterialHash m_MaterialEffectHash;
00394
00396 GLC_Material* m_pCurrentMaterial;
00397
00399 MaterialHash m_TextureToMaterialHash;
00400
00402 BulkDataHash m_BulkDataHash;
00403
00405 DataAccessorHash m_DataAccessorHash;
00406
00408 QHash<QString, QString> m_VerticesSourceHash;
00409
00411 MeshInfo* m_pMeshInfo;
00412
00414 QHash<const QString, MeshInfo*> m_GeometryHash;
00415
00417 QHash<const QString, ColladaNode*> m_ColladaNodeHash;
00418
00420 QList<ColladaNode*> m_TopLevelColladaNode;
00421
00423 QHash<const QString, QString> m_MaterialInstanceMap;
00424
00426 QHash<const QString, GLC_3DRep*> m_3DRepHash;
00427
00429 QHash<const QString, GLC_StructInstance*> m_StructInstanceHash;
00430
00432 QString m_CurrentId;
00433
00435 qint64 m_FileSize;
00436
00438 int m_CurrentOffset;
00439
00441 QSet<QString> m_ListOfAttachedFileName;
00442
00444 bool m_TransparentIsRgbZero;
00445
00446 };
00447
00448
00449 inline bool operator==(const GLC_ColladaToWorld::ColladaVertice& vertice1, const GLC_ColladaToWorld::ColladaVertice& vertice2)
00450 { return (vertice1.m_Values == vertice2.m_Values);}
00451
00452 inline uint qHash(const GLC_ColladaToWorld::ColladaVertice& vertice)
00453 { return qHash(QString::number(vertice.m_Values.at(0)) + QString::number(vertice.m_Values.at(1)) + QString::number(vertice.m_Values.at(2)));}
00454
00455 #endif