From 8b8ad35d017350e53d6ce22c8871e13b68a17dea Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 18 Oct 2025 18:53:27 +0200 Subject: [PATCH] fix: support relative texture paths --- engine/src/renderer/wavefront.cpp | 5 ++++- sandbox/src/main.cpp | 8 ++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/engine/src/renderer/wavefront.cpp b/engine/src/renderer/wavefront.cpp index cd5effd..04db14b 100644 --- a/engine/src/renderer/wavefront.cpp +++ b/engine/src/renderer/wavefront.cpp @@ -196,7 +196,10 @@ void Object::LoadMaterials(const std::filesystem::path& filename) { while (len > 0 && (texPath[len - 1] == ' ' || texPath[len - 1] == '\t')) texPath[--len] = '\0'; - currentMaterial->SetDiffuseTexture(Texture::LoadFile(texPath)); + std::filesystem::path fullPath = filename; + std::filesystem::path texturePath = fullPath.parent_path() / texPath; + + currentMaterial->SetDiffuseTexture(Texture::LoadFile(texturePath)); } break; } diff --git a/sandbox/src/main.cpp b/sandbox/src/main.cpp index 7fd2f11..cf51e7f 100644 --- a/sandbox/src/main.cpp +++ b/sandbox/src/main.cpp @@ -25,7 +25,7 @@ class Game : public IApplication { public: Game() : m_renderer(m_registry) { - Object* lightObj = Object::LoadFile("./assets/sphere.obj"); + Object* lightObj = Object::LoadFile("./assets/common/sphere/sphere.obj"); const auto lght = m_registry.create(); m_registry.emplace(lght, glm::vec3(5.f, 5.f, 5.f), glm::vec3(0.f)); m_registry.emplace(lght, light::LightType::DIRECTIONAL, glm::vec3(1.f, 1.f, 1.f), 1.5f); @@ -35,12 +35,12 @@ public: m_registry.emplace(cameraEntity, glm::vec3(0.f, 2.f, 2.f)); m_registry.emplace(cameraEntity); - Object* targetObj = Object::LoadFile("./assets/monkey.obj"); + Object* targetObj = Object::LoadFile("./assets/wizard/wizard.obj"); const auto targetEntity = m_registry.create(); m_registry.emplace(targetEntity, glm::vec3(0.f, 0.0f, 0.f)); m_registry.emplace(targetEntity, std::shared_ptr(targetObj)); - Object* grass = Object::LoadFile("./assets/cube.obj"); + Object* grass = Object::LoadFile("./assets/common/cube/cube.obj"); const auto cubeEntity = m_registry.create(); m_registry.emplace(cubeEntity, glm::vec3(-1.5f, 0.4f, 0.f)); m_registry.emplace(cubeEntity, std::shared_ptr(grass)); @@ -64,7 +64,7 @@ public: m_registry.emplace(cubeEntity, cubeBatch.id()); } - Object* floorObj = Object::LoadFile("./assets/plane.obj"); + Object* floorObj = Object::LoadFile("./assets/common/plane/plane.obj"); const auto floorEntt = m_registry.create(); m_registry.emplace(floorEntt, glm::vec3(0.f)); m_registry.emplace(floorEntt, std::shared_ptr(floorObj));