MDLFileData.h 25 KB

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