MD2FileData.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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. struct Header
  68. {
  69. uint32_t magic;
  70. uint32_t version;
  71. uint32_t skinWidth;
  72. uint32_t skinHeight;
  73. uint32_t frameSize;
  74. uint32_t numSkins;
  75. uint32_t numVertices;
  76. uint32_t numTexCoords;
  77. uint32_t numTriangles;
  78. uint32_t numGlCommands;
  79. uint32_t numFrames;
  80. uint32_t offsetSkins;
  81. uint32_t offsetTexCoords;
  82. uint32_t offsetTriangles;
  83. uint32_t offsetFrames;
  84. uint32_t offsetGlCommands;
  85. uint32_t offsetEnd;
  86. } PACK_STRUCT;
  87. // ---------------------------------------------------------------------------
  88. /** \brief Data structure for a MD2 OpenGl draw command
  89. */
  90. struct GLCommand
  91. {
  92. float s, t;
  93. uint32_t vertexIndex;
  94. } PACK_STRUCT;
  95. // ---------------------------------------------------------------------------
  96. /** \brief Data structure for a MD2 triangle
  97. */
  98. struct Triangle
  99. {
  100. uint16_t vertexIndices[3];
  101. uint16_t textureIndices[3];
  102. } PACK_STRUCT;
  103. // ---------------------------------------------------------------------------
  104. /** \brief Data structure for a MD2 vertex
  105. */
  106. struct Vertex
  107. {
  108. uint8_t vertex[3];
  109. uint8_t lightNormalIndex;
  110. } PACK_STRUCT;
  111. // ---------------------------------------------------------------------------
  112. /** \brief Data structure for a MD2 frame
  113. */
  114. struct Frame
  115. {
  116. float scale[3];
  117. float translate[3];
  118. char name[16];
  119. Vertex vertices[1];
  120. } PACK_STRUCT;
  121. // ---------------------------------------------------------------------------
  122. /** \brief Data structure for a MD2 texture coordinate
  123. */
  124. struct TexCoord
  125. {
  126. int16_t s;
  127. int16_t t;
  128. } PACK_STRUCT;
  129. // ---------------------------------------------------------------------------
  130. /** \brief Data structure for a MD2 skin
  131. */
  132. struct Skin
  133. {
  134. char name[AI_MD2_MAXQPATH]; /* texture file name */
  135. } PACK_STRUCT;
  136. // reset packing to the original value
  137. #if defined(_MSC_VER) || defined(__BORLANDC__) || defined (__BCPLUSPLUS__)
  138. # pragma pack( pop )
  139. #endif
  140. #undef PACK_STRUCT
  141. // ---------------------------------------------------------------------------
  142. //! Lookup a normal vector from Quake's normal lookup table
  143. //! \param index Input index (0-161)
  144. //! \param vOut Receives the output normal
  145. void LookupNormalIndex(uint8_t index,aiVector3D& vOut);
  146. };
  147. };
  148. #endif // !! include guard