MD2FileData.h 4.7 KB

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