ObjFileData.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. /*
  2. Open Asset Import Library (ASSIMP)
  3. ----------------------------------------------------------------------
  4. Copyright (c) 2006-2008, ASSIMP Development Team
  5. All rights reserved.
  6. Redistribution and use of this software in source and binary forms,
  7. with or without modification, are permitted provided that the
  8. following conditions are met:
  9. * Redistributions of source code must retain the above
  10. copyright notice, this list of conditions and the
  11. following disclaimer.
  12. * Redistributions in binary form must reproduce the above
  13. copyright notice, this list of conditions and the
  14. following disclaimer in the documentation and/or other
  15. materials provided with the distribution.
  16. * Neither the name of the ASSIMP team, nor the names of its
  17. contributors may be used to endorse or promote products
  18. derived from this software without specific prior
  19. written permission of the ASSIMP Development Team.
  20. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  23. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  24. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  25. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  26. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  27. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. ----------------------------------------------------------------------
  32. */
  33. #ifndef OBJ_FILEDATA_H_INC
  34. #define OBJ_FILEDATA_H_INC
  35. #include <vector>
  36. #include <map>
  37. #include "../include/aiTypes.h"
  38. #include "../include/aiMesh.h"
  39. namespace Assimp
  40. {
  41. namespace ObjFile
  42. {
  43. // ------------------------------------------------------------------------------------------------
  44. struct Object;
  45. struct Face;
  46. struct Material;
  47. // ------------------------------------------------------------------------------------------------
  48. //! \struct Face
  49. //! \brief Datastructure for a simple obj-face, descripes discredisation and materials
  50. struct Face
  51. {
  52. typedef std::vector<unsigned int> IndexArray;
  53. //! Primitive type
  54. int m_PrimitiveType;
  55. //! Vertex indices
  56. IndexArray *m_pVertices;
  57. //! Normal indices
  58. IndexArray *m_pNormals;
  59. //! Texture coordinates indices
  60. IndexArray *m_pTexturCoords;
  61. //! Pointer to assigned material
  62. Material *m_pMaterial;
  63. //! \brief Default constructor
  64. //! \param pVertices Pointer to assigned vertex indexbuffer
  65. //! \param pNormals Pointer to assigned normals indexbuffer
  66. //! \param pTexCoords Pointer to assigned texture indexbuffer
  67. Face(std::vector<unsigned int> *pVertices,
  68. std::vector<unsigned int> *pNormals,
  69. std::vector<unsigned int> *pTexCoords) :
  70. m_PrimitiveType( 2 ),
  71. m_pVertices( pVertices ),
  72. m_pNormals( pNormals ),
  73. m_pTexturCoords( pTexCoords ),
  74. m_pMaterial( 0L )
  75. {
  76. // empty
  77. }
  78. //! \brief Destructor
  79. ~Face()
  80. {
  81. // empty
  82. }
  83. };
  84. // ------------------------------------------------------------------------------------------------
  85. //! \struct Object
  86. //! \brief Stores all objects of an objfile object definition
  87. struct Object
  88. {
  89. //! Obejct name
  90. std::string m_strObjName;
  91. //! Assigend face instances
  92. std::vector<Face*> m_Faces;
  93. //! Transformation matrix, stored in OpenGL format
  94. aiMatrix4x4 m_Transformation;
  95. //! All subobjects references by this object
  96. std::vector<Object*> m_SubObjects;
  97. //! \brief Default constructor
  98. Object() :
  99. m_strObjName("")
  100. {
  101. // empty
  102. }
  103. //! \brief Destructor
  104. ~Object()
  105. {
  106. for (std::vector<Object*>::iterator it = m_SubObjects.begin();
  107. it != m_SubObjects.end(); ++it)
  108. {
  109. delete *it;
  110. }
  111. m_SubObjects.clear();
  112. }
  113. };
  114. // ------------------------------------------------------------------------------------------------
  115. //! \struct Material
  116. //! \brief Data structure to store all material specific data
  117. struct Material
  118. {
  119. //! NAme of material description
  120. aiString MaterialName;
  121. //! Name of used texture
  122. aiString texture;
  123. //! Ambient color
  124. aiColor3D ambient;
  125. //! Diffuse color
  126. aiColor3D diffuse;
  127. //! Speculao color
  128. aiColor3D specular;
  129. //! Alpha value
  130. float alpha;
  131. //! Shineness factor
  132. float shineness;
  133. //! Illumination model
  134. int illumination_model;
  135. //! Constructor
  136. Material()
  137. {
  138. // empty
  139. }
  140. // Destructor
  141. ~Material()
  142. {
  143. // empty
  144. }
  145. };
  146. // ------------------------------------------------------------------------------------------------
  147. //! \struct Mesh
  148. //! \brief Data structure to store a mesh
  149. struct Mesh
  150. {
  151. /// Array with pointer to all stored faces
  152. std::vector<Face*> m_Faces;
  153. /// Assigned material
  154. Material *m_pMaterial;
  155. /// Number of stored indices.
  156. unsigned int m_uiNumIndices;
  157. /// Number of UV
  158. unsigned int m_uiUVCoordinates[ AI_MAX_NUMBER_OF_TEXTURECOORDS ];
  159. /// Material index.
  160. unsigned int m_uiMaterialIndex;
  161. /// Constructor
  162. Mesh() :
  163. m_pMaterial(NULL),
  164. m_uiNumIndices(0),
  165. m_uiMaterialIndex(0)
  166. {
  167. memset(m_uiUVCoordinates, 0, sizeof( unsigned int ) * AI_MAX_NUMBER_OF_TEXTURECOORDS);
  168. }
  169. /// Destructor
  170. ~Mesh()
  171. {
  172. // empty
  173. }
  174. };
  175. // ------------------------------------------------------------------------------------------------
  176. //! \struct Model
  177. //! \brief Data structure to store all obj-specific model datas
  178. struct Model
  179. {
  180. typedef std::map<std::string*, std::vector<unsigned int>* > GroupMap;
  181. typedef std::map<std::string*, std::vector<unsigned int>* >::iterator GroupMapIt;
  182. typedef std::map<std::string*, std::vector<unsigned int>* >::const_iterator ConstGroupMapIt;
  183. //! Model name
  184. std::string m_ModelName;
  185. //! List ob assigned objects
  186. std::vector<Object*> m_Objects;
  187. //! Pointer to current object
  188. ObjFile::Object *m_pCurrent;
  189. //! Pointer to current material
  190. ObjFile::Material *m_pCurrentMaterial;
  191. //! Pointer to default material
  192. ObjFile::Material *m_pDefaultMaterial;
  193. //! Vector with all generated materials
  194. std::vector<std::string> m_MaterialLib;
  195. //! Vector with all generated group
  196. std::vector<std::string> m_GroupLib;
  197. //! Vector with all generated vertices
  198. std::vector<aiVector3D*> m_Vertices;
  199. //! vector with all generated normals
  200. std::vector<aiVector3D*> m_Normals;
  201. //! Groupmap
  202. GroupMap m_Groups;
  203. //! Group to face id assignment
  204. std::vector<unsigned int> *m_pGroupFaceIDs;
  205. //! Active group
  206. std::string m_strActiveGroup;
  207. //! Vector with generated texture coordinates
  208. std::vector<aiVector2D*> m_TextureCoord;
  209. //! Current mesh instance
  210. Mesh *m_pCurrentMesh;
  211. //! Vector with stored meshes
  212. std::vector<Mesh*> m_Meshes;
  213. //! Material map
  214. std::map<std::string, Material*> m_MaterialMap;
  215. //! \brief Default constructor
  216. Model() :
  217. m_ModelName(""),
  218. m_pCurrent(NULL),
  219. m_pCurrentMaterial(NULL),
  220. m_pDefaultMaterial(NULL),
  221. m_strActiveGroup(""),
  222. m_pCurrentMesh(NULL)
  223. {
  224. // empty
  225. }
  226. //! \brief Destructor
  227. ~Model()
  228. {
  229. // Clear all stored object instances
  230. for (std::vector<Object*>::iterator it = m_Objects.begin();
  231. it != m_Objects.end(); ++it)
  232. {
  233. delete *it;
  234. }
  235. m_Objects.clear();
  236. // Clear all stored mesh instances
  237. for (std::vector<Mesh*>::iterator it = m_Meshes.begin();
  238. it != m_Meshes.end(); ++it)
  239. {
  240. delete *it;
  241. }
  242. m_Meshes.clear();
  243. }
  244. };
  245. // ------------------------------------------------------------------------------------------------
  246. } // Namespace ObjFile
  247. } // Namespace Assimp
  248. #endif