MDLFileData.h 25 KB

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