vrshoot

view libs/assimp/ObjFileData.h @ 0:b2f14e535253

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 01 Feb 2014 19:58:19 +0200
parents
children
line source
1 /*
2 Open Asset Import Library (assimp)
3 ----------------------------------------------------------------------
5 Copyright (c) 2006-2012, assimp team
6 All rights reserved.
8 Redistribution and use of this software in source and binary forms,
9 with or without modification, are permitted provided that the
10 following conditions are met:
12 * Redistributions of source code must retain the above
13 copyright notice, this list of conditions and the
14 following disclaimer.
16 * Redistributions in binary form must reproduce the above
17 copyright notice, this list of conditions and the
18 following disclaimer in the documentation and/or other
19 materials provided with the distribution.
21 * Neither the name of the assimp team, nor the names of its
22 contributors may be used to endorse or promote products
23 derived from this software without specific prior
24 written permission of the assimp team.
26 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 ----------------------------------------------------------------------
39 */
41 #ifndef OBJ_FILEDATA_H_INC
42 #define OBJ_FILEDATA_H_INC
44 #include <vector>
45 #include <map>
46 #include "assimp/types.h"
47 #include "assimp/mesh.h"
49 namespace Assimp
50 {
52 namespace ObjFile
53 {
54 // ------------------------------------------------------------------------------------------------
55 struct Object;
56 struct Face;
57 struct Material;
59 // ------------------------------------------------------------------------------------------------
60 //! \struct Face
61 //! \brief Data structure for a simple obj-face, describes discredit,l.ation and materials
62 struct Face
63 {
64 typedef std::vector<unsigned int> IndexArray;
66 //! Primitive type
67 aiPrimitiveType m_PrimitiveType;
68 //! Vertex indices
69 IndexArray *m_pVertices;
70 //! Normal indices
71 IndexArray *m_pNormals;
72 //! Texture coordinates indices
73 IndexArray *m_pTexturCoords;
74 //! Pointer to assigned material
75 Material *m_pMaterial;
77 //! \brief Default constructor
78 //! \param pVertices Pointer to assigned vertex indexbuffer
79 //! \param pNormals Pointer to assigned normals indexbuffer
80 //! \param pTexCoords Pointer to assigned texture indexbuffer
81 Face( std::vector<unsigned int> *pVertices,
82 std::vector<unsigned int> *pNormals,
83 std::vector<unsigned int> *pTexCoords,
84 aiPrimitiveType pt = aiPrimitiveType_POLYGON) :
85 m_PrimitiveType( pt ),
86 m_pVertices( pVertices ),
87 m_pNormals( pNormals ),
88 m_pTexturCoords( pTexCoords ),
89 m_pMaterial( 0L )
90 {
91 // empty
92 }
94 //! \brief Destructor
95 ~Face()
96 {
97 delete m_pVertices;
98 m_pVertices = NULL;
100 delete m_pNormals;
101 m_pNormals = NULL;
103 delete m_pTexturCoords;
104 m_pTexturCoords = NULL;
105 }
106 };
108 // ------------------------------------------------------------------------------------------------
109 //! \struct Object
110 //! \brief Stores all objects of an objfile object definition
111 struct Object
112 {
113 enum ObjectType
114 {
115 ObjType,
116 GroupType
117 };
119 //! Object name
120 std::string m_strObjName;
121 //! Transformation matrix, stored in OpenGL format
122 aiMatrix4x4 m_Transformation;
123 //! All sub-objects referenced by this object
124 std::vector<Object*> m_SubObjects;
125 /// Assigned meshes
126 std::vector<unsigned int> m_Meshes;
128 //! \brief Default constructor
129 Object() :
130 m_strObjName("")
131 {
132 // empty
133 }
135 //! \brief Destructor
136 ~Object()
137 {
138 for (std::vector<Object*>::iterator it = m_SubObjects.begin();
139 it != m_SubObjects.end(); ++it)
140 {
141 delete *it;
142 }
143 m_SubObjects.clear();
144 }
145 };
147 // ------------------------------------------------------------------------------------------------
148 //! \struct Material
149 //! \brief Data structure to store all material specific data
150 struct Material
151 {
152 //! Name of material description
153 aiString MaterialName;
155 //! Texture names
156 aiString texture;
157 aiString textureSpecular;
158 aiString textureAmbient;
159 aiString textureBump;
160 aiString textureNormal;
161 aiString textureSpecularity;
162 aiString textureOpacity;
163 aiString textureDisp;
165 //! Ambient color
166 aiColor3D ambient;
167 //! Diffuse color
168 aiColor3D diffuse;
169 //! Specular color
170 aiColor3D specular;
171 //! Alpha value
172 float alpha;
173 //! Shineness factor
174 float shineness;
175 //! Illumination model
176 int illumination_model;
177 //! Index of refraction
178 float ior;
180 //! Constructor
181 Material()
182 : diffuse (0.6f,0.6f,0.6f)
183 , alpha (1.f)
184 , shineness (0.0f)
185 , illumination_model (1)
186 , ior (1.f)
187 {
188 // empty
189 }
191 // Destructor
192 ~Material()
193 {
194 // empty
195 }
196 };
198 // ------------------------------------------------------------------------------------------------
199 //! \struct Mesh
200 //! \brief Data structure to store a mesh
201 struct Mesh
202 {
203 static const unsigned int NoMaterial = ~0u;
205 /// Array with pointer to all stored faces
206 std::vector<Face*> m_Faces;
207 /// Assigned material
208 Material *m_pMaterial;
209 /// Number of stored indices.
210 unsigned int m_uiNumIndices;
211 /// Number of UV
212 unsigned int m_uiUVCoordinates[ AI_MAX_NUMBER_OF_TEXTURECOORDS ];
213 /// Material index.
214 unsigned int m_uiMaterialIndex;
215 /// True, if normals are stored.
216 bool m_hasNormals;
217 /// Constructor
218 Mesh() :
219 m_pMaterial(NULL),
220 m_uiNumIndices(0),
221 m_uiMaterialIndex( NoMaterial ),
222 m_hasNormals(false)
223 {
224 memset(m_uiUVCoordinates, 0, sizeof( unsigned int ) * AI_MAX_NUMBER_OF_TEXTURECOORDS);
225 }
227 /// Destructor
228 ~Mesh()
229 {
230 for (std::vector<Face*>::iterator it = m_Faces.begin();
231 it != m_Faces.end(); ++it)
232 {
233 delete *it;
234 }
235 }
236 };
238 // ------------------------------------------------------------------------------------------------
239 //! \struct Model
240 //! \brief Data structure to store all obj-specific model datas
241 struct Model
242 {
243 typedef std::map<std::string, std::vector<unsigned int>* > GroupMap;
244 typedef std::map<std::string, std::vector<unsigned int>* >::iterator GroupMapIt;
245 typedef std::map<std::string, std::vector<unsigned int>* >::const_iterator ConstGroupMapIt;
247 //! Model name
248 std::string m_ModelName;
249 //! List ob assigned objects
250 std::vector<Object*> m_Objects;
251 //! Pointer to current object
252 ObjFile::Object *m_pCurrent;
253 //! Pointer to current material
254 ObjFile::Material *m_pCurrentMaterial;
255 //! Pointer to default material
256 ObjFile::Material *m_pDefaultMaterial;
257 //! Vector with all generated materials
258 std::vector<std::string> m_MaterialLib;
259 //! Vector with all generated group
260 std::vector<std::string> m_GroupLib;
261 //! Vector with all generated vertices
262 std::vector<aiVector3D> m_Vertices;
263 //! vector with all generated normals
264 std::vector<aiVector3D> m_Normals;
265 //! Group map
266 GroupMap m_Groups;
267 //! Group to face id assignment
268 std::vector<unsigned int> *m_pGroupFaceIDs;
269 //! Active group
270 std::string m_strActiveGroup;
271 //! Vector with generated texture coordinates
272 std::vector<aiVector2D> m_TextureCoord;
273 //! Current mesh instance
274 Mesh *m_pCurrentMesh;
275 //! Vector with stored meshes
276 std::vector<Mesh*> m_Meshes;
277 //! Material map
278 std::map<std::string, Material*> m_MaterialMap;
280 //! \brief Default constructor
281 Model() :
282 m_ModelName(""),
283 m_pCurrent(NULL),
284 m_pCurrentMaterial(NULL),
285 m_pDefaultMaterial(NULL),
286 m_pGroupFaceIDs(NULL),
287 m_strActiveGroup(""),
288 m_pCurrentMesh(NULL)
289 {
290 // empty
291 }
293 //! \brief Destructor
294 ~Model()
295 {
296 // Clear all stored object instances
297 for (std::vector<Object*>::iterator it = m_Objects.begin();
298 it != m_Objects.end(); ++it) {
299 delete *it;
300 }
301 m_Objects.clear();
303 // Clear all stored mesh instances
304 for (std::vector<Mesh*>::iterator it = m_Meshes.begin();
305 it != m_Meshes.end(); ++it) {
306 delete *it;
307 }
308 m_Meshes.clear();
310 for(GroupMapIt it = m_Groups.begin(); it != m_Groups.end(); ++it) {
311 delete it->second;
312 }
313 m_Groups.clear();
315 for ( std::map<std::string, Material*>::iterator it = m_MaterialMap.begin(); it != m_MaterialMap.end(); ++it ) {
316 delete it->second;
317 }
318 }
319 };
321 // ------------------------------------------------------------------------------------------------
323 } // Namespace ObjFile
324 } // Namespace Assimp
326 #endif