MDLFileData.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944
  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. /**
  34. * @file MDLFileData.h
  35. * @brief Definition of in-memory structures for the MDL file format.
  36. *
  37. * The specification has been taken from various sources on the internet.
  38. * - http://tfc.duke.free.fr/coding/mdl-specs-en.html
  39. * - Conitec's MED SDK
  40. * - Many quite long HEX-editor sessions
  41. */
  42. #ifndef AI_MDLFILEHELPER_H_INC
  43. #define AI_MDLFILEHELPER_H_INC
  44. #include <assimp/anim.h>
  45. #include <assimp/mesh.h>
  46. #include <assimp/Compiler/pushpack1.h>
  47. #include <assimp/ByteSwapper.h>
  48. #include <stdint.h>
  49. #include <vector>
  50. struct aiMaterial;
  51. namespace Assimp {
  52. namespace MDL {
  53. // -------------------------------------------------------------------------------------
  54. // to make it easier for us, we test the magic word against both "endiannesses"
  55. // magic bytes used in Quake 1 MDL meshes
  56. #define AI_MDL_MAGIC_NUMBER_BE AI_MAKE_MAGIC("IDPO")
  57. #define AI_MDL_MAGIC_NUMBER_LE AI_MAKE_MAGIC("OPDI")
  58. // magic bytes used in GameStudio A<very low> MDL meshes
  59. #define AI_MDL_MAGIC_NUMBER_BE_GS3 AI_MAKE_MAGIC("MDL2")
  60. #define AI_MDL_MAGIC_NUMBER_LE_GS3 AI_MAKE_MAGIC("2LDM")
  61. // magic bytes used in GameStudio A4 MDL meshes
  62. #define AI_MDL_MAGIC_NUMBER_BE_GS4 AI_MAKE_MAGIC("MDL3")
  63. #define AI_MDL_MAGIC_NUMBER_LE_GS4 AI_MAKE_MAGIC("3LDM")
  64. // magic bytes used in GameStudio A5+ MDL meshes
  65. #define AI_MDL_MAGIC_NUMBER_BE_GS5a AI_MAKE_MAGIC("MDL4")
  66. #define AI_MDL_MAGIC_NUMBER_LE_GS5a AI_MAKE_MAGIC("4LDM")
  67. #define AI_MDL_MAGIC_NUMBER_BE_GS5b AI_MAKE_MAGIC("MDL5")
  68. #define AI_MDL_MAGIC_NUMBER_LE_GS5b AI_MAKE_MAGIC("5LDM")
  69. // magic bytes used in GameStudio A7+ MDL meshes
  70. #define AI_MDL_MAGIC_NUMBER_BE_GS7 AI_MAKE_MAGIC("MDL7")
  71. #define AI_MDL_MAGIC_NUMBER_LE_GS7 AI_MAKE_MAGIC("7LDM")
  72. // common limitations for Quake1 meshes. The loader does not check them,
  73. // (however it warns) but models should not exceed these limits.
  74. #if (!defined AI_MDL_VERSION)
  75. # define AI_MDL_VERSION 6
  76. #endif
  77. #if (!defined AI_MDL_MAX_FRAMES)
  78. # define AI_MDL_MAX_FRAMES 256
  79. #endif
  80. #if (!defined AI_MDL_MAX_UVS)
  81. # define AI_MDL_MAX_UVS 1024
  82. #endif
  83. #if (!defined AI_MDL_MAX_VERTS)
  84. # define AI_MDL_MAX_VERTS 1024
  85. #endif
  86. #if (!defined AI_MDL_MAX_TRIANGLES)
  87. # define AI_MDL_MAX_TRIANGLES 2048
  88. #endif
  89. // material key that is set for dummy materials that are
  90. // just referencing another material
  91. #if (!defined AI_MDL7_REFERRER_MATERIAL)
  92. # define AI_MDL7_REFERRER_MATERIAL "&&&referrer&&&",0,0
  93. #endif
  94. // -------------------------------------------------------------------------------------
  95. /** \struct Header
  96. * \brief Data structure for the MDL main header
  97. */
  98. struct Header {
  99. //! magic number: "IDPO"
  100. uint32_t ident;
  101. //! version number: 6
  102. int32_t version;
  103. //! scale factors for each axis
  104. ai_real scale[3];
  105. //! translation factors for each axis
  106. ai_real translate[3];
  107. //! bounding radius of the mesh
  108. float boundingradius;
  109. //! Position of the viewer's exe. Ignored
  110. ai_real vEyePos[3];
  111. //! Number of textures
  112. int32_t num_skins;
  113. //! Texture width in pixels
  114. int32_t skinwidth;
  115. //! Texture height in pixels
  116. int32_t skinheight;
  117. //! Number of vertices contained in the file
  118. int32_t num_verts;
  119. //! Number of triangles contained in the file
  120. int32_t num_tris;
  121. //! Number of frames contained in the file
  122. int32_t num_frames;
  123. //! 0 = synchron, 1 = random . Ignored
  124. //! (MDLn formats: number of texture coordinates)
  125. int32_t synctype;
  126. //! State flag
  127. int32_t flags;
  128. //! Could be the total size of the file (and not a float)
  129. float size;
  130. } PACK_STRUCT;
  131. // -------------------------------------------------------------------------------------
  132. /** \struct Header_MDL7
  133. * \brief Data structure for the MDL 7 main header
  134. */
  135. struct Header_MDL7 {
  136. //! magic number: "MDL7"
  137. char ident[4];
  138. //! Version number. Ignored
  139. int32_t version;
  140. //! Number of bones in file
  141. uint32_t bones_num;
  142. //! Number of groups in file
  143. uint32_t groups_num;
  144. //! Size of data in the file
  145. uint32_t data_size;
  146. //! Ignored. Used to store entity specific information
  147. int32_t entlump_size;
  148. //! Ignored. Used to store MED related data
  149. int32_t medlump_size;
  150. //! Size of the Bone_MDL7 data structure used in the file
  151. uint16_t bone_stc_size;
  152. //! Size of the Skin_MDL 7 data structure used in the file
  153. uint16_t skin_stc_size;
  154. //! Size of a single color (e.g. in a material)
  155. uint16_t colorvalue_stc_size;
  156. //! Size of the Material_MDL7 data structure used in the file
  157. uint16_t material_stc_size;
  158. //! Size of a texture coordinate set in the file
  159. uint16_t skinpoint_stc_size;
  160. //! Size of a triangle in the file
  161. uint16_t triangle_stc_size;
  162. //! Size of a normal vertex in the file
  163. uint16_t mainvertex_stc_size;
  164. //! Size of a per-frame animated vertex in the file
  165. //! (this is not supported)
  166. uint16_t framevertex_stc_size;
  167. //! Size of a bone animation matrix
  168. uint16_t bonetrans_stc_size;
  169. //! Size of the Frame_MDL7 data structure used in the file
  170. uint16_t frame_stc_size;
  171. } PACK_STRUCT;
  172. // -------------------------------------------------------------------------------------
  173. /** \struct Bone_MDL7
  174. * \brief Data structure for a bone in a MDL7 file
  175. */
  176. struct Bone_MDL7 {
  177. //! Index of the parent bone of *this* bone. 0xffff means:
  178. //! "hey, I have no parent, I'm an orphan"
  179. uint16_t parent_index;
  180. uint8_t _unused_[2];
  181. //! Relative position of the bone (relative to the
  182. //! parent bone)
  183. float x,y,z;
  184. //! Optional name of the bone
  185. char name[1 /* DUMMY SIZE */];
  186. } PACK_STRUCT;
  187. #if (!defined AI_MDL7_BONE_STRUCT_SIZE__NAME_IS_20_CHARS)
  188. # define AI_MDL7_BONE_STRUCT_SIZE__NAME_IS_20_CHARS (16 + 20)
  189. #endif
  190. #if (!defined AI_MDL7_BONE_STRUCT_SIZE__NAME_IS_32_CHARS)
  191. # define AI_MDL7_BONE_STRUCT_SIZE__NAME_IS_32_CHARS (16 + 32)
  192. #endif
  193. #if (!defined AI_MDL7_BONE_STRUCT_SIZE__NAME_IS_NOT_THERE)
  194. # define AI_MDL7_BONE_STRUCT_SIZE__NAME_IS_NOT_THERE (16)
  195. #endif
  196. #if (!defined AI_MDL7_MAX_GROUPNAMESIZE)
  197. # define AI_MDL7_MAX_GROUPNAMESIZE 16
  198. #endif // ! AI_MDL7_MAX_GROUPNAMESIZE
  199. // -------------------------------------------------------------------------------------
  200. /** \struct Group_MDL7
  201. * \brief Group in a MDL7 file
  202. */
  203. struct Group_MDL7 {
  204. //! = '1' -> triangle based Mesh
  205. unsigned char typ;
  206. int8_t deformers;
  207. int8_t max_weights;
  208. int8_t _unused_;
  209. //! size of data for this group in bytes ( MD7_GROUP stc. included).
  210. int32_t groupdata_size;
  211. char name[AI_MDL7_MAX_GROUPNAMESIZE];
  212. //! Number of skins
  213. int32_t numskins;
  214. //! Number of texture coordinates
  215. int32_t num_stpts;
  216. //! Number of triangles
  217. int32_t numtris;
  218. //! Number of vertices
  219. int32_t numverts;
  220. //! Number of frames
  221. int32_t numframes;
  222. } PACK_STRUCT;
  223. #define AI_MDL7_SKINTYPE_MIPFLAG 0x08
  224. #define AI_MDL7_SKINTYPE_MATERIAL 0x10
  225. #define AI_MDL7_SKINTYPE_MATERIAL_ASCDEF 0x20
  226. #define AI_MDL7_SKINTYPE_RGBFLAG 0x80
  227. #if (!defined AI_MDL7_MAX_BONENAMESIZE)
  228. # define AI_MDL7_MAX_BONENAMESIZE 20
  229. #endif // !! AI_MDL7_MAX_BONENAMESIZE
  230. // -------------------------------------------------------------------------------------
  231. /** \struct Deformer_MDL7
  232. * \brief Deformer in a MDL7 file
  233. */
  234. struct Deformer_MDL7 {
  235. int8_t deformer_version; // 0
  236. int8_t deformer_typ; // 0 - bones
  237. int8_t _unused_[2];
  238. int32_t group_index;
  239. int32_t elements;
  240. int32_t deformerdata_size;
  241. } PACK_STRUCT;
  242. // -------------------------------------------------------------------------------------
  243. /** \struct DeformerElement_MDL7
  244. * \brief Deformer element in a MDL7 file
  245. */
  246. struct DeformerElement_MDL7 {
  247. //! bei deformer_typ==0 (==bones) element_index == bone index
  248. int32_t element_index;
  249. char element_name[AI_MDL7_MAX_BONENAMESIZE];
  250. int32_t weights;
  251. } PACK_STRUCT;
  252. // -------------------------------------------------------------------------------------
  253. /** \struct DeformerWeight_MDL7
  254. * \brief Deformer weight in a MDL7 file
  255. */
  256. struct DeformerWeight_MDL7 {
  257. //! for deformer_typ==0 (==bones) index == vertex index
  258. int32_t index;
  259. float weight;
  260. } PACK_STRUCT;
  261. // don't know why this was in the original headers ...
  262. typedef int32_t MD7_MATERIAL_ASCDEFSIZE;
  263. // -------------------------------------------------------------------------------------
  264. /** \struct ColorValue_MDL7
  265. * \brief Data structure for a color value in a MDL7 file
  266. */
  267. struct ColorValue_MDL7 {
  268. float r,g,b,a;
  269. } PACK_STRUCT;
  270. // -------------------------------------------------------------------------------------
  271. /** \struct Material_MDL7
  272. * \brief Data structure for a Material in a MDL7 file
  273. */
  274. struct Material_MDL7 {
  275. //! Diffuse base color of the material
  276. ColorValue_MDL7 Diffuse;
  277. //! Ambient base color of the material
  278. ColorValue_MDL7 Ambient;
  279. //! Specular base color of the material
  280. ColorValue_MDL7 Specular;
  281. //! Emissive base color of the material
  282. ColorValue_MDL7 Emissive;
  283. //! Phong power
  284. float Power;
  285. } PACK_STRUCT;
  286. // -------------------------------------------------------------------------------------
  287. /** \struct Skin
  288. * \brief Skin data structure #1 - used by Quake1, MDL2, MDL3 and MDL4
  289. */
  290. struct Skin {
  291. //! 0 = single (Skin), 1 = group (GroupSkin)
  292. //! For MDL3-5: Defines the type of the skin and there
  293. //! fore the size of the data to skip:
  294. //-------------------------------------------------------
  295. //! 2 for 565 RGB,
  296. //! 3 for 4444 ARGB,
  297. //! 10 for 565 mipmapped,
  298. //! 11 for 4444 mipmapped (bpp = 2),
  299. //! 12 for 888 RGB mipmapped (bpp = 3),
  300. //! 13 for 8888 ARGB mipmapped (bpp = 4)
  301. //-------------------------------------------------------
  302. int32_t group;
  303. //! Texture data
  304. uint8_t *data;
  305. } PACK_STRUCT;
  306. // -------------------------------------------------------------------------------------
  307. /** \struct Skin
  308. * \brief Skin data structure #2 - used by MDL5, MDL6 and MDL7
  309. * \see Skin
  310. */
  311. struct Skin_MDL5 {
  312. int32_t size, width, height;
  313. uint8_t *data;
  314. } PACK_STRUCT;
  315. // maximum length of texture file name
  316. #if (!defined AI_MDL7_MAX_TEXNAMESIZE)
  317. # define AI_MDL7_MAX_TEXNAMESIZE 0x10
  318. #endif
  319. // ---------------------------------------------------------------------------
  320. /** \struct Skin_MDL7
  321. * \brief Skin data structure #3 - used by MDL7 and HMP7
  322. */
  323. struct Skin_MDL7 {
  324. uint8_t typ;
  325. int8_t _unused_[3];
  326. int32_t width;
  327. int32_t height;
  328. char texture_name[AI_MDL7_MAX_TEXNAMESIZE];
  329. } PACK_STRUCT;
  330. // -------------------------------------------------------------------------------------
  331. /** \struct RGB565
  332. * \brief Data structure for a RGB565 pixel in a texture
  333. */
  334. struct RGB565 {
  335. uint16_t r : 5;
  336. uint16_t g : 6;
  337. uint16_t b : 5;
  338. } PACK_STRUCT;
  339. // -------------------------------------------------------------------------------------
  340. /** \struct ARGB4
  341. * \brief Data structure for a ARGB4444 pixel in a texture
  342. */
  343. struct ARGB4 {
  344. uint16_t a : 4;
  345. uint16_t r : 4;
  346. uint16_t g : 4;
  347. uint16_t b : 4;
  348. } /*PACK_STRUCT*/;
  349. // -------------------------------------------------------------------------------------
  350. /** \struct GroupSkin
  351. * \brief Skin data structure #2 (group of pictures)
  352. */
  353. struct GroupSkin {
  354. //! 0 = single (Skin), 1 = group (GroupSkin)
  355. int32_t group;
  356. //! Number of images
  357. int32_t nb;
  358. //! Time for each image
  359. float *time;
  360. //! Data of each image
  361. uint8_t **data;
  362. } PACK_STRUCT;
  363. // -------------------------------------------------------------------------------------
  364. /** \struct TexCoord
  365. * \brief Texture coordinate data structure used by the Quake1 MDL format
  366. */
  367. struct TexCoord {
  368. //! Is the vertex on the noundary between front and back piece?
  369. int32_t onseam;
  370. //! Texture coordinate in the tx direction
  371. int32_t s;
  372. //! Texture coordinate in the ty direction
  373. int32_t t;
  374. } PACK_STRUCT;
  375. // -------------------------------------------------------------------------------------
  376. /** \struct TexCoord_MDL3
  377. * \brief Data structure for an UV coordinate in the 3DGS MDL3 format
  378. */
  379. struct TexCoord_MDL3 {
  380. //! position, horizontally in range 0..skinwidth-1
  381. int16_t u;
  382. //! position, vertically in range 0..skinheight-1
  383. int16_t v;
  384. } PACK_STRUCT;
  385. // -------------------------------------------------------------------------------------
  386. /** \struct TexCoord_MDL7
  387. * \brief Data structure for an UV coordinate in the 3DGS MDL7 format
  388. */
  389. struct TexCoord_MDL7 {
  390. //! position, horizontally in range 0..1
  391. float u;
  392. //! position, vertically in range 0..1
  393. float v;
  394. } PACK_STRUCT;
  395. // -------------------------------------------------------------------------------------
  396. /** \struct SkinSet_MDL7
  397. * \brief Skin set data structure for the 3DGS MDL7 format
  398. * MDL7 references UV coordinates per face via an index list.
  399. * This allows the use of multiple skins per face with just one
  400. * UV coordinate set.
  401. */
  402. struct SkinSet_MDL7
  403. {
  404. //! Index into the UV coordinate list
  405. uint16_t st_index[3]; // size 6
  406. //! Material index
  407. int32_t material; // size 4
  408. } PACK_STRUCT;
  409. // -------------------------------------------------------------------------------------
  410. /** \struct Triangle
  411. * \brief Triangle data structure for the Quake1 MDL format
  412. */
  413. struct Triangle
  414. {
  415. //! 0 = backface, 1 = frontface
  416. int32_t facesfront;
  417. //! Vertex indices
  418. int32_t vertex[3];
  419. } PACK_STRUCT;
  420. // -------------------------------------------------------------------------------------
  421. /** \struct Triangle_MDL3
  422. * \brief Triangle data structure for the 3DGS MDL3 format
  423. */
  424. struct Triangle_MDL3
  425. {
  426. //! Index of 3 3D vertices in range 0..numverts
  427. uint16_t index_xyz[3];
  428. //! Index of 3 skin vertices in range 0..numskinverts
  429. uint16_t index_uv[3];
  430. } PACK_STRUCT;
  431. // -------------------------------------------------------------------------------------
  432. /** \struct Triangle_MDL7
  433. * \brief Triangle data structure for the 3DGS MDL7 format
  434. */
  435. struct Triangle_MDL7
  436. {
  437. //! Vertex indices
  438. uint16_t v_index[3]; // size 6
  439. //! Two skinsets. The second will be used for multi-texturing
  440. SkinSet_MDL7 skinsets[2];
  441. } PACK_STRUCT;
  442. #if (!defined AI_MDL7_TRIANGLE_STD_SIZE_ONE_UV)
  443. # define AI_MDL7_TRIANGLE_STD_SIZE_ONE_UV (6+sizeof(SkinSet_MDL7)-sizeof(uint32_t))
  444. #endif
  445. #if (!defined AI_MDL7_TRIANGLE_STD_SIZE_ONE_UV_WITH_MATINDEX)
  446. # define AI_MDL7_TRIANGLE_STD_SIZE_ONE_UV_WITH_MATINDEX (6+sizeof(SkinSet_MDL7))
  447. #endif
  448. #if (!defined AI_MDL7_TRIANGLE_STD_SIZE_TWO_UV)
  449. # define AI_MDL7_TRIANGLE_STD_SIZE_TWO_UV (6+2*sizeof(SkinSet_MDL7))
  450. #endif
  451. // Helper constants for Triangle::facesfront
  452. #if (!defined AI_MDL_BACKFACE)
  453. # define AI_MDL_BACKFACE 0x0
  454. #endif
  455. #if (!defined AI_MDL_FRONTFACE)
  456. # define AI_MDL_FRONTFACE 0x1
  457. #endif
  458. // -------------------------------------------------------------------------------------
  459. /** \struct Vertex
  460. * \brief Vertex data structure
  461. */
  462. struct Vertex
  463. {
  464. uint8_t v[3];
  465. uint8_t normalIndex;
  466. } PACK_STRUCT;
  467. // -------------------------------------------------------------------------------------
  468. struct Vertex_MDL4
  469. {
  470. uint16_t v[3];
  471. uint8_t normalIndex;
  472. uint8_t unused;
  473. } PACK_STRUCT;
  474. #define AI_MDL7_FRAMEVERTEX120503_STCSIZE 16
  475. #define AI_MDL7_FRAMEVERTEX030305_STCSIZE 26
  476. // -------------------------------------------------------------------------------------
  477. /** \struct Vertex_MDL7
  478. * \brief Vertex data structure used in MDL7 files
  479. */
  480. struct Vertex_MDL7
  481. {
  482. float x,y,z;
  483. uint16_t vertindex; // = bone index
  484. union {
  485. uint8_t norm162index;
  486. float norm[3];
  487. };
  488. } PACK_STRUCT;
  489. // -------------------------------------------------------------------------------------
  490. /** \struct BoneTransform_MDL7
  491. * \brief bone transformation matrix structure used in MDL7 files
  492. */
  493. struct BoneTransform_MDL7
  494. {
  495. //! 4*3
  496. float m [4*4];
  497. //! the index of this vertex, 0.. header::bones_num - 1
  498. uint16_t bone_index;
  499. //! I HATE 3DGS AND THE SILLY DEVELOPER WHO DESIGNED
  500. //! THIS STUPID FILE FORMAT!
  501. int8_t _unused_[2];
  502. } PACK_STRUCT;
  503. #define AI_MDL7_MAX_FRAMENAMESIZE 16
  504. // -------------------------------------------------------------------------------------
  505. /** \struct Frame_MDL7
  506. * \brief Frame data structure used by MDL7 files
  507. */
  508. struct Frame_MDL7
  509. {
  510. char frame_name[AI_MDL7_MAX_FRAMENAMESIZE];
  511. uint32_t vertices_count;
  512. uint32_t transmatrix_count;
  513. };
  514. // -------------------------------------------------------------------------------------
  515. /** \struct SimpleFrame
  516. * \brief Data structure for a simple frame
  517. */
  518. struct SimpleFrame
  519. {
  520. //! Minimum vertex of the bounding box
  521. Vertex bboxmin;
  522. //! Maximum vertex of the bounding box
  523. Vertex bboxmax;
  524. //! Name of the frame
  525. char name[16];
  526. //! Vertex list of the frame
  527. Vertex *verts;
  528. } PACK_STRUCT;
  529. // -------------------------------------------------------------------------------------
  530. /** \struct Frame
  531. * \brief Model frame data structure
  532. */
  533. struct Frame
  534. {
  535. //! 0 = simple frame, !0 = group frame
  536. int32_t type;
  537. //! Frame data
  538. SimpleFrame frame;
  539. } PACK_STRUCT;
  540. // -------------------------------------------------------------------------------------
  541. struct SimpleFrame_MDLn_SP
  542. {
  543. //! Minimum vertex of the bounding box
  544. Vertex_MDL4 bboxmin;
  545. //! Maximum vertex of the bounding box
  546. Vertex_MDL4 bboxmax;
  547. //! Name of the frame
  548. char name[16];
  549. //! Vertex list of the frame
  550. Vertex_MDL4 *verts;
  551. } PACK_STRUCT;
  552. // -------------------------------------------------------------------------------------
  553. /** \struct GroupFrame
  554. * \brief Data structure for a group of frames
  555. */
  556. struct GroupFrame
  557. {
  558. //! 0 = simple frame, !0 = group frame
  559. int32_t type;
  560. int32_t numframes;
  561. //! Minimum vertex for all single frames
  562. Vertex min;
  563. //! Maximum vertex for all single frames
  564. Vertex max;
  565. //! List of times for all single frames
  566. float *times;
  567. //! List of single frames
  568. SimpleFrame *frames;
  569. } PACK_STRUCT;
  570. #include <assimp/Compiler/poppack1.h>
  571. // -------------------------------------------------------------------------------------
  572. /** \struct IntFace_MDL7
  573. * \brief Internal data structure to temporarily represent a face
  574. */
  575. struct IntFace_MDL7 {
  576. // provide a constructor for our own convenience
  577. IntFace_MDL7() AI_NO_EXCEPT {
  578. ::memset( mIndices, 0, sizeof(uint32_t) *3);
  579. ::memset( iMatIndex, 0, sizeof( unsigned int) *2);
  580. }
  581. //! Vertex indices
  582. uint32_t mIndices[3];
  583. //! Material index (maximally two channels, which are joined later)
  584. unsigned int iMatIndex[2];
  585. };
  586. // -------------------------------------------------------------------------------------
  587. /** \struct IntMaterial_MDL7
  588. * \brief Internal data structure to temporarily represent a material
  589. * which has been created from two single materials along with the
  590. * original material indices.
  591. */
  592. struct IntMaterial_MDL7 {
  593. // provide a constructor for our own convenience
  594. IntMaterial_MDL7() AI_NO_EXCEPT
  595. : pcMat( nullptr ) {
  596. ::memset( iOldMatIndices, 0, sizeof(unsigned int) *2);
  597. }
  598. //! Material instance
  599. aiMaterial* pcMat;
  600. //! Old material indices
  601. unsigned int iOldMatIndices[2];
  602. };
  603. // -------------------------------------------------------------------------------------
  604. /** \struct IntBone_MDL7
  605. * \brief Internal data structure to represent a bone in a MDL7 file with
  606. * all of its animation channels assigned to it.
  607. */
  608. struct IntBone_MDL7 : aiBone
  609. {
  610. //! Default constructor
  611. IntBone_MDL7() AI_NO_EXCEPT : iParent (0xffff)
  612. {
  613. pkeyPositions.reserve(30);
  614. pkeyScalings.reserve(30);
  615. pkeyRotations.reserve(30);
  616. }
  617. //! Parent bone of the bone
  618. uint64_t iParent;
  619. //! Relative position of the bone
  620. aiVector3D vPosition;
  621. //! Array of position keys
  622. std::vector<aiVectorKey> pkeyPositions;
  623. //! Array of scaling keys
  624. std::vector<aiVectorKey> pkeyScalings;
  625. //! Array of rotation keys
  626. std::vector<aiQuatKey> pkeyRotations;
  627. };
  628. // -------------------------------------------------------------------------------------
  629. //! Describes a MDL7 frame
  630. struct IntFrameInfo_MDL7
  631. {
  632. //! Construction from an existing frame header
  633. IntFrameInfo_MDL7(BE_NCONST MDL::Frame_MDL7* _pcFrame,unsigned int _iIndex)
  634. : iIndex(_iIndex)
  635. , pcFrame(_pcFrame)
  636. {}
  637. //! Index of the frame
  638. unsigned int iIndex;
  639. //! Points to the header of the frame
  640. BE_NCONST MDL::Frame_MDL7* pcFrame;
  641. };
  642. // -------------------------------------------------------------------------------------
  643. //! Describes a MDL7 mesh group
  644. struct IntGroupInfo_MDL7
  645. {
  646. //! Default constructor
  647. IntGroupInfo_MDL7() AI_NO_EXCEPT
  648. : iIndex(0)
  649. , pcGroup(nullptr)
  650. , pcGroupUVs(nullptr)
  651. , pcGroupTris(nullptr)
  652. , pcGroupVerts(nullptr)
  653. {}
  654. //! Construction from an existing group header
  655. IntGroupInfo_MDL7(BE_NCONST MDL::Group_MDL7* _pcGroup, unsigned int _iIndex)
  656. : iIndex(_iIndex)
  657. , pcGroup(_pcGroup)
  658. , pcGroupUVs()
  659. , pcGroupTris()
  660. , pcGroupVerts()
  661. {}
  662. //! Index of the group
  663. unsigned int iIndex;
  664. //! Points to the header of the group
  665. BE_NCONST MDL::Group_MDL7* pcGroup;
  666. //! Points to the beginning of the uv coordinate section
  667. BE_NCONST MDL::TexCoord_MDL7* pcGroupUVs;
  668. //! Points to the beginning of the triangle section
  669. MDL::Triangle_MDL7* pcGroupTris;
  670. //! Points to the beginning of the vertex section
  671. BE_NCONST MDL::Vertex_MDL7* pcGroupVerts;
  672. };
  673. // -------------------------------------------------------------------------------------
  674. //! Holds the data that belongs to a MDL7 mesh group
  675. struct IntGroupData_MDL7
  676. {
  677. IntGroupData_MDL7() AI_NO_EXCEPT
  678. : bNeed2UV(false)
  679. {}
  680. //! Array of faces that belong to the group
  681. std::vector<MDL::IntFace_MDL7> pcFaces;
  682. //! Array of vertex positions
  683. std::vector<aiVector3D> vPositions;
  684. //! Array of vertex normals
  685. std::vector<aiVector3D> vNormals;
  686. //! Array of bones indices
  687. std::vector<unsigned int> aiBones;
  688. //! First UV coordinate set
  689. std::vector<aiVector3D> vTextureCoords1;
  690. //! Optional second UV coordinate set
  691. std::vector<aiVector3D> vTextureCoords2;
  692. //! Specifies whether there are two texture
  693. //! coordinate sets required
  694. bool bNeed2UV;
  695. };
  696. // -------------------------------------------------------------------------------------
  697. //! Holds data from an MDL7 file that is shared by all mesh groups
  698. struct IntSharedData_MDL7 {
  699. //! Default constructor
  700. IntSharedData_MDL7() AI_NO_EXCEPT
  701. : apcOutBones(),
  702. iNum()
  703. {
  704. abNeedMaterials.reserve(12);
  705. }
  706. //! Destruction: properly delete all allocated resources
  707. ~IntSharedData_MDL7()
  708. {
  709. // kill all bones
  710. if (this->apcOutBones)
  711. {
  712. for (unsigned int m = 0; m < iNum;++m)
  713. delete this->apcOutBones[m];
  714. delete[] this->apcOutBones;
  715. }
  716. }
  717. //! Specifies which materials are used
  718. std::vector<bool> abNeedMaterials;
  719. //! List of all materials
  720. std::vector<aiMaterial*> pcMats;
  721. //! List of all bones
  722. IntBone_MDL7** apcOutBones;
  723. //! number of bones
  724. unsigned int iNum;
  725. };
  726. // -------------------------------------------------------------------------------------
  727. //! Contains input data for GenerateOutputMeshes_3DGS_MDL7
  728. struct IntSplitGroupData_MDL7
  729. {
  730. //! Construction from a given shared data set
  731. IntSplitGroupData_MDL7(IntSharedData_MDL7& _shared,
  732. std::vector<aiMesh*>& _avOutList)
  733. : aiSplit(), shared(_shared), avOutList(_avOutList)
  734. {
  735. }
  736. //! Destruction: properly delete all allocated resources
  737. ~IntSplitGroupData_MDL7()
  738. {
  739. // kill all face lists
  740. if(this->aiSplit)
  741. {
  742. for (unsigned int m = 0; m < shared.pcMats.size();++m)
  743. delete this->aiSplit[m];
  744. delete[] this->aiSplit;
  745. }
  746. }
  747. //! Contains a list of all faces per material
  748. std::vector<unsigned int>** aiSplit;
  749. //! Shared data for all groups of the model
  750. IntSharedData_MDL7& shared;
  751. //! List of meshes
  752. std::vector<aiMesh*>& avOutList;
  753. };
  754. }
  755. } // end namespaces
  756. #endif // !! AI_MDLFILEHELPER_H_INC