Skip to content

Commit

Permalink
Added groups
Browse files Browse the repository at this point in the history
  • Loading branch information
denis authored and denis committed Nov 15, 2024
1 parent 4b613ff commit 0eaff10
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 24 deletions.
68 changes: 53 additions & 15 deletions Engine/include/SceneData/SceneExporterLayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ namespace Prisma
if (type == "MESH")
{
auto mesh = std::dynamic_pointer_cast<Mesh>(n);
static std::map<std::string, Texture> texturesLoaded;
// Deserialize textures
if (j.contains("textures"))
{
Expand All @@ -361,9 +362,17 @@ namespace Prisma
}
else
{
texture.name(t.second);
texture.loadTexture({t.second, true});
textures.push_back(texture);
if (texturesLoaded.find(t.second) == texturesLoaded.end())
{
texture.name(t.second);
texture.loadTexture({t.second, true});
textures.push_back(texture);
texturesLoaded[t.second] = texture;
}
else
{
textures.push_back(texturesLoaded[t.second]);
}
}
material->diffuse(textures);
}
Expand All @@ -377,9 +386,17 @@ namespace Prisma
}
else
{
texture.name(t.second);
texture.loadTexture({t.second});
textures.push_back(texture);
if (texturesLoaded.find(t.second) == texturesLoaded.end())
{
texture.name(t.second);
texture.loadTexture({t.second});
textures.push_back(texture);
texturesLoaded[t.second] = texture;
}
else
{
textures.push_back(texturesLoaded[t.second]);
}
}
material->normal(textures);
}
Expand All @@ -393,9 +410,16 @@ namespace Prisma
}
else
{
texture.name(t.second);
texture.loadTexture({t.second});
textures.push_back(texture);
if (texturesLoaded.find(t.second) == texturesLoaded.end())
{
texture.name(t.second);
texture.loadTexture({t.second});
textures.push_back(texture);
}
else
{
textures.push_back(texturesLoaded[t.second]);
}
}
material->roughness_metalness(textures);
}
Expand All @@ -409,9 +433,16 @@ namespace Prisma
}
else
{
texture.name(t.second);
texture.loadTexture({t.second});
textures.push_back(texture);
if (texturesLoaded.find(t.second) == texturesLoaded.end())
{
texture.name(t.second);
texture.loadTexture({t.second});
textures.push_back(texture);
}
else
{
textures.push_back(texturesLoaded[t.second]);
}
}
material->specular(textures);
}
Expand All @@ -425,9 +456,16 @@ namespace Prisma
}
else
{
texture.name(t.second);
texture.loadTexture({t.second});
textures.push_back(texture);
if (texturesLoaded.find(t.second) == texturesLoaded.end())
{
texture.name(t.second);
texture.loadTexture({t.second});
textures.push_back(texture);
}
else
{
textures.push_back(texturesLoaded[t.second]);
}
}
material->ambientOcclusion(textures);
}
Expand Down
2 changes: 1 addition & 1 deletion Engine/include/SceneData/SceneLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ namespace Prisma
std::vector<Texture> loadMaterialTextures(aiMaterial* mat, aiTextureType type, bool srgb = false);
void loadLights(const aiScene* currentScene, std::shared_ptr<Node> root);

std::vector<Texture> textures_loaded;
std::map<std::string, Texture> m_texturesLoaded;
std::shared_ptr<Scene> m_scene;
std::string m_folder;
NodeHelper m_nodeFinder;
Expand Down
14 changes: 6 additions & 8 deletions Engine/src/SceneData/SceneLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,14 +372,12 @@ std::vector<Prisma::Texture> Prisma::SceneLoader::loadMaterialTextures(aiMateria
aiString str;
mat->GetTexture(type, i, &str);
bool skip = false;
for (auto& texture : textures_loaded)

if (m_texturesLoaded.find(m_folder + str.C_Str()) != m_texturesLoaded.end())
{
if (texture.name() == m_folder + str.C_Str())
{
textures.push_back(texture);
skip = true;
break;
}
textures.push_back(m_texturesLoaded[m_folder + str.C_Str()]);
skip = true;
break;
}
if (!skip)
{
Expand All @@ -394,7 +392,7 @@ std::vector<Prisma::Texture> Prisma::SceneLoader::loadMaterialTextures(aiMateria
{
texture.name(name);
textures.push_back(texture);
textures_loaded.push_back(texture);
m_texturesLoaded[m_folder + str.C_Str()] = texture;
}
}
}
Expand Down

0 comments on commit 0eaff10

Please sign in to comment.