MDLParser
Simple and modern library for parsing the Source engine model formats
Loading...
Searching...
No Matches
mdl.hpp
1#pragma once
2
3#include "./structs/mdl.hpp"
4#include <cstdint>
5#include <memory>
6#include <optional>
7#include <string>
8#include <vector>
9
10namespace MdlParser {
14 class Mdl {
15 public:
19 struct Mesh {
26 int32_t material;
27
32 int32_t vertexOffset;
33
37 int32_t vertexCount;
38 };
39
43 struct Model {
47 std::vector<Mesh> meshes;
48
52 int32_t vertexOffset;
53
58
62 int32_t vertexCount;
63 };
64
69 struct BodyPart {
73 std::string name;
74
78 std::vector<Model> models;
79 };
80
84 struct Bone {
88 std::string name;
89
93 int32_t parent;
94
95 Structs::Vector position;
96 Structs::Quaternion orientation;
97 Structs::RadianEuler orientationEuler;
98 Structs::Vector positionScale;
99 Structs::Vector orientationScale;
100
105
109 int32_t flags;
110 };
111
115 struct Texture {
120 std::string name;
121 int32_t flags;
122 };
123
131 explicit Mdl(
132 const std::weak_ptr<std::vector<std::byte>>& data, const std::optional<int32_t>& checksum = std::nullopt
133 );
134
140 [[nodiscard]] int32_t getChecksum() const;
141
146 [[nodiscard]] const std::vector<BodyPart>& getBodyParts() const;
147
155 [[nodiscard]] const std::vector<std::string>& getTextureDirectories() const;
156
162 [[nodiscard]] const std::vector<Texture>& getTextures() const;
163
172 [[nodiscard]] const std::vector<std::vector<int16_t>>& getSkinLookupTable() const;
173
180 [[nodiscard]] const std::vector<Bone>& getBones() const;
181
182 private:
184 std::optional<Structs::Mdl::Header2> header2;
185
186 std::vector<BodyPart> bodyParts;
187
188 std::vector<std::string> textureDirectories;
189 std::vector<Texture> textures;
190 std::vector<std::vector<int16_t>> skins;
191
192 std::vector<Bone> bones;
193 };
194}
Definition: mdl.hpp:14
int32_t getChecksum() const
Definition: mdl.cpp:156
const std::vector< std::vector< int16_t > > & getSkinLookupTable() const
Definition: mdl.cpp:172
const std::vector< std::string > & getTextureDirectories() const
Definition: mdl.cpp:164
const std::vector< Bone > & getBones() const
Definition: mdl.cpp:176
const std::vector< Texture > & getTextures() const
Definition: mdl.cpp:168
const std::vector< BodyPart > & getBodyParts() const
Definition: mdl.cpp:160
Definition: MDLParser.hpp:6
Definition: mdl.hpp:69
std::vector< Model > models
Definition: mdl.hpp:78
std::string name
Definition: mdl.hpp:73
Definition: mdl.hpp:84
int32_t flags
Definition: mdl.hpp:109
int32_t parent
Definition: mdl.hpp:93
std::string name
Definition: mdl.hpp:88
Structs::Matrix3x4 poseToBone
Definition: mdl.hpp:104
Definition: mdl.hpp:19
int32_t material
Definition: mdl.hpp:26
int32_t vertexCount
Definition: mdl.hpp:37
int32_t vertexOffset
Definition: mdl.hpp:32
Definition: mdl.hpp:43
int32_t vertexOffset
Definition: mdl.hpp:52
int32_t tangentsOffset
Definition: mdl.hpp:57
int32_t vertexCount
Definition: mdl.hpp:62
std::vector< Mesh > meshes
Definition: mdl.hpp:47
Definition: mdl.hpp:115
std::string name
Definition: mdl.hpp:120
Definition: common.hpp:21
Definition: mdl.hpp:147
Definition: common.hpp:14
Definition: common.hpp:10