1/*
2Open Asset Import Library (assimp)
3----------------------------------------------------------------------
4
5Copyright (c) 2006-2017, assimp team
6
7All rights reserved.
8
9Redistribution and use of this software in source and binary forms,
10with or without modification, are permitted provided that the
11following 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
27THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
32SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
34DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
35THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37OF 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 "ByteSwapper.h"
60#include <stdint.h>
61#include <vector>
62
63struct aiMaterial;
64
65namespace Assimp {
66namespace MDL {
67
68// -------------------------------------------------------------------------------------
69// to make it easier for us, we test the magic word against both "endianesses"
70
71// magic bytes used in Quake 1 MDL meshes
72#define AI_MDL_MAGIC_NUMBER_BE AI_MAKE_MAGIC("IDPO")
73#define AI_MDL_MAGIC_NUMBER_LE AI_MAKE_MAGIC("OPDI")
74
75// magic bytes used in GameStudio A<very low> MDL meshes
76#define AI_MDL_MAGIC_NUMBER_BE_GS3 AI_MAKE_MAGIC("MDL2")
77#define AI_MDL_MAGIC_NUMBER_LE_GS3 AI_MAKE_MAGIC("2LDM")
78
79// magic bytes used in GameStudio A4 MDL meshes
80#define AI_MDL_MAGIC_NUMBER_BE_GS4 AI_MAKE_MAGIC("MDL3")
81#define AI_MDL_MAGIC_NUMBER_LE_GS4 AI_MAKE_MAGIC("3LDM")
82
83// magic bytes used in GameStudio A5+ MDL meshes
84#define AI_MDL_MAGIC_NUMBER_BE_GS5a AI_MAKE_MAGIC("MDL4")
85#define AI_MDL_MAGIC_NUMBER_LE_GS5a AI_MAKE_MAGIC("4LDM")
86#define AI_MDL_MAGIC_NUMBER_BE_GS5b AI_MAKE_MAGIC("MDL5")
87#define AI_MDL_MAGIC_NUMBER_LE_GS5b AI_MAKE_MAGIC("5LDM")
88
89// magic bytes used in GameStudio A7+ MDL meshes
90#define AI_MDL_MAGIC_NUMBER_BE_GS7 AI_MAKE_MAGIC("MDL7")
91#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# define AI_MDL_VERSION 6
97#endif
98#if (!defined AI_MDL_MAX_FRAMES)
99# 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# define AI_MDL_MAX_VERTS 1024
106#endif
107#if (!defined AI_MDL_MAX_TRIANGLES)
108# 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# 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 */
121struct 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 */
174struct 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 */
233struct 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# 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# 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# define AI_MDL7_BONE_STRUCT_SIZE__NAME_IS_NOT_THERE (16)
257#endif
258
259#if (!defined AI_MDL7_MAX_GROUPNAMESIZE)
260# 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 */
267struct 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#define AI_MDL7_SKINTYPE_MATERIAL 0x10
297#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 */
308struct 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 */
322struct 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 */
333struct 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 ...
340typedef int32_t MD7_MATERIAL_ASCDEFSIZE;
341
342// -------------------------------------------------------------------------------------
343/** \struct ColorValue_MDL7
344 * \brief Data structure for a color value in a MDL7 file
345 */
346struct 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 */
354struct 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 */
375struct 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 */
399struct 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# 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 */
413struct 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 */
425struct 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 */
435struct 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 */
446struct 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 */
464struct 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 */
479struct 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 */
491struct 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 */
506struct 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 */
519struct 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 */
532struct 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 */
545struct 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# 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# 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# 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 */
576struct Vertex
577{
578 uint8_t v[3];
579 uint8_t normalIndex;
580} PACK_STRUCT;
581
582
583// -------------------------------------------------------------------------------------
584struct Vertex_MDL4
585{
586 uint16_t v[3];
587 uint8_t normalIndex;
588 uint8_t unused;
589} PACK_STRUCT;
590
591#define AI_MDL7_FRAMEVERTEX120503_STCSIZE 16
592#define AI_MDL7_FRAMEVERTEX030305_STCSIZE 26
593
594// -------------------------------------------------------------------------------------
595/** \struct Vertex_MDL7
596 * \brief Vertex data structure used in MDL7 files
597 */
598struct 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 };
606} PACK_STRUCT;
607
608// -------------------------------------------------------------------------------------
609/** \struct BoneTransform_MDL7
610 * \brief bone transformation matrix structure used in MDL7 files
611 */
612struct 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 */
632struct 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 */
644struct 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 */
663struct 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// -------------------------------------------------------------------------------------
674struct 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 */
693struct GroupFrame
694{
695 //! 0 = simple frame, !0 = group frame
696 int32_t type;
697
698 //! Minimum vertex for all single frames
699 Vertex min;
700
701 //! Maximum vertex for all single frames
702 Vertex max;
703
704 //! Time for all single frames
705 float *time;
706
707 //! List of single frames
708 SimpleFrame *frames;
709} PACK_STRUCT;
710
711#include "./../include/assimp/Compiler/poppack1.h"
712
713// -------------------------------------------------------------------------------------
714/** \struct IntFace_MDL7
715 * \brief Internal data structure to temporarily represent a face
716 */
717struct IntFace_MDL7 {
718 // provide a constructor for our own convenience
719 IntFace_MDL7()
720 {
721 // set everything to zero
722 mIndices[0] = mIndices[1] = mIndices[2] = 0;
723 iMatIndex[0] = iMatIndex[1] = 0;
724 }
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 */
739struct IntMaterial_MDL7
740{
741 // provide a constructor for our own convenience
742 IntMaterial_MDL7()
743 {
744 pcMat = NULL;
745 iOldMatIndices[0] = iOldMatIndices[1] = 0;
746 }
747
748 //! Material instance
749 aiMaterial* pcMat;
750
751 //! Old material indices
752 unsigned int iOldMatIndices[2];
753};
754
755// -------------------------------------------------------------------------------------
756/** \struct IntBone_MDL7
757 * \brief Internal data structure to represent a bone in a MDL7 file with
758 * all of its animation channels assigned to it.
759 */
760struct IntBone_MDL7 : aiBone
761{
762 //! Default constructor
763 IntBone_MDL7() : iParent (0xffff)
764 {
765 pkeyPositions.reserve(30);
766 pkeyScalings.reserve(30);
767 pkeyRotations.reserve(30);
768 }
769
770 //! Parent bone of the bone
771 uint64_t iParent;
772
773 //! Relative position of the bone
774 aiVector3D vPosition;
775
776 //! Array of position keys
777 std::vector<aiVectorKey> pkeyPositions;
778
779 //! Array of scaling keys
780 std::vector<aiVectorKey> pkeyScalings;
781
782 //! Array of rotation keys
783 std::vector<aiQuatKey> pkeyRotations;
784};
785
786// -------------------------------------------------------------------------------------
787//! Describes a MDL7 frame
788struct IntFrameInfo_MDL7
789{
790 //! Construction from an existing frame header
791 IntFrameInfo_MDL7(BE_NCONST MDL::Frame_MDL7* _pcFrame,unsigned int _iIndex)
792 : iIndex(_iIndex)
793 , pcFrame(_pcFrame)
794 {}
795
796 //! Index of the frame
797 unsigned int iIndex;
798
799 //! Points to the header of the frame
800 BE_NCONST MDL::Frame_MDL7* pcFrame;
801};
802
803// -------------------------------------------------------------------------------------
804//! Describes a MDL7 mesh group
805struct IntGroupInfo_MDL7
806{
807 //! Default constructor
808 IntGroupInfo_MDL7()
809 : iIndex(0)
810 , pcGroup(NULL)
811 , pcGroupUVs(NULL)
812 , pcGroupTris(NULL)
813 , pcGroupVerts(NULL)
814 {}
815
816 //! Construction from an existing group header
817 IntGroupInfo_MDL7(BE_NCONST MDL::Group_MDL7* _pcGroup, unsigned int _iIndex)
818 : iIndex(_iIndex)
819 , pcGroup(_pcGroup)
820 , pcGroupUVs()
821 , pcGroupTris()
822 , pcGroupVerts()
823 {}
824
825 //! Index of the group
826 unsigned int iIndex;
827
828 //! Points to the header of the group
829 BE_NCONST MDL::Group_MDL7* pcGroup;
830
831 //! Points to the beginning of the uv coordinate section
832 BE_NCONST MDL::TexCoord_MDL7* pcGroupUVs;
833
834 //! Points to the beginning of the triangle section
835 MDL::Triangle_MDL7* pcGroupTris;
836
837 //! Points to the beginning of the vertex section
838 BE_NCONST MDL::Vertex_MDL7* pcGroupVerts;
839};
840
841// -------------------------------------------------------------------------------------
842//! Holds the data that belongs to a MDL7 mesh group
843struct IntGroupData_MDL7
844{
845 IntGroupData_MDL7()
846 : pcFaces(NULL), bNeed2UV(false)
847 {}
848
849 //! Array of faces that belong to the group
850 MDL::IntFace_MDL7* pcFaces;
851
852 //! Array of vertex positions
853 std::vector<aiVector3D> vPositions;
854
855 //! Array of vertex normals
856 std::vector<aiVector3D> vNormals;
857
858 //! Array of bones indices
859 std::vector<unsigned int> aiBones;
860
861 //! First UV coordinate set
862 std::vector<aiVector3D> vTextureCoords1;
863
864 //! Optional second UV coordinate set
865 std::vector<aiVector3D> vTextureCoords2;
866
867 //! Specifies whether there are two texture
868 //! coordinate sets required
869 bool bNeed2UV;
870};
871
872// -------------------------------------------------------------------------------------
873//! Holds data from an MDL7 file that is shared by all mesh groups
874struct IntSharedData_MDL7
875{
876 //! Default constructor
877 IntSharedData_MDL7()
878 : apcOutBones(),
879 iNum()
880 {
881 abNeedMaterials.reserve(10);
882 }
883
884 //! Destruction: properly delete all allocated resources
885 ~IntSharedData_MDL7()
886 {
887 // kill all bones
888 if (this->apcOutBones)
889 {
890 for (unsigned int m = 0; m < iNum;++m)
891 delete this->apcOutBones[m];
892 delete[] this->apcOutBones;
893 }
894 }
895
896 //! Specifies which materials are used
897 std::vector<bool> abNeedMaterials;
898
899 //! List of all materials
900 std::vector<aiMaterial*> pcMats;
901
902 //! List of all bones
903 IntBone_MDL7** apcOutBones;
904
905 //! number of bones
906 unsigned int iNum;
907};
908
909// -------------------------------------------------------------------------------------
910//! Contains input data for GenerateOutputMeshes_3DGS_MDL7
911struct IntSplitGroupData_MDL7
912{
913 //! Construction from a given shared data set
914 IntSplitGroupData_MDL7(IntSharedData_MDL7& _shared,
915 std::vector<aiMesh*>& _avOutList)
916
917 : aiSplit(), shared(_shared), avOutList(_avOutList)
918 {
919 }
920
921 //! Destruction: properly delete all allocated resources
922 ~IntSplitGroupData_MDL7()
923 {
924 // kill all face lists
925 if(this->aiSplit)
926 {
927 for (unsigned int m = 0; m < shared.pcMats.size();++m)
928 delete this->aiSplit[m];
929 delete[] this->aiSplit;
930 }
931 }
932
933 //! Contains a list of all faces per material
934 std::vector<unsigned int>** aiSplit;
935
936 //! Shared data for all groups of the model
937 IntSharedData_MDL7& shared;
938
939 //! List of meshes
940 std::vector<aiMesh*>& avOutList;
941};
942
943
944}
945} // end namespaces
946
947#endif // !! AI_MDLFILEHELPER_H_INC
948