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