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
40 .read(boneWeight.weight)
41 .read(boneWeight.bones)
42 .read(boneWeight.boneCount)
43 .read(position)
44 .read(normal)
45 .read(uv);
46 // tangents are assigned below
47 }
48
49 stream.seek(tangentsOffset);
50 for (std::size_t i = 0; i < this->numVerticesInLOD[0]; i++) {
51 this->vertices.at(i).tangent = stream.read<math::Vec4f>();
52 }
53
54 stream.seek(fixupsOffset);
55 for (int i = 0; i < fixupsCount; i++) {
56 auto& [LOD, sourceVertexID, vertexCount] = this->fixups.emplace_back();
57 stream >> LOD >> sourceVertexID >> vertexCount;
58 }
59
60 return true;
61}
constexpr int32_t VVD_ID
Definition VVD.cpp:9
consteval uint32_t makeFourCC(const char fourCC[4])
Creates a FourCC identifier from a string of 4 characters.
Definition Binary.h:20
int32_t checksum
Definition MDL.h:707
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