From 430b799e5435e79632b11e10f438758958d7905f Mon Sep 17 00:00:00 2001 From: Jake Ryan Date: Thu, 1 Aug 2024 23:52:05 -0700 Subject: [PATCH] Fixed incorrect handling of models with no materials --- src/Application.cpp | 3 --- src/Scene.cpp | 2 +- src/SceneLoader.cpp | 4 ++-- src/SceneLoader.h | 2 +- 4 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/Application.cpp b/src/Application.cpp index 5b35a8e..76c8202 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -275,9 +275,6 @@ Application::Application(const CreateInfo& createInfo) glfwSetWindowPos(window, videoMode->width / 2 - windowFramebufferWidth / 2 + monitorLeft, videoMode->height / 2 - windowFramebufferHeight / 2 + monitorTop); glfwSetWindowUserPointer(window, this); - //glfwMakeContextCurrent(window); - //glfwSwapInterval(vsyncEnabled ? 1 : 0); - // TODO: configure vsync glfwSetCursorPosCallback(window, ApplicationAccess::CursorPosCallback); glfwSetCursorEnterCallback(window, ApplicationAccess::CursorEnterCallback); diff --git a/src/Scene.cpp b/src/Scene.cpp index 5c77802..dc37359 100644 --- a/src/Scene.cpp +++ b/src/Scene.cpp @@ -94,7 +94,7 @@ namespace Scene { auto& meshInstanceId = meshInstanceIds.emplace_back(renderer.RegisterMeshInstance({ .meshGeometry = meshGeometryIds[baseMeshGeometryIndex + meshIndex], - .material = materialIds[baseMaterialIndex + materialIndex], + .material = materialIds[materialIndex.has_value() ? baseMaterialIndex + *materialIndex : 0], })); auto meshId = meshIds.emplace_back(renderer.SpawnMesh(meshInstanceId)); diff --git a/src/SceneLoader.cpp b/src/SceneLoader.cpp index babaf10..7c28a77 100644 --- a/src/SceneLoader.cpp +++ b/src/SceneLoader.cpp @@ -1026,11 +1026,11 @@ namespace Utility rawMeshIndex = it->second; } - auto materialId = primitive.materialIndex.has_value() ? uint32_t(primitive.materialIndex.value()) : 0; + auto materialId = primitive.materialIndex; if (skipMaterials) { - materialId = 0; + materialId = std::nullopt; } node->meshes.emplace_back(rawMeshIndex, materialId); diff --git a/src/SceneLoader.h b/src/SceneLoader.h index 33e822a..5632ec5 100644 --- a/src/SceneLoader.h +++ b/src/SceneLoader.h @@ -36,7 +36,7 @@ namespace Utility struct MeshIndices { size_t meshIndex; - size_t materialIndex; + std::optional materialIndex; }; std::vector meshes; std::optional light; // TODO: hold a light without position/direction type safety