MDLFileData.h 25 KB

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