2008-05-09 17:24:28 +00:00
|
|
|
/*
|
2008-05-22 10:20:31 +00:00
|
|
|
Open Asset Import Library (ASSIMP)
|
2008-05-09 17:24:28 +00:00
|
|
|
----------------------------------------------------------------------
|
|
|
|
|
2010-04-10 15:30:22 +00:00
|
|
|
Copyright (c) 2006-2010, ASSIMP Development Team
|
2008-05-09 17:24:28 +00:00
|
|
|
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.
|
|
|
|
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
#ifndef OBJ_FILEDATA_H_INC
|
|
|
|
#define OBJ_FILEDATA_H_INC
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <map>
|
2008-05-21 15:35:28 +00:00
|
|
|
#include "../include/aiTypes.h"
|
2008-08-14 21:25:50 +00:00
|
|
|
#include "../include/aiMesh.h"
|
2008-05-05 12:36:31 +00:00
|
|
|
|
|
|
|
namespace Assimp
|
|
|
|
{
|
|
|
|
|
|
|
|
namespace ObjFile
|
|
|
|
{
|
2008-06-03 21:32:56 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2008-05-05 12:36:31 +00:00
|
|
|
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
|
2009-08-02 17:11:38 +00:00
|
|
|
Face( std::vector<unsigned int> *pVertices,
|
2008-05-05 12:36:31 +00:00
|
|
|
std::vector<unsigned int> *pNormals,
|
|
|
|
std::vector<unsigned int> *pTexCoords) :
|
2008-07-02 18:12:54 +00:00
|
|
|
m_PrimitiveType( 2 ),
|
|
|
|
m_pVertices( pVertices ),
|
|
|
|
m_pNormals( pNormals ),
|
|
|
|
m_pTexturCoords( pTexCoords ),
|
|
|
|
m_pMaterial( 0L )
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
// empty
|
|
|
|
}
|
|
|
|
|
|
|
|
//! \brief Destructor
|
|
|
|
~Face()
|
|
|
|
{
|
2009-08-02 17:11:38 +00:00
|
|
|
delete m_pVertices;
|
|
|
|
m_pVertices = NULL;
|
|
|
|
delete m_pNormals;
|
|
|
|
m_pNormals = NULL;
|
|
|
|
delete m_pTexturCoords;
|
|
|
|
m_pTexturCoords = NULL;
|
2008-05-05 12:36:31 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
//! \struct Object
|
|
|
|
//! \brief Stores all objects of an objfile object definition
|
|
|
|
struct Object
|
|
|
|
{
|
|
|
|
//! Obejct name
|
|
|
|
std::string m_strObjName;
|
|
|
|
//! Assigend face instances
|
|
|
|
std::vector<Face*> m_Faces;
|
|
|
|
//! Transformation matrix, stored in OpenGL format
|
|
|
|
aiMatrix4x4 m_Transformation;
|
|
|
|
//! All subobjects references by this object
|
|
|
|
std::vector<Object*> m_SubObjects;
|
|
|
|
|
|
|
|
//! \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
|
|
|
|
{
|
2009-02-05 18:13:34 +00:00
|
|
|
//! Name of material description
|
2008-05-05 12:36:31 +00:00
|
|
|
aiString MaterialName;
|
2009-01-18 23:48:25 +00:00
|
|
|
|
|
|
|
//! Texture names
|
2008-05-05 12:36:31 +00:00
|
|
|
aiString texture;
|
2009-01-18 23:48:25 +00:00
|
|
|
aiString textureSpecular;
|
|
|
|
aiString textureAmbient;
|
|
|
|
aiString textureBump;
|
|
|
|
aiString textureSpecularity;
|
2009-02-05 18:13:34 +00:00
|
|
|
aiString textureOpacity;
|
2009-01-18 23:48:25 +00:00
|
|
|
|
2008-06-03 21:32:56 +00:00
|
|
|
//! Ambient color
|
2008-05-05 12:36:31 +00:00
|
|
|
aiColor3D ambient;
|
2008-06-03 21:32:56 +00:00
|
|
|
//! Diffuse color
|
2008-05-05 12:36:31 +00:00
|
|
|
aiColor3D diffuse;
|
2008-06-03 21:32:56 +00:00
|
|
|
//! Speculao color
|
2008-05-05 12:36:31 +00:00
|
|
|
aiColor3D specular;
|
2008-06-03 21:32:56 +00:00
|
|
|
//! Alpha value
|
2008-05-05 12:36:31 +00:00
|
|
|
float alpha;
|
2008-06-03 21:32:56 +00:00
|
|
|
//! Shineness factor
|
2008-05-05 12:36:31 +00:00
|
|
|
float shineness;
|
2008-06-03 21:32:56 +00:00
|
|
|
//! Illumination model
|
2008-05-05 12:36:31 +00:00
|
|
|
int illumination_model;
|
2009-02-05 18:13:34 +00:00
|
|
|
//! Index of refraction
|
|
|
|
float ior;
|
2008-07-02 18:12:54 +00:00
|
|
|
|
2008-08-14 21:25:50 +00:00
|
|
|
//! Constructor
|
2008-07-02 18:12:54 +00:00
|
|
|
Material()
|
2009-02-05 18:13:34 +00:00
|
|
|
: diffuse (0.6f,0.6f,0.6f)
|
|
|
|
, alpha (1.f)
|
2009-03-04 19:46:18 +00:00
|
|
|
, shineness (0.0f)
|
2009-02-05 18:13:34 +00:00
|
|
|
, illumination_model (1)
|
2010-02-06 23:52:41 +00:00
|
|
|
, ior (1.f)
|
2008-07-02 18:12:54 +00:00
|
|
|
{
|
2008-08-14 21:25:50 +00:00
|
|
|
// empty
|
2008-07-02 18:12:54 +00:00
|
|
|
}
|
|
|
|
|
2008-08-14 21:25:50 +00:00
|
|
|
// Destructor
|
2008-07-02 18:12:54 +00:00
|
|
|
~Material()
|
|
|
|
{
|
2008-08-14 21:25:50 +00:00
|
|
|
// empty
|
2008-07-02 18:12:54 +00:00
|
|
|
}
|
2008-05-05 12:36:31 +00:00
|
|
|
};
|
|
|
|
|
2008-06-03 21:32:56 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
//! \struct Mesh
|
|
|
|
//! \brief Data structure to store a mesh
|
|
|
|
struct Mesh
|
|
|
|
{
|
2008-08-14 21:25:50 +00:00
|
|
|
/// Array with pointer to all stored faces
|
2008-06-03 21:32:56 +00:00
|
|
|
std::vector<Face*> m_Faces;
|
2008-08-14 21:25:50 +00:00
|
|
|
/// Assigned material
|
2008-06-03 21:32:56 +00:00
|
|
|
Material *m_pMaterial;
|
2008-08-14 21:25:50 +00:00
|
|
|
/// Number of stored indices.
|
2008-07-02 18:12:54 +00:00
|
|
|
unsigned int m_uiNumIndices;
|
2008-08-14 21:25:50 +00:00
|
|
|
/// Number of UV
|
|
|
|
unsigned int m_uiUVCoordinates[ AI_MAX_NUMBER_OF_TEXTURECOORDS ];
|
|
|
|
/// Material index.
|
2008-07-02 18:12:54 +00:00
|
|
|
unsigned int m_uiMaterialIndex;
|
2009-08-02 17:11:38 +00:00
|
|
|
/// True, if normals are stored.
|
2008-09-22 08:16:37 +00:00
|
|
|
bool m_hasNormals;
|
2008-08-14 21:25:50 +00:00
|
|
|
/// Constructor
|
2008-06-03 21:32:56 +00:00
|
|
|
Mesh() :
|
2008-07-02 18:12:54 +00:00
|
|
|
m_pMaterial(NULL),
|
|
|
|
m_uiNumIndices(0),
|
2008-09-22 08:16:37 +00:00
|
|
|
m_uiMaterialIndex(0),
|
|
|
|
m_hasNormals(false)
|
2008-07-02 18:12:54 +00:00
|
|
|
{
|
2008-08-14 21:25:50 +00:00
|
|
|
memset(m_uiUVCoordinates, 0, sizeof( unsigned int ) * AI_MAX_NUMBER_OF_TEXTURECOORDS);
|
2008-07-02 18:12:54 +00:00
|
|
|
}
|
|
|
|
|
2008-08-14 21:25:50 +00:00
|
|
|
/// Destructor
|
2008-07-02 18:12:54 +00:00
|
|
|
~Mesh()
|
2008-06-03 21:32:56 +00:00
|
|
|
{
|
2008-09-22 08:16:37 +00:00
|
|
|
for (std::vector<Face*>::iterator it = m_Faces.begin();
|
|
|
|
it != m_Faces.end(); ++it)
|
|
|
|
{
|
|
|
|
delete *it;
|
|
|
|
}
|
|
|
|
|
2008-06-03 21:32:56 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
//! \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
|
2009-04-19 10:36:36 +00:00
|
|
|
std::vector<aiVector3D> m_Vertices;
|
2008-05-05 12:36:31 +00:00
|
|
|
//! vector with all generated normals
|
2009-04-19 10:36:36 +00:00
|
|
|
std::vector<aiVector3D> m_Normals;
|
2008-05-05 12:36:31 +00:00
|
|
|
//! Groupmap
|
|
|
|
GroupMap m_Groups;
|
2008-05-16 17:57:48 +00:00
|
|
|
//! Group to face id assignment
|
2008-05-05 12:36:31 +00:00
|
|
|
std::vector<unsigned int> *m_pGroupFaceIDs;
|
|
|
|
//! Active group
|
|
|
|
std::string m_strActiveGroup;
|
|
|
|
//! Vector with generated texture coordinates
|
2009-04-19 10:36:36 +00:00
|
|
|
std::vector<aiVector2D> m_TextureCoord;
|
2008-06-03 21:32:56 +00:00
|
|
|
//! Current mesh instance
|
|
|
|
Mesh *m_pCurrentMesh;
|
|
|
|
//! Vector with stored meshes
|
|
|
|
std::vector<Mesh*> m_Meshes;
|
2008-05-05 12:36:31 +00:00
|
|
|
//! Material map
|
|
|
|
std::map<std::string, Material*> m_MaterialMap;
|
|
|
|
|
2008-06-03 21:32:56 +00:00
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
//! \brief Default constructor
|
|
|
|
Model() :
|
|
|
|
m_ModelName(""),
|
|
|
|
m_pCurrent(NULL),
|
|
|
|
m_pCurrentMaterial(NULL),
|
|
|
|
m_pDefaultMaterial(NULL),
|
2008-06-03 21:32:56 +00:00
|
|
|
m_strActiveGroup(""),
|
|
|
|
m_pCurrentMesh(NULL)
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
// empty
|
|
|
|
}
|
|
|
|
|
2008-06-03 21:32:56 +00:00
|
|
|
//! \brief Destructor
|
2008-05-05 12:36:31 +00:00
|
|
|
~Model()
|
|
|
|
{
|
2008-06-03 21:32:56 +00:00
|
|
|
// Clear all stored object instances
|
2008-05-05 12:36:31 +00:00
|
|
|
for (std::vector<Object*>::iterator it = m_Objects.begin();
|
2008-06-03 21:32:56 +00:00
|
|
|
it != m_Objects.end(); ++it)
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
delete *it;
|
|
|
|
}
|
|
|
|
m_Objects.clear();
|
2008-06-03 21:32:56 +00:00
|
|
|
|
|
|
|
// Clear all stored mesh instances
|
|
|
|
for (std::vector<Mesh*>::iterator it = m_Meshes.begin();
|
|
|
|
it != m_Meshes.end(); ++it)
|
|
|
|
{
|
|
|
|
delete *it;
|
|
|
|
}
|
2008-09-22 08:16:37 +00:00
|
|
|
|
2008-06-03 21:32:56 +00:00
|
|
|
m_Meshes.clear();
|
2008-09-22 08:16:37 +00:00
|
|
|
|
|
|
|
for(GroupMapIt it = m_Groups.begin();
|
|
|
|
it != m_Groups.end(); ++it)
|
|
|
|
{
|
|
|
|
delete it->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_Groups.clear();
|
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2008-08-14 21:25:50 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
} // Namespace ObjFile
|
|
|
|
} // Namespace Assimp
|
|
|
|
|
|
|
|
#endif
|