summaryrefslogtreecommitdiffstats
path: root/3rdparty/assimp/code/ObjFileData.h
blob: 7edfee51e1ecfc0085e41f78b9ef426cac5b32cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
/*
Open Asset Import Library (ASSIMP)
----------------------------------------------------------------------

Copyright (c) 2006-2010, ASSIMP Development Team
All rights reserved.

Redistribution and use of this software in source and binary forms,
with or without modification, are permitted provided that the
following conditions are met:

* Redistributions of source code must retain the above
  copyright notice, this list of conditions and the
  following disclaimer.

* Redistributions in binary form must reproduce the above
  copyright notice, this list of conditions and the
  following disclaimer in the documentation and/or other
  materials provided with the distribution.

* Neither the name of the ASSIMP team, nor the names of its
  contributors may be used to endorse or promote products
  derived from this software without specific prior
  written permission of the ASSIMP Development Team.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

----------------------------------------------------------------------
*/

#ifndef OBJ_FILEDATA_H_INC
#define OBJ_FILEDATA_H_INC

#include <vector>
#include <map>
#include "../include/aiTypes.h"
#include "../include/aiMesh.h"

namespace Assimp
{

namespace ObjFile
{
// ------------------------------------------------------------------------------------------------
struct Object;
struct Face;
struct Material;

// ------------------------------------------------------------------------------------------------
//!    \struct    Face
//!    \brief    Datastructure for a simple obj-face, descripes discredisation and materials
struct Face
{
    typedef std::vector<unsigned int> IndexArray;

    //!    Primitive type
    int m_PrimitiveType;
    //!    Vertex indices
    IndexArray *m_pVertices;
    //!    Normal indices
    IndexArray *m_pNormals;
    //!    Texture coordinates indices
    IndexArray *m_pTexturCoords;
    //!    Pointer to assigned material
    Material *m_pMaterial;

    //!    \brief    Default constructor
    //!    \param    pVertices    Pointer to assigned vertex indexbuffer
    //!    \param    pNormals    Pointer to assigned normals indexbuffer
    //!    \param    pTexCoords    Pointer to assigned texture indexbuffer
    Face( std::vector<unsigned int> *pVertices,
            std::vector<unsigned int> *pNormals,
            std::vector<unsigned int> *pTexCoords) :
        m_PrimitiveType( 2 ),
        m_pVertices( pVertices ),
        m_pNormals( pNormals ),
        m_pTexturCoords( pTexCoords ),
        m_pMaterial( 0L )
    {
        // empty
    }

    //!    \brief    Destructor
    ~Face()
    {
        delete m_pVertices;
        m_pVertices = NULL;
        delete m_pNormals;
        m_pNormals = NULL;
        delete m_pTexturCoords;
        m_pTexturCoords = NULL;
    }
};

// ------------------------------------------------------------------------------------------------
//!    \struct    Object
//!    \brief    Stores all objects of an objfile object definition
struct Object
{
    enum ObjectType
    {
        ObjType,
        GroupType
    };

    //!    Object name
    std::string m_strObjName;
    //!    Transformation matrix, stored in OpenGL format
    aiMatrix4x4 m_Transformation;
    //!    All sub-objects referenced by this object
    std::vector<Object*> m_SubObjects;
    ///    Assigned meshes
    std::vector<unsigned int> m_Meshes;

    //!    \brief    Default constructor
    Object() :
        m_strObjName("")
    {
        // empty
    }

    //!    \brief    Destructor
    ~Object()
    {
        for (std::vector<Object*>::iterator it = m_SubObjects.begin();
            it != m_SubObjects.end(); ++it)
        {
            delete *it;
        }
        m_SubObjects.clear();
    }
};

// ------------------------------------------------------------------------------------------------
//!    \struct    Material
//!    \brief    Data structure to store all material specific data
struct Material
{
    //!    Name of material description
    aiString MaterialName;

    //!    Texture names
    aiString texture;
    aiString textureSpecular;
    aiString textureAmbient;
    aiString textureBump;
    aiString textureSpecularity;
    aiString textureOpacity;

    //!    Ambient color
    aiColor3D ambient;
    //!    Diffuse color
    aiColor3D diffuse;
    //!    Speculao color
    aiColor3D specular;
    //!    Alpha value
    float alpha;
    //!    Shineness factor
    float shineness;
    //!    Illumination model
    int illumination_model;
    //! Index of refraction
    float ior;

    //!    Constructor
    Material()
        :    diffuse (0.6f,0.6f,0.6f)
        ,    alpha    (1.f)
        ,    shineness (0.0f)
        ,    illumination_model (1)
        ,    ior        (1.f)
    {
        // empty
    }

    // Destructor
    ~Material()
    {
        // empty
    }
};

// ------------------------------------------------------------------------------------------------
//!    \struct    Mesh
//!    \brief    Data structure to store a mesh
struct Mesh
{
    static const unsigned int NoMaterial = 999999999;

    ///    Array with pointer to all stored faces
    std::vector<Face*> m_Faces;
    ///    Assigned material
    Material *m_pMaterial;
    ///    Number of stored indices.
    unsigned int m_uiNumIndices;
    /// Number of UV
    unsigned int m_uiUVCoordinates[ AI_MAX_NUMBER_OF_TEXTURECOORDS ];
    ///    Material index.
    unsigned int m_uiMaterialIndex;
    ///    True, if normals are stored.
    bool m_hasNormals;
    ///    Constructor
    Mesh() :
        m_pMaterial(NULL),
        m_uiNumIndices(0),
        m_uiMaterialIndex( NoMaterial ),
        m_hasNormals(false)
    {
        memset(m_uiUVCoordinates, 0, sizeof( unsigned int ) * AI_MAX_NUMBER_OF_TEXTURECOORDS);
    }

    ///    Destructor
    ~Mesh()
    {
        for (std::vector<Face*>::iterator it = m_Faces.begin();
            it != m_Faces.end(); ++it)
        {
            delete *it;
        }

    }
};

// ------------------------------------------------------------------------------------------------
//!    \struct    Model
//!    \brief    Data structure to store all obj-specific model datas
struct Model
{
    typedef std::map<std::string*, std::vector<unsigned int>* > GroupMap;
    typedef std::map<std::string*, std::vector<unsigned int>* >::iterator GroupMapIt;
    typedef std::map<std::string*, std::vector<unsigned int>* >::const_iterator ConstGroupMapIt;

    //!    Model name
    std::string m_ModelName;
    //!    List ob assigned objects
    std::vector<Object*> m_Objects;
    //!    Pointer to current object
    ObjFile::Object *m_pCurrent;
    //!    Pointer to current material
    ObjFile::Material *m_pCurrentMaterial;
    //!    Pointer to default material
    ObjFile::Material *m_pDefaultMaterial;
    //!    Vector with all generated materials
    std::vector<std::string> m_MaterialLib;
    //!    Vector with all generated group
    std::vector<std::string> m_GroupLib;
    //!    Vector with all generated vertices
    std::vector<aiVector3D> m_Vertices;
    //!    vector with all generated normals
    std::vector<aiVector3D> m_Normals;
    //!    Groupmap
    GroupMap m_Groups;
    //!    Group to face id assignment
    std::vector<unsigned int> *m_pGroupFaceIDs;
    //!    Active group
    std::string m_strActiveGroup;
    //!    Vector with generated texture coordinates
    std::vector<aiVector2D> m_TextureCoord;
    //!    Current mesh instance
    Mesh *m_pCurrentMesh;
    //!    Vector with stored meshes
    std::vector<Mesh*> m_Meshes;
    //!    Material map
    std::map<std::string, Material*> m_MaterialMap;


    //!    \brief    Default constructor
    Model() :
        m_ModelName(""),
        m_pCurrent(NULL),
        m_pCurrentMaterial(NULL),
        m_pDefaultMaterial(NULL),
        m_strActiveGroup(""),
        m_pCurrentMesh(NULL)
    {
        // empty
    }

    //!    \brief    Destructor
    ~Model()
    {
        // Clear all stored object instances
        for (std::vector<Object*>::iterator it = m_Objects.begin();
            it != m_Objects.end(); ++it)
        {
            delete *it;
        }
        m_Objects.clear();

        // Clear all stored mesh instances
        for (std::vector<Mesh*>::iterator it = m_Meshes.begin();
            it != m_Meshes.end(); ++it)
        {
            delete *it;
        }

        m_Meshes.clear();

        for (GroupMapIt it = m_Groups.begin();
            it != m_Groups.end(); ++it)
        {
            delete it->second;
        }

        m_Groups.clear();
    }
};

// ------------------------------------------------------------------------------------------------

} // Namespace ObjFile
} // Namespace Assimp

#endif