SourcePP
Several modern C++20 libraries for sanely parsing Valve's formats.
Loading...
Searching...
No Matches
VVD.cpp
Go to the documentation of this file.
1#include <mdlpp/structs/VVD.h>
2
3#include <BufferStream.h>
4
5using namespace mdlpp::VVD;
6using namespace sourcepp;
7
8constexpr int32_t VVD_ID = 'I' + ('D' << 8) + ('S' << 16) + ('V' << 24);
9
10bool VVD::open(const std::byte* data, std::size_t size, const MDL::MDL& mdl) {
11 BufferStreamReadOnly stream{data, size};
12
13 if (stream.read<int32_t>() != VVD_ID) {
14 return false;
15 }
16
17 if (stream.read(this->version); this->version != 4) {
18 return false;
19 }
20
21 if (stream.read<int32_t>() != mdl.checksum) {
22 return false;
23 }
24
25 stream
26 .read(this->numLODs)
27 .read(this->numVerticesInLOD);
28
29 const auto fixupsCount = stream.read<int32_t>();
30 const auto fixupsOffset = stream.read<int32_t>();
31 const auto verticesOffset = stream.read<int32_t>();
32 const auto tangentsOffset = stream.read<int32_t>();
33
34 stream.seek(verticesOffset);
35 for (int i = 0; i < this->numVerticesInLOD[0]; i++) {
36 auto& [boneWeight, position, normal, uv, tangent] = this->vertices.emplace_back();
37
38 stream.read(boneWeight.weight);
39
40 std::array<int8_t, MAX_BONES_PER_VERTEX> bones{};
41 stream.read(bones);
42 const auto boneCount = stream.read<int8_t>();
43 for (int8_t j = 0; j < boneCount && j < MAX_BONES_PER_VERTEX; j++) {
44 boneWeight.bones.push_back(bones[j]);
45 }
46
47 stream
48 .read(position)
49 .read(normal)
50 .read(uv);
51 // tangents are assigned below
52 }
53
54 stream.seek(tangentsOffset);
55 for (std::size_t i = 0; i < this->numVerticesInLOD[0]; i++) {
56 this->vertices.at(i).tangent = stream.read<math::Vec4f>();
57 }
58
59 stream.seek(fixupsOffset);
60 for (int i = 0; i < fixupsCount; i++) {
61 auto& [LOD, sourceVertexID, vertexCount] = this->fixups.emplace_back();
62 stream >> LOD >> sourceVertexID >> vertexCount;
63 }
64
65 return true;
66}
constexpr int32_t VVD_ID
Definition: VVD.cpp:8
Definition: VVD.h:10
constexpr int MAX_BONES_PER_VERTEX
Definition: Generic.h:12
Definition: LZMA.h:11
int32_t checksum
Definition: MDL.h:287
std::array< int32_t, MAX_LOD_COUNT > numVerticesInLOD
Definition: VVD.h:46
int32_t numLODs
Definition: VVD.h:44
std::vector< Fixup > fixups
Definition: VVD.h:50
bool open(const std::byte *data, std::size_t size, const MDL::MDL &mdl)
Definition: VVD.cpp:10
std::vector< Vertex > vertices
Definition: VVD.h:53