MD2FileData.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /** @file Defines the helper data structures for importing MD2 files */
  2. #ifndef AI_MD2FILEHELPER_H_INC
  3. #define AI_MD2FILEHELPER_H_INC
  4. #include <string>
  5. #include <vector>
  6. #include <sstream>
  7. #include "../include/aiTypes.h"
  8. #include "../include/aiMesh.h"
  9. #include "../include/aiAnim.h"
  10. #if defined(_MSC_VER) || defined(__BORLANDC__) || defined (__BCPLUSPLUS__)
  11. # pragma pack(push,1)
  12. # define PACK_STRUCT
  13. #elif defined( __GNUC__ )
  14. # define PACK_STRUCT __attribute__((packed))
  15. #else
  16. # error Compiler not supported
  17. #endif
  18. namespace Assimp
  19. {
  20. //http://linux.ucla.edu/~phaethon/q3/formats/md2-schoenblum.html
  21. namespace MD2
  22. {
  23. #define AI_MD2_MAGIC_NUMBER_BE 'IDP2'
  24. #define AI_MD2_MAGIC_NUMBER_LE '2PDI'
  25. // common limitations
  26. #define AI_MD2_VERSION 15
  27. #define AI_MD2_MAXQPATH 64
  28. #define AI_MD2_MAX_FRAMES 512
  29. #define AI_MD2_MAX_SKINS 32
  30. #define AI_MD2_MAX_VERTS 2048
  31. #define AI_MD2_MAX_TRIANGLES 4096
  32. // ---------------------------------------------------------------------------
  33. /** \brief Data structure for the MD2 main header
  34. */
  35. // ---------------------------------------------------------------------------
  36. struct Header
  37. {
  38. int32_t magic;
  39. int32_t version;
  40. int32_t skinWidth;
  41. int32_t skinHeight;
  42. int32_t frameSize;
  43. int32_t numSkins;
  44. int32_t numVertices;
  45. int32_t numTexCoords;
  46. int32_t numTriangles;
  47. int32_t numGlCommands;
  48. int32_t numFrames;
  49. int32_t offsetSkins;
  50. int32_t offsetTexCoords;
  51. int32_t offsetTriangles;
  52. int32_t offsetFrames;
  53. int32_t offsetGlCommands;
  54. int32_t offsetEnd;
  55. } PACK_STRUCT;
  56. // ---------------------------------------------------------------------------
  57. /** \brief Data structure for a MD2 OpenGl draw command
  58. */
  59. // ---------------------------------------------------------------------------
  60. struct GLCommand
  61. {
  62. float s, t;
  63. uint32_t vertexIndex;
  64. } PACK_STRUCT;
  65. // ---------------------------------------------------------------------------
  66. /** \brief Data structure for a MD2 triangle
  67. */
  68. // ---------------------------------------------------------------------------
  69. struct Triangle
  70. {
  71. uint16_t vertexIndices[3];
  72. uint16_t textureIndices[3];
  73. } PACK_STRUCT;
  74. // ---------------------------------------------------------------------------
  75. /** \brief Data structure for a MD2 vertex
  76. */
  77. // ---------------------------------------------------------------------------
  78. struct Vertex
  79. {
  80. uint8_t vertex[3];
  81. uint8_t lightNormalIndex;
  82. } PACK_STRUCT;
  83. // ---------------------------------------------------------------------------
  84. /** \brief Data structure for a MD2 frame
  85. */
  86. // ---------------------------------------------------------------------------
  87. struct Frame
  88. {
  89. float scale[3];
  90. float translate[3];
  91. char name[16];
  92. Vertex vertices[1];
  93. } PACK_STRUCT;
  94. // ---------------------------------------------------------------------------
  95. /** \brief Data structure for a MD2 texture coordinate
  96. */
  97. // ---------------------------------------------------------------------------
  98. struct TexCoord
  99. {
  100. int16_t s;
  101. int16_t t;
  102. } PACK_STRUCT;
  103. // ---------------------------------------------------------------------------
  104. /** \brief Data structure for a MD2 skin
  105. */
  106. // ---------------------------------------------------------------------------
  107. struct Skin
  108. {
  109. char name[AI_MD2_MAXQPATH]; /* texture file name */
  110. } PACK_STRUCT;
  111. // reset packing to the original value
  112. #if defined(_MSC_VER) || defined(__BORLANDC__) || defined (__BCPLUSPLUS__)
  113. # pragma pack( pop )
  114. #endif
  115. #undef PACK_STRUCT
  116. };
  117. };
  118. #endif // !! include guard