XFileHelper.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. /*
  2. Open Asset Import Library (assimp)
  3. ----------------------------------------------------------------------
  4. Copyright (c) 2006-2016, 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 "Defines.h"
  44. namespace Assimp
  45. {
  46. namespace XFile
  47. {
  48. /** Helper structure representing a XFile mesh face */
  49. struct Face
  50. {
  51. std::vector<unsigned int> mIndices;
  52. };
  53. /** Helper structure representing a texture filename inside a material and its potential source */
  54. struct TexEntry
  55. {
  56. std::string mName;
  57. bool mIsNormalMap; // true if the texname was specified in a NormalmapFilename tag
  58. TexEntry() { mIsNormalMap = false; }
  59. TexEntry( const std::string& pName, bool pIsNormalMap = false)
  60. : mName( pName), mIsNormalMap( pIsNormalMap)
  61. { /* done */ }
  62. };
  63. /** Helper structure representing a XFile material */
  64. struct Material
  65. {
  66. std::string mName;
  67. bool mIsReference; // if true, mName holds a name by which the actual material can be found in the material list
  68. aiColor4D mDiffuse;
  69. ai_real mSpecularExponent;
  70. aiColor3D mSpecular;
  71. aiColor3D mEmissive;
  72. std::vector<TexEntry> mTextures;
  73. size_t sceneIndex; ///< the index under which it was stored in the scene's material list
  74. Material()
  75. : mIsReference(false),
  76. mSpecularExponent(),
  77. sceneIndex(SIZE_MAX)
  78. {}
  79. };
  80. /** Helper structure to represent a bone weight */
  81. struct BoneWeight
  82. {
  83. unsigned int mVertex;
  84. ai_real mWeight;
  85. };
  86. /** Helper structure to represent a bone in a mesh */
  87. struct Bone
  88. {
  89. std::string mName;
  90. std::vector<BoneWeight> mWeights;
  91. aiMatrix4x4 mOffsetMatrix;
  92. };
  93. /** Helper structure to represent an XFile mesh */
  94. struct Mesh
  95. {
  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 = "") { mName = pName; mNumTextures = 0; mNumColorSets = 0; }
  109. };
  110. /** Helper structure to represent a XFile frame */
  111. struct Node
  112. {
  113. std::string mName;
  114. aiMatrix4x4 mTrafoMatrix;
  115. Node* mParent;
  116. std::vector<Node*> mChildren;
  117. std::vector<Mesh*> mMeshes;
  118. Node() { mParent = NULL; }
  119. explicit Node( Node* pParent) { mParent = pParent; }
  120. ~Node()
  121. {
  122. for( unsigned int a = 0; a < mChildren.size(); a++)
  123. delete mChildren[a];
  124. for( unsigned int a = 0; a < mMeshes.size(); a++)
  125. delete mMeshes[a];
  126. }
  127. };
  128. struct MatrixKey
  129. {
  130. double mTime;
  131. aiMatrix4x4 mMatrix;
  132. };
  133. /** Helper structure representing a single animated bone in a XFile */
  134. struct AnimBone
  135. {
  136. std::string mBoneName;
  137. std::vector<aiVectorKey> mPosKeys; // either three separate key sequences for position, rotation, scaling
  138. std::vector<aiQuatKey> mRotKeys;
  139. std::vector<aiVectorKey> mScaleKeys;
  140. std::vector<MatrixKey> mTrafoKeys; // or a combined key sequence of transformation matrices.
  141. };
  142. /** Helper structure to represent an animation set in a XFile */
  143. struct Animation
  144. {
  145. std::string mName;
  146. std::vector<AnimBone*> mAnims;
  147. ~Animation()
  148. {
  149. for( unsigned int a = 0; a < mAnims.size(); a++)
  150. delete mAnims[a];
  151. }
  152. };
  153. /** Helper structure analogue to aiScene */
  154. struct Scene
  155. {
  156. Node* mRootNode;
  157. std::vector<Mesh*> mGlobalMeshes; // global meshes found outside of any frames
  158. std::vector<Material> mGlobalMaterials; // global materials found outside of any meshes.
  159. std::vector<Animation*> mAnims;
  160. unsigned int mAnimTicksPerSecond;
  161. Scene() { mRootNode = NULL; mAnimTicksPerSecond = 0; }
  162. ~Scene()
  163. {
  164. delete mRootNode;
  165. for( unsigned int a = 0; a < mGlobalMeshes.size(); a++)
  166. delete mGlobalMeshes[a];
  167. for( unsigned int a = 0; a < mAnims.size(); a++)
  168. delete mAnims[a];
  169. }
  170. };
  171. } // end of namespace XFile
  172. } // end of namespace Assimp
  173. #endif // AI_XFILEHELPER_H_INC