MDCFileData.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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 MDC files
  34. **********************************************************************
  35. File format specification:
  36. http://themdcfile.planetwolfenstein.gamespy.com/MDC_File_Format.pdf
  37. **********************************************************************
  38. */
  39. #ifndef AI_MDCFILEHELPER_H_INC
  40. #define AI_MDCFILEHELPER_H_INC
  41. #include "../include/aiTypes.h"
  42. #include "../include/aiMesh.h"
  43. #include "../include/aiAnim.h"
  44. #if defined(_MSC_VER) || defined(__BORLANDC__) || defined (__BCPLUSPLUS__)
  45. # pragma pack(push,1)
  46. # define PACK_STRUCT
  47. #elif defined( __GNUC__ )
  48. # define PACK_STRUCT __attribute__((packed))
  49. #else
  50. # error Compiler not supported
  51. #endif
  52. namespace Assimp {
  53. namespace MDC {
  54. #define AI_MDC_MAGIC_NUMBER_BE 'CPDI'
  55. #define AI_MDC_MAGIC_NUMBER_LE 'IDPC'
  56. // common limitations
  57. #define AI_MDC_VERSION 2
  58. #define AI_MDC_MAXQPATH 64
  59. #define AI_MDC_MAX_BONES 128
  60. #define AI_MDC_CVERT_BIAS 127.0f
  61. #define AI_MDC_DELTA_SCALING 4.0f
  62. #define AI_MDC_BASE_SCALING (1.0f / 64.0f)
  63. // ---------------------------------------------------------------------------
  64. /** \brief Data structure for a MDC file's main header
  65. */
  66. struct Header
  67. {
  68. uint32_t ulIdent ;
  69. uint32_t ulVersion ;
  70. char ucName [ AI_MDC_MAXQPATH ] ;
  71. uint32_t ulFlags ;
  72. uint32_t ulNumFrames ;
  73. uint32_t ulNumTags ;
  74. uint32_t ulNumSurfaces ;
  75. uint32_t ulNumSkins ;
  76. uint32_t ulOffsetBorderFrames ;
  77. uint32_t ulOffsetTagNames ;
  78. uint32_t ulOffsetTagFrames ;
  79. uint32_t ulOffsetSurfaces ;
  80. uint32_t ulOffsetEnd ;
  81. } PACK_STRUCT ;
  82. // ---------------------------------------------------------------------------
  83. /** \brief Data structure for a MDC file's surface header
  84. */
  85. struct Surface
  86. {
  87. uint32_t ulIdent ;
  88. char ucName [ AI_MDC_MAXQPATH ] ;
  89. uint32_t ulFlags ;
  90. uint32_t ulNumCompFrames ;
  91. uint32_t ulNumBaseFrames ;
  92. uint32_t ulNumShaders ;
  93. uint32_t ulNumVertices ;
  94. uint32_t ulNumTriangles ;
  95. uint32_t ulOffsetTriangles ;
  96. uint32_t ulOffsetShaders ;
  97. uint32_t ulOffsetTexCoords ;
  98. uint32_t ulOffsetBaseVerts ;
  99. uint32_t ulOffsetCompVerts ;
  100. uint32_t ulOffsetFrameBaseFrames ;
  101. uint32_t ulOffsetFrameCompFrames ;
  102. uint32_t ulOffsetEnd ;
  103. } PACK_STRUCT;
  104. // ---------------------------------------------------------------------------
  105. /** \brief Data structure for a MDC frame
  106. */
  107. struct Frame
  108. {
  109. //! bounding box minimum coords
  110. aiVector3D bboxMin ;
  111. //! bounding box maximum coords
  112. aiVector3D bboxMax ;
  113. //! local origin of the frame
  114. aiVector3D localOrigin ;
  115. //! radius of the BB
  116. float radius ;
  117. //! Name of the frame
  118. char name [ 16 ] ;
  119. } PACK_STRUCT;
  120. // ---------------------------------------------------------------------------
  121. /** \brief Data structure for a MDC triangle
  122. */
  123. struct Triangle
  124. {
  125. uint32_t aiIndices[3];
  126. } PACK_STRUCT;
  127. // ---------------------------------------------------------------------------
  128. /** \brief Data structure for a MDC texture coordinate
  129. */
  130. struct TexturCoord
  131. {
  132. float u,v;
  133. } PACK_STRUCT;
  134. // ---------------------------------------------------------------------------
  135. /** \brief Data structure for a MDC base vertex
  136. */
  137. struct BaseVertex
  138. {
  139. int16_t x,y,z;
  140. uint16_t normal;
  141. } PACK_STRUCT;
  142. // ---------------------------------------------------------------------------
  143. /** \brief Data structure for a MDC compressed vertex
  144. */
  145. struct CompressedVertex
  146. {
  147. uint8_t xd,yd,zd,nd;
  148. } PACK_STRUCT;
  149. // ---------------------------------------------------------------------------
  150. /** \brief Data structure for a MDC shader
  151. */
  152. struct Shader
  153. {
  154. char ucName [ AI_MDC_MAXQPATH ] ;
  155. uint32_t ulPath;
  156. } PACK_STRUCT;
  157. // reset packing to the original value
  158. #if defined(_MSC_VER) || defined(__BORLANDC__) || defined (__BCPLUSPLUS__)
  159. # pragma pack( pop )
  160. #endif
  161. #undef PACK_STRUCT
  162. // ---------------------------------------------------------------------------
  163. /** Build a floating point vertex from the compressed data in MDC files
  164. */
  165. void BuildVertex(const Frame& frame,
  166. const BaseVertex& bvert,
  167. const CompressedVertex& cvert,
  168. aiVector3D& vXYZOut,
  169. aiVector3D& vNorOut);
  170. }}
  171. #endif // !! AI_MDCFILEHELPER_H_INC