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>
5
6using namespace mdlpp::VVD;
7using namespace sourcepp;
8
9constexpr int32_t VVD_ID = parser::binary::makeFourCC("IDSV");
10
11bool VVD::open(const std::byte* data, std::size_t size, const MDL::MDL& mdl) {
12 BufferStreamReadOnly stream{data, size};
13
14 if (stream.read<int32_t>() != VVD_ID) {
15 return false;
16 }
17
18 if (stream.read(this->version); this->version != 4) {
19 return false;
20 }
21
22 if (stream.read<int32_t>() != mdl.checksum) {
23 return false;
24 }
25
26 stream
27 .read(this->numLODs)
28 .read(this->numVerticesInLOD);
29
30 const auto fixupsCount = stream.read<int32_t>();
31 const auto fixupsOffset = stream.read<int32_t>();
32 const auto verticesOffset = stream.read<int32_t>();
33 const auto tangentsOffset = stream.read<int32_t>();
34
35 stream.seek(verticesOffset);
36 for (int i = 0; i < this->numVerticesInLOD[0]; i++) {
37 auto& [boneWeight, position, normal, uv, tangent] = this->vertices.emplace_back();
38
39 stream.read(boneWeight.weight);
40
41 std::array<int8_t, MAX_BONES_PER_VERTEX> bones{};
42 stream.read(bones);
43 const auto boneCount = stream.read<int8_t>();
44 for (int8_t j = 0; j < boneCount && j < MAX_BONES_PER_VERTEX; j++) {
45 boneWeight.bones.push_back(bones[j]);
46 }
47
48 stream
49 .read(position)
50 .read(normal)
51 .read(uv);
52 // tangents are assigned below
53 }
54
55 stream.seek(tangentsOffset);
56 for (std::size_t i = 0; i < this->numVerticesInLOD[0]; i++) {
57 this->vertices.at(i).tangent = stream.read<math::Vec4f>();
58 }
59
60 stream.seek(fixupsOffset);
61 for (int i = 0; i < fixupsCount; i++) {
62 auto& [LOD, sourceVertexID, vertexCount] = this->fixups.emplace_back();
63 stream >> LOD >> sourceVertexID >> vertexCount;
64 }
65
66 return true;
67}
constexpr int32_t VVD_ID
Definition: VVD.cpp:9
Definition: VVD.h:10
constexpr int MAX_BONES_PER_VERTEX
Definition: Generic.h:12
consteval uint32_t makeFourCC(const char fourCC[4])
Creates a FourCC identifier from a string of 4 characters.
Definition: Binary.h:18
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:11
std::vector< Vertex > vertices
Definition: VVD.h:53