-
Notifications
You must be signed in to change notification settings - Fork 1
/
M3.bt
507 lines (451 loc) · 11.9 KB
/
M3.bt
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
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
//------------------------------------------------
// File: M3 MDX file format
// Authors: Songzee
// Version: 4
// Purpose: Help parsing the new MDX format used in Warcraft 3 Reforged
//------------------------------------------------
//-------------------//
// globals //
//-------------------//
local long endOfMTLS;
local long endOfGEOS;
local long endOfGEOA;
local long endOfBONE;
local long endOfATCH;
local long endOfPIVT;
//--------------------------//
// helper structs //
//--------------------------//
typedef struct {
char seqName[80];
long seqIntStart;
long seqIntEnd;
float seqMoveSpeed;
long seqNoLoop;
float seqRarity;
long seqLong;
byte unk[28];
} SEQUENCE;
typedef struct {
int unk4;
int unk5;
int unk6;
char shaderName[80]; // shader name
} SHADERREF;
typedef struct {
char texturePath[268];
} TEXTUREPATH;
typedef struct {
float x;
float y;
} VECTOR2;
typedef struct {
float x;
float y;
float z;
} VECTOR3;
typedef struct {
float x;
float y;
float z;
float w;
} VECTOR4;
typedef struct {
int frame;
float state;
} FRAMESTATE;
typedef struct {
float x;
float y;
float z;
float w;
} QUATERNION;
typedef struct (int lineType){
int time;
VECTOR3 point;
if (lineType > 1)
{
VECTOR3 inTan;
VECTOR3 outTan;
}
} TRACKPOINT3;
typedef struct (int lineType){
int time;
QUATERNION point;
if (lineType > 1)
{
QUATERNION inTan;
QUATERNION outTan;
}
} TRACKPOINT4;
typedef struct (int size) {
char theString[size];
} STRING;
typedef struct (int size) {
byte data[size];
} SKIP;
typedef struct{
float row[3];
} MATRIX3x4[4];
typedef struct{
MATRIX3x4 matrix;
} READMATRIX3x4;
typedef struct{
byte boneIndex0;
byte boneIndex1;
byte boneIndex2;
byte boneIndex3;
byte boneWeight0;
byte boneWeight1;
byte boneWeight2;
byte boneWeight3;
} BONEWEIGHT;
//---------------------//
// subchunks //
//---------------------//
typedef struct {
char KMTA[4];
int nunks;
int unk1; // always 1
int type; // always -1
local int totalUnks = nunks * 8;
byte unk2[totalUnks];
byte unk3[160];
// if it has shader name, haven't figured out why but the last LAYS doesn't
if (FTell() < endOfMTLS)
{
SHADERREF shaderRef; // reference to the shader
}
} KMTA;
typedef struct {
char LAYS[4];
int numberOfLAYS;
int fmode;
int shade;
int unk;
int texture;
int unk2; // always -1
float alpha;
byte unk3[8]; // big numbers always the same
if (numberOfLAYS > 1)
{
KMTA kmta;
}
else
{
SHADERREF shaderRef; // reference to the shader
}
} LAYS;
typedef struct {
char VRTX[4];
int numberOfVerts;
VECTOR3 vertices[numberOfVerts];
} VRTX;
typedef struct {
char NRMS[4];
int numberOfNormals;
VECTOR3 normals[numberOfNormals];
} NRMS;
typedef struct {
char PTYP[4];
int numberOfPTYP;
byte unk[(numberOfPTYP + 1) * 8];
} PTYP;
typedef struct {
char PVTX[4];
int numberOfIndices;
short indices[numberOfIndices];
} PVTX;
typedef struct {
char GNDX[4];
int numberOfVertexGroups;
if (numberOfVertexGroups > 0)
byte vertexGroup[numberOfVertexGroups];
} GNDX;
typedef struct {
char MTGC[4];
int numberOfMatricesGroupCount;
int matrixGroupCount[numberOfMatricesGroupCount];
} MTGC;
typedef struct {
char MATS[4];
int numberOfBoneMatrices;
int boneMatrices[numberOfBoneMatrices];
int submeshID; // mesh ID, used for correctly assigning materials
int submeshID1; // same ID
int submeshID2; // same ID
int submeshID3; // same ID
char meshName[112]; // mesh name
} MATS;
typedef struct {
char TANG[4];
int numberOfTangents;
VECTOR4 tangents[numberOfTangents];
} TANG;
typedef struct {
char SKIN[4];
int numberOfSkins;
BONEWEIGHT boneWeight[numberOfSkins/8];
} SKIN;
typedef struct {
char UVAS[4];
int unk;
} UVAS;
typedef struct {
char UVBS[4];
int numberOfUVs;
VECTOR2 UVs[numberOfUVs];
if (FTell() < endOfGEOS)
int unk; // there's always an extra 4 bytes between the meshes, except the last one
} UVBS;
typedef struct {
int num;
int ltype;
int unk;
FRAMESTATE framestates[num];
} KGAO;
typedef struct {
int num;
int lineType;
int unk1;
TRACKPOINT3 translationTrack(lineType)[num] <optimize=false>;
} KGTR;
typedef struct {
int num;
int lineType;
int unk1;
TRACKPOINT4 rotationTrack(lineType)[num] <optimize=false>;
} KGRT;
typedef struct {
int num;
int lineType;
int unk1;
TRACKPOINT3 scaleTrack(lineType)[num] <optimize=false>;
} KGSC;
//------------------//
// chunks //
//------------------//
typedef struct {
char MDLX[4]; // "MDLX"
char VERS[4]; // "VERS"
int versionA; // version a = 4
int versionB; // version b = 900
} HEADER;
typedef struct {
char MODL[4]; // "MODL"
int MODLSize; // chunk size
char modelName[336]; // model name
int unk1; // ??
int unk2; // ??
byte unk[28]; // ???????
} MODL;
typedef struct {
char SEQS[4]; // "SEQS"
int SEQSsize; // chunk size
local int nSeqs = SEQSsize / 0x84; // number of animation sequences
SEQUENCE sequence[nSeqs]; // animation sequence structs
} SEQS;
typedef struct {
local long start = FTell();
char MTLS[4]; // "MTLS"
int MTLSSize; // chunk size
int unk1; // ??
byte unk2[88]; // ?????????
endOfMTLS = start + MTLSSize;
while (FTell() < endOfMTLS)
{
LAYS lays; // subchunk layers
}
} MTLS;
typedef struct {
char TEXS[4]; // "TEXS"
int TEXSSize; // chunk size
local int totalTextures = TEXSSize / 268; // total number of textures
TEXTUREPATH texturepaths[totalTextures]; // texture paths
} TEXS;
typedef struct {
char GEOS[4]; // chunk name
int GEOSSize; // chunk size
endOfGEOS = FTell() + GEOSSize;
int unk;
while (FTell() < endOfGEOS)
{
VRTX vrtx; // mesh vertices
NRMS nrms; // mesh normals
PTYP ptyp; // primitive type
PVTX pvtx; // mesh triangles
GNDX gndx; // vertex groups
MTGC mtgc; // matrices group count
MATS mats; // bone matrices
TANG tang; // mesh tangents
SKIN skin; // vertex weights
UVAS uvas; // ?? always 1, could be second UV layer if >1
UVBS uvbs; // mesh UVs
}
} GEOS;
typedef struct {
char GEOA[4];
int GEOASize;
endOfGEOA = FTell() + GEOASize;
while (FTell() < endOfGEOA)
{
int bytes;
int unk1;
int unk2;
int unk3;
int unk4;
int unk5;
int j;
char k;
char g;
char a;
char o;
if (k == 'K' && g == 'G' && a == 'A' && o == 'O')
KGAO kgao;
else
FSeek(FTell() - 4);
}
} GEOA;
typedef struct {
char BONE[4];
int BONESize;
endOfBONE = FTell() + BONESize;
local long end;
while (FTell() < endOfBONE)
{
int bytes; // size of data for this bone
end = FTell() + bytes - 4; // stream end position for this bone
STRING name(80); // bone name
int index; // index of the bone (they're in order anyway 0, 1, 2..)
int parent; // bone parent index
int unk1; // always 256
while (FTell() < end)
{
char ID1; // type of transform
char ID2;
char ID3;
char ID4;
if (ID1 == 'K' && ID2 == 'G' && ID3 == 'T' && ID4 == 'R')
{
KGTR kgtr; // read translation track
}
else if (ID1 == 'K' && ID2 == 'G' && ID3 == 'R' && ID4 == 'T')
{
KGRT kgrt; // read rotation track
}
else if (ID1 == 'K' && ID2 == 'G' && ID3 == 'S' && ID4 == 'C')
{
KGSC kgsc; // read scale track
}
}
int id; // ?? always -1
int aid; // ?? always -1
}
} BONE;
typedef struct {
char ATCH[4];
int ATCHSize;
endOfATCH = FTell() + ATCHSize;
local long end;
while (FTell() < endOfATCH)
{
int bytes; // size of this attachment data
end = FTell() + bytes - 4;
int unk1; // ??
STRING name(80); // name of the area where it's attached (ex: head)
int index; // attachment index (starts after last bone)
int parent; // bone index for this attachment
int unk2; // ??
while (FTell() < end)
{
char ID1; // type of transform
char ID2;
char ID3;
char ID4;
if (ID1 == 'K' && ID2 == 'G' && ID3 == 'T' && ID4 == 'R')
{
KGTR kgtr; // read translation track
}
else if (ID1 == 'K' && ID2 == 'G' && ID3 == 'R' && ID4 == 'T')
{
KGRT kgrt; // read rotation track
}
else if (ID1 == 'K' && ID2 == 'G' && ID3 == 'S' && ID4 == 'C')
{
KGSC kgsc; // read scale track
}
else
{
SKIP unk3(260); // empty space
}
}
}
} ATCH;
typedef struct {
char PIVT[4];
int PIVTSize;
endOfPIVT = FTell() + PIVTSize;
while (FTell() < endOfPIVT)
{
VECTOR3 pivot;
}
} PIVT;
typedef struct {
char CORN[4];
int CORNSize;
FSeek(FTell() + CORNSize);
// soon tm
} CORN;
typedef struct {
char RIBB[4];
int RIBBSize;
FSeek(FTell() + RIBBSize);
// soon tm
} RIBB;
typedef struct {
char CAMS[4];
int CAMSSize;
FSeek(FTell() + CAMSSize);
// soon tm
} CAMS;
typedef struct {
char EVTS[4];
int EVTSSize;
FSeek(FTell() + EVTSSize);
// soon tm
} EVTS;
typedef struct {
char CLID[4];
int CLIDSize;
FSeek(FTell() + CLIDSize);
// soon tm
} CLID;
typedef struct {
char FAFX[4];
int FAFXSize;
FSeek(FTell() + FAFXSize);
// soon tm
} FAFX;
typedef struct {
char BPOS[4];
int BPOSSize;
int count;
READMATRIX3x4 bindPose[count]; // they only store 3x4, bottom row is always (0,0,0,1) // thanks Deamon
} BPOS;
HEADER header; // header
MODL modl; // model info
SEQS seqs; // animation sequences
MTLS mtls; // materials
TEXS texs; // textures
GEOS geos; // geometry meshes
GEOA geoa; // geometry animation
BONE bone; // bone animation
ATCH atch; // bone attachments (bones/positions where item models are attached)
PIVT pivt; // bone pivots
CORN corn; // ?? lol
RIBB ribb; // ?? ribbon emitter
CAMS cams; // cameras
EVTS evts; // events
CLID clid; // colliders
FAFX fafx; // effects (particles ?)
BPOS bpos; // bones binding poses