add relative path for materials in obj files and for OBJ elements in scenes

This commit is contained in:
2025-01-21 16:15:07 +01:00
parent 8fbaf4a75c
commit 46ef719f29
16 changed files with 81 additions and 24 deletions

View File

@ -6,7 +6,7 @@
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/01/16 15:00:49 by tomoron #+# #+# */
/* Updated: 2025/01/18 18:32:42 by tomoron ### ########.fr */
/* Updated: 2025/01/21 16:01:21 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
@ -18,7 +18,7 @@
class ObjParser
{
public:
ObjParser(std::string &filename);
ObjParser(std::string &filename, std::string &scene_filename);
~ObjParser();
void parse(Scene &scene, glm::vec3 offset, float scale, glm::mat4 transform);
@ -31,10 +31,12 @@ class ObjParser
void parseMtl(std::stringstream &line, Scene &scene);
bool addTriangleFromPolygon(std::vector<glm::vec3> &vertices, int inv);
void addTriangle(glm::vec3 v1, glm::vec3 v2, glm::vec3 v3);
std::string getFilePath(std::string &file);
int pointInTriangle(glm::vec3 pts[3], std::vector<glm::vec3> vertices, size_t cur);
std::vector<std::string> objSplit(std::string str, std::string delim);
void getFaceVertices(std::vector<glm::vec3> &faceVertices, std::stringstream &line);
std::string _filename;
std::ifstream _file;
std::vector<glm::vec3> _vertices;
std::vector<glm::vec2> _textureVertices;

View File

@ -6,7 +6,7 @@
/* By: TheRed <TheRed@students.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/12/26 21:37:37 by TheRed #+# #+# */
/* Updated: 2025/01/16 15:02:01 by tomoron ### ########.fr */
/* Updated: 2025/01/21 15:15:13 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
@ -18,7 +18,7 @@
class SceneParser
{
public:
SceneParser(Scene *scene);
SceneParser(Scene *scene, char *filename);
bool parseLine(const std::string &line);
@ -28,6 +28,7 @@ class SceneParser
void parseObj(std::stringstream &line);
Scene *_scene;
std::string _filename;
std::map<std::string, std::function<Object *(std::stringstream &)>> object_parsers;
};