MDLFileData.h 26 KB

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