GLC_lib  2.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
glc_objtoworld.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  Version 2.0.0, packaged on July 2010.
6 
7  http://glc-lib.sourceforge.net
8 
9  GLC-lib is free software; you can redistribute it and/or modify
10  it under the terms of the GNU Lesser General Public License as published by
11  the Free Software Foundation; either version 3 of the License, or
12  (at your option) any later version.
13 
14  GLC-lib is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public License
20  along with GLC-lib; if not, write to the Free Software
21  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 
23 *****************************************************************************/
24 
26 
27 #ifndef GLC_OBJTOWORLD_H_
28 #define GLC_OBJTOWORLD_H_
29 
30 #include <QFile>
31 #include <QString>
32 #include <QObject>
33 #include <QHash>
34 #include <QVector>
35 #include <QStringList>
36 
37 #include "../maths/glc_vector3d.h"
38 #include "../maths/glc_vector2df.h"
39 #include "../maths/glc_vector3df.h"
40 #include "../geometry/glc_mesh.h"
41 
42 #include "../glc_config.h"
43 
45 {
51 };
52 
53 class GLC_World;
54 class GLC_ObjMtlLoader;
55 class QGLContext;
56 
59 
68 
69 class GLC_LIB_EXPORT GLC_ObjToWorld : public QObject
70 {
71  Q_OBJECT
72 
73 public:
74  // OBJ Vertice (Position index, Normal index and TexCoord index)
75  struct ObjVertice
76  {
78  : m_Values(3)
79  {
80  m_Values[0]= 0;
81  m_Values[1]= 0;
82  m_Values[2]= 0;
83  }
84  ObjVertice(int v1, int v2, int v3)
85  : m_Values(3)
86  {
87  m_Values[0]= v1;
88  m_Values[1]= v2;
89  m_Values[2]= v3;
90  }
91 
92  QVector<int> m_Values;
93  };
94 
95  // Material assignement
97  {
99  : m_Offset(0)
100  , m_size(0)
101  {}
102  int m_Offset;
103  int m_size;
104  };
105 
106  // Current OBJ Mesh
108  {
109  CurrentObjMesh(const QString materialName)
110  : m_pMesh(new GLC_Mesh())
111  , m_Positions()
112  , m_Normals()
113  , m_Texels()
114  , m_Index()
115  , m_pLastOffsetSize(new MatOffsetSize())
116  , m_Materials()
117  , m_NextFreeIndex(0)
118  , m_ObjVerticeIndexMap()
119  {
120  m_Materials.insert(materialName, m_pLastOffsetSize);
121  }
123  {
124  QHash<QString, MatOffsetSize*>::iterator i= m_Materials.begin();
125  while (m_Materials.constEnd() != i)
126  {
127  delete i.value();
128  ++i;
129  }
130  }
132  QList<float> m_Positions;
133  QList<float> m_Normals;
134  QList<float> m_Texels;
137  // Pointer to the last matOffsetSize
139  // QHash containing material id and associated offset and size
140  QHash<QString, MatOffsetSize*> m_Materials;
144  QHash<ObjVertice, GLuint> m_ObjVerticeIndexMap;
145  };
146 
148 
150 
151 
152 public:
153  GLC_ObjToWorld();
154  virtual ~GLC_ObjToWorld();
156 
158 
160 
161 public:
163  GLC_World* CreateWorldFromObj(QFile &file);
164 
166  inline QStringList listOfAttachedFileName() const{return m_ListOfAttachedFileName;}
168 
170 // Private services functions
172 private:
174  QString getMtlLibFileName(QString);
175 
177  void scanLigne(QString &);
178 
180  void changeGroup(QString);
181 
183  QList<float> extract3dVect(QString &);
184 
186  QList<float> extract2dVect(QString &);
187 
189  void extractFaceIndex(QString &);
190 
192  void setCurrentMaterial(QString &line);
193 
195  void extractVertexIndex(QString ligne, int &Coordinate, int &Normal, int &TextureCoordinate);
196 
198  void setObjType(QString &);
199 
201  GLC_Vector3df computeNormal(GLuint, GLuint, GLuint);
202 
204  void clear();
205 
207  void mergeLines(QString*, QTextStream*);
208 
210  void addCurrentObjMeshToWorld();
211 
212 
213 
215 // Qt Signals
217  signals:
218  void currentQuantum(int);
219 
221 // Private members
223 private:
226 
228  QString m_FileName;
229 
232 
235 
238 
241 
243  QHash<QString, int> m_CurrentMeshMaterials;
244 
247 
250 
252  QList<float> m_Positions;
253 
255  QList<float> m_Normals;
256 
258  QList<float> m_Texels;
259 
263 
267 
268 
270 
271 };
272 
273 // To use ObjVertice as a QHash key
274 inline bool operator==(const GLC_ObjToWorld::ObjVertice& vertice1, const GLC_ObjToWorld::ObjVertice& vertice2)
275 { return (vertice1.m_Values == vertice2.m_Values);}
276 
277 inline uint qHash(const GLC_ObjToWorld::ObjVertice& vertice)
278 { return qHash(QString::number(vertice.m_Values.at(0)) + QString::number(vertice.m_Values.at(1)) + QString::number(vertice.m_Values.at(2)));}
279 
280 
281 #endif /*GLC_OBJTOWORLD_H_*/

©2005-2013 Laurent Ribon