vrshoot
diff 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 diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/libs/assimp/ObjFileData.h Sat Feb 01 19:58:19 2014 +0200 1.3 @@ -0,0 +1,326 @@ 1.4 +/* 1.5 +Open Asset Import Library (assimp) 1.6 +---------------------------------------------------------------------- 1.7 + 1.8 +Copyright (c) 2006-2012, assimp team 1.9 +All rights reserved. 1.10 + 1.11 +Redistribution and use of this software in source and binary forms, 1.12 +with or without modification, are permitted provided that the 1.13 +following conditions are met: 1.14 + 1.15 +* Redistributions of source code must retain the above 1.16 + copyright notice, this list of conditions and the 1.17 + following disclaimer. 1.18 + 1.19 +* Redistributions in binary form must reproduce the above 1.20 + copyright notice, this list of conditions and the 1.21 + following disclaimer in the documentation and/or other 1.22 + materials provided with the distribution. 1.23 + 1.24 +* Neither the name of the assimp team, nor the names of its 1.25 + contributors may be used to endorse or promote products 1.26 + derived from this software without specific prior 1.27 + written permission of the assimp team. 1.28 + 1.29 +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1.30 +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1.31 +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1.32 +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 1.33 +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 1.34 +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 1.35 +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 1.36 +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 1.37 +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 1.38 +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 1.39 +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 1.40 + 1.41 +---------------------------------------------------------------------- 1.42 +*/ 1.43 + 1.44 +#ifndef OBJ_FILEDATA_H_INC 1.45 +#define OBJ_FILEDATA_H_INC 1.46 + 1.47 +#include <vector> 1.48 +#include <map> 1.49 +#include "assimp/types.h" 1.50 +#include "assimp/mesh.h" 1.51 + 1.52 +namespace Assimp 1.53 +{ 1.54 + 1.55 +namespace ObjFile 1.56 +{ 1.57 +// ------------------------------------------------------------------------------------------------ 1.58 +struct Object; 1.59 +struct Face; 1.60 +struct Material; 1.61 + 1.62 +// ------------------------------------------------------------------------------------------------ 1.63 +//! \struct Face 1.64 +//! \brief Data structure for a simple obj-face, describes discredit,l.ation and materials 1.65 +struct Face 1.66 +{ 1.67 + typedef std::vector<unsigned int> IndexArray; 1.68 + 1.69 + //! Primitive type 1.70 + aiPrimitiveType m_PrimitiveType; 1.71 + //! Vertex indices 1.72 + IndexArray *m_pVertices; 1.73 + //! Normal indices 1.74 + IndexArray *m_pNormals; 1.75 + //! Texture coordinates indices 1.76 + IndexArray *m_pTexturCoords; 1.77 + //! Pointer to assigned material 1.78 + Material *m_pMaterial; 1.79 + 1.80 + //! \brief Default constructor 1.81 + //! \param pVertices Pointer to assigned vertex indexbuffer 1.82 + //! \param pNormals Pointer to assigned normals indexbuffer 1.83 + //! \param pTexCoords Pointer to assigned texture indexbuffer 1.84 + Face( std::vector<unsigned int> *pVertices, 1.85 + std::vector<unsigned int> *pNormals, 1.86 + std::vector<unsigned int> *pTexCoords, 1.87 + aiPrimitiveType pt = aiPrimitiveType_POLYGON) : 1.88 + m_PrimitiveType( pt ), 1.89 + m_pVertices( pVertices ), 1.90 + m_pNormals( pNormals ), 1.91 + m_pTexturCoords( pTexCoords ), 1.92 + m_pMaterial( 0L ) 1.93 + { 1.94 + // empty 1.95 + } 1.96 + 1.97 + //! \brief Destructor 1.98 + ~Face() 1.99 + { 1.100 + delete m_pVertices; 1.101 + m_pVertices = NULL; 1.102 + 1.103 + delete m_pNormals; 1.104 + m_pNormals = NULL; 1.105 + 1.106 + delete m_pTexturCoords; 1.107 + m_pTexturCoords = NULL; 1.108 + } 1.109 +}; 1.110 + 1.111 +// ------------------------------------------------------------------------------------------------ 1.112 +//! \struct Object 1.113 +//! \brief Stores all objects of an objfile object definition 1.114 +struct Object 1.115 +{ 1.116 + enum ObjectType 1.117 + { 1.118 + ObjType, 1.119 + GroupType 1.120 + }; 1.121 + 1.122 + //! Object name 1.123 + std::string m_strObjName; 1.124 + //! Transformation matrix, stored in OpenGL format 1.125 + aiMatrix4x4 m_Transformation; 1.126 + //! All sub-objects referenced by this object 1.127 + std::vector<Object*> m_SubObjects; 1.128 + /// Assigned meshes 1.129 + std::vector<unsigned int> m_Meshes; 1.130 + 1.131 + //! \brief Default constructor 1.132 + Object() : 1.133 + m_strObjName("") 1.134 + { 1.135 + // empty 1.136 + } 1.137 + 1.138 + //! \brief Destructor 1.139 + ~Object() 1.140 + { 1.141 + for (std::vector<Object*>::iterator it = m_SubObjects.begin(); 1.142 + it != m_SubObjects.end(); ++it) 1.143 + { 1.144 + delete *it; 1.145 + } 1.146 + m_SubObjects.clear(); 1.147 + } 1.148 +}; 1.149 + 1.150 +// ------------------------------------------------------------------------------------------------ 1.151 +//! \struct Material 1.152 +//! \brief Data structure to store all material specific data 1.153 +struct Material 1.154 +{ 1.155 + //! Name of material description 1.156 + aiString MaterialName; 1.157 + 1.158 + //! Texture names 1.159 + aiString texture; 1.160 + aiString textureSpecular; 1.161 + aiString textureAmbient; 1.162 + aiString textureBump; 1.163 + aiString textureNormal; 1.164 + aiString textureSpecularity; 1.165 + aiString textureOpacity; 1.166 + aiString textureDisp; 1.167 + 1.168 + //! Ambient color 1.169 + aiColor3D ambient; 1.170 + //! Diffuse color 1.171 + aiColor3D diffuse; 1.172 + //! Specular color 1.173 + aiColor3D specular; 1.174 + //! Alpha value 1.175 + float alpha; 1.176 + //! Shineness factor 1.177 + float shineness; 1.178 + //! Illumination model 1.179 + int illumination_model; 1.180 + //! Index of refraction 1.181 + float ior; 1.182 + 1.183 + //! Constructor 1.184 + Material() 1.185 + : diffuse (0.6f,0.6f,0.6f) 1.186 + , alpha (1.f) 1.187 + , shineness (0.0f) 1.188 + , illumination_model (1) 1.189 + , ior (1.f) 1.190 + { 1.191 + // empty 1.192 + } 1.193 + 1.194 + // Destructor 1.195 + ~Material() 1.196 + { 1.197 + // empty 1.198 + } 1.199 +}; 1.200 + 1.201 +// ------------------------------------------------------------------------------------------------ 1.202 +//! \struct Mesh 1.203 +//! \brief Data structure to store a mesh 1.204 +struct Mesh 1.205 +{ 1.206 + static const unsigned int NoMaterial = ~0u; 1.207 + 1.208 + /// Array with pointer to all stored faces 1.209 + std::vector<Face*> m_Faces; 1.210 + /// Assigned material 1.211 + Material *m_pMaterial; 1.212 + /// Number of stored indices. 1.213 + unsigned int m_uiNumIndices; 1.214 + /// Number of UV 1.215 + unsigned int m_uiUVCoordinates[ AI_MAX_NUMBER_OF_TEXTURECOORDS ]; 1.216 + /// Material index. 1.217 + unsigned int m_uiMaterialIndex; 1.218 + /// True, if normals are stored. 1.219 + bool m_hasNormals; 1.220 + /// Constructor 1.221 + Mesh() : 1.222 + m_pMaterial(NULL), 1.223 + m_uiNumIndices(0), 1.224 + m_uiMaterialIndex( NoMaterial ), 1.225 + m_hasNormals(false) 1.226 + { 1.227 + memset(m_uiUVCoordinates, 0, sizeof( unsigned int ) * AI_MAX_NUMBER_OF_TEXTURECOORDS); 1.228 + } 1.229 + 1.230 + /// Destructor 1.231 + ~Mesh() 1.232 + { 1.233 + for (std::vector<Face*>::iterator it = m_Faces.begin(); 1.234 + it != m_Faces.end(); ++it) 1.235 + { 1.236 + delete *it; 1.237 + } 1.238 + } 1.239 +}; 1.240 + 1.241 +// ------------------------------------------------------------------------------------------------ 1.242 +//! \struct Model 1.243 +//! \brief Data structure to store all obj-specific model datas 1.244 +struct Model 1.245 +{ 1.246 + typedef std::map<std::string, std::vector<unsigned int>* > GroupMap; 1.247 + typedef std::map<std::string, std::vector<unsigned int>* >::iterator GroupMapIt; 1.248 + typedef std::map<std::string, std::vector<unsigned int>* >::const_iterator ConstGroupMapIt; 1.249 + 1.250 + //! Model name 1.251 + std::string m_ModelName; 1.252 + //! List ob assigned objects 1.253 + std::vector<Object*> m_Objects; 1.254 + //! Pointer to current object 1.255 + ObjFile::Object *m_pCurrent; 1.256 + //! Pointer to current material 1.257 + ObjFile::Material *m_pCurrentMaterial; 1.258 + //! Pointer to default material 1.259 + ObjFile::Material *m_pDefaultMaterial; 1.260 + //! Vector with all generated materials 1.261 + std::vector<std::string> m_MaterialLib; 1.262 + //! Vector with all generated group 1.263 + std::vector<std::string> m_GroupLib; 1.264 + //! Vector with all generated vertices 1.265 + std::vector<aiVector3D> m_Vertices; 1.266 + //! vector with all generated normals 1.267 + std::vector<aiVector3D> m_Normals; 1.268 + //! Group map 1.269 + GroupMap m_Groups; 1.270 + //! Group to face id assignment 1.271 + std::vector<unsigned int> *m_pGroupFaceIDs; 1.272 + //! Active group 1.273 + std::string m_strActiveGroup; 1.274 + //! Vector with generated texture coordinates 1.275 + std::vector<aiVector2D> m_TextureCoord; 1.276 + //! Current mesh instance 1.277 + Mesh *m_pCurrentMesh; 1.278 + //! Vector with stored meshes 1.279 + std::vector<Mesh*> m_Meshes; 1.280 + //! Material map 1.281 + std::map<std::string, Material*> m_MaterialMap; 1.282 + 1.283 + //! \brief Default constructor 1.284 + Model() : 1.285 + m_ModelName(""), 1.286 + m_pCurrent(NULL), 1.287 + m_pCurrentMaterial(NULL), 1.288 + m_pDefaultMaterial(NULL), 1.289 + m_pGroupFaceIDs(NULL), 1.290 + m_strActiveGroup(""), 1.291 + m_pCurrentMesh(NULL) 1.292 + { 1.293 + // empty 1.294 + } 1.295 + 1.296 + //! \brief Destructor 1.297 + ~Model() 1.298 + { 1.299 + // Clear all stored object instances 1.300 + for (std::vector<Object*>::iterator it = m_Objects.begin(); 1.301 + it != m_Objects.end(); ++it) { 1.302 + delete *it; 1.303 + } 1.304 + m_Objects.clear(); 1.305 + 1.306 + // Clear all stored mesh instances 1.307 + for (std::vector<Mesh*>::iterator it = m_Meshes.begin(); 1.308 + it != m_Meshes.end(); ++it) { 1.309 + delete *it; 1.310 + } 1.311 + m_Meshes.clear(); 1.312 + 1.313 + for(GroupMapIt it = m_Groups.begin(); it != m_Groups.end(); ++it) { 1.314 + delete it->second; 1.315 + } 1.316 + m_Groups.clear(); 1.317 + 1.318 + for ( std::map<std::string, Material*>::iterator it = m_MaterialMap.begin(); it != m_MaterialMap.end(); ++it ) { 1.319 + delete it->second; 1.320 + } 1.321 + } 1.322 +}; 1.323 + 1.324 +// ------------------------------------------------------------------------------------------------ 1.325 + 1.326 +} // Namespace ObjFile 1.327 +} // Namespace Assimp 1.328 + 1.329 +#endif