forked from MontagueM/MontevenDynamicExtractor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.cpp
74 lines (68 loc) · 1.73 KB
/
index.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include "index.h"
void IndexBufferHeader::getHeader(std::string x)
{
bool bIsStride4;
memcpy((char*)&bIsStride4, data + 0x1, 1);
if (bIsStride4) stride = 4;
}
void IndexBuffer::getFaces(Mesh* mesh, PrimitiveType primType)
{
int fileSize = getData();
int increment = 3;
std::vector<uint32_t> intFacesData;
intFacesData.reserve((floor(fileSize / stride)));
for (int i = 0; i < fileSize; i += stride)
{
uint32_t face = 0;
memcpy((char*)&face, data + i, stride);
intFacesData.push_back(face);
}
if (primType == TriangleStrip) increment = 1;
int j = 0;
int faceIndex = 0;
while (true)
{
if (faceIndex >= intFacesData.size() - 2 && primType == TriangleStrip)
{
mesh->faceMap[faceIndex] = mesh->faces.size() - 1;
if (faceIndex == intFacesData.size())
{
mesh->faceMap[faceIndex + 1] = mesh->faces.size() - 1;
break;
}
faceIndex++;
continue;
}
else if (faceIndex == intFacesData.size() && primType == Triangles)
{
mesh->faceMap[faceIndex] = mesh->faces.size() - 1;
break;
}
// Check vector break
bool bEnd = false;
for (int i = 0; i < 3; i++)
{
if (intFacesData[faceIndex + i] == 65535 or intFacesData[faceIndex + i] == 4294967295)
{
bEnd = true;
break;
}
}
if (bEnd)
{
j = 0;
mesh->faceMap[faceIndex] = mesh->faces.size() - 1;
faceIndex += increment;
continue;
}
std::vector<uint32_t> face;
if (primType == Triangles || j % 2 == 0)
face = std::vector<uint32_t>(intFacesData.begin() + faceIndex, intFacesData.begin() + faceIndex + 3);
else
face = {intFacesData[faceIndex + 1], intFacesData[faceIndex], intFacesData[faceIndex + 2] };
mesh->faces.push_back(face);
mesh->faceMap[faceIndex] = mesh->faces.size() - 1;
faceIndex += increment;
j++;
}
}