Skip to content

Commit

Permalink
Added Log & Texture File Extension Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
wagrenier committed Dec 13, 2023
1 parent 2f15dea commit 188b6c7
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 20 deletions.
18 changes: 10 additions & 8 deletions ModelConverter/game/Model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ void Model::ExtractModel()

void Model::BuildScene()
{
this->Model::ConvertToNodeBinaryTree();
this->ConvertToNodeBinaryTree();
this->scene->mNumMeshes = this->aiMeshes.size();
this->scene->mMeshes = this->aiMeshes.data();
this->scene->mNumMaterials = this->aiMaterials.size();
Expand All @@ -72,6 +72,7 @@ void Model::BuildScene()
void Model::ConvertToNodeBinaryTree()
{
this->scene->mRootNode = aiNodes[0];

for (auto i = 0; i < aiNodes.size(); i++)
{
aiNodes[i]->mNumMeshes = aiMeshesIndex[i].size();
Expand Down Expand Up @@ -235,11 +236,15 @@ void Model::ReadSGD(PK2_HEAD* mdlPak)
return;
}

programLogger->info("----- # of SGD {} -----\n", mdlPak->pack_num);

for (auto i = 0; i < mdlPak->pack_num; i++)
{
PrintSGDBeginning(i);
sgdCurr = (SGDFILEHEADER *) GetFileInPak(mdlPak, i);
sgdRemap(sgdCurr);
TraverseProcUnit(sgdCurr);
PrintSGDEnding(i);
}
}

Expand Down Expand Up @@ -336,20 +341,17 @@ void Model::HandleTri2DataBlock(SGDPROCUNITHEADER *pHead) {
}

void Model::HandleMeshDataBlock(SGDPROCUNITHEADER *pHead) {
SGDVUMESHPOINTNUM *pMeshInfo;

if (pHead->VUMeshDesc.ucMeshType == 0) {
return;
}
else if (pHead->VUMeshDesc.ucMeshType == 0x80) {

if (pHead->VUMeshDesc.ucMeshType == 0x80) {
// This just adds a triangle below the character, probably for getting floor coordinates of the model
pMeshInfo = (SGDVUMESHPOINTNUM *) &pHead[2];
//pMeshInfo = (SGDVUMESHPOINTNUM *) &pHead[2];
return;
}
else {
pMeshInfo = (SGDVUMESHPOINTNUM *) &pHead[4];
}

auto *pMeshInfo = (SGDVUMESHPOINTNUM *) &pHead[4];
auto pProcData = (SGDPROCUNITDATA *) &pHead[1];

SGDVUMESHSTDATA *sgdMeshData;
Expand Down
2 changes: 1 addition & 1 deletion ModelConverter/game/packfile.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include <stdint.h>
#include <cstdint>

typedef struct
{
Expand Down
25 changes: 15 additions & 10 deletions ModelConverter/utils/assimp_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ aiMesh *CreateNewMesh(unsigned int numPoints, int matIndex) {
m->mPrimitiveTypes = aiPrimitiveType_TRIANGLE;

m->mNumVertices = numPoints;
m->mVertices = new aiVector3D[numPoints];
m->mNormals = new aiVector3D[numPoints];
m->mTextureCoords[0] = new aiVector3D[numPoints];
m->mVertices = new aiVector3D[m->mNumVertices];
m->mNormals = new aiVector3D[m->mNumVertices];
m->mTextureCoords[0] = new aiVector3D[m->mNumVertices];
m->mNumUVComponents[0] = 2;
m->mNumFaces = numPoints - 2;
m->mFaces = new aiFace[numPoints - 2];
m->mFaces = new aiFace[m->mNumFaces];

//m->mAABB = aiAABB();
//m->mAABB.mMin = aiVector3D(boundingBoxMin.x, boundingBoxMin.y, boundingBoxMin.z);
Expand All @@ -39,7 +39,7 @@ aiMesh *CreateNewMesh(unsigned int numPoints, int matIndex) {
return m;
}

aiMaterial *FindMaterial(std::vector<aiMaterial *> materials, const std::string& name, int *matIndex) {
aiMaterial *FindMaterial(const std::vector<aiMaterial *>& materials, const std::string& name, int *matIndex) {
aiMaterial *currentMaterial = nullptr;

for(auto i = 0; i < materials.size(); i++)
Expand All @@ -60,10 +60,12 @@ aiMaterial *CreateNewMaterial(std::filesystem::path exportFolder, const std::str
auto currentMaterial = new aiMaterial();

currentMaterial->AddProperty(&s, AI_MATKEY_NAME);
pMaterial->vDiffuse.w /= 128.0f;
pMaterial->vAmbient.w /= 128.0f;
pMaterial->vEmission.w /= 128.0f;
pMaterial->vSpecular.w /= 128.0f;

// Scale the float value for W
pMaterial->vDiffuse.w = 255.0f * pMaterial->vDiffuse.w / 128.0f;
pMaterial->vAmbient.w = 255.0f * pMaterial->vAmbient.w / 128.0f;
pMaterial->vEmission.w = 255.0f * pMaterial->vEmission.w / 128.0f;
pMaterial->vSpecular.w = 255.0f * pMaterial->vSpecular.w / 128.0f;

currentMaterial->AddProperty(&pMaterial->vDiffuse, 1, AI_MATKEY_COLOR_DIFFUSE);
currentMaterial->AddProperty(&pMaterial->vAmbient, 1, AI_MATKEY_COLOR_AMBIENT);
Expand All @@ -75,7 +77,10 @@ aiMaterial *CreateNewMaterial(std::filesystem::path exportFolder, const std::str
return currentMaterial;
}

auto texName = name + ".png";
// TODO: Filter the value name to remove extensions
std::filesystem::path p(name);

auto texName = p.stem().string() + ".png";
SaveImage(exportFolder, texName, t->GetWidth(), t->GetHeight(), 4, t->GetRawData());
auto b = aiString(texName);
currentMaterial->AddProperty(&b, AI_MATKEY_TEXTURE(aiTextureType_DIFFUSE, 0));
Expand Down
2 changes: 1 addition & 1 deletion ModelConverter/utils/assimp_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

int GetNumberOfParents(aiNode* n);
aiMesh* CreateNewMesh(unsigned int numPoints, int matIndex);
aiMaterial *FindMaterial(std::vector<aiMaterial *> materials, const std::string& name, int *matIndex);
aiMaterial *FindMaterial(const std::vector<aiMaterial *>& materials, const std::string& name, int *matIndex);
aiMaterial* CreateNewMaterial(std::filesystem::path exportFolder, const std::string& name, Texture *t, SGDMATERIAL* pMaterial);
void ExportScene(std::filesystem::path exportFolder, const std::string& format, aiScene *scene, int exporterOptions);
void CreateBone(aiMesh *mesh, Matrix4x4 *mat, const aiString& name);
Expand Down
8 changes: 8 additions & 0 deletions ModelConverter/utils/logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ void PrintBlockEnding(int i) {
programLogger->info("----- End Block {} -----\n", i);
}

void PrintSGDBeginning(int i) {
programLogger->info("----- Begin SGD {} -----", i);
}

void PrintSGDEnding(int i) {
programLogger->info("----- End SGD {} -----\n", i);
}

void InitLogging() {
spdlog::set_pattern("[%H:%M:%S] [%n] [%^%l%$] [thread %t] %v");

Expand Down
2 changes: 2 additions & 0 deletions ModelConverter/utils/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@ void PrintBlockInfo(SGDPROCUNITHEADER *pHead, SGDFILEHEADER* pSGDTop);
void PrintEmptyBlock();
void PrintBlockBeginning(int i);
void PrintBlockEnding(int i);
void PrintSGDBeginning(int i);
void PrintSGDEnding(int i);

#endif //FATALSTACK_LOGGING_H

0 comments on commit 188b6c7

Please sign in to comment.