GLC_lib  2.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
glc_colladatoworld.h
Go to the documentation of this file.
1 /****************************************************************************
2 
3  This file is part of the GLC-lib library.
4  Copyright (C) 2005-2008 Laurent Ribon (laumaya@users.sourceforge.net)
5  http://glc-lib.sourceforge.net
6 
7  GLC-lib is free software; you can redistribute it and/or modify
8  it under the terms of the GNU Lesser General Public License as published by
9  the Free Software Foundation; either version 3 of the License, or
10  (at your option) any later version.
11 
12  GLC-lib is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU Lesser General Public License for more details.
16 
17  You should have received a copy of the GNU Lesser General Public License
18  along with GLC-lib; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 
21  *****************************************************************************/
23 
24 #ifndef GLC_COLLADATOWORLD_H_
25 #define GLC_COLLADATOWORLD_H_
26 
27 #include <QObject>
28 #include <QString>
29 #include <QFile>
30 #include <QXmlStreamReader>
31 #include <QHash>
32 #include <QColor>
33 
34 #include "../shading/glc_material.h"
35 #include "../geometry/glc_mesh.h"
36 #include "../sceneGraph/glc_structoccurence.h"
37 
38 #include "../glc_config.h"
39 
40 class GLC_World;
41 class QGLContext;
42 
45 
46 
47 class GLC_LIB_EXPORT GLC_ColladaToWorld : public QObject
48 {
49 private:
50  Q_OBJECT
51 
52  // The 3 supported semantic
53  enum Semantic
54  { // Values are very important !
55  VERTEX= 0,
56  NORMAL= 1,
57  TEXCOORD= 2
58  };
59 
60  // input data info
61  struct InputData
62  {
63  int m_Offset;
64  QString m_Source;
66  };
67 public:
68  // Collada Vertice (Position index, Normal index and TexCoord index)
70  {
72  : m_Values(3)
73  {
74  m_Values[0]= 0;
75  m_Values[1]= 0;
76  m_Values[2]= 0;
77  }
78 
79  QVector<int> m_Values;
80  };
81 private:
82 
83  // Material assignement
85  {
86  int m_Offset;
87  int m_size;
88  };
89 
90  // Accessor a source data (bulk)
91  struct Accessor
92  {
94  : m_Count(0)
95  , m_Offset(0)
96  , m_Stride(1)
97  {}
98  unsigned int m_Count;
99  unsigned int m_Offset;
100  unsigned int m_Stride;
101  };
102 
103  // The loading mesh info
104  struct MeshInfo
105  {
107  : m_pMesh(NULL)
108  , m_Datas(3)
109  , m_Mapping()
110  , m_Index()
111  , m_FreeIndex(0)
112  {}
113 
114  ~MeshInfo() {delete m_pMesh;}
115  // Mesh of the mesh info
117  // Bulk data vector (Position, normal, texel)
118  QVector<QList<float> > m_Datas;
119  // Mapping between collada vertice and index
120  QHash<ColladaVertice, GLuint> m_Mapping;
121  // Triangle index
123  // Next index Position
124  GLuint m_FreeIndex;
125  // QHash containing material id and associated offset and size
126  QHash<QString, MatOffsetSize> m_Materials;
127  };
128 
129  // The collada Node
130  struct ColladaNode
131  {
132  ColladaNode(const QString id, ColladaNode* pParent)
133  : m_Id(id)
134  , m_Matrix()
135  , m_InstanceGeometryIDs()
136  , m_InstanceOffNodeIds()
137  , m_ChildNodes()
138  , m_pParent(pParent)
139  {}
140  // Destrucot not needed
141  // The node id
142  QString m_Id;
143  // Position matrix
145  // Instance geometry id
146  QList<QString> m_InstanceGeometryIDs;
147  // Instance off another node
148  QList<QString> m_InstanceOffNodeIds;
149  // Child Node
150  QList<ColladaNode*> m_ChildNodes;
151  // Parent Node
153  };
154 
155  typedef QHash<const QString, GLC_Material*> MaterialHash;
156  typedef QHash<const QString, QList<float> > BulkDataHash;
157  typedef QHash<const QString, Accessor> DataAccessorHash;
159 
161 
162 public:
165 
167  virtual ~GLC_ColladaToWorld();
169 
171 
173 
174 public:
176  GLC_World* CreateWorldFromCollada(QFile &);
177 
179  inline QStringList listOfAttachedFileName() const
180  {return m_ListOfAttachedFileName.toList();}
181 
183 
185 // Qt Signals
187  signals:
188  void currentQuantum(int);
189 
191 
193 
194 private:
196  void goToElement(const QString&);
197 
199  void goToEndElement(const QString&);
200 
201  // Return the content of an element
202  QString getContent(const QString&);
203 
205  QString readAttribute(const QString&, bool required= false);
206 
209  void checkForXmlError(const QString&);
210 
212  void throwException(const QString&);
213 
215  void clear();
216 
218  void loadLibraryImage();
219 
221  void loadImage();
222 
224  void loadLibraryMaterials();
225 
227  void loadMaterial();
228 
230  void loadLibraryEffects();
231 
233  void loadEffect();
234 
236  void loadProfileCommon();
237 
239  void loadNewParam();
240 
242  void loadSurface(const QString&);
243 
245  void loadSampler2D(const QString&);
246 
248  void loadTechnique();
249 
251  void loadMaterialTechnique(const QString&);
252 
254  void loadCommonColorOrTexture(const QString&);
255 
257  void loadTransparent();
258 
260  void loadTransparency(const QString&);
261 
263  void loadShininess(const QString&);
264 
266  QColor readXmlColor();
267 
269  void loadLibraryGeometries();
270 
272  void loadGeometry();
273 
275  void loadMesh();
276 
278  void loadVertexBulkData();
279 
281  void loadTechniqueCommon();
282 
284  void loadAccessor();
285 
287  void loadVertices();
288 
290  void loadPolylist();
291 
293  void loadPolygons();
294 
296  void addPolylistToCurrentMesh(const QList<InputData>&, const QList<int>&, const QList<int>&, const QString&);
297 
299  void computeNormalOfCurrentPrimitiveOfCurrentMesh(int offset);
300 
302  void loadTriangles();
303 
305  void addTrianglesToCurrentMesh(const QList<InputData>&, const QList<int>&, const QString&);
306 
308  void loadLibraryNodes();
309 
311  void loadLibraryContollers();
312 
314  void loadVisualScenes();
315 
317  void loadInstanceGeometry(ColladaNode*);
318 
320  void loadInstanceNode(ColladaNode*);
321 
323  void loadInstanceController(ColladaNode*);
324 
326  void loadController();
327 
329  ColladaNode* loadNode(ColladaNode*);
330 
332  void translateNode(ColladaNode*);
333 
335  void scaleNode(ColladaNode*);
336 
338  void rotateNode(ColladaNode*);
339 
341  void composeMatrixNode(ColladaNode*);
342 
344  void loadScene();
345 
347  void linkTexturesToMaterials();
348 
350  void createMesh();
351 
353  void createSceneGraph();
354 
356  GLC_StructOccurence* createOccurenceFromNode(ColladaNode*);
357 
359  void updateProgressBar();
360 
361 
362 
364 
365 // Private members
367 private:
370 
372  QXmlStreamReader* m_pStreamReader;
373 
375  QString m_FileName;
376 
378  QFile* m_pFile;
379 
381  QHash<QString, QString> m_ImageFileHash;
382 
384  QHash<QString, QString> m_MaterialLibHash;
385 
387  QHash<QString, QString> m_SurfaceImageHash;
388 
390  QHash<QString, QString> m_Sampler2DSurfaceHash;
391 
394 
397 
400 
403 
406 
408  QHash<QString, QString> m_VerticesSourceHash;
409 
412 
414  QHash<const QString, MeshInfo*> m_GeometryHash;
415 
417  QHash<const QString, ColladaNode*> m_ColladaNodeHash;
418 
420  QList<ColladaNode*> m_TopLevelColladaNode;
421 
423  QHash<const QString, QString> m_MaterialInstanceMap;
424 
426  QHash<const QString, GLC_3DRep*> m_3DRepHash;
427 
429  QHash<const QString, GLC_StructInstance*> m_StructInstanceHash;
430 
432  QString m_CurrentId;
433 
435  qint64 m_FileSize;
436 
439 
442 
445 
446 };
447 
448 // To use ColladaVertice as a QHash key
450 { return (vertice1.m_Values == vertice2.m_Values);}
451 
452 inline uint qHash(const GLC_ColladaToWorld::ColladaVertice& vertice)
453 { return qHash(QString::number(vertice.m_Values.at(0)) + QString::number(vertice.m_Values.at(1)) + QString::number(vertice.m_Values.at(2)));}
454 
455 #endif /* GLC_COLLADATOWORLD_H_ */

©2005-2013 Laurent Ribon