2
0

MD4FileData.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. /*
  2. Open Asset Import Library (ASSIMP)
  3. ----------------------------------------------------------------------
  4. Copyright (c) 2006-2020, ASSIMP Development 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 Development 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 MD4 files */
  34. #ifndef AI_MD4FILEHELPER_H_INC
  35. #define AI_MD4FILEHELPER_H_INC
  36. #include <string>
  37. #include <vector>
  38. #include <sstream>
  39. #include <assimp/types.h>
  40. #include <assimp/mesh.h>
  41. #include <assimp/anim.h>
  42. #if defined(_MSC_VER) || defined(__BORLANDC__) || defined (__BCPLUSPLUS__)
  43. # pragma pack(push,1)
  44. # define PACK_STRUCT
  45. #elif defined( __GNUC__ )
  46. # define PACK_STRUCT __attribute__((packed))
  47. #else
  48. # error Compiler not supported
  49. #endif
  50. namespace Assimp
  51. {
  52. // http://gongo.quakedev.com/md4.html
  53. namespace MD4
  54. {
  55. #define AI_MD4_MAGIC_NUMBER_BE 'IDP4'
  56. #define AI_MD4_MAGIC_NUMBER_LE '4PDI'
  57. // common limitations
  58. #define AI_MD4_VERSION 4
  59. #define AI_MD4_MAXQPATH 64
  60. #define AI_MD4_MAX_FRAMES 2028
  61. #define AI_MD4_MAX_SURFACES 32
  62. #define AI_MD4_MAX_BONES 256
  63. #define AI_MD4_MAX_VERTS 4096
  64. #define AI_MD4_MAX_TRIANGLES 8192
  65. // ---------------------------------------------------------------------------
  66. /** \brief Data structure for the MD4 main header
  67. */
  68. // ---------------------------------------------------------------------------
  69. struct Header
  70. {
  71. //! magic number
  72. int32_t magic;
  73. //! file format version
  74. int32_t version;
  75. //! original name in .pak archive
  76. unsigned char name[ AI_MD4_MAXQPATH ];
  77. //! number of frames in the file
  78. int32_t NUM_FRAMES;
  79. //! number of bones in the file
  80. int32_t NUM_BONES;
  81. //! number of surfaces in the file
  82. int32_t NUM_SURFACES;
  83. //! offset of the first frame
  84. int32_t OFS_FRAMES;
  85. //! offset of the first bone
  86. int32_t OFS_BONES;
  87. //! offset of the first surface
  88. int32_t OFS_SURFACES;
  89. //! end of file
  90. int32_t OFS_EOF;
  91. } PACK_STRUCT;
  92. // ---------------------------------------------------------------------------
  93. /** \brief Stores the local transformation matrix of a bone
  94. */
  95. // ---------------------------------------------------------------------------
  96. struct BoneFrame
  97. {
  98. float matrix[3][4];
  99. } PACK_STRUCT;
  100. // ---------------------------------------------------------------------------
  101. /** \brief Stores the name / parent index / flag of a node
  102. */
  103. // ---------------------------------------------------------------------------
  104. struct BoneName
  105. {
  106. char name[32] ;
  107. int parent ;
  108. int flags ;
  109. } PACK_STRUCT;
  110. // ---------------------------------------------------------------------------
  111. /** \brief Data structure for a surface in a MD4 file
  112. */
  113. // ---------------------------------------------------------------------------
  114. struct Surface
  115. {
  116. int32_t ident;
  117. char name[64];
  118. char shader[64];
  119. int32_t shaderIndex;
  120. int32_t lodBias;
  121. int32_t minLod;
  122. int32_t ofsHeader;
  123. int32_t numVerts;
  124. int32_t ofsVerts;
  125. int32_t numTris;
  126. int32_t ofsTris;
  127. int32_t numBoneRefs;
  128. int32_t ofsBoneRefs;
  129. int32_t ofsCollapseMap;
  130. int32_t ofsEnd;
  131. } PACK_STRUCT;
  132. // ---------------------------------------------------------------------------
  133. /** \brief Data structure for a MD4 vertex' weight
  134. */
  135. // ---------------------------------------------------------------------------
  136. struct Weight
  137. {
  138. int32_t boneIndex;
  139. float boneWeight;
  140. float offset[3];
  141. } PACK_STRUCT;
  142. // ---------------------------------------------------------------------------
  143. /** \brief Data structure for a vertex in a MD4 file
  144. */
  145. // ---------------------------------------------------------------------------
  146. struct Vertex
  147. {
  148. float vertex[3];
  149. float normal[3];
  150. float texCoords[2];
  151. int32_t numWeights;
  152. Weight weights[1];
  153. } PACK_STRUCT;
  154. // ---------------------------------------------------------------------------
  155. /** \brief Data structure for a triangle in a MD4 file
  156. */
  157. // ---------------------------------------------------------------------------
  158. struct Triangle
  159. {
  160. int32_t indexes[3];
  161. } PACK_STRUCT;
  162. // ---------------------------------------------------------------------------
  163. /** \brief Data structure for a MD4 frame
  164. */
  165. // ---------------------------------------------------------------------------
  166. struct Frame
  167. {
  168. float bounds[3][2];
  169. float localOrigin[3];
  170. float radius;
  171. BoneFrame bones[1];
  172. } PACK_STRUCT;
  173. // reset packing to the original value
  174. #if defined(_MSC_VER) || defined(__BORLANDC__) || defined (__BCPLUSPLUS__)
  175. # pragma pack( pop )
  176. #endif
  177. #undef PACK_STRUCT
  178. };
  179. };
  180. #endif // !! AI_MD4FILEHELPER_H_INC