ObjFileData.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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. struct Object;
  43. struct Face;
  44. struct Material;
  45. // ------------------------------------------------------------------------------------------------
  46. //! \struct Face
  47. //! \brief Datastructure for a simple obj-face, descripes discredisation and materials
  48. struct Face
  49. {
  50. typedef std::vector<unsigned int> IndexArray;
  51. //! Primitive type
  52. int m_PrimitiveType;
  53. //! Vertex indices
  54. IndexArray *m_pVertices;
  55. //! Normal indices
  56. IndexArray *m_pNormals;
  57. //! Texture coordinates indices
  58. IndexArray *m_pTexturCoords;
  59. //! Pointer to assigned material
  60. Material *m_pMaterial;
  61. //! \brief Default constructor
  62. //! \param pVertices Pointer to assigned vertex indexbuffer
  63. //! \param pNormals Pointer to assigned normals indexbuffer
  64. //! \param pTexCoords Pointer to assigned texture indexbuffer
  65. Face(std::vector<unsigned int> *pVertices,
  66. std::vector<unsigned int> *pNormals,
  67. std::vector<unsigned int> *pTexCoords) :
  68. m_PrimitiveType(2),
  69. m_pVertices(pVertices),
  70. m_pNormals(pNormals),
  71. m_pTexturCoords(pTexCoords),
  72. m_pMaterial(0L)
  73. {
  74. // empty
  75. }
  76. //! \brief Destructor
  77. ~Face()
  78. {
  79. // empty
  80. }
  81. };
  82. // ------------------------------------------------------------------------------------------------
  83. //! \struct Object
  84. //! \brief Stores all objects of an objfile object definition
  85. struct Object
  86. {
  87. //! Obejct name
  88. std::string m_strObjName;
  89. //! Assigend face instances
  90. std::vector<Face*> m_Faces;
  91. //! Transformation matrix, stored in OpenGL format
  92. aiMatrix4x4 m_Transformation;
  93. //! All subobjects references by this object
  94. std::vector<Object*> m_SubObjects;
  95. //! \brief Default constructor
  96. Object() :
  97. m_strObjName("")
  98. {
  99. // empty
  100. }
  101. //! \brief Destructor
  102. ~Object()
  103. {
  104. for (std::vector<Object*>::iterator it = m_SubObjects.begin();
  105. it != m_SubObjects.end(); ++it)
  106. {
  107. delete *it;
  108. }
  109. m_SubObjects.clear();
  110. }
  111. };
  112. // ------------------------------------------------------------------------------------------------
  113. //! \struct Material
  114. //! \brief Data structure to store all material specific data
  115. struct Material
  116. {
  117. aiString MaterialName;
  118. aiString texture;
  119. aiColor3D ambient;
  120. aiColor3D diffuse;
  121. aiColor3D specular;
  122. float alpha;
  123. float shineness;
  124. int illumination_model;
  125. };
  126. // ------------------------------------------------------------------------------------------------
  127. //! \struct Model
  128. //! \brief Data structure to store all obj-specific model datas
  129. struct Model
  130. {
  131. typedef std::map<std::string*, std::vector<unsigned int>* > GroupMap;
  132. typedef std::map<std::string*, std::vector<unsigned int>* >::iterator GroupMapIt;
  133. typedef std::map<std::string*, std::vector<unsigned int>* >::const_iterator ConstGroupMapIt;
  134. //! Model name
  135. std::string m_ModelName;
  136. //! List ob assigned objects
  137. std::vector<Object*> m_Objects;
  138. //! Pointer to current object
  139. ObjFile::Object *m_pCurrent;
  140. //! Pointer to current material
  141. ObjFile::Material *m_pCurrentMaterial;
  142. //! Pointer to default material
  143. ObjFile::Material *m_pDefaultMaterial;
  144. //! Vector with all generated materials
  145. std::vector<std::string> m_MaterialLib;
  146. //! Vector with all generated group
  147. std::vector<std::string> m_GroupLib;
  148. //! Vector with all generated vertices
  149. std::vector<aiVector3D*> m_Vertices;
  150. //! vector with all generated normals
  151. std::vector<aiVector3D*> m_Normals;
  152. //! Groupmap
  153. GroupMap m_Groups;
  154. //! Group to face id assignment
  155. std::vector<unsigned int> *m_pGroupFaceIDs;
  156. //! Active group
  157. std::string m_strActiveGroup;
  158. //! Vector with generated texture coordinates
  159. std::vector<aiVector2D*> m_TextureCoord;
  160. //! Material map
  161. std::map<std::string, Material*> m_MaterialMap;
  162. //! \brief Default constructor
  163. Model() :
  164. m_ModelName(""),
  165. m_pCurrent(NULL),
  166. m_pCurrentMaterial(NULL),
  167. m_pDefaultMaterial(NULL),
  168. m_strActiveGroup("")
  169. {
  170. // empty
  171. }
  172. //! \brief DEstructor
  173. ~Model()
  174. {
  175. for (std::vector<Object*>::iterator it = m_Objects.begin();
  176. it != m_Objects.end(); ++it)
  177. {
  178. delete *it;
  179. }
  180. m_Objects.clear();
  181. }
  182. };
  183. } // Namespace ObjFile
  184. } // Namespace Assimp
  185. #endif