XFileHelper.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. /*
  2. Open Asset Import Library (assimp)
  3. ----------------------------------------------------------------------
  4. Copyright (c) 2006-2020, assimp 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 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. /** @file Defines the helper data structures for importing XFiles */
  34. #ifndef AI_XFILEHELPER_H_INC
  35. #define AI_XFILEHELPER_H_INC
  36. #include <string>
  37. #include <vector>
  38. #include <stdint.h>
  39. #include <assimp/types.h>
  40. #include <assimp/quaternion.h>
  41. #include <assimp/mesh.h>
  42. #include <assimp/anim.h>
  43. #include <assimp/Defines.h>
  44. namespace Assimp {
  45. namespace XFile {
  46. /** Helper structure representing a XFile mesh face */
  47. struct Face {
  48. std::vector<unsigned int> mIndices;
  49. };
  50. /** Helper structure representing a texture filename inside a material and its potential source */
  51. struct TexEntry {
  52. std::string mName;
  53. bool mIsNormalMap; // true if the texname was specified in a NormalmapFilename tag
  54. TexEntry() AI_NO_EXCEPT
  55. : mName()
  56. , mIsNormalMap(false) {
  57. // empty
  58. }
  59. TexEntry(const std::string& pName, bool pIsNormalMap = false)
  60. : mName(pName)
  61. , mIsNormalMap(pIsNormalMap) {
  62. // empty
  63. }
  64. };
  65. /** Helper structure representing a XFile material */
  66. struct Material {
  67. std::string mName;
  68. bool mIsReference; // if true, mName holds a name by which the actual material can be found in the material list
  69. aiColor4D mDiffuse;
  70. ai_real mSpecularExponent;
  71. aiColor3D mSpecular;
  72. aiColor3D mEmissive;
  73. std::vector<TexEntry> mTextures;
  74. size_t sceneIndex; ///< the index under which it was stored in the scene's material list
  75. Material() AI_NO_EXCEPT
  76. : mIsReference(false)
  77. , mSpecularExponent()
  78. , sceneIndex(SIZE_MAX) {
  79. // empty
  80. }
  81. };
  82. /** Helper structure to represent a bone weight */
  83. struct BoneWeight {
  84. unsigned int mVertex;
  85. ai_real mWeight;
  86. };
  87. /** Helper structure to represent a bone in a mesh */
  88. struct Bone
  89. {
  90. std::string mName;
  91. std::vector<BoneWeight> mWeights;
  92. aiMatrix4x4 mOffsetMatrix;
  93. };
  94. /** Helper structure to represent an XFile mesh */
  95. struct Mesh {
  96. std::string mName;
  97. std::vector<aiVector3D> mPositions;
  98. std::vector<Face> mPosFaces;
  99. std::vector<aiVector3D> mNormals;
  100. std::vector<Face> mNormFaces;
  101. unsigned int mNumTextures;
  102. std::vector<aiVector2D> mTexCoords[AI_MAX_NUMBER_OF_TEXTURECOORDS];
  103. unsigned int mNumColorSets;
  104. std::vector<aiColor4D> mColors[AI_MAX_NUMBER_OF_COLOR_SETS];
  105. std::vector<unsigned int> mFaceMaterials;
  106. std::vector<Material> mMaterials;
  107. std::vector<Bone> mBones;
  108. explicit Mesh(const std::string &pName = "") AI_NO_EXCEPT
  109. : mName( pName )
  110. , mPositions()
  111. , mPosFaces()
  112. , mNormals()
  113. , mNormFaces()
  114. , mNumTextures(0)
  115. , mTexCoords{}
  116. , mNumColorSets(0)
  117. , mColors{}
  118. , mFaceMaterials()
  119. , mMaterials()
  120. , mBones() {
  121. // empty
  122. }
  123. };
  124. /** Helper structure to represent a XFile frame */
  125. struct Node {
  126. std::string mName;
  127. aiMatrix4x4 mTrafoMatrix;
  128. Node* mParent;
  129. std::vector<Node*> mChildren;
  130. std::vector<Mesh*> mMeshes;
  131. Node() AI_NO_EXCEPT
  132. : mName()
  133. , mTrafoMatrix()
  134. , mParent(nullptr)
  135. , mChildren()
  136. , mMeshes() {
  137. // empty
  138. }
  139. explicit Node( Node* pParent)
  140. : mName()
  141. , mTrafoMatrix()
  142. , mParent(pParent)
  143. , mChildren()
  144. , mMeshes() {
  145. // empty
  146. }
  147. ~Node() {
  148. for (unsigned int a = 0; a < mChildren.size(); ++a ) {
  149. delete mChildren[a];
  150. }
  151. for (unsigned int a = 0; a < mMeshes.size(); ++a) {
  152. delete mMeshes[a];
  153. }
  154. }
  155. };
  156. struct MatrixKey {
  157. double mTime;
  158. aiMatrix4x4 mMatrix;
  159. };
  160. /** Helper structure representing a single animated bone in a XFile */
  161. struct AnimBone {
  162. std::string mBoneName;
  163. std::vector<aiVectorKey> mPosKeys; // either three separate key sequences for position, rotation, scaling
  164. std::vector<aiQuatKey> mRotKeys;
  165. std::vector<aiVectorKey> mScaleKeys;
  166. std::vector<MatrixKey> mTrafoKeys; // or a combined key sequence of transformation matrices.
  167. };
  168. /** Helper structure to represent an animation set in a XFile */
  169. struct Animation
  170. {
  171. std::string mName;
  172. std::vector<AnimBone*> mAnims;
  173. ~Animation()
  174. {
  175. for( unsigned int a = 0; a < mAnims.size(); a++)
  176. delete mAnims[a];
  177. }
  178. };
  179. /** Helper structure analogue to aiScene */
  180. struct Scene
  181. {
  182. Node* mRootNode;
  183. std::vector<Mesh*> mGlobalMeshes; // global meshes found outside of any frames
  184. std::vector<Material> mGlobalMaterials; // global materials found outside of any meshes.
  185. std::vector<Animation*> mAnims;
  186. unsigned int mAnimTicksPerSecond;
  187. Scene() AI_NO_EXCEPT
  188. : mRootNode(nullptr)
  189. , mGlobalMeshes()
  190. , mGlobalMaterials()
  191. , mAnimTicksPerSecond(0) {
  192. // empty
  193. }
  194. ~Scene() {
  195. delete mRootNode;
  196. mRootNode = nullptr;
  197. for (unsigned int a = 0; a < mGlobalMeshes.size(); ++a ) {
  198. delete mGlobalMeshes[a];
  199. }
  200. for (unsigned int a = 0; a < mAnims.size(); ++a ) {
  201. delete mAnims[a];
  202. }
  203. }
  204. };
  205. } // end of namespace XFile
  206. } // end of namespace Assimp
  207. #endif // AI_XFILEHELPER_H_INC