MD2FileData.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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 MD2 files */
  34. #ifndef AI_MD2FILEHELPER_H_INC
  35. #define AI_MD2FILEHELPER_H_INC
  36. #include <string>
  37. #include <vector>
  38. #include <sstream>
  39. #include "../include/aiTypes.h"
  40. #include "../include/aiMesh.h"
  41. #include "../include/aiAnim.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://linux.ucla.edu/~phaethon/q3/formats/md2-schoenblum.html
  53. namespace MD2
  54. {
  55. #define AI_MD2_MAGIC_NUMBER_BE 'IDP2'
  56. #define AI_MD2_MAGIC_NUMBER_LE '2PDI'
  57. // common limitations
  58. #define AI_MD2_VERSION 15
  59. #define AI_MD2_MAXQPATH 64
  60. #define AI_MD2_MAX_FRAMES 512
  61. #define AI_MD2_MAX_SKINS 32
  62. #define AI_MD2_MAX_VERTS 2048
  63. #define AI_MD2_MAX_TRIANGLES 4096
  64. // ---------------------------------------------------------------------------
  65. /** \brief Data structure for the MD2 main header
  66. */
  67. // ---------------------------------------------------------------------------
  68. struct Header
  69. {
  70. int32_t magic;
  71. int32_t version;
  72. int32_t skinWidth;
  73. int32_t skinHeight;
  74. int32_t frameSize;
  75. int32_t numSkins;
  76. int32_t numVertices;
  77. int32_t numTexCoords;
  78. int32_t numTriangles;
  79. int32_t numGlCommands;
  80. int32_t numFrames;
  81. int32_t offsetSkins;
  82. int32_t offsetTexCoords;
  83. int32_t offsetTriangles;
  84. int32_t offsetFrames;
  85. int32_t offsetGlCommands;
  86. int32_t offsetEnd;
  87. } PACK_STRUCT;
  88. // ---------------------------------------------------------------------------
  89. /** \brief Data structure for a MD2 OpenGl draw command
  90. */
  91. // ---------------------------------------------------------------------------
  92. struct GLCommand
  93. {
  94. float s, t;
  95. uint32_t vertexIndex;
  96. } PACK_STRUCT;
  97. // ---------------------------------------------------------------------------
  98. /** \brief Data structure for a MD2 triangle
  99. */
  100. // ---------------------------------------------------------------------------
  101. struct Triangle
  102. {
  103. uint16_t vertexIndices[3];
  104. uint16_t textureIndices[3];
  105. } PACK_STRUCT;
  106. // ---------------------------------------------------------------------------
  107. /** \brief Data structure for a MD2 vertex
  108. */
  109. // ---------------------------------------------------------------------------
  110. struct Vertex
  111. {
  112. uint8_t vertex[3];
  113. uint8_t lightNormalIndex;
  114. } PACK_STRUCT;
  115. // ---------------------------------------------------------------------------
  116. /** \brief Data structure for a MD2 frame
  117. */
  118. // ---------------------------------------------------------------------------
  119. struct Frame
  120. {
  121. float scale[3];
  122. float translate[3];
  123. char name[16];
  124. Vertex vertices[1];
  125. } PACK_STRUCT;
  126. // ---------------------------------------------------------------------------
  127. /** \brief Data structure for a MD2 texture coordinate
  128. */
  129. // ---------------------------------------------------------------------------
  130. struct TexCoord
  131. {
  132. int16_t s;
  133. int16_t t;
  134. } PACK_STRUCT;
  135. // ---------------------------------------------------------------------------
  136. /** \brief Data structure for a MD2 skin
  137. */
  138. // ---------------------------------------------------------------------------
  139. struct Skin
  140. {
  141. char name[AI_MD2_MAXQPATH]; /* texture file name */
  142. } PACK_STRUCT;
  143. // reset packing to the original value
  144. #if defined(_MSC_VER) || defined(__BORLANDC__) || defined (__BCPLUSPLUS__)
  145. # pragma pack( pop )
  146. #endif
  147. #undef PACK_STRUCT
  148. };
  149. };
  150. #endif // !! include guard