ObjFileData.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. #ifndef OBJ_FILEDATA_H_INC
  2. #define OBJ_FILEDATA_H_INC
  3. #include <vector>
  4. #include <map>
  5. #include "aiTypes.h"
  6. namespace Assimp
  7. {
  8. namespace ObjFile
  9. {
  10. struct Object;
  11. struct Face;
  12. struct Material;
  13. // ------------------------------------------------------------------------------------------------
  14. //! \struct Face
  15. //! \brief Datastructure for a simple obj-face, descripes discredisation and materials
  16. struct Face
  17. {
  18. typedef std::vector<unsigned int> IndexArray;
  19. //! Primitive type
  20. int m_PrimitiveType;
  21. //! Vertex indices
  22. IndexArray *m_pVertices;
  23. //! Normal indices
  24. IndexArray *m_pNormals;
  25. //! Texture coordinates indices
  26. IndexArray *m_pTexturCoords;
  27. //! Pointer to assigned material
  28. Material *m_pMaterial;
  29. //! \brief Default constructor
  30. //! \param pVertices Pointer to assigned vertex indexbuffer
  31. //! \param pNormals Pointer to assigned normals indexbuffer
  32. //! \param pTexCoords Pointer to assigned texture indexbuffer
  33. Face(std::vector<unsigned int> *pVertices,
  34. std::vector<unsigned int> *pNormals,
  35. std::vector<unsigned int> *pTexCoords) :
  36. m_PrimitiveType(2),
  37. m_pVertices(pVertices),
  38. m_pNormals(pNormals),
  39. m_pTexturCoords(pTexCoords),
  40. m_pMaterial(0L)
  41. {
  42. // empty
  43. }
  44. //! \brief Destructor
  45. ~Face()
  46. {
  47. // empty
  48. }
  49. };
  50. // ------------------------------------------------------------------------------------------------
  51. //! \struct Object
  52. //! \brief Stores all objects of an objfile object definition
  53. struct Object
  54. {
  55. //! Obejct name
  56. std::string m_strObjName;
  57. //! Assigend face instances
  58. std::vector<Face*> m_Faces;
  59. //! Transformation matrix, stored in OpenGL format
  60. aiMatrix4x4 m_Transformation;
  61. //! All subobjects references by this object
  62. std::vector<Object*> m_SubObjects;
  63. //! \brief Default constructor
  64. Object() :
  65. m_strObjName("")
  66. {
  67. // empty
  68. }
  69. //! \brief Destructor
  70. ~Object()
  71. {
  72. for (std::vector<Object*>::iterator it = m_SubObjects.begin();
  73. it != m_SubObjects.end(); ++it)
  74. {
  75. delete *it;
  76. }
  77. m_SubObjects.clear();
  78. }
  79. };
  80. // ------------------------------------------------------------------------------------------------
  81. //! \struct Material
  82. //! \brief Data structure to store all material specific data
  83. struct Material
  84. {
  85. aiString MaterialName;
  86. aiString texture;
  87. aiColor3D ambient;
  88. aiColor3D diffuse;
  89. aiColor3D specular;
  90. float alpha;
  91. float shineness;
  92. int illumination_model;
  93. };
  94. // ------------------------------------------------------------------------------------------------
  95. //! \struct Model
  96. //! \brief Data structure to store all obj-specific model datas
  97. struct Model
  98. {
  99. typedef std::map<std::string*, std::vector<unsigned int>* > GroupMap;
  100. typedef std::map<std::string*, std::vector<unsigned int>* >::iterator GroupMapIt;
  101. typedef std::map<std::string*, std::vector<unsigned int>* >::const_iterator ConstGroupMapIt;
  102. //! Model name
  103. std::string m_ModelName;
  104. //! List ob assigned objects
  105. std::vector<Object*> m_Objects;
  106. //! Pointer to current object
  107. ObjFile::Object *m_pCurrent;
  108. //! Pointer to current material
  109. ObjFile::Material *m_pCurrentMaterial;
  110. //! Pointer to default material
  111. ObjFile::Material *m_pDefaultMaterial;
  112. //! Vector with all generated materials
  113. std::vector<std::string> m_MaterialLib;
  114. //! Vector with all generated group
  115. std::vector<std::string> m_GroupLib;
  116. //! Vector with all generated vertices
  117. std::vector<aiVector3D_t*> m_Vertices;
  118. //! vector with all generated normals
  119. std::vector<aiVector3D_t*> m_Normals;
  120. //! Groupmap
  121. GroupMap m_Groups;
  122. std::vector<unsigned int> *m_pGroupFaceIDs;
  123. //! Active group
  124. std::string m_strActiveGroup;
  125. //! Vector with generated texture coordinates
  126. std::vector<aiVector2D_t*> m_TextureCoord;
  127. //! Material map
  128. std::map<std::string, Material*> m_MaterialMap;
  129. //! \brief Default constructor
  130. Model() :
  131. m_ModelName(""),
  132. m_pCurrent(NULL),
  133. m_pCurrentMaterial(NULL),
  134. m_pDefaultMaterial(NULL),
  135. m_strActiveGroup("")
  136. {
  137. // empty
  138. }
  139. //! \brief DEstructor
  140. ~Model()
  141. {
  142. for (std::vector<Object*>::iterator it = m_Objects.begin();
  143. it != m_Objects.end(); ++it)
  144. {
  145. delete *it;
  146. }
  147. m_Objects.clear();
  148. }
  149. };
  150. } // Namespace ObjFile
  151. } // Namespace Assimp
  152. #endif