~ | Fixing multiple loading same texture

This commit is contained in:
RedShip
2025-02-03 18:40:40 +01:00
committed by tomoron
parent e332161e7a
commit 7ffc43b7cb
2 changed files with 28 additions and 12 deletions

View File

@ -6,7 +6,7 @@
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/27 14:52:10 by TheRed #+# #+# */
/* Updated: 2025/01/22 16:37:32 by tomoron ### ########.fr */
/* Updated: 2025/02/03 18:17:48 by ycontre ### ########.fr */
/* */
/* ************************************************************************** */
@ -31,6 +31,7 @@
# include "imgui/imgui_impl_glfw.h"
# include "imgui/imgui_impl_opengl3.h"
# include <algorithm>
# include <string.h>
# include <iostream>
# include <fstream>

View File

@ -6,7 +6,7 @@
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/01/16 15:00:33 by tomoron #+# #+# */
/* Updated: 2025/01/31 19:53:44 by ycontre ### ########.fr */
/* Updated: 2025/02/03 18:40:04 by ycontre ### ########.fr */
/* */
/* ************************************************************************** */
@ -322,18 +322,38 @@ void ObjParser::parseMtl(std::stringstream &input_line, Scene &scene)
if (!(lineStream >> path))
throw std::runtime_error("OBJ: syntax error while getting material texture");
mat->texture_index = scene.getTextures().size();
scene.addTexture(getFilePath(_filename) + path);
path = getFilePath(_filename) + path;
std::vector<std::string> previous_textures = scene.getTextures();
std::vector<std::string>::iterator it = std::find(previous_textures.begin(), previous_textures.end(), path);
if (it != previous_textures.end())
mat->texture_index = std::distance(previous_textures.begin(), it);
else
{
mat->texture_index = previous_textures.size();;
scene.addTexture(path);
}
}
else if (identifier == "map_Ke")
{
std::string path;
if (!(lineStream >> path))
throw std::runtime_error("OBJ: syntax error while getting material texture");
throw std::runtime_error("OBJ: syntax error while getting emissive texture");
mat->emission_texture_index = scene.getEmissionTextures().size();
scene.addEmissionTexture(getFilePath(_filename) + path);
path = getFilePath(_filename) + path;
std::vector<std::string> previous_textures = scene.getEmissionTextures();
std::vector<std::string>::iterator it = std::find(previous_textures.begin(), previous_textures.end(), path);
if (it != previous_textures.end())
mat->texture_index = std::distance(previous_textures.begin(), it);
else
{
mat->texture_index = previous_textures.size();;
scene.addEmissionTexture(path);
}
if (mat->emission == 0)
mat->emission = 1;
@ -347,11 +367,6 @@ void ObjParser::parseMtl(std::stringstream &input_line, Scene &scene)
_matNames[matName] = scene.getMaterialData().size() - 1;
}
file.close();
for(auto i = _matNames.begin(); i != _matNames.end(); i++)
{
std::cout << "key : " << i->first << std::endl;
std::cout << "value :" << i->second << std::endl;
}
}
void ObjParser::parse(Scene &scene, glm::vec3 offset, float scale, glm::mat4 transform)