MDCFileData.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. /*
  2. Open Asset Import Library (assimp)
  3. ----------------------------------------------------------------------
  4. Copyright (c) 2006-2016, 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 "endianesses"
  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. {
  63. uint32_t ulIdent ;
  64. uint32_t ulVersion ;
  65. char ucName [ AI_MDC_MAXQPATH ] ;
  66. uint32_t ulFlags ;
  67. uint32_t ulNumFrames ;
  68. uint32_t ulNumTags ;
  69. uint32_t ulNumSurfaces ;
  70. uint32_t ulNumSkins ;
  71. uint32_t ulOffsetBorderFrames ;
  72. uint32_t ulOffsetTagNames ;
  73. uint32_t ulOffsetTagFrames ;
  74. uint32_t ulOffsetSurfaces ;
  75. uint32_t ulOffsetEnd ;
  76. } PACK_STRUCT ;
  77. // ---------------------------------------------------------------------------
  78. /** \brief Data structure for a MDC file's surface header
  79. */
  80. struct Surface
  81. {
  82. uint32_t ulIdent ;
  83. char ucName [ AI_MDC_MAXQPATH ] ;
  84. uint32_t ulFlags ;
  85. uint32_t ulNumCompFrames ;
  86. uint32_t ulNumBaseFrames ;
  87. uint32_t ulNumShaders ;
  88. uint32_t ulNumVertices ;
  89. uint32_t ulNumTriangles ;
  90. uint32_t ulOffsetTriangles ;
  91. uint32_t ulOffsetShaders ;
  92. uint32_t ulOffsetTexCoords ;
  93. uint32_t ulOffsetBaseVerts ;
  94. uint32_t ulOffsetCompVerts ;
  95. uint32_t ulOffsetFrameBaseFrames ;
  96. uint32_t ulOffsetFrameCompFrames ;
  97. uint32_t ulOffsetEnd;
  98. Surface()
  99. : ulIdent(),
  100. ulFlags(),
  101. ulNumCompFrames(),
  102. ulNumBaseFrames(),
  103. ulNumShaders(),
  104. ulNumVertices(),
  105. ulNumTriangles(),
  106. ulOffsetTriangles(),
  107. ulOffsetShaders(),
  108. ulOffsetTexCoords(),
  109. ulOffsetBaseVerts(),
  110. ulOffsetCompVerts(),
  111. ulOffsetFrameBaseFrames(),
  112. ulOffsetFrameCompFrames(),
  113. ulOffsetEnd()
  114. {
  115. ucName[AI_MDC_MAXQPATH-1] = '\0';
  116. }
  117. } PACK_STRUCT;
  118. // ---------------------------------------------------------------------------
  119. /** \brief Data structure for a MDC frame
  120. */
  121. struct Frame
  122. {
  123. //! bounding box minimum coords
  124. aiVector3D bboxMin ;
  125. //! bounding box maximum coords
  126. aiVector3D bboxMax ;
  127. //! local origin of the frame
  128. aiVector3D localOrigin ;
  129. //! radius of the BB
  130. float radius ;
  131. //! Name of the frame
  132. char name [ 16 ] ;
  133. } PACK_STRUCT;
  134. // ---------------------------------------------------------------------------
  135. /** \brief Data structure for a MDC triangle
  136. */
  137. struct Triangle
  138. {
  139. uint32_t aiIndices[3];
  140. } PACK_STRUCT;
  141. // ---------------------------------------------------------------------------
  142. /** \brief Data structure for a MDC texture coordinate
  143. */
  144. struct TexturCoord
  145. {
  146. float u,v;
  147. } PACK_STRUCT;
  148. // ---------------------------------------------------------------------------
  149. /** \brief Data structure for a MDC base vertex
  150. */
  151. struct BaseVertex
  152. {
  153. int16_t x,y,z;
  154. uint16_t normal;
  155. } PACK_STRUCT;
  156. // ---------------------------------------------------------------------------
  157. /** \brief Data structure for a MDC compressed vertex
  158. */
  159. struct CompressedVertex
  160. {
  161. uint8_t xd,yd,zd,nd;
  162. } PACK_STRUCT;
  163. // ---------------------------------------------------------------------------
  164. /** \brief Data structure for a MDC shader
  165. */
  166. struct Shader
  167. {
  168. char ucName [ AI_MDC_MAXQPATH ] ;
  169. uint32_t ulPath;
  170. } PACK_STRUCT;
  171. #include <assimp/Compiler/poppack1.h>
  172. // ---------------------------------------------------------------------------
  173. /** Build a floating point vertex from the compressed data in MDC files
  174. */
  175. void BuildVertex(const Frame& frame,
  176. const BaseVertex& bvert,
  177. const CompressedVertex& cvert,
  178. aiVector3D& vXYZOut,
  179. aiVector3D& vNorOut);
  180. }}
  181. #endif // !! AI_MDCFILEHELPER_H_INC