Cafu Engine
Loader_mdl_hl2_vtx.hpp
1 /*
2 Cafu Engine, http://www.cafu.de/
3 Copyright (c) Carsten Fuchs and other contributors.
4 This project is licensed under the terms of the MIT license.
5 */
6 
7 #ifndef CAFU_HL2_MDL_VTX_STRIPS_DATA_HPP_INCLUDED
8 #define CAFU_HL2_MDL_VTX_STRIPS_DATA_HPP_INCLUDED
9 
10 #if defined(_MSC_VER)
11  #pragma pack(push, 1)
12  #define GCC_PACKED
13 #elif defined(__GNUG__)
14  #define GCC_PACKED __attribute__ ((packed))
15 #endif
16 
17 
18 namespace HL2mdl
19 {
21  {
22  uint32_t HardwareID;
23  uint32_t NewBoneID;
24  } GCC_PACKED;
25 
26 
27  /// This class corresponds to StudioVertexT in the vvd file.
28  /// It works like this: If we have these instances:
29  ///
30  /// vtxVertexT vtxVertex;
31  /// vtxMeshT vtxMesh; // The mesh related to vtxVertex.
32  /// StudioMeshT StudioMesh; // The mesh sibling related to vtxMesh.
33  ///
34  /// then the StudioVertexT related to vtxVertex is found like this:
35  ///
36  /// StudioVertexT sv = StudioMesh.GetVertices()[vtxVert.Sibling];
37  ///
38  struct vtxVertexT
39  {
40  uint8_t BoneWeightIndex[HL2mdl_MAX_NUM_BONES_PER_VERT]; ///< These index into `sv`'s bones. Can this ever be different from `[0, 1, 2]`? If so, why?
41  uint8_t NumBones; ///< Same as `sv.BoneWeights.NumBones`.
42  uint16_t Sibling; ///< See class description for usage.
43 
44  /// For software-skinned vertices, these are indices into the mdl file's list of
45  /// bones, that is, same as `sv.BoneWeights.Bone[i]` for each `i < NumBones`.
46  /// For hardware-skinned vertices, these are hardware bone indices (different from
47  /// software-skinned vertices if the hardware limits the max number of bones??).
48  uint8_t Bone[HL2mdl_MAX_NUM_BONES_PER_VERT];
49 
50 
51  std::ostream& print(std::ostream& os, const char* indent) const;
52  } GCC_PACKED;
53 
54 
55  /// A strip is a portion of a strip group.
56  struct vtxStripT
57  {
58  enum FlagsT
59  {
60  IS_TRILIST = 1,
61  IS_TRISTRIP = 2 ///< May contain degenerate triangles.
62  };
63 
64  uint32_t NumIndices;
65  uint32_t IndicesOffset;
66 
67  uint32_t NumVerts;
68  uint32_t VertsOffset;
69 
70  uint16_t NumBones; ///< What's this? The max. number of bones to be used, clamping/overriding the value in vtxVertexT?
71  uint8_t Flags;
72 
73  uint32_t NumBoneStateChanges;
74  uint32_t BoneStateChangesOffset;
75 
76 
77  vtxBoneStateChangeT* GetBoneStateChanges() const
78  {
79  return (vtxBoneStateChangeT*)(((uint8_t*)this) + BoneStateChangesOffset);
80  }
81 
82  std::ostream& print(std::ostream& os, const char* indent) const;
83  } GCC_PACKED;
84 
85 
86  /// A strip group is a locking group, representing a single vertex buffer and a single index buffer.
88  {
89  enum FlagsT { IS_FLEXED = 1, IS_HWSKINNED = 2, IS_DELTA_FLEXED = 4 };
90 
91  uint32_t NumVerts;
92  uint32_t VertsOffset;
93 
94  uint32_t NumIndices;
95  uint32_t IndicesOffset;
96 
97  uint32_t NumStrips;
98  uint32_t StripsOffset;
99 
100  uint8_t Flags;
101 
102 
103  vtxVertexT* GetVertices() const
104  {
105  return (vtxVertexT*)(((uint8_t*)this) + VertsOffset);
106  }
107 
108  uint16_t* GetIndices() const
109  {
110  return (uint16_t*)(((uint8_t*)this) + IndicesOffset);
111  }
112 
113  vtxStripT* GetStrips() const
114  {
115  return (vtxStripT*)(((uint8_t*)this) + StripsOffset);
116  }
117 
118  std::ostream& print(std::ostream& os, const char* indent) const;
119  } GCC_PACKED;
120 
121 
122  /// This class corresponds to StudioMeshT in the mdl file. A mesh has exactly one material
123  /// associated with it and contains up to four locking groups (see vtxStripGroupT::FlagsT):
124  /// flexed / non-flexed, hardware skinned / software skinned.
125  struct vtxMeshT
126  {
127  enum FlagsT { IS_TEETH = 1, IS_EYES = 2 };
128 
129  uint32_t NumStripGroups;
130  uint32_t StripGroupsOffset;
131  uint8_t Flags;
132 
133 
134  vtxStripGroupT* GetStripGroups() const
135  {
136  return (vtxStripGroupT*)(((uint8_t*)this) + StripGroupsOffset);
137  }
138 
139  std::ostream& print(std::ostream& os, const char* indent) const;
140  } GCC_PACKED;
141 
142 
144  {
145  uint32_t NumMeshes; ///< One vtxMeshT for each StudioMeshT.
146  uint32_t MeshesOffset;
147  float SwitchPoint;
148 
149 
150  vtxMeshT* GetMeshes() const
151  {
152  return (vtxMeshT*)(((uint8_t*)this) + MeshesOffset);
153  }
154 
155  std::ostream& print(std::ostream& os, const char* indent) const;
156  } GCC_PACKED;
157 
158 
159  /// This class corresponds to StudioModelT in the mdl file.
160  struct vtxModelT
161  {
162  uint32_t NumLODs; ///< Must match the NumLODs value in StripsHeaderT.
163  uint32_t LODsOffset;
164 
165 
166  vtxModelLODT* GetLODs() const
167  {
168  return (vtxModelLODT*)(((uint8_t*)this) + LODsOffset);
169  }
170 
171  std::ostream& print(std::ostream& os, const char* indent) const;
172  } GCC_PACKED;
173 
174 
175  /// This class corresponds to StudioBodyPartT in the mdl file.
177  {
178  uint32_t NumModels;
179  uint32_t ModelsOffset;
180 
181 
182  vtxModelT* GetModels() const
183  {
184  return (vtxModelT*)(((uint8_t*)this) + ModelsOffset);
185  }
186 
187  std::ostream& print(std::ostream& os, const char* indent) const;
188  } GCC_PACKED;
189 
190 
192  {
193  uint16_t MatID;
194  uint32_t ReplacementMatNameOffset;
195 
196 
197  const char* GetMaterialReplacementName() const
198  {
199  return (const char*)(((uint8_t*)this) + ReplacementMatNameOffset);
200  }
201 
202  // std::ostream& print(std::ostream& os, const char* indent) const;
203  } GCC_PACKED;
204 
205 
207  {
208  uint32_t NumMatReplacements;
209  uint32_t MatReplacementsOffset;
210 
211 
212  vtxMaterialReplacementT* GetMaterialReplacements() const
213  {
214  return (vtxMaterialReplacementT*)(((uint8_t*)this) + MatReplacementsOffset);
215  }
216 
217  // std::ostream& print(std::ostream& os, const char* indent) const;
218  } GCC_PACKED;
219 
220 
221  /// This is the header of a VTX strips data file.
223  {
224  public:
225 
226  static const uint32_t FILE_VERSION; ///< The currently supported file format version.
227 
228  uint32_t Version; ///< Must be FILE_VERSION.
229 
230  uint32_t VertCacheSize; ///< These four are hardware-specific parameters that affect how the model is to be optimized.
231  uint16_t MaxBonesPerStrip;
232  uint16_t MaxBonesPerTri;
233  uint32_t MaxBonesPerVert;
234 
235  uint32_t Checksum; ///< Must match the checksum in StudioHeaderT.
236 
237  uint32_t NumLODs; ///< The same value is repeated in each vtxModelT.
238  uint32_t MatReplacementListsOffset; ///< One per LOD.
239 
240  uint32_t NumBodyParts;
241  uint32_t BodyPartsOffset;
242 
243 
244  public:
245 
246  vtxMaterialReplacementListT* GetMaterialReplacementLists() const
247  {
248  return (vtxMaterialReplacementListT*)(((uint8_t*)this) + MatReplacementListsOffset);
249  }
250 
251  vtxBodyPartT* GetBodyParts() const
252  {
253  return (vtxBodyPartT*)(((uint8_t*)this) + BodyPartsOffset);
254  }
255 
256  std::ostream& print(std::ostream& os, const char* indent) const;
257  } GCC_PACKED;
258 }
259 
260 
261 #if defined(_MSC_VER)
262  #pragma pack(pop)
263 #endif
264 #undef GCC_PACKED
265 
266 #endif
uint8_t BoneWeightIndex[HL2mdl_MAX_NUM_BONES_PER_VERT]
These index into sv's bones. Can this ever be different from [0, 1, 2]? If so, why?
Definition: Loader_mdl_hl2_vtx.hpp:40
Definition: Loader_mdl_hl2_vtx.hpp:20
uint32_t Version
Must be FILE_VERSION.
Definition: Loader_mdl_hl2_vtx.hpp:228
uint32_t NumLODs
The same value is repeated in each vtxModelT.
Definition: Loader_mdl_hl2_vtx.hpp:237
This is the header of a VTX strips data file.
Definition: Loader_mdl_hl2_vtx.hpp:222
uint32_t VertCacheSize
These four are hardware-specific parameters that affect how the model is to be optimized.
Definition: Loader_mdl_hl2_vtx.hpp:230
uint32_t MatReplacementListsOffset
One per LOD.
Definition: Loader_mdl_hl2_vtx.hpp:238
static const uint32_t FILE_VERSION
The currently supported file format version.
Definition: Loader_mdl_hl2_vtx.hpp:226
uint16_t Sibling
See class description for usage.
Definition: Loader_mdl_hl2_vtx.hpp:42
This class corresponds to StudioBodyPartT in the mdl file.
Definition: Loader_mdl_hl2_vtx.hpp:176
uint16_t NumBones
What's this? The max. number of bones to be used, clamping/overriding the value in vtxVertexT...
Definition: Loader_mdl_hl2_vtx.hpp:70
A strip group is a locking group, representing a single vertex buffer and a single index buffer...
Definition: Loader_mdl_hl2_vtx.hpp:87
This class corresponds to StudioVertexT in the vvd file.
Definition: Loader_mdl_hl2_vtx.hpp:38
This class corresponds to StudioMeshT in the mdl file.
Definition: Loader_mdl_hl2_vtx.hpp:125
uint8_t NumBones
Same as sv.BoneWeights.NumBones.
Definition: Loader_mdl_hl2_vtx.hpp:41
Definition: Loader_mdl_hl2_vtx.hpp:206
uint32_t NumMeshes
One vtxMeshT for each StudioMeshT.
Definition: Loader_mdl_hl2_vtx.hpp:145
May contain degenerate triangles.
Definition: Loader_mdl_hl2_vtx.hpp:61
uint32_t NumLODs
Must match the NumLODs value in StripsHeaderT.
Definition: Loader_mdl_hl2_vtx.hpp:162
Definition: Loader_mdl_hl2_vtx.hpp:191
A strip is a portion of a strip group.
Definition: Loader_mdl_hl2_vtx.hpp:56
FlagsT
Definition: Loader_mdl_hl2_vtx.hpp:58
This class corresponds to StudioModelT in the mdl file.
Definition: Loader_mdl_hl2_vtx.hpp:160
uint8_t Bone[HL2mdl_MAX_NUM_BONES_PER_VERT]
For software-skinned vertices, these are indices into the mdl file's list of bones, that is, same as sv.BoneWeights.Bone[i] for each i < NumBones.
Definition: Loader_mdl_hl2_vtx.hpp:48
uint32_t Checksum
Must match the checksum in StudioHeaderT.
Definition: Loader_mdl_hl2_vtx.hpp:235
Definition: Loader_mdl_hl2_vtx.hpp:143