Skip to content
This repository was archived by the owner on Dec 11, 2025. It is now read-only.

Commit d3091aa

Browse files
committed
Add support for subdirectory for textures
1 parent 70801b9 commit d3091aa

2 files changed

Lines changed: 48 additions & 16 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,3 +362,4 @@ MigrationBackup/
362362
# Fody - auto-generated XML schema
363363
FodyWeavers.xsd
364364
/Model Exporter/ColladaFile.hxx
365+
/main

Model Exporter/main.cxx

Lines changed: 47 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#define _CRT_SECURE_NO_WARNINGS
2+
#include "3rdParty/umHalf.h"
3+
24
#include <array>
35
#include <algorithm>
46
#include <iostream>
@@ -8,10 +10,9 @@
810
#include <unordered_map>
911

1012
//#include "ColladaFile.hxx"
11-
#include "3rdParty/umHalf.h"
1213

1314
// Defines
14-
#define PROJECT_VERSION "v1.0.4"
15+
#define PROJECT_VERSION "v1.0.5"
1516
#define PROJECT_NAME "Model Exporter " PROJECT_VERSION
1617

1718
// SDK Stuff
@@ -117,14 +118,27 @@ namespace Helper
117118

118119
namespace TextureFiles
119120
{
120-
std::unordered_map<uint32_t, std::string> m_Map;
121-
void Initialize(std::string p_Path)
121+
std::unordered_map<std::string, std::unordered_map<uint32_t, std::string>> m_Map;
122+
std::vector<std::string> m_SupportedExtensions = { ".JPG", ".JPEG", ".PNG", ".TIFF", ".TIF", ".BMP", ".TGA", ".GIF", ".HDR", ".EXR", ".DDS" };
123+
124+
void ItterFolder(std::string p_Path, std::string p_Folder)
122125
{
123-
std::vector<std::string> m_SupportedExtensions = { ".JPG", ".JPEG", ".PNG", ".TIFF", ".TIF", ".BMP", ".TGA", ".GIF", ".HDR", ".EXR", ".DDS" };
126+
std::unordered_map<uint32_t, std::string>& m_TextureMap = m_Map[p_Folder];
127+
std::string m_Path = p_Path;
128+
if (!p_Folder.empty())
129+
m_Path += "\\" + p_Folder;
130+
124131
try
125132
{
126-
for (auto& m_Entry : std::filesystem::directory_iterator(p_Path))
133+
for (auto& m_Entry : std::filesystem::directory_iterator(m_Path))
127134
{
135+
if (m_Entry.is_directory())
136+
{
137+
if (p_Folder.empty())
138+
ItterFolder(p_Path, m_Entry.path().filename().string());
139+
continue;
140+
}
141+
128142
if (!m_Entry.is_regular_file())
129143
continue;
130144

@@ -135,25 +149,42 @@ namespace Helper
135149
continue;
136150

137151
std::string m_TextureName = m_Entry.path().stem().string();
138-
m_Map[SDK::StringHashUpper32(&m_TextureName[0])] = m_Entry.path().filename().string();
152+
m_TextureMap[SDK::StringHashUpper32(&m_TextureName[0])] = m_Entry.path().filename().string();
139153
}
140154
}
141155
catch (...)
142156
{
143-
printf("[ WARNING ] Failed to fetch texture files because 'directory_iterator' got IO Error.!\n");
157+
// Retard...
144158
}
159+
}
160+
161+
void Initialize(std::string p_Path)
162+
{
163+
ItterFolder(p_Path, "");
145164

146165
if (m_Map.size())
147166
printf("[ ~ ] Found %zu textures in output folder.\n", m_Map.size());
148167
}
149168

150-
std::string TryGet(uint32_t p_NameUID)
169+
std::string TryGet(std::string p_FileName, uint32_t p_NameUID)
151170
{
152-
auto m_Find = m_Map.find(p_NameUID);
153-
if (m_Find == m_Map.end())
154-
return "";
171+
// Find based on filename first...
172+
std::unordered_map<uint32_t, std::string>& m_TextureMap = m_Map[p_FileName];
173+
{
174+
auto m_Find = m_TextureMap.find(p_NameUID);
175+
if (m_Find != m_TextureMap.end())
176+
return (*m_Find).second;
177+
}
178+
179+
// Find in every map...
180+
for (auto& m_Pair : m_Map)
181+
{
182+
auto m_Find = m_Pair.second.find(p_NameUID);
183+
if (m_Find != m_Pair.second.end())
184+
return (*m_Find).second;
185+
}
155186

156-
return (*m_Find).second;
187+
return "";
157188
}
158189
}
159190
}
@@ -355,7 +386,7 @@ int main(int p_Argc, char** p_Argv)
355386
if (Helper::GetTextureColor(m_Diffuse->m_NameUID, m_MtlBase.m_Kd))
356387
continue; // The texture would use one pixel color so we don't include it...
357388

358-
m_MtlBase.m_MapKd = Helper::TextureFiles::TryGet(m_Diffuse->m_NameUID);
389+
m_MtlBase.m_MapKd = Helper::TextureFiles::TryGet(m_PermFile.m_Name, m_Diffuse->m_NameUID);
359390
if (!m_MtlBase.m_MapKd.empty())
360391
{
361392
printf("\t\t\tDiffuse: %s\n", &m_MtlBase.m_MapKd[0]);
@@ -381,7 +412,7 @@ int main(int p_Argc, char** p_Argv)
381412
if (!m_Bump)
382413
continue;
383414

384-
m_MtlBase.m_MapBump = Helper::TextureFiles::TryGet(m_Bump->m_NameUID);
415+
m_MtlBase.m_MapBump = Helper::TextureFiles::TryGet(m_PermFile.m_Name, m_Bump->m_NameUID);
385416
if (!m_MtlBase.m_MapBump.empty())
386417
{
387418
printf("\t\t\tBump: %s\n", &m_MtlBase.m_MapBump[0]);
@@ -407,7 +438,7 @@ int main(int p_Argc, char** p_Argv)
407438
if (!m_Specular)
408439
continue;
409440

410-
m_MtlBase.m_MapKs = Helper::TextureFiles::TryGet(m_Specular->m_NameUID);
441+
m_MtlBase.m_MapKs = Helper::TextureFiles::TryGet(m_PermFile.m_Name, m_Specular->m_NameUID);
411442
if (!m_MtlBase.m_MapKs.empty())
412443
{
413444
printf("\t\t\tSpecular: %s\n", &m_MtlBase.m_MapKs[0]);

0 commit comments

Comments
 (0)