SourcePP
Several modern C++20 libraries for sanely parsing Valve's formats.
Loading...
Searching...
No Matches
MDL.h
Go to the documentation of this file.
1#pragma once
2
3#include <array>
4#include <cstddef>
5#include <cstdint>
6#include <string>
7#include <vector>
8
9#include "Generic.h"
10
11namespace mdlpp::MDL {
12
13struct Bone {
14 enum Flags : int32_t {
16 // todo(flags): Bone
17 };
18
19 //int32_t nameIndex;
20 std::string name;
21
22 int32_t parent;
23 std::array<int32_t, 6> boneController;
24 sourcepp::math::Vec3f position;
26 sourcepp::math::Vec3f rotationEuler;
27 sourcepp::math::Vec3f positionScale;
28 sourcepp::math::Vec3f rotationScale;
29 sourcepp::math::Mat3x4f poseToBose;
32 int32_t procType;
33 int32_t procIndex;
34 int32_t physicsBone;
35
36 //int32_t surfacePropNameIndex;
37 std::string surfacePropName;
38
39 int32_t contents;
40
41 //int32_t _unused0[8];
42};
44
46 int32_t bone;
47 int32_t type;
48 float start;
49 float end;
50 int32_t rest;
51 int32_t inputField;
52
53 //int32_t _unused0[8];
54};
55
56struct HitboxSet {
57 //int32_t nameIndex;
58 std::string name;
59
60 //int32_t hitboxCount;
61 //int32_t hitboxIndex;
62 std::vector<BBox> hitboxes;
63};
64
65/*
66struct AnimDesc {
67 enum Flags : int32_t {
68 FLAG_NONE = 0,
69 FLAG_RAW_POS = 1 << 0,
70 FLAG_RAW_ROT = 1 << 1,
71 FLAG_ANIM_POS = 1 << 2,
72 FLAG_ANIM_ROT = 1 << 3,
73 FLAG_DELTA = 1 << 4,
74 FLAG_RAW_ROT2 = 1 << 5,
75 };
76
77 //int32_t basePointer;
78
79 //int32_t nameIndex;
80 std::string name;
81 float fps;
82
83 Flags flags;
84
85 int32_t frameCount;
86
87 //int32_t movementCount;
88 //int32_t movementIndex;
89
90 //int32_t _unused0[6];
91
92 //int32_t animBlock;
93 //int32_t animIndex;
94
95 //int32_t ikRuleCount;
96 //int32_t ikRuleIndex;
97
98 //int32_t animBlockIKRuleIndex;
99
100 //int32_t localHierarchyIndexCount;
101 //int32_t localHierarchyIndex;
102
103 //int32_t sectionIndex;
104 //int32_t sectionFrames;
105
106 //int16_t zeroFrameSpan;
107 //int16_t zeroFrameCount;
108 //int32_t zeroFrameIndex;
109 //float zeroFrameStallTime;
110};
111SOURCEPP_BITWISE_ENUM(AnimDesc::Flags)
112
113struct SequenceDesc {
114 enum Flags : int32_t {
115 FLAG_NONE = 0,
116 FLAG_LOOPING = 1 << 0,
117 };
118
119 //int32_t basePointer;
120
121 //int32_t labelIndex;
122 //int32_t activityLabelIndex;
123
124 Flags flags;
125
126 //int32_t activity;
127 //int32_t activityWeight;
128
129 //int32_t eventCount;
130 //int32_t eventIndex;
131
132 sourcepp::Vec3f boundingBoxMin;
133 sourcepp::Vec3f boundingBoxMax;
134
135 int32_t blendCount;
136
137 int32_t animIndexIndex;
138
139 int32_t movementIndex;
140
141 int32_t groupSize[2];
142 int32_t paramIndex[2];
143 float paramStart[2];
144 float paramEnd[2];
145 int32_t paramParent;
146
147 float fadeInTime;
148 float fadeOutTime;
149
150 int32_t localEntryNode;
151 int32_t localExitNode;
152
153 int32_t nodeFlags;
154
155 float entryPhase;
156 float exitPhase;
157
158 float lastFrame;
159
160 int32_t nextSequence;
161 int32_t pose;
162
163 int32_t ikRuleCount;
164
165 //int32_t autoLayerCount;
166 //int32_t autoLayerIndex;
167
168 int32_t weightListIndex;
169
170 int32_t poseKeyIndex;
171
172 //int32_t ikLockCount;
173 //int32_t ikLockIndex;
174
175 //int32_t keyValueIndex;
176 //int32_t keyValueSize;
177
178 int32_t cyclePoseIndex;
179
180 //int32_t _unused0[7];
181};
182SOURCEPP_BITWISE_ENUM(SequenceDesc::Flags)
183*/
184
185struct Material {
186 enum Flags : int32_t {
188 // todo(flags): Material (Texture in MDL)
189 };
190
191 //int32_t nameIndex;
192 std::string name;
193
195
196 //int32_t used; // No idea what this is
197 //int32_t _unused0[13];
198};
200
201struct Mesh {
202 int32_t material;
203
204 //int32_t modelOffset;
205
206 // These do not map to raw memory
209
210 //int32_t flexesCount;
211 //int32_t flexesOffset;
212
215
216 int32_t meshID;
217
218 sourcepp::math::Vec3f center;
219
220 //int32_t modelVertexData;
221 //int32_t numLODVertexes[MAX_LOD_COUNT];
222 //int32_t _unused[8];
223};
224
225struct Model {
226 //char name[64];
227 std::string name;
228
229 int32_t type;
230
232
233 //int32_t meshesCount;
234 //int32_t meshesOffset;
235 std::vector<Mesh> meshes;
236
237 // These do not map to raw memory
240 //int32_t tangentsOffset;
241
242 //int32_t attachmentsCount;
243 //int32_t attachmentsOffset;
244
245 //int32_t eyeballsCount;
246 //int32_t eyeballsOffset;
247
248 //int32_t _unused0[10];
249};
250
251struct BodyPart {
252 //int32_t nameOffset;
253 std::string name;
254
255 //int32_t modelsCount;
256 int32_t base; // No idea what this is, might as well expose it
257 //int32_t modelsOffset;
258 std::vector<Model> models;
259};
260
261struct MDL {
262 [[nodiscard]] bool open(const std::byte* data, std::size_t size);
263
264 enum Flags : int32_t {
283 };
284
285 //int32_t id;
286 int32_t version;
287 int32_t checksum;
288
289 //char name[64];
290 std::string name;
291 //int32_t dataLength;
292
293 sourcepp::math::Vec3f eyePosition;
294 sourcepp::math::Vec3f illuminationPosition;
295 sourcepp::math::Vec3f hullMin;
296 sourcepp::math::Vec3f hullMax;
297 sourcepp::math::Vec3f viewBBoxMin;
298 sourcepp::math::Vec3f viewBBoxMax;
299
301
302 //int32_t boneCount;
303 //int32_t boneOffset;
304 std::vector<Bone> bones;
305
306 //int32_t boneControllerCount;
307 //int32_t boneControllerOffset;
308 std::vector<BoneController> boneControllers;
309
310 //int32_t hitboxCount;
311 //int32_t hitboxOffset;
312 std::vector<HitboxSet> hitboxSets;
313
314 //int32_t localAnimationCount;
315 //int32_t localAnimationOffset;
316
317 //int32_t localSequenceCount;
318 //int32_t localSequenceOffset;
319
322
323 //int32_t materialCount;
324 //int32_t materialOffset;
325 std::vector<Material> materials;
326
327 //int32_t materialDirCount;
328 //int32_t materialDirOffset;
329 std::vector<std::string> materialDirectories;
330
331 //int32_t skinReferenceCount;
332 //int32_t skinReferenceFamilyCount;
333 //int32_t skinReferenceIndex;
334 // Each vector is an individual skin, which holds indices into the materials vector
335 std::vector<std::vector<int16_t>> skins;
336
337 //int32_t bodyPartCount;
338 //int32_t bodyPartOffset;
339 std::vector<BodyPart> bodyParts;
340
341 //int32_t attachmentCount;
342 //int32_t attachmentOffset;
343
344 //int32_t localNodeCount;
345 //int32_t localNodeIndex;
346 //int32_t localNodeNameIndex;
347
348 //int32_t flexDescCount;
349 //int32_t flexDescIndex;
350
351 //int32_t flexControllerCount;
352 //int32_t flexControllerIndex;
353
354 //int32_t flexRulesCount;
355 //int32_t flexRulesIndex;
356
357 //int32_t ikChainCount;
358 //int32_t ikChainIndex;
359
360 //int32_t mouthsCount;
361 //int32_t mouthsIndex;
362
363 //int32_t localPoseParamCount;
364 //int32_t localPoseParamIndex;
365
366 //int32_t surfacePropertyIndex;
367
368 //int32_t keyValueIndex;
369 //int32_t keyValueCount;
370
371 //int32_t ikLockCount;
372 //int32_t ikLockIndex;
373
374 //float mass;
375 //int32_t contentsFlags;
376
377 //int32_t includeModelCount;
378 //int32_t includeModelIndex;
379
380 //int32_t virtualModel;
381
382 //int32_t animationBlocksNameIndex;
383
384 //int32_t animationBlocksCount;
385 //int32_t animationBlocksIndex;
386
387 //int32_t animationBlockModel;
388
389 //int32_t boneTableNameIndex;
390
391 //int32_t vertexBase;
392 //int32_t offsetBase;
393
394 //std::byte directionalDotProduct;
395
396 //uint8_t rootLOD;
397 //uint8_t numAllowedRootLODs;
398
399 //std::byte _unused0;
400 //int32_t _unused1;
401
402 //int32_t flexControllerUICount;
403 //int32_t flexControllerUIIndex;
404
405 //float vertAnimFixedPointScale;
406 //int32_t _unused2;
407
408 // todo: header 2
409 //int32_t header2Offset;
410
411 //int32_t _unused3;
412};
414
415} // namespace mdlpp::MDL
#define SOURCEPP_BITFLAGS_ENUM(Enum)
Defines bitwise operators for an enum or enum class.
Definition: Macros.h:26
Definition: MDL.h:11
Vec4f Quat
Definition: Math.h:330
std::vector< Model > models
Definition: MDL.h:258
std::string name
Definition: MDL.h:253
int32_t base
Definition: MDL.h:256
sourcepp::math::Quat rotationQuat
Definition: MDL.h:25
sourcepp::math::Quat alignment
Definition: MDL.h:30
sourcepp::math::Vec3f rotationEuler
Definition: MDL.h:26
sourcepp::math::Vec3f positionScale
Definition: MDL.h:27
sourcepp::math::Vec3f position
Definition: MDL.h:24
sourcepp::math::Vec3f rotationScale
Definition: MDL.h:28
int32_t procType
Definition: MDL.h:32
int32_t procIndex
Definition: MDL.h:33
std::string name
Definition: MDL.h:20
Flags flags
Definition: MDL.h:31
std::array< int32_t, 6 > boneController
Definition: MDL.h:23
int32_t physicsBone
Definition: MDL.h:34
sourcepp::math::Mat3x4f poseToBose
Definition: MDL.h:29
int32_t parent
Definition: MDL.h:22
std::string surfacePropName
Definition: MDL.h:37
int32_t contents
Definition: MDL.h:39
std::string name
Definition: MDL.h:58
std::vector< BBox > hitboxes
Definition: MDL.h:62
sourcepp::math::Vec3f viewBBoxMax
Definition: MDL.h:298
sourcepp::math::Vec3f hullMax
Definition: MDL.h:296
std::vector< Material > materials
Definition: MDL.h:325
int32_t activityListVersion
Definition: MDL.h:320
Flags flags
Definition: MDL.h:300
bool open(const std::byte *data, std::size_t size)
Definition: MDL.cpp:11
@ FLAG_BUILT_IN_PREVIEW_MODE
Definition: MDL.h:277
@ FLAG_FORCE_PHONEME_CROSSFADE
Definition: MDL.h:274
@ FLAG_VERT_ANIM_FIXED_POINT_SCALE
Definition: MDL.h:281
@ FLAG_STATIC_PROP
Definition: MDL.h:269
@ FLAG_OBSOLETE
Definition: MDL.h:272
@ FLAG_AUTOGENERATED_HITBOX
Definition: MDL.h:266
@ FLAG_FLEXES_CONVERTED
Definition: MDL.h:276
@ FLAG_TRANSLUCENT_TWO_PASS
Definition: MDL.h:268
@ FLAG_CONSTANT_DIRECTIONAL_LIGHT_DOT
Definition: MDL.h:275
@ FLAG_DO_NOT_CAST_SHADOWS
Definition: MDL.h:278
@ FLAG_EXTRA_VERTEX_DATA
Definition: MDL.h:282
@ FLAG_NO_FORCED_FADE
Definition: MDL.h:273
@ FLAG_CAST_TEXTURE_SHADOWS
Definition: MDL.h:279
@ FLAG_SUBDIVISION_SURFACE
Definition: MDL.h:280
@ FLAG_FORCE_OPAQUE
Definition: MDL.h:267
@ FLAG_HAS_SHADOW_LOD
Definition: MDL.h:270
@ FLAG_USE_SHADOW_LOD_MATERIALS
Definition: MDL.h:271
std::string name
Definition: MDL.h:290
sourcepp::math::Vec3f viewBBoxMin
Definition: MDL.h:297
sourcepp::math::Vec3f eyePosition
Definition: MDL.h:293
sourcepp::math::Vec3f hullMin
Definition: MDL.h:295
std::vector< std::vector< int16_t > > skins
Definition: MDL.h:335
std::vector< std::string > materialDirectories
Definition: MDL.h:329
int32_t checksum
Definition: MDL.h:287
sourcepp::math::Vec3f illuminationPosition
Definition: MDL.h:294
std::vector< BodyPart > bodyParts
Definition: MDL.h:339
std::vector< BoneController > boneControllers
Definition: MDL.h:308
std::vector< Bone > bones
Definition: MDL.h:304
int32_t eventsIndexed
Definition: MDL.h:321
int32_t version
Definition: MDL.h:286
std::vector< HitboxSet > hitboxSets
Definition: MDL.h:312
std::string name
Definition: MDL.h:192
int32_t materialParam
Definition: MDL.h:214
sourcepp::math::Vec3f center
Definition: MDL.h:218
int32_t material
Definition: MDL.h:202
int32_t meshID
Definition: MDL.h:216
int32_t materialType
Definition: MDL.h:213
int32_t verticesCount
Definition: MDL.h:207
int32_t verticesOffset
Definition: MDL.h:208
int32_t verticesCount
Definition: MDL.h:238
float boundingRadius
Definition: MDL.h:231
int32_t verticesOffset
Definition: MDL.h:239
std::vector< Mesh > meshes
Definition: MDL.h:235
int32_t type
Definition: MDL.h:229
std::string name
Definition: MDL.h:227