MDLFileData.h 25 KB

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