Skip to content

Commit ba32ce6

Browse files
committed
mdlpp: addressing review comments
1 parent 2ec33b0 commit ba32ce6

File tree

5 files changed

+199
-210
lines changed

5 files changed

+199
-210
lines changed

include/mdlpp/structs/Generic.h

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,21 @@ struct BBox {
2727
struct Movement {
2828
enum Flags : int32_t {
2929
FLAG_NONE = 0,
30-
FLAG_X = 0x00000001,
31-
FLAG_Y = 0x00000002,
32-
FLAG_Z = 0x00000004,
33-
FLAG_XR = 0x00000008,
34-
FLAG_YR = 0x00000010,
35-
FLAG_ZR = 0x00000020,
36-
FLAG_LX = 0x00000040,
37-
FLAG_LY = 0x00000080,
38-
FLAG_LZ = 0x00000100,
39-
FLAG_LXR = 0x00000200,
40-
FLAG_LYR = 0x00000400,
41-
FLAG_LZR = 0x00000800,
42-
FLAG_LINEAR = 0x00001000,
43-
FLAG_TYPES = 0x0003FFFF,
44-
FLAG_RLOOP = 0x00040000,
30+
FLAG_X = 1 << 0,
31+
FLAG_Y = 1 << 1,
32+
FLAG_Z = 1 << 2,
33+
FLAG_XR = 1 << 3,
34+
FLAG_YR = 1 << 4,
35+
FLAG_ZR = 1 << 5,
36+
FLAG_LX = 1 << 6,
37+
FLAG_LY = 1 << 7,
38+
FLAG_LZ = 1 << 8,
39+
FLAG_LXR = 1 << 9,
40+
FLAG_LYR = 1 << 10,
41+
FLAG_LZR = 1 << 11,
42+
FLAG_LINEAR = 1 << 12,
43+
FLAG_TYPES = FLAG_X | FLAG_Y | FLAG_Z | FLAG_XR | FLAG_YR | FLAG_ZR | FLAG_LX | FLAG_LY | FLAG_LZ | FLAG_LX | FLAG_LYR | FLAG_LZR | FLAG_LINEAR,
44+
FLAG_RLOOP = 1 << 18,
4545
};
4646

4747
int32_t endFrame;
@@ -73,6 +73,6 @@ union AnimValue {
7373
static_assert(sizeof(AnimValue) == 2);
7474

7575
// x/y/z or pitch/yaw/roll
76-
using AnimValuePtr = std::array<int16_t, 3>;
76+
using AnimValuePtr = sourcepp::math::Vec3i16;
7777

7878
} // namespace mdlpp

include/mdlpp/structs/MDL.h

Lines changed: 56 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <cstdint>
66
#include <optional>
77
#include <string>
8+
#include <variant>
89
#include <vector>
910

1011
#include "Generic.h"
@@ -14,30 +15,31 @@ namespace mdlpp::MDL {
1415
struct Bone {
1516
enum Flags : int32_t {
1617
FLAG_NONE = 0,
17-
FLAG_CALCULATE_MASK = 0x0000001F,
18-
FLAG_PHYSICALLY_SIMULATED = 0x00000001,
19-
FLAG_PHYSICS_PROCEDURAL = 0x00000002,
20-
FLAG_ALWAYS_PROCEDURAL = 0x00000004,
21-
FLAG_SCREEN_ALIGN_SPHERE = 0x00000008,
22-
FLAG_SCREEN_ALIGN_CYLINDER = 0x00000010,
23-
FLAG_USED_MASK = 0x0007FF00,
24-
FLAG_USED_BY_ANYTHING = 0x0007FF00,
25-
FLAG_USED_BY_HITBOX = 0x00000100,
26-
FLAG_USED_BY_ATTACHMENT = 0x00000200,
27-
FLAG_USED_BY_VERTEX_MASK = 0x0003FC00,
28-
FLAG_USED_BY_VERTEX_LOD0 = 0x00000400,
29-
FLAG_USED_BY_VERTEX_LOD1 = 0x00000800,
30-
FLAG_USED_BY_VERTEX_LOD2 = 0x00001000,
31-
FLAG_USED_BY_VERTEX_LOD3 = 0x00002000,
32-
FLAG_USED_BY_VERTEX_LOD4 = 0x00004000,
33-
FLAG_USED_BY_VERTEX_LOD5 = 0x00008000,
34-
FLAG_USED_BY_VERTEX_LOD6 = 0x00010000,
35-
FLAG_USED_BY_VERTEX_LOD7 = 0x00020000,
36-
FLAG_USED_BY_BONE_MERGE = 0x00040000,
37-
FLAG_TYPE_MASK = 0x00F00000,
38-
FLAG_FIXED_ALIGNMENT = 0x00100000,
39-
FLAG_HAS_SAVEFRAME_POS = 0x00200000,
40-
FLAG_HAS_SAVEFRAME_ROT = 0x00400000,
18+
FLAG_PHYSICALLY_SIMULATED = 1 << 0,
19+
FLAG_PHYSICS_PROCEDURAL = 1 << 1,
20+
FLAG_ALWAYS_PROCEDURAL = 1 << 2,
21+
FLAG_SCREEN_ALIGN_SPHERE = 1 << 3,
22+
FLAG_SCREEN_ALIGN_CYLINDER = 1 << 4,
23+
FLAG_CALCULATE_MASK = FLAG_PHYSICALLY_SIMULATED | FLAG_PHYSICS_PROCEDURAL | FLAG_ALWAYS_PROCEDURAL | FLAG_SCREEN_ALIGN_SPHERE | FLAG_SCREEN_ALIGN_CYLINDER,
24+
FLAG_USED_BY_HITBOX = 1 << 8,
25+
FLAG_USED_BY_ATTACHMENT = 1 << 9,
26+
FLAG_USED_BY_VERTEX_LOD0 = 1 << 10,
27+
FLAG_USED_BY_VERTEX_LOD1 = 1 << 11,
28+
FLAG_USED_BY_VERTEX_LOD2 = 1 << 12,
29+
FLAG_USED_BY_VERTEX_LOD3 = 1 << 13,
30+
FLAG_USED_BY_VERTEX_LOD4 = 1 << 14,
31+
FLAG_USED_BY_VERTEX_LOD5 = 1 << 15,
32+
FLAG_USED_BY_VERTEX_LOD6 = 1 << 16,
33+
FLAG_USED_BY_VERTEX_LOD7 = 1 << 17,
34+
FLAG_USED_BY_BONE_MERGE = 1 << 18,
35+
FLAG_USED_BY_VERTEX_MASK = FLAG_USED_BY_VERTEX_LOD0 | FLAG_USED_BY_VERTEX_LOD1 | FLAG_USED_BY_VERTEX_LOD2 | FLAG_USED_BY_VERTEX_LOD3 | FLAG_USED_BY_VERTEX_LOD4 | FLAG_USED_BY_VERTEX_LOD5 | FLAG_USED_BY_VERTEX_LOD6 | FLAG_USED_BY_VERTEX_LOD7,
36+
FLAG_USED_MASK = FLAG_USED_BY_HITBOX | FLAG_USED_BY_ATTACHMENT | FLAG_USED_BY_VERTEX_MASK | FLAG_USED_BY_BONE_MERGE,
37+
FLAG_USED_BY_ANYTHING = FLAG_USED_MASK,
38+
FLAG_FIXED_ALIGNMENT = 1 << 20,
39+
FLAG_HAS_SAVEFRAME_POS = 1 << 21,
40+
FLAG_HAS_SAVEFRAME_ROT = 1 << 22,
41+
FLAG_EMPTY_SLOT = 1 << 23,
42+
FLAG_TYPE_MASK = FLAG_FIXED_ALIGNMENT | FLAG_HAS_SAVEFRAME_POS | FLAG_HAS_SAVEFRAME_ROT | FLAG_EMPTY_SLOT,
4143
};
4244

4345
//int32_t nameIndex;
@@ -101,8 +103,7 @@ struct AnimBoneData {
101103
Flags flags;
102104

103105
// static data when RAW flags are set
104-
std::optional<sourcepp::math::QuatCompressed48> staticRotation48;
105-
std::optional<sourcepp::math::QuatCompressed64> staticRotation64;
106+
std::variant<std::monostate, sourcepp::math::QuatCompressed48, sourcepp::math::QuatCompressed64> staticRotation;
106107
std::optional<sourcepp::math::Vec3Compressed48> staticPosition;
107108

108109
// keyframe data when ANIM flags are set
@@ -119,8 +120,8 @@ struct IKError {
119120
};
120121

121122
struct CompressedIKError {
122-
float scale[6];
123-
int16_t offset[6];
123+
sourcepp::math::Vec<6, float> scale;
124+
sourcepp::math::Vec<6, int16_t> offset;
124125
std::vector<AnimValue> animValues;
125126
};
126127

@@ -220,7 +221,9 @@ struct Event {
220221
float cycle;
221222
int32_t event;
222223
int32_t type;
223-
std::array<char, 64> options;
224+
225+
//char options[64];
226+
std::string options;
224227

225228
//int32_t eventNameIndex;
226229
std::string eventName;
@@ -316,10 +319,10 @@ SOURCEPP_BITFLAGS_ENUM(SequenceDesc::Flags)
316319

317320
struct Material {
318321
enum Flags : int32_t {
319-
FLAG_NONE = 0,
320-
// Note: mstudiotexture_t.flags field exists in MDL binary format but is never set by studiomdl compiler.
321-
// The field remains 0 in all compiled MDL files. RELATIVE_TEXTURE_PATH_SPECIFIED (0x1) exists in the
322-
// compiler source but is not written to the file format.
322+
FLAG_NONE = 0,
323+
FLAG_RELATIVE_TEXTURE_PATH_SPECIFIED = 1 << 0,
324+
// Note: mstudiotexture_t.flags field exists in the format but is never set by the studiomdl compiler.
325+
// The engine might still check this flag, so it is exposed here anyway.
323326
};
324327

325328
//int32_t nameIndex;
@@ -338,25 +341,25 @@ struct Eyeball {
338341

339342
int32_t bone;
340343
sourcepp::math::Vec3f org;
341-
float zoffset;
344+
float zOffset;
342345
float radius;
343346
sourcepp::math::Vec3f up;
344347
sourcepp::math::Vec3f forward;
345348
int32_t texture;
346349

347350
//int32_t unused1;
348-
float iris_scale;
351+
float irisScale;
349352
//int32_t unused2;
350353

351-
std::array<int32_t, 3> upperflexdesc;
352-
std::array<int32_t, 3> lowerflexdesc;
353-
std::array<float, 3> uppertarget;
354-
std::array<float, 3> lowertarget;
354+
std::array<int32_t, 3> upperFlexDesc;
355+
std::array<int32_t, 3> lowerFlexDesc;
356+
std::array<float, 3> upperTarget;
357+
std::array<float, 3> lowerTarget;
355358

356-
int32_t upperlidflexdesc;
357-
int32_t lowerlidflexdesc;
359+
int32_t upperLidFlexDesc;
360+
int32_t lowerLidFlexDesc;
358361
//int32_t unused[4];
359-
bool m_bNonFACS;
362+
bool nonFACS;
360363
//char unused3[3];
361364
//int32_t unused4[7];
362365
};
@@ -379,11 +382,11 @@ struct VertexAnimWrinkle {
379382
uint8_t side;
380383
std::array<int16_t, 3> delta;
381384
std::array<int16_t, 3> ndelta;
382-
int16_t wrinkledelta;
385+
int16_t wrinkleDelta;
383386
};
384387

385388
struct MeshFlex {
386-
int32_t flexdesc;
389+
int32_t flexDescIndex;
387390

388391
// control curve
389392
float target0;
@@ -396,8 +399,8 @@ struct MeshFlex {
396399
std::vector<VertexAnim> vertAnims;
397400
std::vector<VertexAnimWrinkle> vertAnimsWrinkle;
398401

399-
int32_t flexpair;
400-
uint8_t vertanimtype; // 0=normal, 1=wrinkle
402+
int32_t flexPair;
403+
uint8_t vertAnimType; // 0=normal, 1=wrinkle
401404
//uint8_t unusedchar[3];
402405
//int32_t unused[6];
403406
};
@@ -508,7 +511,7 @@ struct FlexControllerUI {
508511
std::string controllerName1; // right controller (stereo)
509512
std::string controllerName2; // value controller (NWAY only)
510513

511-
uint8_t remaptype;
514+
uint8_t remapType;
512515
bool stereo;
513516
//uint8_t unused[2];
514517
};
@@ -533,7 +536,7 @@ struct IKChain {
533536
struct Mouth {
534537
int32_t bone;
535538
sourcepp::math::Vec3f forward;
536-
int32_t flexdesc;
539+
int32_t flexDescIndex;
537540
};
538541

539542
enum FlexOpType : int32_t {
@@ -725,21 +728,21 @@ struct MDL {
725728
//int32_t includeModelIndex;
726729
std::vector<IncludeModel> includeModels;
727730

728-
int32_t virtualModel;
731+
// int32_t virtualModel;
729732

730733
//int32_t animationBlocksNameIndex;
731734
//int32_t animationBlocksCount;
732735
//int32_t animationBlocksIndex;
733736
std::string animationBlocksName;
734737
std::vector<AnimBlock> animationBlocks;
735738

736-
int32_t animationBlockModel;
739+
// int32_t animationBlockModel;
737740

738741
//int32_t boneTableByNameIndex;
739742
std::vector<uint8_t> boneTableByName;
740743

741-
int32_t vertexBase;
742-
int32_t offsetBase;
744+
// int32_t vertexBase;
745+
// int32_t offsetBase;
743746

744747
uint8_t directionalDotProduct;
745748
uint8_t rootLOD;
@@ -755,7 +758,7 @@ struct MDL {
755758
float vertAnimFixedPointScale;
756759
//int32_t _unused2;
757760

758-
int32_t studiohdr2index;
761+
int32_t studioHdr2Index;
759762

760763
//int32_t _unused3;
761764

include/sourcepp/Math.h

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -386,18 +386,13 @@ struct QuatCompressed64 {
386386
static_assert(std::is_trivially_copyable_v<QuatCompressed64>);
387387

388388
/// Lower precision Vec3 compressed to 6 bytes
389-
struct Vec3Compressed48 {
390-
uint16_t x : 16;
391-
uint16_t y : 16;
392-
uint16_t z : 16;
389+
struct Vec3Compressed48 : Vec3ui16 {
390+
using Vec3ui16::Vec;
393391

394392
[[nodiscard]] Vec3f decompress() const {
395-
// Convert from 16-bit unsigned integers to floating point values in the range [-1, 1]
396-
// Note: Actual positions need to be multiplied by bone's positionScale after decompression
397-
const float fx = (static_cast<float>(this->x) / 32767.5f) - 1.f; // x / ((2^16 - 1) / 2) - 1
398-
const float fy = (static_cast<float>(this->y) / 32767.5f) - 1.f; // x / ((2^16 - 1) / 2) - 1
399-
const float fz = (static_cast<float>(this->z) / 32767.5f) - 1.f; // x / ((2^16 - 1) / 2) - 1
400-
393+
const float fx = (static_cast<float>((*this)[0]) / 32767.5f) - 1.f;
394+
const float fy = (static_cast<float>((*this)[1]) / 32767.5f) - 1.f;
395+
const float fz = (static_cast<float>((*this)[2]) / 32767.5f) - 1.f;
401396
return {fx, fy, fz};
402397
}
403398
};

0 commit comments

Comments
 (0)