fix: support relative texture paths
This commit is contained in:
@ -196,7 +196,10 @@ void Object::LoadMaterials(const std::filesystem::path& filename) {
|
|||||||
while (len > 0 && (texPath[len - 1] == ' ' || texPath[len - 1] == '\t'))
|
while (len > 0 && (texPath[len - 1] == ' ' || texPath[len - 1] == '\t'))
|
||||||
texPath[--len] = '\0';
|
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;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
class Game : public IApplication {
|
class Game : public IApplication {
|
||||||
public:
|
public:
|
||||||
Game() : m_renderer(m_registry) {
|
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();
|
const auto lght = m_registry.create();
|
||||||
m_registry.emplace<transform>(lght, glm::vec3(5.f, 5.f, 5.f), glm::vec3(0.f));
|
m_registry.emplace<transform>(lght, glm::vec3(5.f, 5.f, 5.f), glm::vec3(0.f));
|
||||||
m_registry.emplace<light>(lght, light::LightType::DIRECTIONAL, glm::vec3(1.f, 1.f, 1.f), 1.5f);
|
m_registry.emplace<light>(lght, light::LightType::DIRECTIONAL, glm::vec3(1.f, 1.f, 1.f), 1.5f);
|
||||||
@ -35,12 +35,12 @@ public:
|
|||||||
m_registry.emplace<transform>(cameraEntity, glm::vec3(0.f, 2.f, 2.f));
|
m_registry.emplace<transform>(cameraEntity, glm::vec3(0.f, 2.f, 2.f));
|
||||||
m_registry.emplace<camera>(cameraEntity);
|
m_registry.emplace<camera>(cameraEntity);
|
||||||
|
|
||||||
Object* targetObj = Object::LoadFile("./assets/monkey.obj");
|
Object* targetObj = Object::LoadFile("./assets/wizard/wizard.obj");
|
||||||
const auto targetEntity = m_registry.create();
|
const auto targetEntity = m_registry.create();
|
||||||
m_registry.emplace<transform>(targetEntity, glm::vec3(0.f, 0.0f, 0.f));
|
m_registry.emplace<transform>(targetEntity, glm::vec3(0.f, 0.0f, 0.f));
|
||||||
m_registry.emplace<mesh>(targetEntity, std::shared_ptr<Object>(targetObj));
|
m_registry.emplace<mesh>(targetEntity, std::shared_ptr<Object>(targetObj));
|
||||||
|
|
||||||
Object* grass = Object::LoadFile("./assets/cube.obj");
|
Object* grass = Object::LoadFile("./assets/common/cube/cube.obj");
|
||||||
const auto cubeEntity = m_registry.create();
|
const auto cubeEntity = m_registry.create();
|
||||||
m_registry.emplace<transform>(cubeEntity, glm::vec3(-1.5f, 0.4f, 0.f));
|
m_registry.emplace<transform>(cubeEntity, glm::vec3(-1.5f, 0.4f, 0.f));
|
||||||
m_registry.emplace<mesh>(cubeEntity, std::shared_ptr<Object>(grass));
|
m_registry.emplace<mesh>(cubeEntity, std::shared_ptr<Object>(grass));
|
||||||
@ -64,7 +64,7 @@ public:
|
|||||||
m_registry.emplace<batch::item>(cubeEntity, cubeBatch.id());
|
m_registry.emplace<batch::item>(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();
|
const auto floorEntt = m_registry.create();
|
||||||
m_registry.emplace<transform>(floorEntt, glm::vec3(0.f));
|
m_registry.emplace<transform>(floorEntt, glm::vec3(0.f));
|
||||||
m_registry.emplace<mesh>(floorEntt, std::shared_ptr<Object>(floorObj));
|
m_registry.emplace<mesh>(floorEntt, std::shared_ptr<Object>(floorObj));
|
||||||
|
Reference in New Issue
Block a user