MDCFileData.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /*
  2. Open Asset Import Library (assimp)
  3. ----------------------------------------------------------------------
  4. Copyright (c) 2006-2025, 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 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 <assimp/types.h>
  42. #include <assimp/mesh.h>
  43. #include <assimp/anim.h>
  44. #include <assimp/Compiler/pushpack1.h>
  45. #include <stdint.h>
  46. namespace Assimp {
  47. namespace MDC {
  48. // to make it easier for us, we test the magic word against both "endiannesses"
  49. #define AI_MDC_MAGIC_NUMBER_BE AI_MAKE_MAGIC("CPDI")
  50. #define AI_MDC_MAGIC_NUMBER_LE AI_MAKE_MAGIC("IDPC")
  51. // common limitations
  52. #define AI_MDC_VERSION 2
  53. #define AI_MDC_MAXQPATH 64
  54. #define AI_MDC_MAX_BONES 128
  55. #define AI_MDC_CVERT_BIAS 127.0f
  56. #define AI_MDC_DELTA_SCALING 4.0f
  57. #define AI_MDC_BASE_SCALING (1.0f / 64.0f)
  58. // ---------------------------------------------------------------------------
  59. /** \brief Data structure for a MDC file's main header
  60. */
  61. struct Header {
  62. uint32_t ulIdent ;
  63. uint32_t ulVersion ;
  64. char ucName [ AI_MDC_MAXQPATH ] ;
  65. uint32_t ulFlags ;
  66. uint32_t ulNumFrames ;
  67. uint32_t ulNumTags ;
  68. uint32_t ulNumSurfaces ;
  69. uint32_t ulNumSkins ;
  70. uint32_t ulOffsetBorderFrames ;
  71. uint32_t ulOffsetTagNames ;
  72. uint32_t ulOffsetTagFrames ;
  73. uint32_t ulOffsetSurfaces ;
  74. uint32_t ulOffsetEnd ;
  75. } PACK_STRUCT ;
  76. // ---------------------------------------------------------------------------
  77. /** \brief Data structure for a MDC file's surface header
  78. */
  79. struct Surface {
  80. uint32_t ulIdent ;
  81. char ucName [ AI_MDC_MAXQPATH ] ;
  82. uint32_t ulFlags ;
  83. uint32_t ulNumCompFrames ;
  84. uint32_t ulNumBaseFrames ;
  85. uint32_t ulNumShaders ;
  86. uint32_t ulNumVertices ;
  87. uint32_t ulNumTriangles ;
  88. uint32_t ulOffsetTriangles ;
  89. uint32_t ulOffsetShaders ;
  90. uint32_t ulOffsetTexCoords ;
  91. uint32_t ulOffsetBaseVerts ;
  92. uint32_t ulOffsetCompVerts ;
  93. uint32_t ulOffsetFrameBaseFrames ;
  94. uint32_t ulOffsetFrameCompFrames ;
  95. uint32_t ulOffsetEnd;
  96. Surface() AI_NO_EXCEPT
  97. : ulIdent()
  98. , ulFlags()
  99. , ulNumCompFrames()
  100. , ulNumBaseFrames()
  101. , ulNumShaders()
  102. , ulNumVertices()
  103. , ulNumTriangles()
  104. , ulOffsetTriangles()
  105. , ulOffsetShaders()
  106. , ulOffsetTexCoords()
  107. , ulOffsetBaseVerts()
  108. , ulOffsetCompVerts()
  109. , ulOffsetFrameBaseFrames()
  110. , ulOffsetFrameCompFrames()
  111. , ulOffsetEnd() {
  112. ucName[AI_MDC_MAXQPATH-1] = '\0';
  113. }
  114. } PACK_STRUCT;
  115. // ---------------------------------------------------------------------------
  116. /** \brief Data structure for a MDC frame
  117. */
  118. struct Frame {
  119. //! bounding box minimum coords
  120. aiVector3D bboxMin ;
  121. //! bounding box maximum coords
  122. aiVector3D bboxMax ;
  123. //! local origin of the frame
  124. aiVector3D localOrigin ;
  125. //! radius of the BB
  126. float radius ;
  127. //! Name of the frame
  128. char name [ 16 ] ;
  129. } /*PACK_STRUCT*/;
  130. // ---------------------------------------------------------------------------
  131. /** \brief Data structure for a MDC triangle
  132. */
  133. struct Triangle {
  134. uint32_t aiIndices[3];
  135. } PACK_STRUCT;
  136. // ---------------------------------------------------------------------------
  137. /** \brief Data structure for a MDC texture coordinate
  138. */
  139. struct TexturCoord {
  140. float u,v;
  141. } PACK_STRUCT;
  142. // ---------------------------------------------------------------------------
  143. /** \brief Data structure for a MDC base vertex
  144. */
  145. struct BaseVertex {
  146. int16_t x,y,z;
  147. uint16_t normal;
  148. } PACK_STRUCT;
  149. // ---------------------------------------------------------------------------
  150. /** \brief Data structure for a MDC compressed vertex
  151. */
  152. struct CompressedVertex {
  153. uint8_t xd,yd,zd,nd;
  154. } PACK_STRUCT;
  155. // ---------------------------------------------------------------------------
  156. /** \brief Data structure for a MDC shader
  157. */
  158. struct Shader {
  159. char ucName [ AI_MDC_MAXQPATH ] ;
  160. uint32_t ulPath;
  161. } PACK_STRUCT;
  162. #include <assimp/Compiler/poppack1.h>
  163. // ---------------------------------------------------------------------------
  164. /** Build a floating point vertex from the compressed data in MDC files
  165. */
  166. void BuildVertex(const Frame& frame,
  167. const BaseVertex& bvert,
  168. const CompressedVertex& cvert,
  169. aiVector3D& vXYZOut,
  170. aiVector3D& vNorOut);
  171. }
  172. }
  173. #endif // !! AI_MDCFILEHELPER_H_INC