From d1f624b2eb843c0630c4544b3b6e3a011f3fffa3 Mon Sep 17 00:00:00 2001 From: Xiao Qi Date: Wed, 2 Nov 2022 21:09:53 +0800 Subject: [PATCH] Removed SHMeshData declaration/definition in graphics middle end Renamed some data members in SHMeshData Replaced calls and references to mesh data in Primitive Generator --- .../src/Assets/Asset Types/SHAssetIncludes.h | 2 +- .../{SHMeshAsset.h => SHModelAsset.h} | 14 +++--- .../{SHMeshLoader.cpp => SHModelLoader.cpp} | 46 +++++++++---------- .../{SHMeshLoader.h => SHModelLoader.h} | 8 ++-- .../Graphics/MiddleEnd/Meshes/SHMeshData.h | 36 --------------- .../MiddleEnd/Meshes/SHPrimitiveGenerator.cpp | 38 +++++++-------- .../MiddleEnd/Meshes/SHPrimitiveGenerator.h | 3 +- .../src/Resource/SHResourceManager.hpp | 2 +- 8 files changed, 57 insertions(+), 92 deletions(-) rename SHADE_Engine/src/Assets/Asset Types/{SHMeshAsset.h => SHModelAsset.h} (78%) rename SHADE_Engine/src/Assets/Libraries/Loaders/{SHMeshLoader.cpp => SHModelLoader.cpp} (51%) rename SHADE_Engine/src/Assets/Libraries/Loaders/{SHMeshLoader.h => SHModelLoader.h} (82%) delete mode 100644 SHADE_Engine/src/Graphics/MiddleEnd/Meshes/SHMeshData.h diff --git a/SHADE_Engine/src/Assets/Asset Types/SHAssetIncludes.h b/SHADE_Engine/src/Assets/Asset Types/SHAssetIncludes.h index 1c1ed44a..f4fb49f0 100644 --- a/SHADE_Engine/src/Assets/Asset Types/SHAssetIncludes.h +++ b/SHADE_Engine/src/Assets/Asset Types/SHAssetIncludes.h @@ -1,4 +1,4 @@ #pragma once -#include "SHMeshAsset.h" +#include "SHModelAsset.h" #include "SHTextureAsset.h" \ No newline at end of file diff --git a/SHADE_Engine/src/Assets/Asset Types/SHMeshAsset.h b/SHADE_Engine/src/Assets/Asset Types/SHModelAsset.h similarity index 78% rename from SHADE_Engine/src/Assets/Asset Types/SHMeshAsset.h rename to SHADE_Engine/src/Assets/Asset Types/SHModelAsset.h index 0ef5267b..45b06198 100644 --- a/SHADE_Engine/src/Assets/Asset Types/SHMeshAsset.h +++ b/SHADE_Engine/src/Assets/Asset Types/SHModelAsset.h @@ -28,21 +28,21 @@ namespace SHADE struct SHMeshData { std::string name; - std::vector vertexPosition; - std::vector vertexTangent; - std::vector vertexNormal; - std::vector texCoords; + std::vector vertexPositions; + std::vector vertexTangents; + std::vector vertexNormals; + std::vector vertexTexCoords; std::vector indices; }; - struct SHMeshAssetHeader + struct SHModelAssetHeader { size_t meshCount; }; - struct SH_API SHMeshAsset : SHAssetData + struct SH_API SHModelAsset : SHAssetData { - SHMeshAssetHeader header; + SHModelAssetHeader header; std::vector headers; std::vector meshes; }; diff --git a/SHADE_Engine/src/Assets/Libraries/Loaders/SHMeshLoader.cpp b/SHADE_Engine/src/Assets/Libraries/Loaders/SHModelLoader.cpp similarity index 51% rename from SHADE_Engine/src/Assets/Libraries/Loaders/SHMeshLoader.cpp rename to SHADE_Engine/src/Assets/Libraries/Loaders/SHModelLoader.cpp index 7520bb84..57d92b57 100644 --- a/SHADE_Engine/src/Assets/Libraries/Loaders/SHMeshLoader.cpp +++ b/SHADE_Engine/src/Assets/Libraries/Loaders/SHModelLoader.cpp @@ -1,5 +1,5 @@ /*************************************************************************//** - * \file SHMeshLoader.cpp + * \file SHModelLoader.cpp * \author Loh Xiao Qi * \date 30 September 2022 * \brief Implementation for Mesh loader. Accounts for custom binary format @@ -11,12 +11,12 @@ * of DigiPen Institute of Technology is prohibited. *****************************************************************************/ #include "SHpch.h" -#include "SHMeshLoader.h" +#include "SHModelLoader.h" #include namespace SHADE { - void SHMeshLoader::ReadHeader(std::ifstream& file, SHMeshDataHeader& header) noexcept + void SHModelLoader::ReadHeader(std::ifstream& file, SHMeshDataHeader& header) noexcept { file.read( reinterpret_cast(&header), @@ -24,29 +24,29 @@ namespace SHADE ); } - void SHMeshLoader::ReadData(std::ifstream& file, SHMeshDataHeader const& header, SHMeshData& data) noexcept + void SHModelLoader::ReadData(std::ifstream& file, SHMeshDataHeader const& header, SHMeshData& data) noexcept { auto const vertexVec3Byte{ sizeof(SHVec3) * header.vertexCount }; auto const vertexVec2Byte{ sizeof(SHVec2) * header.indexCount }; - data.vertexPosition.resize(header.vertexCount); - data.vertexTangent.resize(header.vertexCount); - data.vertexNormal.resize(header.vertexCount); - data.texCoords.resize(header.vertexCount); + data.vertexPositions.resize(header.vertexCount); + data.vertexTangents.resize(header.vertexCount); + data.vertexNormals.resize(header.vertexCount); + data.vertexTexCoords.resize(header.vertexCount); data.indices.resize(header.indexCount); file.read(data.name.data(), header.charCount); - file.read(reinterpret_cast(data.vertexPosition.data()), vertexVec3Byte); - file.read(reinterpret_cast(data.vertexTangent.data()), vertexVec3Byte); - file.read(reinterpret_cast(data.vertexNormal.data()), vertexVec3Byte); - file.read(reinterpret_cast(data.texCoords.data()), vertexVec2Byte); + file.read(reinterpret_cast(data.vertexPositions.data()), vertexVec3Byte); + file.read(reinterpret_cast(data.vertexTangents.data()), vertexVec3Byte); + file.read(reinterpret_cast(data.vertexNormals.data()), vertexVec3Byte); + file.read(reinterpret_cast(data.vertexTexCoords.data()), vertexVec2Byte); file.read(reinterpret_cast(data.indices.data()), sizeof(uint32_t) * header.indexCount); } - void SHMeshLoader::LoadSHMesh(AssetPath path, SHMeshAsset& mesh) noexcept + void SHModelLoader::LoadSHMesh(AssetPath path, SHModelAsset& model) noexcept { std::ifstream file{ path.string(), std::ios::in | std::ios::binary }; if (!file.is_open()) @@ -58,31 +58,31 @@ namespace SHADE file.seekg(0); file.read( - reinterpret_cast(&mesh.header), - sizeof(SHMeshAssetHeader) + reinterpret_cast(&model.header), + sizeof(SHModelAssetHeader) ); - mesh.headers.resize(mesh.header.meshCount); - mesh.meshes.resize(mesh.header.meshCount); + model.headers.resize(model.header.meshCount); + model.meshes.resize(model.header.meshCount); - for (auto i{ 0 }; i < mesh.header.meshCount; ++i) + for (auto i{ 0 }; i < model.header.meshCount; ++i) { - ReadHeader(file, mesh.headers[i]); - ReadData(file, mesh.headers[i], mesh.meshes[i]); + ReadHeader(file, model.headers[i]); + ReadData(file, model.headers[i], model.meshes[i]); } file.close(); } - SHAssetData* SHMeshLoader::Load(AssetPath path) + SHAssetData* SHModelLoader::Load(AssetPath path) { - auto result = new SHMeshAsset(); + auto result = new SHModelAsset(); LoadSHMesh(path, *result); return result; } - void SHMeshLoader::Write(SHAssetData const* data, AssetPath path) + void SHModelLoader::Write(SHAssetData const* data, AssetPath path) { } diff --git a/SHADE_Engine/src/Assets/Libraries/Loaders/SHMeshLoader.h b/SHADE_Engine/src/Assets/Libraries/Loaders/SHModelLoader.h similarity index 82% rename from SHADE_Engine/src/Assets/Libraries/Loaders/SHMeshLoader.h rename to SHADE_Engine/src/Assets/Libraries/Loaders/SHModelLoader.h index e45ada90..688e628e 100644 --- a/SHADE_Engine/src/Assets/Libraries/Loaders/SHMeshLoader.h +++ b/SHADE_Engine/src/Assets/Libraries/Loaders/SHModelLoader.h @@ -1,5 +1,5 @@ /*************************************************************************//** - * \file SHMeshLoader.h + * \file SHModelLoader.h * \author Loh Xiao Qi * \date 30 September 2022 * \brief Library to load gltf mesh files and custom binary format @@ -10,19 +10,19 @@ * of DigiPen Institute of Technology is prohibited. *****************************************************************************/ #pragma once -#include "Assets/Asset Types/SHMeshAsset.h" +#include "Assets/Asset Types/SHModelAsset.h" #include "SHAssetLoader.h" #include namespace SHADE { - class SHMeshLoader : public SHAssetLoader + class SHModelLoader : public SHAssetLoader { void ReadHeader(std::ifstream& file, SHMeshDataHeader& header) noexcept; void ReadData(std::ifstream& file, SHMeshDataHeader const& header, SHMeshData& data) noexcept; public: - void LoadSHMesh(AssetPath path, SHMeshAsset& meshes) noexcept; + void LoadSHMesh(AssetPath path, SHModelAsset& model) noexcept; SHAssetData* Load(AssetPath path) override; void Write(SHAssetData const* data, AssetPath path) override; }; diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Meshes/SHMeshData.h b/SHADE_Engine/src/Graphics/MiddleEnd/Meshes/SHMeshData.h deleted file mode 100644 index 2f7d320b..00000000 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Meshes/SHMeshData.h +++ /dev/null @@ -1,36 +0,0 @@ -/************************************************************************************//*! -\file SHPrimitiveGenerator.h -\author Tng Kah Wei, kahwei.tng, 390009620 -\par email: kahwei.tng\@digipen.edu -\date Sep 18, 2022 -\brief Contains the static class definition of SHPrimitiveGenerator. - -Copyright (C) 2022 DigiPen Institute of Technology. -Reproduction or disclosure of this file or its contents without the prior written consent -of DigiPen Institute of Technology is prohibited. -*//*************************************************************************************/ -#pragma once - -// STL Includes -#include -// Project Includes -#include "Math/SHMath.h" -#include "Graphics/MiddleEnd/Interface/SHMeshLibrary.h" - -namespace SHADE -{ - /*************************************************************************************/ - /*! - \brief - Static class that contains functions for generating 3D primitives. - */ - /*************************************************************************************/ - struct SHMeshData - { - std::vector VertexPositions; - std::vector VertexTexCoords; - std::vector VertexTangents; - std::vector VertexNormals; - std::vector Indices; - }; -} \ No newline at end of file diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Meshes/SHPrimitiveGenerator.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Meshes/SHPrimitiveGenerator.cpp index be181beb..e76d940f 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Meshes/SHPrimitiveGenerator.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Meshes/SHPrimitiveGenerator.cpp @@ -22,7 +22,7 @@ namespace SHADE { SHMeshData mesh; - mesh.VertexPositions = + mesh.vertexPositions = { // front SHVec3(-0.5f, -0.5f, 0.5f), @@ -61,7 +61,7 @@ namespace SHADE SHVec3(-0.5f, 0.5f, -0.5f) }; - mesh.VertexTexCoords = + mesh.vertexTexCoords = { SHVec2(0.0f, 1.0f), SHVec2(1.0f, 1.0f), @@ -99,7 +99,7 @@ namespace SHADE SHVec2(0.0f, 0.0f) }; - mesh.VertexTangents = + mesh.vertexTangents = { // front SHVec3(1.0f, 0.0f, 0.0f), @@ -139,7 +139,7 @@ namespace SHADE }; - mesh.VertexNormals = + mesh.vertexNormals = { // front SHVec3(0.0f, 0.0f, 1.0f), @@ -178,7 +178,7 @@ namespace SHADE SHVec3(-1.0f, 0.0f, 0.0f) }; - mesh.Indices = + mesh.indices = { 0, 1, 2, 0, 2, 3, 4, 5, 6, 4, 6, 7, @@ -196,13 +196,13 @@ namespace SHADE static SHMeshData meshData = Cube(); return meshLibrary.AddMesh ( - static_cast(meshData.VertexPositions.size()), - meshData.VertexPositions.data(), - meshData.VertexTexCoords.data(), - meshData.VertexTangents.data(), - meshData.VertexNormals.data(), - static_cast(meshData.Indices.size()), - meshData.Indices.data() + static_cast(meshData.vertexPositions.size()), + meshData.vertexPositions.data(), + meshData.vertexTexCoords.data(), + meshData.vertexTangents.data(), + meshData.vertexNormals.data(), + static_cast(meshData.indices.size()), + meshData.indices.data() ); } @@ -211,13 +211,13 @@ namespace SHADE static SHMeshData meshData = Cube(); return gfxSystem.AddMesh ( - static_cast(meshData.VertexPositions.size()), - meshData.VertexPositions.data(), - meshData.VertexTexCoords.data(), - meshData.VertexTangents.data(), - meshData.VertexNormals.data(), - static_cast(meshData.Indices.size()), - meshData.Indices.data() + static_cast(meshData.vertexPositions.size()), + meshData.vertexPositions.data(), + meshData.vertexTexCoords.data(), + meshData.vertexTangents.data(), + meshData.vertexNormals.data(), + static_cast(meshData.indices.size()), + meshData.indices.data() ); } } \ No newline at end of file diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Meshes/SHPrimitiveGenerator.h b/SHADE_Engine/src/Graphics/MiddleEnd/Meshes/SHPrimitiveGenerator.h index dd059a29..852374fa 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Meshes/SHPrimitiveGenerator.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Meshes/SHPrimitiveGenerator.h @@ -13,7 +13,8 @@ of DigiPen Institute of Technology is prohibited. // Project Includes #include "Math/SHMath.h" -#include "SHMeshData.h" +#include "Assets/Asset Types/SHModelAsset.h" +#include "Graphics/MiddleEnd/Interface/SHMeshLibrary.h" #include "SH_API.h" namespace SHADE diff --git a/SHADE_Engine/src/Resource/SHResourceManager.hpp b/SHADE_Engine/src/Resource/SHResourceManager.hpp index 072adaa2..d078ce48 100644 --- a/SHADE_Engine/src/Resource/SHResourceManager.hpp +++ b/SHADE_Engine/src/Resource/SHResourceManager.hpp @@ -49,7 +49,7 @@ namespace SHADE throw std::runtime_error("[SHResourceManager] Attempted to load graphics resource without a SHGraphicsSystem installed."); // Load - const SHMeshAsset* assetData = SHAssetManager::GetData(assetId); + const SHModelAsset* assetData = SHAssetManager::GetData(assetId); if (assetData == nullptr) { SHLog::Warning("[SHResourceManager] Attempted to load an asset with an invalid Asset ID.");