XFileHelper.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /** @file Defines the helper data structures for importing XFiles */
  2. #ifndef AI_XFILEHELPER_H_INC
  3. #define AI_XFILEHELPER_H_INC
  4. #include <string>
  5. #include <vector>
  6. #include "../include/aiTypes.h"
  7. #include "../include/aiQuaternion.h"
  8. #include "../include/aiMesh.h"
  9. #include "../include/aiAnim.h"
  10. namespace Assimp
  11. {
  12. namespace XFile
  13. {
  14. /** Helper structure representing a XFile mesh face */
  15. struct Face
  16. {
  17. std::vector<unsigned int> mIndices;
  18. };
  19. /** Helper structure representing a XFile material */
  20. struct Material
  21. {
  22. std::string mName;
  23. bool mIsReference; // if true, mName holds a name by which the actual material can be found in the material list
  24. aiColor4D mDiffuse;
  25. float mSpecularExponent;
  26. aiColor3D mSpecular;
  27. aiColor3D mEmissive;
  28. std::vector<std::string> mTextures;
  29. Material() { mIsReference = false; }
  30. };
  31. /** Helper structure to represent a bone weight */
  32. struct BoneWeight
  33. {
  34. unsigned int mVertex;
  35. float mWeight;
  36. };
  37. /** Helper structure to represent a bone in a mesh */
  38. struct Bone
  39. {
  40. std::string mName;
  41. std::vector<BoneWeight> mWeights;
  42. aiMatrix4x4 mOffsetMatrix;
  43. };
  44. /** Helper structure to represent an XFile mesh */
  45. struct Mesh
  46. {
  47. std::vector<aiVector3D> mPositions;
  48. std::vector<Face> mPosFaces;
  49. std::vector<aiVector3D> mNormals;
  50. std::vector<Face> mNormFaces;
  51. unsigned int mNumTextures;
  52. std::vector<aiVector2D> mTexCoords[AI_MAX_NUMBER_OF_TEXTURECOORDS];
  53. unsigned int mNumColorSets;
  54. std::vector<aiColor4D> mColors[AI_MAX_NUMBER_OF_COLOR_SETS];
  55. std::vector<unsigned int> mFaceMaterials;
  56. std::vector<Material> mMaterials;
  57. std::vector<Bone> mBones;
  58. Mesh() { mNumTextures = 0; mNumColorSets = 0; }
  59. };
  60. /** Helper structure to represent a XFile frame */
  61. struct Node
  62. {
  63. std::string mName;
  64. aiMatrix4x4 mTrafoMatrix;
  65. Node* mParent;
  66. std::vector<Node*> mChildren;
  67. std::vector<Mesh*> mMeshes;
  68. Node() { mParent = NULL; }
  69. Node( Node* pParent) { mParent = pParent; }
  70. ~Node()
  71. {
  72. for( unsigned int a = 0; a < mChildren.size(); a++)
  73. delete mChildren[a];
  74. for( unsigned int a = 0; a < mMeshes.size(); a++)
  75. delete mMeshes[a];
  76. }
  77. };
  78. struct MatrixKey
  79. {
  80. double mTime;
  81. aiMatrix4x4 mMatrix;
  82. };
  83. /** Helper structure representing a single animated bone in a XFile */
  84. struct AnimBone
  85. {
  86. std::string mBoneName;
  87. std::vector<aiVectorKey> mPosKeys; // either three separate key sequences for position, rotation, scaling
  88. std::vector<aiQuatKey> mRotKeys;
  89. std::vector<aiVectorKey> mScaleKeys;
  90. std::vector<MatrixKey> mTrafoKeys; // or a combined key sequence of transformation matrices.
  91. };
  92. /** Helper structure to represent an animation set in a XFile */
  93. struct Animation
  94. {
  95. std::string mName;
  96. std::vector<AnimBone*> mAnims;
  97. ~Animation()
  98. {
  99. for( unsigned int a = 0; a < mAnims.size(); a++)
  100. delete mAnims[a];
  101. }
  102. };
  103. /** Helper structure analogue to aiScene */
  104. struct Scene
  105. {
  106. Node* mRootNode;
  107. std::vector<Mesh*> mGlobalMeshes; // global meshes found outside of any frames
  108. std::vector<Material> mGlobalMaterials; // global materials found outside of any meshes.
  109. std::vector<Animation*> mAnims;
  110. unsigned int mAnimTicksPerSecond;
  111. Scene() { mRootNode = NULL; mAnimTicksPerSecond = 0; }
  112. ~Scene()
  113. {
  114. delete mRootNode;
  115. for( unsigned int a = 0; a < mGlobalMeshes.size(); a++)
  116. delete mGlobalMeshes[a];
  117. for( unsigned int a = 0; a < mAnims.size(); a++)
  118. delete mAnims[a];
  119. }
  120. };
  121. } // end of namespace XFile
  122. } // end of namespace Assimp
  123. #endif // AI_XFILEHELPER_H_INC