diff --git a/include/Mesh3D.h b/include/Mesh3D.h index bde7940..0d90aed 100644 --- a/include/Mesh3D.h +++ b/include/Mesh3D.h @@ -12,8 +12,8 @@ namespace djalim { public: Mesh3D(); - Mesh3D(const std::string& filepath); - void loadOBJFile(const std::string& filepath); + Mesh3D(const std::string& filepath, bool flipObjectVertically = false); + void loadOBJFile(const std::string& filepath, bool flipObjectVertically = false); public: Texture2D texture; glm::vec3 position = {0.0f, 0.0f, 0.0f}; diff --git a/src/core/Mesh3D.cpp b/src/core/Mesh3D.cpp index 4041bd5..61add7b 100644 --- a/src/core/Mesh3D.cpp +++ b/src/core/Mesh3D.cpp @@ -23,11 +23,11 @@ struct objFace { djalim::Mesh3D::Mesh3D(){} -djalim::Mesh3D::Mesh3D(const std::string& filepath) { - loadOBJFile(filepath); +djalim::Mesh3D::Mesh3D(const std::string& filepath, bool flipObjectVertically) { + loadOBJFile(filepath, flipObjectVertically); } -void djalim::Mesh3D::loadOBJFile(const std::string& filepath) { +void djalim::Mesh3D::loadOBJFile(const std::string& filepath, bool flipObjectVertically) { std::ifstream file(filepath); if (!file.is_open()) { std::cerr << "Failed to open OBJ file: " << filepath << std::endl; @@ -48,7 +48,10 @@ void djalim::Mesh3D::loadOBJFile(const std::string& filepath) { if (type == "v") { float x, y, z; ss >> x >> y >> z; - vertices.push_back({x, y, z}); + if(flipObjectVertically) + vertices.push_back({x, -y, z}); + else + vertices.push_back({x, y, z}); numMeshVertices++; } else if (type == "vn") { diff --git a/src/core/engine.cpp b/src/core/engine.cpp index a29de3f..385ec04 100644 --- a/src/core/engine.cpp +++ b/src/core/engine.cpp @@ -65,7 +65,8 @@ void djalim::OpenGlEngine::createObject(std::string name, std::string textures, void djalim::OpenGlEngine::createObject(std::string name, std::string textures, std::string filepath){ // Load the mesh from the file - objects[name] = std::make_unique(Mesh3D(filepath)); + bool flip = (name == "mimikyu"); + objects[name] = std::make_unique(Mesh3D(filepath, flip)); bool textureLoaded = objects[name]->texture.loadTexture(textures);