MDRFileData.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. /*
  2. Open Asset Import Library (ASSIMP)
  3. ----------------------------------------------------------------------
  4. Copyright (c) 2006-2008, 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 MDR files */
  34. #ifndef AI_MDRFILEHELPER_H_INC
  35. #define AI_MDRFILEHELPER_H_INC
  36. #include "../include/aiTypes.h"
  37. #include "../include/aiMesh.h"
  38. #include "../include/aiAnim.h"
  39. #if defined(_MSC_VER) || defined(__BORLANDC__) || defined (__BCPLUSPLUS__)
  40. # pragma pack(push,1)
  41. # define PACK_STRUCT
  42. #elif defined( __GNUC__ )
  43. # define PACK_STRUCT __attribute__((packed))
  44. #else
  45. # error Compiler not supported
  46. #endif
  47. namespace Assimp {
  48. namespace MDR {
  49. #define AI_MDR_MAGIC_NUMBER_BE 'RDM5'
  50. #define AI_MDR_MAGIC_NUMBER_LE '5MDR'
  51. // common limitations
  52. #define AI_MDR_VERSION 2
  53. #define AI_MDR_MAXQPATH 64
  54. #define AI_MDR_MAX_BONES 128
  55. // ---------------------------------------------------------------------------
  56. /** \brief Data structure for a vertex weight in a MDR file
  57. */
  58. struct Weight
  59. {
  60. //! these are indexes into the boneReferences
  61. //! not the global per-frame bone list
  62. uint32_t boneIndex;
  63. //! weight of this bone
  64. float boneWeight;
  65. //! offset of this bone
  66. aiVector3D offset;
  67. } PACK_STRUCT;
  68. // ---------------------------------------------------------------------------
  69. /** \brief Data structure for a vertex in a MDR file
  70. */
  71. struct Vertex
  72. {
  73. aiVector3D normal;
  74. aiVector2D texCoords;
  75. uint32_t numWeights;
  76. Weight weights[1]; // variable sized
  77. } PACK_STRUCT;
  78. // ---------------------------------------------------------------------------
  79. /** \brief Data structure for a triangle in a MDR file
  80. */
  81. struct Triangle
  82. {
  83. uint32_t indexes[3];
  84. } PACK_STRUCT;
  85. // ---------------------------------------------------------------------------
  86. /** \brief Data structure for a surface in a MDR file
  87. */
  88. struct Surface
  89. {
  90. uint32_t ident;
  91. char name[AI_MDR_MAXQPATH]; // polyset name
  92. char shader[AI_MDR_MAXQPATH];
  93. uint32_t shaderIndex;
  94. int32_t ofsHeader; // this will be a negative number
  95. uint32_t numVerts;
  96. uint32_t ofsVerts;
  97. uint32_t numTriangles;
  98. uint32_t ofsTriangles;
  99. // Bone references are a set of ints representing all the bones
  100. // present in any vertex weights for this surface. This is
  101. // needed because a model may have surfaces that need to be
  102. // drawn at different sort times, and we don't want to have
  103. // to re-interpolate all the bones for each surface.
  104. uint32_t numBoneReferences;
  105. uint32_t ofsBoneReferences;
  106. uint32_t ofsEnd; // next surface follows
  107. } PACK_STRUCT;
  108. // ---------------------------------------------------------------------------
  109. /** \brief Data structure for a bone in a MDR file
  110. */
  111. struct Bone
  112. {
  113. float matrix[3][4];
  114. } PACK_STRUCT;
  115. // ---------------------------------------------------------------------------
  116. /** \brief Data structure for a frame in a MDR file
  117. */
  118. struct Frame {
  119. aiVector3D bounds[2]; // bounds of all surfaces of all LOD's for this frame
  120. aiVector3D localOrigin; // midpoint of bounds, used for sphere cull
  121. float radius; // dist from localOrigin to corner
  122. char name[16];
  123. Bone bones[1]; // [numBones]
  124. } PACK_STRUCT;
  125. // ---------------------------------------------------------------------------
  126. /** \brief Data structure for a compressed bone in a MDR file
  127. */
  128. struct CompBone
  129. {
  130. unsigned char Comp[24]; // MC_COMP_BYTES is in MatComp.h, but don't want to couple
  131. } PACK_STRUCT;
  132. // ---------------------------------------------------------------------------
  133. /** \brief Data structure for a compressed frame in a MDR file
  134. */
  135. struct CompFrame
  136. {
  137. aiVector3D bounds[2]; // bounds of all surfaces of all LOD's for this frame
  138. aiVector3D localOrigin; // midpoint of bounds, used for sphere cull
  139. float radius; // dist from localOrigin to corner
  140. CompBone bones[1]; // [numBones]
  141. } PACK_STRUCT;
  142. // ---------------------------------------------------------------------------
  143. /** \brief Data structure for a LOD in a MDR file
  144. */
  145. struct LOD
  146. {
  147. uint32_t numSurfaces;
  148. uint32_t ofsSurfaces; // first surface, others follow
  149. uint32_t ofsEnd; // next lod follows
  150. } ;
  151. // ---------------------------------------------------------------------------
  152. /** \brief Data structure for a tag (= attachment) in a MDR file
  153. */
  154. struct Tag
  155. {
  156. uint32_t boneIndex;
  157. char name[32];
  158. } PACK_STRUCT;
  159. // ---------------------------------------------------------------------------
  160. /** \brief Header data structure for a MDR file
  161. */
  162. struct Header
  163. {
  164. uint32_t ident;
  165. uint32_t version;
  166. char name[AI_MDR_MAXQPATH];
  167. // frames and bones are shared by all levels of detail
  168. int32_t numFrames;
  169. uint32_t numBones;
  170. uint32_t ofsFrames;
  171. // each level of detail has completely separate sets of surfaces
  172. uint32_t numLODs;
  173. uint32_t ofsLODs;
  174. uint32_t numTags;
  175. uint32_t ofsTags;
  176. uint32_t ofsEnd;
  177. } PACK_STRUCT;
  178. // reset packing to the original value
  179. #if defined(_MSC_VER) || defined(__BORLANDC__) || defined (__BCPLUSPLUS__)
  180. # pragma pack( pop )
  181. #endif
  182. #undef PACK_STRUCT
  183. };
  184. };
  185. #endif // !! AI_MDRFILEHELPER_H_INC