summaryrefslogtreecommitdiff
path: root/src/mesh/assimp-master/code/AssetLib/MD4/MD4FileData.h
blob: 880df32308da431cc6d8ade83cfbe2023911d814 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
/*
Open Asset Import Library (ASSIMP)
----------------------------------------------------------------------

Copyright (c) 2006-2020, ASSIMP Development Team
All rights reserved.

Redistribution and use of this software in source and binary forms,
with or without modification, are permitted provided that the
following conditions are met:

* Redistributions of source code must retain the above
  copyright notice, this list of conditions and the
  following disclaimer.

* Redistributions in binary form must reproduce the above
  copyright notice, this list of conditions and the
  following disclaimer in the documentation and/or other
  materials provided with the distribution.

* Neither the name of the ASSIMP team, nor the names of its
  contributors may be used to endorse or promote products
  derived from this software without specific prior
  written permission of the ASSIMP Development Team.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

----------------------------------------------------------------------
*/

/** @file Defines the helper data structures for importing MD4 files  */
#ifndef AI_MD4FILEHELPER_H_INC
#define AI_MD4FILEHELPER_H_INC

#include <string>
#include <vector>
#include <sstream>

#include <assimp/types.h>
#include <assimp/mesh.h>
#include <assimp/anim.h>

#if defined(_MSC_VER) ||  defined(__BORLANDC__) ||  defined (__BCPLUSPLUS__)
#   pragma pack(push,1)
#   define PACK_STRUCT
#elif defined( __GNUC__ )
#   define PACK_STRUCT  __attribute__((packed))
#else
#   error Compiler not supported
#endif


namespace Assimp
{
// http://gongo.quakedev.com/md4.html
namespace MD4
{

#define AI_MD4_MAGIC_NUMBER_BE  'IDP4'
#define AI_MD4_MAGIC_NUMBER_LE  '4PDI'

// common limitations
#define AI_MD4_VERSION          4
#define AI_MD4_MAXQPATH         64
#define AI_MD4_MAX_FRAMES       2028
#define AI_MD4_MAX_SURFACES     32
#define AI_MD4_MAX_BONES        256
#define AI_MD4_MAX_VERTS        4096
#define AI_MD4_MAX_TRIANGLES    8192

// ---------------------------------------------------------------------------
/** \brief Data structure for the MD4 main header
 */
// ---------------------------------------------------------------------------
struct Header
{
    //! magic number
    int32_t magic;

    //! file format version
    int32_t version;

    //! original name in .pak archive
    unsigned char name[ AI_MD4_MAXQPATH ];

    //! number of frames in the file
    int32_t NUM_FRAMES;

    //! number of bones in the file
    int32_t NUM_BONES;

    //! number of surfaces in the file
    int32_t NUM_SURFACES;

    //! offset of the first frame
    int32_t OFS_FRAMES;

    //! offset of the first bone
    int32_t OFS_BONES;

    //! offset of the first surface
    int32_t OFS_SURFACES;

    //! end of file
    int32_t OFS_EOF;
} PACK_STRUCT;

// ---------------------------------------------------------------------------
/** \brief Stores the local transformation matrix of a bone
 */
// ---------------------------------------------------------------------------
struct BoneFrame
{
    float matrix[3][4];
} PACK_STRUCT;

// ---------------------------------------------------------------------------
/** \brief Stores the name / parent index / flag of a node
 */
// ---------------------------------------------------------------------------
struct  BoneName
{
    char name[32] ;
    int parent ;
    int flags ;
}  PACK_STRUCT;

// ---------------------------------------------------------------------------
/** \brief Data structure for a surface in a MD4 file
 */
// ---------------------------------------------------------------------------
struct Surface
{
    int32_t ident;
    char name[64];
    char shader[64];
    int32_t shaderIndex;
    int32_t lodBias;
    int32_t minLod;
    int32_t ofsHeader;
    int32_t numVerts;
    int32_t ofsVerts;
    int32_t numTris;
    int32_t ofsTris;
    int32_t numBoneRefs;
    int32_t ofsBoneRefs;
    int32_t ofsCollapseMap;
    int32_t ofsEnd;
} PACK_STRUCT;


// ---------------------------------------------------------------------------
/** \brief Data structure for a MD4 vertex' weight
 */
// ---------------------------------------------------------------------------
struct Weight
{
    int32_t boneIndex;
    float boneWeight;
    float offset[3];
} PACK_STRUCT;

// ---------------------------------------------------------------------------
/** \brief Data structure for a vertex in a MD4 file
 */
// ---------------------------------------------------------------------------
struct Vertex
{
    float vertex[3];
    float normal[3];
    float texCoords[2];
    int32_t numWeights;
    Weight weights[1];
} PACK_STRUCT;

// ---------------------------------------------------------------------------
/** \brief Data structure for a triangle in a MD4 file
 */
// ---------------------------------------------------------------------------
struct Triangle
{
    int32_t indexes[3];
} PACK_STRUCT;

// ---------------------------------------------------------------------------
/** \brief Data structure for a MD4 frame
 */
// ---------------------------------------------------------------------------
struct Frame
{
    float bounds[3][2];
    float localOrigin[3];
    float radius;
    BoneFrame bones[1];
} PACK_STRUCT;


// reset packing to the original value
#if defined(_MSC_VER) ||  defined(__BORLANDC__) || defined (__BCPLUSPLUS__)
#   pragma pack( pop )
#endif
#undef PACK_STRUCT


};
};

#endif // !! AI_MD4FILEHELPER_H_INC