MD2FileData.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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 MD2FileData.h
  34. * @brief Defines helper data structures for importing MD2 files
  35. * http://linux.ucla.edu/~phaethon/q3/formats/md2-schoenblum.html
  36. */
  37. #ifndef AI_MD2FILEHELPER_H_INC
  38. #define AI_MD2FILEHELPER_H_INC
  39. #include <assimp/types.h>
  40. #include <assimp/mesh.h>
  41. #include <assimp/anim.h>
  42. #include <stdint.h>
  43. #include <assimp/Compiler/pushpack1.h>
  44. namespace Assimp {
  45. namespace MD2 {
  46. // to make it easier for us, we test the magic word against both "endianesses"
  47. #define AI_MD2_MAGIC_NUMBER_BE AI_MAKE_MAGIC("IDP2")
  48. #define AI_MD2_MAGIC_NUMBER_LE AI_MAKE_MAGIC("2PDI")
  49. // common limitations
  50. #define AI_MD2_VERSION 15
  51. #define AI_MD2_MAXQPATH 64
  52. #define AI_MD2_MAX_FRAMES 512
  53. #define AI_MD2_MAX_SKINS 32
  54. #define AI_MD2_MAX_VERTS 2048
  55. #define AI_MD2_MAX_TRIANGLES 4096
  56. // ---------------------------------------------------------------------------
  57. /** \brief Data structure for the MD2 main header
  58. */
  59. struct Header
  60. {
  61. uint32_t magic;
  62. uint32_t version;
  63. uint32_t skinWidth;
  64. uint32_t skinHeight;
  65. uint32_t frameSize;
  66. uint32_t numSkins;
  67. uint32_t numVertices;
  68. uint32_t numTexCoords;
  69. uint32_t numTriangles;
  70. uint32_t numGlCommands;
  71. uint32_t numFrames;
  72. uint32_t offsetSkins;
  73. uint32_t offsetTexCoords;
  74. uint32_t offsetTriangles;
  75. uint32_t offsetFrames;
  76. uint32_t offsetGlCommands;
  77. uint32_t offsetEnd;
  78. } PACK_STRUCT;
  79. // ---------------------------------------------------------------------------
  80. /** \brief Data structure for a MD2 OpenGl draw command
  81. */
  82. struct GLCommand
  83. {
  84. float s, t;
  85. uint32_t vertexIndex;
  86. } PACK_STRUCT;
  87. // ---------------------------------------------------------------------------
  88. /** \brief Data structure for a MD2 triangle
  89. */
  90. struct Triangle
  91. {
  92. uint16_t vertexIndices[3];
  93. uint16_t textureIndices[3];
  94. } PACK_STRUCT;
  95. // ---------------------------------------------------------------------------
  96. /** \brief Data structure for a MD2 vertex
  97. */
  98. struct Vertex
  99. {
  100. uint8_t vertex[3];
  101. uint8_t lightNormalIndex;
  102. } PACK_STRUCT;
  103. // ---------------------------------------------------------------------------
  104. /** \brief Data structure for a MD2 frame
  105. */
  106. struct Frame
  107. {
  108. float scale[3];
  109. float translate[3];
  110. char name[16];
  111. Vertex vertices[1];
  112. } PACK_STRUCT;
  113. // ---------------------------------------------------------------------------
  114. /** \brief Data structure for a MD2 texture coordinate
  115. */
  116. struct TexCoord
  117. {
  118. uint16_t s;
  119. uint16_t t;
  120. } PACK_STRUCT;
  121. // ---------------------------------------------------------------------------
  122. /** \brief Data structure for a MD2 skin
  123. */
  124. struct Skin
  125. {
  126. char name[AI_MD2_MAXQPATH]; /* texture file name */
  127. } PACK_STRUCT;
  128. #include <assimp/Compiler/poppack1.h>
  129. // ---------------------------------------------------------------------------
  130. //! Lookup a normal vector from Quake's normal lookup table
  131. //! \param index Input index (0-161)
  132. //! \param vOut Receives the output normal
  133. void LookupNormalIndex(uint8_t index,aiVector3D& vOut);
  134. }
  135. }
  136. #endif // !! include guard