diff --git a/AssetLoader/interface/GLTFLoader.hpp b/AssetLoader/interface/GLTFLoader.hpp index a9858e8..e86dec7 100644 --- a/AssetLoader/interface/GLTFLoader.hpp +++ b/AssetLoader/interface/GLTFLoader.hpp @@ -145,32 +145,32 @@ struct Primitive { - Uint32 FirstIndex = 0; - Uint32 IndexCount = 0; - Uint32 VertexCount = 0; - Material& material; - bool hasIndices; - - BoundBox BB; - bool IsValidBB = false; - - Primitive(Uint32 _FirstIndex, - Uint32 _IndexCount, - Uint32 _VertexCount, - Material& _material) : + const Uint32 FirstIndex; + const Uint32 IndexCount; + const Uint32 VertexCount; + const Uint32 MaterialId; + + const BoundBox BB; + + Primitive(Uint32 _FirstIndex, + Uint32 _IndexCount, + Uint32 _VertexCount, + Uint32 _MaterialId, + const float3& BBMin, + const float3& BBMax) : FirstIndex{_FirstIndex}, IndexCount{_IndexCount}, VertexCount{_VertexCount}, - material{_material}, - hasIndices{_IndexCount > 0} - { - } - - void SetBoundingBox(const float3& min, const float3& max) - { - BB.Min = min; - BB.Max = max; - IsValidBB = true; + MaterialId{_MaterialId}, + BB{BBMin, BBMax} + { + } + + Primitive(Primitive&&) = default; + + bool HasIndices() const + { + return IndexCount > 0; } }; @@ -178,7 +178,7 @@ struct Mesh { - std::vector> Primitives; + std::vector Primitives; BoundBox BB; @@ -220,7 +220,7 @@ Skin* _Skin = nullptr; Int32 SkinIndex = -1; float3 Translation; - float3 Scale = float3(1.0f, 1.0f, 1.0f); + float3 Scale = float3{1, 1, 1}; Quaternion Rotation; BoundBox BVH; BoundBox AABB; diff --git a/AssetLoader/src/GLTFLoader.cpp b/AssetLoader/src/GLTFLoader.cpp index 6665b89..f54a330 100644 --- a/AssetLoader/src/GLTFLoader.cpp +++ b/AssetLoader/src/GLTFLoader.cpp @@ -531,30 +531,27 @@ return; } } - std::unique_ptr newPrimitive( - new Primitive // - { - indexStart, - indexCount, - vertexCount, - primitive.material > -1 ? Materials[primitive.material] : Materials.back() // - } // + NewMesh->Primitives.emplace_back( // + indexStart, + indexCount, + vertexCount, + primitive.material >= 0 ? static_cast(primitive.material) : static_cast(Materials.size() - 1), + PosMin, + PosMax + // ); - - newPrimitive->SetBoundingBox(PosMin, PosMax); - NewMesh->Primitives.push_back(std::move(newPrimitive)); } // Mesh BB from BBs of primitives for (const auto& prim : NewMesh->Primitives) { - if (prim->IsValidBB && !NewMesh->IsValidBB) - { - NewMesh->BB = prim->BB; + if (!NewMesh->IsValidBB) + { + NewMesh->BB = prim.BB; NewMesh->IsValidBB = true; } - float3 bb_min = std::min(NewMesh->BB.Min, prim->BB.Min); - float3 bb_max = std::max(NewMesh->BB.Max, prim->BB.Max); + float3 bb_min = std::min(NewMesh->BB.Min, prim.BB.Min); + float3 bb_max = std::max(NewMesh->BB.Max, prim.BB.Max); NewMesh->SetBoundingBox(bb_min, bb_max); } NewNode->_Mesh = std::move(NewMesh);