-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMds.h
executable file
·272 lines (188 loc) · 6.38 KB
/
CMds.h
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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
/*
CMds.h
Author: Tom Naughton
Description: Based on code from Michael Bristol
*/
/*
******************************************
* Wrapper of id software's MDS file format
* Michael Bristol
*
* MDS file format property of id software
* This was adapted from the MD4 format released with FAKK2
* - code Copyright (C) 1999 by Ritual Entertainment, Inc
* Provided as a portion of the FAKK2 toolkit
**************************************/
#ifndef _ID_MDS_H_
#define _ID_MDS_H_
#include "CMd3.h"
#define ALIAS_VERSION2 8
#define ALIAS_VERSION3 15
#define ID_HEADER_MDS 'WSDM' //'IDP4'
#define MAX_QPATH 64
#define MDS_VERSION 4
#define MDS_MAX_BONES 128
// ------------------------- MDS file structures -------------------------------
class MDSHeader
{
public:
UInt32 ident; // "MDSW"
UInt32 version; // 0x0004
char name[MAX_QPATH]; // Model name eg. "body.mds"
float lodScale; // LOD Scale
float lodBias; // LOD Bias
UInt32 numFrames; // Number of animation frames
UInt32 numBones; // Number of bones
UInt32 offsetFrames; // Offset of animation frames (see MDSFrame)
UInt32 offsetBones; // Offset of bones (see MDSBone)
UInt32 torsoParent; // Index of torso parent bone
UInt32 numSurfaces; // Number of surfaces
UInt32 offsetSurfaces; // Offset of surfaces (numSurfaces * MDS_Surface)
UInt32 numTags; // Number of tags
UInt32 offsetTags; // Offset of tags (numTags * MDS_Tag)
UInt32 offsetEnd; // Offset of end of file
void loadFromStream(CPakStream *inItem);
Boolean isValid();
void debugDump();
} ;
class MDSWeight
{
public:
UInt32 boneIndex; // Index of bone in the main bone list
float weight; // Bone weighting (from 0.0 to 1.0)
float xyz[3]; // xyz bone space position of vertex
void loadFromStream(CPakStream *inItem);
} ;
class MDSVertex
{
public:
float normal[3]; // Vertex normal vector. In base pose/model space I presume.
float texCoords[2]; // Texture (s,t) co-ordinates
UInt32 numWeights; // Number of bone weights affecting this vertex
UInt32 fixedParent; // Stay equidistant from this parent
float fixedDist; // Fixed distance from parent
void loadFromStream(CPakStream *inItem);
MDSWeight *_weights;
} ;
class MDSPoly
{
public:
UInt32 vind[3]; // Vertex indices
void loadFromStream(CPakStream *inItem);
} ;
class MDSBoneRef
{
public:
UInt32 Ref;
void loadFromStream(CPakStream *inItem);
} ;
class MDSSurface
{
public:
UInt32 ident; // Always 0x0008
char name[64]; // Name of surface
char shader[64]; // Name of shader
UInt32 shaderIndex; // Used in game only
SInt32 minLod; // Minimum Lod level
SInt32 offsetHeader; // Offset of this surface header, always negative
UInt32 numVerts; // Number of vertices
UInt32 offsetVerts; // Offset of vertices (MDSVertex * numVerts)
UInt32 numTris; // Number of triangles
UInt32 offsetTris; // Offset of triangles (MDSTriangle * numTris)
UInt32 offsetCollapseMap; // Offset of the collapse map (UInt32 * numVerts in size)
UInt32 numBoneRefs; // Number of bone references (bones that influence this surface)
UInt32 offsetBoneRefs; // Offset of bone refs (UInt32 * numBones)
UInt32 offsetEnd; // Offset of the end of this surface, from start of MDSSurface header.
// The next surface (if there are more) can be found at this offset.
MDSVertex *_vertices;
MDSPoly *_triangles;
MDSBoneRef *_bonerefs;
void loadFromStream(CPakStream *inItem);
void debugDump();
} ;
// 80 bytes
class MDSBone
{
public:
char name[64]; // Bone name
SInt32 parentIndex; // Bone parent index (-1 if root)
float torsoWeight; // 0.0 to 1.0
float parentDist; // Distance from parent bone to this bone's pivot point
UInt32 flags; // Bit 0 is set if bone is a tag
void loadFromStream(CPakStream *inItem);
void debugDump();
} ;
// 12 bytes
class MDSBoneFrame
{
public:
// unsigned char data[12];
short Orientation[3];
short Position[3]; // /64 on input
void loadFromStream(CPakStream *inItem);
void debugDump();
} ;
class MDSCompressedBoneFrame
{
SInt16 angles[4]; // Defines the bone orientation
SInt16 offsetAngles[2]; // Defines the direction of the bone pivot from this bone's parent
void loadFromStream(CPakStream *inItem);
};
// 52 bytes
class MDSFrame
{
public:
float bboxMin[3]; // Bounding box min
float bboxMax[3]; // Bounding box max
float localOrigin[3]; // Local origin
float radius; // Radius of bounding sphere (used for runtime culling)
float parentOffset[3]; // Offset of parent bone from origin
// Following this structure is a list of compressed bone frames
MDSCompressedBoneFrame bones; // [numBones]
void loadFromStream(CPakStream *inItem);
void debugDump();
} ;
// I believe this just advertises which bones to call 'tags' ... in the old sense
class MDSTag
{
public:
char name[64]; // Name of tag
float torsoWeight; // 0.0, 0.3
UInt32 boneIndex; // Index of bone this tag is attached to
void loadFromStream(CPakStream *inItem);
} ;
class MDSTriangle
{
UInt32 vertexIndices[3]; // 3 indices into the surface's vertex list
void loadFromStream(CPakStream *inItem);
};
class CMds: public CMd3
{
public:
CMds(CResourceManager *resources);
virtual ~CMds();
virtual Boolean init(CPakStream *inItem);
virtual void Draw(CModelInstance *instance, renderingAttributes_t *renderingAttributes);
virtual void DrawLinks(CModelInstance *instance, renderingAttributes_t *rendering);
virtual void loadMeshTextures(CModelInstance *instance);
virtual SInt16 frameCount() ;
virtual UInt32 tagNum();
virtual UInt32 meshNum();
virtual ModelType modelType();
virtual int tagIndexWithName(const char *name);
virtual string tagNameForFrameAtIndex(short frame, short index);
virtual md3_tag_t *tagForFrameAtIndex(short frame, short index);
virtual Boolean canExportFormat(ExportFormatT format);
protected:
void DrawSurface(CModelInstance *instance, renderingAttributes_t *rendering , MDSSurface *surface);
MDSHeader *_header;
MDSBone *_bones;
MDSFrame *_frames;
MDSBoneFrame *_boneFrames;
MDSSurface *_surfaces;
MDSTag *_tags;
typedef vector<md3_tag_t*> tagArray;
tagArray *_convertedTags;
};
#endif // _ID_MDS_H_