XFileHelper.h 5.6 KB

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