From 1fef8e6cba361c84c2aa91868ffe8966fe3824fa Mon Sep 17 00:00:00 2001 From: Dynamitos Date: Sat, 25 Jan 2025 19:20:12 +0100 Subject: [PATCH] adding tex coords --- src/scene/BVH.cpp | 3 ++- src/scene/BVH.h | 9 +++++---- src/util/Model.h | 1 + src/util/ModelLoader.cpp | 1 + 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/scene/BVH.cpp b/src/scene/BVH.cpp index 80ccfaf..863e89a 100644 --- a/src/scene/BVH.cpp +++ b/src/scene/BVH.cpp @@ -31,6 +31,7 @@ void BVH::generate() for (uint32_t i = 0; i < model->positions.size(); ++i) { positionPool.push_back(model->positions[i]); + texCoordsPool.push_back(model->texCoords[i]); } for (uint32_t i = 0; i < model->indices.size(); ++i) { @@ -120,7 +121,7 @@ std::vector BVH::generateIntersections(const PNode& currentNod return leftResults; } -std::optional BVH::intersectModel(ModelReference reference, const Ray ray) const +std::optional BVH::intersectModel(const ModelReference& reference, const Ray ray) const { std::optional intersection = {}; float distance = 0; diff --git a/src/scene/BVH.h b/src/scene/BVH.h index c90908b..20e94a7 100644 --- a/src/scene/BVH.h +++ b/src/scene/BVH.h @@ -8,9 +8,9 @@ struct ModelReference { - uint32_t positionOffset; - uint32_t indicesOffset; - uint32_t numIndices; + uint32_t positionOffset = 0; + uint32_t indicesOffset = 0; + uint32_t numIndices = 0; }; class BVH @@ -24,6 +24,7 @@ public: private: std::vector positionPool; + std::vector texCoordsPool; std::vector indicesPool; std::vector edgesPool; std::vector faceNormalsPool; @@ -42,5 +43,5 @@ private: std::vector models; std::vector generateIntersections(const PNode& currentNode, Ray ray) const; - std::optional intersectModel(ModelReference reference, Ray ray) const; + std::optional intersectModel(const ModelReference& reference, Ray ray) const; }; \ No newline at end of file diff --git a/src/util/Model.h b/src/util/Model.h index 02bf4e5..d41c7b4 100644 --- a/src/util/Model.h +++ b/src/util/Model.h @@ -21,6 +21,7 @@ class Model public: AABB boundingBox; std::vector positions; + std::vector texCoords; std::vector indices; std::vector edges; std::vector faceNormals; diff --git a/src/util/ModelLoader.cpp b/src/util/ModelLoader.cpp index 2a1e67e..9e04c8d 100644 --- a/src/util/ModelLoader.cpp +++ b/src/util/ModelLoader.cpp @@ -19,6 +19,7 @@ std::vector ModelLoader::loadModel(std::string_view filename) { auto aiVert = mesh->mVertices[v]; model->positions.push_back(glm::vec3(aiVert.x, aiVert.y, aiVert.z)); + model->texCoords.push_back(glm::vec2(mesh->mTextureCoords[0][v].x, mesh->mTextureCoords[0][v].y)); aabb.adjust(model->positions.back()); } for (int i = 0; i < mesh->mNumFaces; ++i)