MDLFileData.h 25 KB

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