MDLParser
Simple and modern library for parsing the Source engine model formats
Loading...
Searching...
No Matches
mdl.hpp
1#pragma once
2
3#include "common.hpp"
4#include "../enums.hpp"
5#include "../limits.hpp"
6#include <array>
7#include <cstdint>
8
9namespace MdlParser::Structs::Mdl {
10 using Limits::MAX_NUM_LODS;
11
12#pragma pack(push, 1)
13
14 // These are not used and are only here for alignment
15 // Pointers have been replaced with int32 to mimic a 32-bit system
17 int32_t pVertexData;
18 int32_t pTangentData;
19 };
20
22 int32_t modelvertexdata;
23 std::array<int32_t, MAX_NUM_LODS> numLODVertexes;
24 };
25
26 struct Bone {
27 int32_t szNameIndex;
28
29 int32_t parent;
30 std::array<int32_t, 6> boneControllers;
31
32 Vector pos;
33 Quaternion quat;
34 RadianEuler rot;
35
36 Vector posScale;
37 Vector rotScale;
38
39 Matrix3x4 poseToBone;
40 Quaternion qAlignment;
41
42 int32_t flags;
43
44 int32_t procType;
45 int32_t procIndex;
46
47 int32_t physicsBoneIndex;
48 int32_t surfacePropIndex;
49
50 int32_t contents;
51
52 std::array<int32_t, 8> unused;
53 };
54
55 struct Texture {
56 int32_t szNameIndex;
57
58 // TODO: Determine matching enum for these
59 int32_t flags;
60
61 int32_t used; // ?????
62 int32_t unused1;
63
64 // Two pointers that are unused even in engine
65 int32_t material;
66 int32_t clientmaterial;
67
68 std::array<int32_t, 10> unused;
69 };
70
71 struct Flex {
72 int32_t flexDesc;
73
74 float target0;
75 float target1;
76 float target2;
77 float target3;
78
79 int32_t vertsCount;
80 int32_t vertsOffset;
81
82 int32_t flexPair;
83 Enums::Mdl::VertAnimType vertAnimType;
84
85 std::array<uint8_t, 3> unused0;
86 std::array<int32_t, 6> unused1;
87 };
88
89 struct Mesh {
90 int32_t material;
91
92 int32_t modelIndex;
93
94 int32_t vertsCount;
95 int32_t vertsOffset;
96
97 int32_t flexesCount;
98 int32_t flexesOffset;
99
100 int32_t materialType;
101 int32_t materialParam;
102
103 int32_t meshId;
104
105 Vector centre;
106
107 // Unused, only for alignment
108 mstudio_meshvertexdata_t vertexdata;
109
110 std::array<int32_t, 8> unused;
111 };
112
113 struct Model {
114 std::array<char, 64> name;
115
116 int32_t type;
117
118 float boundingRadius;
119
120 int32_t meshesCount;
121 int32_t meshesOffset;
122
123 int32_t vertsCount;
124 int32_t vertsOffset;
125 int32_t tangentsOffset;
126
127 int32_t attachmentsCount;
128 int32_t attachmentsOffset;
129
130 int32_t eyeballsCount;
131 int32_t eyeballsOffset;
132
133 // Unused, only for alignment
134 mstudio_modelvertexdata_t vertexdata;
135
136 std::array<int32_t, 8> unused;
137 };
138
139 struct BodyPart {
140 int32_t szNameIndex;
141
142 int32_t modelsCount;
143 int32_t base;
144 int32_t modelsOffset;
145 };
146
147 struct Header {
148 static const int32_t MAX_SUPPORTED_VERSION = 48;
149
150 int32_t id; // Model format ID (IDST)
151 int32_t version;
152 int32_t checksum;
153 std::array<char, 64> name;
154 int32_t dataLength; // Size of the file
155
156 Vector eyePosition;
157 Vector illumPosition;
158
159 Vector hullMin;
160 Vector hullMax;
161 Vector viewMin; // Valve dev wiki doesn't know what this is, but likely the render bounds
162 Vector viewMax;
163
164 Enums::Mdl::Flags flags;
165
166 int32_t boneCount;
167 int32_t boneOffset;
168
169 int32_t boneControllerCount;
170 int32_t boneControllerOffset;
171
172 int32_t hitboxCount;
173 int32_t hitboxOffset;
174
175 int32_t localAnimCount;
176 int32_t localAnimOffset;
177
178 int32_t localSequenceCount;
179 int32_t localSequenceOffset;
180
181 int32_t activityListVersion;
182 int32_t eventsIndexed;
183
184 int32_t textureCount;
185 int32_t textureOffset;
186
187 int32_t textureDirCount;
188 int32_t textureDirOffset;
189
190 int32_t skinRefCount;
191 int32_t skinFamilyCount;
192 int32_t skinRefOffset;
193
194 int32_t bodypartCount;
195 int32_t bodypartOffset;
196
197 int32_t attachmentCount;
198 int32_t attachmentOffset;
199
200 int32_t localnodeCount;
201 int32_t localnodeOffset;
202 int32_t localnodeNameOffset;
203
204 int32_t flexDescCount;
205 int32_t flexDescOffset;
206
207 int32_t flexControllerCount;
208 int32_t flexControllerOffset;
209
210 int32_t flexRulesCount;
211 int32_t flexRulesOffset;
212
213 int32_t ikChainCount;
214 int32_t ikChainOffset;
215
216 int32_t mouthsCount;
217 int32_t mouthsOffset;
218
219 int32_t localPoseParamCount;
220 int32_t localPoseParamIndex;
221
222 int32_t surfacePropIndex;
223
224 int32_t keyvalueOffset;
225 int32_t keyvalueCount;
226
227 int32_t ikLockCount;
228 int32_t ikLockIndex;
229
230 float mass;
231 int32_t
232 contents; // Valve dev wiki doesn't know what this is but most likely contents flags https://wiki.facepunch.com/gmod/Enums/CONTENTS
233
234 int32_t includeModelCount;
235 int32_t includeModelOffset;
236
237 int32_t virtualModel;
238
239 int32_t animBlocksNameOffset;
240 int32_t animBlocksCount;
241 int32_t animBlocksOffset;
242
243 int32_t animBlockModel;
244
245 int32_t boneTableNameOffset;
246
247 int32_t vertexBase;
248 int32_t offsetBase;
249
250 uint8_t directionalDotProduct;
251
252 uint8_t rootLoD;
253
254 uint8_t numAllowedRootLoDs;
255
256 uint8_t unused0;
257 int32_t unused1;
258
259 int32_t flexControllerUICount;
260 int32_t flexControllerUIOffset;
261
262 float vertAnimFixedPointScale;
263 int32_t unused2;
264
265 int32_t header2Offset;
266 int32_t unused3;
267 };
268
269 struct Header2 {
270 int32_t srcBoneTransformCount;
271 int32_t srcBoneTransformOffset;
272
273 int32_t illumPositionAttachmentOffset;
274
275 float maxEyeDeflection;
276
277 int32_t linearBoneOffset;
278
279 int32_t szNameIndex;
280
281 int32_t boneFlexDriverCount;
282 int32_t boneFlexDriverOffset;
283
284 std::array<int32_t, 56> reserved;
285 };
286
287#pragma pack(pop)
288}
Flags
Definition: enums.hpp:16
Definition: common.hpp:21
Definition: mdl.hpp:139
Definition: mdl.hpp:26
Definition: mdl.hpp:71
Definition: mdl.hpp:269
Definition: mdl.hpp:147
Definition: mdl.hpp:89
Definition: mdl.hpp:113
Definition: mdl.hpp:55
Definition: common.hpp:14
Definition: common.hpp:10