Skip to content
This repository has been archived by the owner on Jun 26, 2024. It is now read-only.

Disabled debug printing and and issue with large models. #4

Merged
merged 2 commits into from
Feb 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions fbxmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,25 @@ FbxMesh* FbxModel::createMesh(Submesh* submesh) {
std::vector<float_t> v = submesh->vertPos[i];
mesh->SetControlPointAt(FbxVector4(-v[0], v[2], v[1]), i);
}
for (auto& face : submesh->faces)
{
mesh->BeginPolygon();
mesh->AddPolygon(face[0]);
mesh->AddPolygon(face[1]);
mesh->AddPolygon(face[2]);
mesh->EndPolygon();
if (submesh->isU32) {
for (auto& face : submesh->facesu32)
{
mesh->BeginPolygon();
mesh->AddPolygon(face[0]);
mesh->AddPolygon(face[1]);
mesh->AddPolygon(face[2]);
mesh->EndPolygon();
}
}
else {
for (auto& face : submesh->faces)
{
mesh->BeginPolygon();
mesh->AddPolygon(face[0]);
mesh->AddPolygon(face[1]);
mesh->AddPolygon(face[2]);
mesh->EndPolygon();
}
}
return mesh;
}
Expand Down
2 changes: 2 additions & 0 deletions helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,12 @@ class Submesh
std::vector<std::vector<float>> vertUV;
std::vector<std::vector<float>> vertCol;
std::vector<std::vector<int16_t>> faces;
std::vector<std::vector<uint32_t>> facesu32;
std::vector<uint16_t> vertNormW;
std::vector<std::vector<float>> vertColSlots;
int lodLevel;
std::string name;
bool isU32;
int type;
int indexCount;
int indexOffset;
Expand Down
56 changes: 39 additions & 17 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,38 @@ namespace fs = std::filesystem;

#pragma region Parsers

bool parseIndexBufferInMemory(int vertexCount, bool isU32Indexes, int fileSize)
bool parseIndexBufferInMemory(int vertexCount, int fileSize)
{
int e = 0;
int b = 0;
int l = 0;
int16_t face;
uint32_t u32face;
int n = vertexCount;
for (int i = 0; i < fileSize; i += 0x6) {
std::vector<int16_t> intFace;
intFace.reserve(3);
for (int j = 0; j < 3; j++) {
memcpy((char*)&face, data + i + j * 2, 2);
intFace.push_back(face);
if (submesh->isU32) {
std::vector<uint32_t> intFace;
intFace.reserve(3);
for (int j = 0; j < 3; j++) {
memcpy((char*)&u32face, data + i + j * 4, 4);
intFace.push_back(u32face);
}
i += 6;
if (face > vertexCount)
break;
submesh->facesu32.push_back(intFace);
}
else {
std::vector<int16_t> intFace;
intFace.reserve(3);
for (int j = 0; j < 3; j++) {
memcpy((char*)&face, data + i + j * 2, 2);
intFace.push_back(face);
}
if (face > vertexCount)
break;
submesh->faces.push_back(intFace);
}
if (face > vertexCount)
break;
submesh->faces.push_back(intFace);
//im not proud of this...
//it also doesnt work half the time :]
if (lodCulling) {
Expand Down Expand Up @@ -226,9 +241,14 @@ int main(int argc, char* argv[])
fileSize = getFile();
parseUVBufferInMemory(fileSize, utrans, vtrans, uoff, voff);
delete[] data;
bool isu32 = false;
fileSize = getFile();
memcpy((void*)&isu32, data + 1, 1);
submesh->isU32 = isu32;
delete[] data;
hash = uint32ToHexStr(indexBuffer);
fileSize = getFile();
parseIndexBufferInMemory(submesh->vertPos.size(), false, fileSize);
parseIndexBufferInMemory(submesh->vertPos.size(), fileSize);
delete[] data;
//for later
/*
Expand All @@ -253,7 +273,7 @@ int main(int argc, char* argv[])
submesh->faces.clear();
submesh->vertPos.clear();
submesh->vertUV.clear();

//parse MATERIALS ?
if (sarge.exists("texex")) {
hash = modelHash;
Expand Down Expand Up @@ -345,7 +365,7 @@ int main(int argc, char* argv[])
delete[] data;
free(texture);
//TGA/PNG/Other support

std::string dxgiFormat = DXGI_FORMAT[textureFormat];
std::string texconv = "texconv.exe \"" + fullSavePath + "\" -nologo -y -ft PNG -f " + dxgiFormat;
system(texconv.c_str());
Expand Down Expand Up @@ -400,7 +420,6 @@ int main(int argc, char* argv[])

std::cout << modelHash + ".fbx extracted.\n";
}

else if (batchPkg != "") {
std::string outputName;
Package pkg(batchPkg, packagesPath);
Expand Down Expand Up @@ -434,10 +453,8 @@ int main(int argc, char* argv[])
memcpy((char*)&vertexBuffer, data + fileSize - 0x10, 4);
memcpy((char*)&uvBuffer, data + fileSize - 0xC, 4);
memcpy((char*)&vcBuffer, data + fileSize - 0x8, 4);
if (indexBuffer < 0x80800000 || vertexBuffer < 0x80800000 || uvBuffer < 0x80800000 || vcBuffer < 0x80800000) {
std::cout << std::to_string(indexBuffer) + " " + std::to_string(vertexBuffer) + " " + std::to_string(uvBuffer) + " " + std::to_string(vcBuffer) << std::endl;
if (indexBuffer < 0x80800000 || vertexBuffer < 0x80800000 || uvBuffer < 0x80800000 || vcBuffer < 0x80800000)
continue;
}
float utrans, vtrans, uoff, voff;
memcpy((void*)&utrans, data + 0x58, 4);
memcpy((void*)&vtrans, data + 0x5C, 4);
Expand All @@ -463,9 +480,14 @@ int main(int argc, char* argv[])
delete[] data;
hash.clear();
}
bool isu32 = false;
fileSize = getFile();
memcpy((void*)&isu32, data + 1, 1);
submesh->isU32 = isu32;
delete[] data;
hash = uint32ToHexStr(indexBuffer);
fileSize = getFile();
parseIndexBufferInMemory(submesh->vertPos.size(), false, fileSize);
parseIndexBufferInMemory(submesh->vertPos.size(), fileSize);
delete[] data;

std::string fbxpath = outputPath + "/" + modelhash + ".fbx";
Expand Down