MDLFileData.h 26 KB

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