MDLFileData.h 26 KB

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