ObjFileData.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  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. namespace Assimp
  39. {
  40. namespace ObjFile
  41. {
  42. // ------------------------------------------------------------------------------------------------
  43. struct Object;
  44. struct Face;
  45. struct Material;
  46. // ------------------------------------------------------------------------------------------------
  47. //! \struct Face
  48. //! \brief Datastructure for a simple obj-face, descripes discredisation and materials
  49. struct Face
  50. {
  51. typedef std::vector<unsigned int> IndexArray;
  52. //! Primitive type
  53. int m_PrimitiveType;
  54. //! Vertex indices
  55. IndexArray *m_pVertices;
  56. //! Normal indices
  57. IndexArray *m_pNormals;
  58. //! Texture coordinates indices
  59. IndexArray *m_pTexturCoords;
  60. //! Pointer to assigned material
  61. Material *m_pMaterial;
  62. //! \brief Default constructor
  63. //! \param pVertices Pointer to assigned vertex indexbuffer
  64. //! \param pNormals Pointer to assigned normals indexbuffer
  65. //! \param pTexCoords Pointer to assigned texture indexbuffer
  66. Face(std::vector<unsigned int> *pVertices,
  67. std::vector<unsigned int> *pNormals,
  68. std::vector<unsigned int> *pTexCoords) :
  69. m_PrimitiveType( 2 ),
  70. m_pVertices( pVertices ),
  71. m_pNormals( pNormals ),
  72. m_pTexturCoords( pTexCoords ),
  73. m_pMaterial( 0L )
  74. {
  75. // empty
  76. }
  77. //! \brief Destructor
  78. ~Face()
  79. {
  80. // empty
  81. }
  82. };
  83. // ------------------------------------------------------------------------------------------------
  84. //! \struct Object
  85. //! \brief Stores all objects of an objfile object definition
  86. struct Object
  87. {
  88. //! Obejct name
  89. std::string m_strObjName;
  90. //! Assigend face instances
  91. std::vector<Face*> m_Faces;
  92. //! Transformation matrix, stored in OpenGL format
  93. aiMatrix4x4 m_Transformation;
  94. //! All subobjects references by this object
  95. std::vector<Object*> m_SubObjects;
  96. //! \brief Default constructor
  97. Object() :
  98. m_strObjName("")
  99. {
  100. // empty
  101. }
  102. //! \brief Destructor
  103. ~Object()
  104. {
  105. for (std::vector<Object*>::iterator it = m_SubObjects.begin();
  106. it != m_SubObjects.end(); ++it)
  107. {
  108. delete *it;
  109. }
  110. m_SubObjects.clear();
  111. }
  112. };
  113. // ------------------------------------------------------------------------------------------------
  114. //! \struct Material
  115. //! \brief Data structure to store all material specific data
  116. struct Material
  117. {
  118. //! NAme of material description
  119. aiString MaterialName;
  120. //! Name of used texture
  121. aiString texture;
  122. //! Ambient color
  123. aiColor3D ambient;
  124. //! Diffuse color
  125. aiColor3D diffuse;
  126. //! Speculao color
  127. aiColor3D specular;
  128. //! Alpha value
  129. float alpha;
  130. //! Shineness factor
  131. float shineness;
  132. //! Illumination model
  133. int illumination_model;
  134. Material()
  135. {
  136. }
  137. ~Material()
  138. {
  139. }
  140. };
  141. // ------------------------------------------------------------------------------------------------
  142. //! \struct Mesh
  143. //! \brief Data structure to store a mesh
  144. struct Mesh
  145. {
  146. std::vector<Face*> m_Faces;
  147. Material *m_pMaterial;
  148. unsigned int m_uiNumIndices;
  149. unsigned int m_uiMaterialIndex;
  150. Mesh() :
  151. m_pMaterial(NULL),
  152. m_uiNumIndices(0),
  153. m_uiMaterialIndex(0)
  154. {
  155. // empty
  156. }
  157. ~Mesh()
  158. {
  159. // empty
  160. }
  161. };
  162. // ------------------------------------------------------------------------------------------------
  163. //! \struct Model
  164. //! \brief Data structure to store all obj-specific model datas
  165. struct Model
  166. {
  167. typedef std::map<std::string*, std::vector<unsigned int>* > GroupMap;
  168. typedef std::map<std::string*, std::vector<unsigned int>* >::iterator GroupMapIt;
  169. typedef std::map<std::string*, std::vector<unsigned int>* >::const_iterator ConstGroupMapIt;
  170. //! Model name
  171. std::string m_ModelName;
  172. //! List ob assigned objects
  173. std::vector<Object*> m_Objects;
  174. //! Pointer to current object
  175. ObjFile::Object *m_pCurrent;
  176. //! Pointer to current material
  177. ObjFile::Material *m_pCurrentMaterial;
  178. //! Pointer to default material
  179. ObjFile::Material *m_pDefaultMaterial;
  180. //! Vector with all generated materials
  181. std::vector<std::string> m_MaterialLib;
  182. //! Vector with all generated group
  183. std::vector<std::string> m_GroupLib;
  184. //! Vector with all generated vertices
  185. std::vector<aiVector3D*> m_Vertices;
  186. //! vector with all generated normals
  187. std::vector<aiVector3D*> m_Normals;
  188. //! Groupmap
  189. GroupMap m_Groups;
  190. //! Group to face id assignment
  191. std::vector<unsigned int> *m_pGroupFaceIDs;
  192. //! Active group
  193. std::string m_strActiveGroup;
  194. //! Vector with generated texture coordinates
  195. std::vector<aiVector2D*> m_TextureCoord;
  196. //! Current mesh instance
  197. Mesh *m_pCurrentMesh;
  198. //! Vector with stored meshes
  199. std::vector<Mesh*> m_Meshes;
  200. //! Material map
  201. std::map<std::string, Material*> m_MaterialMap;
  202. //! \brief Default constructor
  203. Model() :
  204. m_ModelName(""),
  205. m_pCurrent(NULL),
  206. m_pCurrentMaterial(NULL),
  207. m_pDefaultMaterial(NULL),
  208. m_strActiveGroup(""),
  209. m_pCurrentMesh(NULL)
  210. {
  211. // empty
  212. }
  213. //! \brief Destructor
  214. ~Model()
  215. {
  216. // Clear all stored object instances
  217. for (std::vector<Object*>::iterator it = m_Objects.begin();
  218. it != m_Objects.end(); ++it)
  219. {
  220. delete *it;
  221. }
  222. m_Objects.clear();
  223. // Clear all stored mesh instances
  224. for (std::vector<Mesh*>::iterator it = m_Meshes.begin();
  225. it != m_Meshes.end(); ++it)
  226. {
  227. delete *it;
  228. }
  229. m_Meshes.clear();
  230. }
  231. };
  232. } // Namespace ObjFile
  233. } // Namespace Assimp
  234. #endif