mirror of
https://github.com/TheRedShip/RT_GPU.git
synced 2025-09-27 18:48:36 +02:00
~ | Fixing multiple loading same texture
This commit is contained in:
@ -6,7 +6,7 @@
|
|||||||
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
|
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/09/27 14:52:10 by TheRed #+# #+# */
|
/* 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_glfw.h"
|
||||||
# include "imgui/imgui_impl_opengl3.h"
|
# include "imgui/imgui_impl_opengl3.h"
|
||||||
|
|
||||||
|
# include <algorithm>
|
||||||
# include <string.h>
|
# include <string.h>
|
||||||
# include <iostream>
|
# include <iostream>
|
||||||
# include <fstream>
|
# include <fstream>
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
|
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/01/16 15:00:33 by tomoron #+# #+# */
|
/* 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))
|
if (!(lineStream >> path))
|
||||||
throw std::runtime_error("OBJ: syntax error while getting material texture");
|
throw std::runtime_error("OBJ: syntax error while getting material texture");
|
||||||
|
|
||||||
mat->texture_index = scene.getTextures().size();
|
path = getFilePath(_filename) + path;
|
||||||
scene.addTexture(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")
|
else if (identifier == "map_Ke")
|
||||||
{
|
{
|
||||||
std::string path;
|
std::string path;
|
||||||
|
|
||||||
if (!(lineStream >> 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();
|
path = getFilePath(_filename) + path;
|
||||||
scene.addEmissionTexture(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)
|
if (mat->emission == 0)
|
||||||
mat->emission = 1;
|
mat->emission = 1;
|
||||||
@ -347,11 +367,6 @@ void ObjParser::parseMtl(std::stringstream &input_line, Scene &scene)
|
|||||||
_matNames[matName] = scene.getMaterialData().size() - 1;
|
_matNames[matName] = scene.getMaterialData().size() - 1;
|
||||||
}
|
}
|
||||||
file.close();
|
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)
|
void ObjParser::parse(Scene &scene, glm::vec3 offset, float scale, glm::mat4 transform)
|
||||||
|
Reference in New Issue
Block a user