From c4be9b1cba4f04d4831a31d3a9f9061ee36c3c00 Mon Sep 17 00:00:00 2001 From: Xiao Qi Date: Sat, 19 Nov 2022 21:16:24 +0800 Subject: [PATCH] Initial commit, change of data structs containing data for model and animation assets. Changed all other references to previous mode and mesh asset names --- .../Asset Types/Models/SHAnimationAsset.h | 88 +++++++++++++++++++ .../Assets/Asset Types/Models/SHMeshAsset.h | 60 +++++++++++++ .../Asset Types/{ => Models}/SHModelAsset.h | 30 +++---- .../Assets/Asset Types/Models/SHRigAsset.h | 48 ++++++++++ .../src/Assets/Asset Types/SHAnimationAsset.h | 30 ------- .../src/Assets/Asset Types/SHAssetIncludes.h | 2 +- .../Libraries/Loaders/SHModelLoader.cpp | 8 +- .../Assets/Libraries/Loaders/SHModelLoader.h | 4 +- SHADE_Engine/src/Assets/SHAssetManager.cpp | 4 +- .../MiddleEnd/Interface/SHDebugDrawSystem.cpp | 4 +- .../MiddleEnd/Meshes/SHPrimitiveGenerator.cpp | 16 ++-- .../MiddleEnd/Meshes/SHPrimitiveGenerator.h | 22 ++--- SHADE_Engine/src/Resource/SHResourceManager.h | 4 +- 13 files changed, 238 insertions(+), 82 deletions(-) create mode 100644 SHADE_Engine/src/Assets/Asset Types/Models/SHAnimationAsset.h create mode 100644 SHADE_Engine/src/Assets/Asset Types/Models/SHMeshAsset.h rename SHADE_Engine/src/Assets/Asset Types/{ => Models}/SHModelAsset.h (61%) create mode 100644 SHADE_Engine/src/Assets/Asset Types/Models/SHRigAsset.h delete mode 100644 SHADE_Engine/src/Assets/Asset Types/SHAnimationAsset.h diff --git a/SHADE_Engine/src/Assets/Asset Types/Models/SHAnimationAsset.h b/SHADE_Engine/src/Assets/Asset Types/Models/SHAnimationAsset.h new file mode 100644 index 00000000..d7128977 --- /dev/null +++ b/SHADE_Engine/src/Assets/Asset Types/Models/SHAnimationAsset.h @@ -0,0 +1,88 @@ +/*************************************************************************//** + * \file SHAnimationAsset.h + * \author Loh Xiao Qi + * \date October 2022 + * \brief + * + * 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 + +#include "Math/SHMath.h" +#include "Assets/Asset Types/SHAssetData.h" + +#include + + +namespace SHADE +{ + enum class SHAnimationBehaviour : uint8_t + { + DEFAULT = 0x0, + CONSTANT = 0x1, + LINEAR = 0x2, + REPEAT = 0x3 + }; + + // Smallest data containers + struct PositionKey + { + float time; + SHVec3 value; + }; + + struct RotationKey + { + float time; + SHVec4 value; + }; + + struct ScaleKey + { + float time; + SHVec3 value; + }; + + // Headers for read/write + struct SHAnimNodeInfo + { + uint32_t charCount; + uint32_t posKeyCount; + uint32_t rotKeyCount; + uint32_t scaKeyCount; + }; + + struct SHAnimDataHeader + { + uint32_t charCount; + uint32_t animNodeCount; + std::vector nodeHeaders; + }; + + // Main data containers + struct SHAnimData + { + std::string name; + SHAnimationBehaviour pre; + SHAnimationBehaviour post; + + std::vector positionKeys; + std::vector rotationKeys; + std::vector scaleKeys; + + }; + + struct SH_API SHAnimAsset : SHAssetData + { + std::string name; + + double duration; + double ticksPerSecond; + + std::vector nodeChannels; + //std::vector meshChannels; + //std::vector morphMeshChannels; + }; +} \ No newline at end of file diff --git a/SHADE_Engine/src/Assets/Asset Types/Models/SHMeshAsset.h b/SHADE_Engine/src/Assets/Asset Types/Models/SHMeshAsset.h new file mode 100644 index 00000000..c10e0cc3 --- /dev/null +++ b/SHADE_Engine/src/Assets/Asset Types/Models/SHMeshAsset.h @@ -0,0 +1,60 @@ +/****************************************************************************** + * \file SHMeshAsset.h + * \author Loh Xiao Qi + * \date 19 November 2022 + * \brief + * + * \copyright Copyright (c) 2021 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 + +#include "Math/SHMath.h" +#include "Assets/Asset Types/SHAssetData.h" + +#include +#include + +namespace SHADE +{ + struct SHMeshDataHeader + { + uint32_t vertexCount; + uint32_t indexCount; + uint32_t charCount; + uint32_t boneCount; + std::string name; + }; + + struct MeshBoneInfo + { + uint32_t charCount; + uint32_t weightCount; // Size should be same as boneCount + }; + + struct BoneWeight + { + uint32_t index; + float weight; + }; + + struct MeshBone + { + std::string name; + SHMatrix offset; + std::vector weights; + }; + + struct SH_API SHMeshAsset : SHAssetData + { + SHMeshDataHeader header; + std::vector VertexPositions; + std::vector VertexTangents; + std::vector VertexNormals; + std::vector VertexTexCoords; + std::vector Indices; + std::vector BonesInfo; + std::vector Bones; + }; +} diff --git a/SHADE_Engine/src/Assets/Asset Types/SHModelAsset.h b/SHADE_Engine/src/Assets/Asset Types/Models/SHModelAsset.h similarity index 61% rename from SHADE_Engine/src/Assets/Asset Types/SHModelAsset.h rename to SHADE_Engine/src/Assets/Asset Types/Models/SHModelAsset.h index c057678b..4425f555 100644 --- a/SHADE_Engine/src/Assets/Asset Types/SHModelAsset.h +++ b/SHADE_Engine/src/Assets/Asset Types/Models/SHModelAsset.h @@ -13,36 +13,26 @@ #pragma once #include -#include "Math/SHMath.h" -#include "SHAssetData.h" + +#include "Assets/Asset Types/Models/SHAnimationAsset.h" +#include "Assets/Asset Types/Models/SHMeshAsset.h" +#include "Assets/Asset Types/Models/SHRigAsset.h" namespace SHADE { - struct SHMeshAssetHeader - { - uint32_t vertexCount; - uint32_t indexCount; - std::string name; - }; - struct SHModelAssetHeader { size_t meshCount; - }; - - struct SH_API SHMeshData : SHAssetData - { - SHMeshAssetHeader header; - std::vector VertexPositions; - std::vector VertexTangents; - std::vector VertexNormals; - std::vector VertexTexCoords; - std::vector Indices; + size_t animCount; }; struct SH_API SHModelAsset : SHAssetData { SHModelAssetHeader header; - std::vector subMeshes; + + SHRigAsset rig; + + std::vector meshes; + std::vector anims; }; } \ No newline at end of file diff --git a/SHADE_Engine/src/Assets/Asset Types/Models/SHRigAsset.h b/SHADE_Engine/src/Assets/Asset Types/Models/SHRigAsset.h new file mode 100644 index 00000000..09ce5658 --- /dev/null +++ b/SHADE_Engine/src/Assets/Asset Types/Models/SHRigAsset.h @@ -0,0 +1,48 @@ +/****************************************************************************** + * \file SHRigAsset.h + * \author Loh Xiao Qi + * \date 19 November 2022 + * \brief + * + * \copyright Copyright (c) 2021 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 + +#include "Math/SHMath.h" +#include "Assets/Asset Types/SHAssetData.h" + +#include + +namespace SHADE +{ + struct RigDataHeader + { + uint32_t nodeCount; + std::vector charCounts; + }; + + struct RigNodeData + { + std::string name; + SHMatrix transform; + }; + + struct RigNode + { + uint32_t idRef; + std::vector children; + }; + + struct SH_API SHRigAsset : SHAssetData + { + ~SHRigAsset() + { + delete root; + } + + std::map nodeDataCollection; + RigNode* root; + }; +} diff --git a/SHADE_Engine/src/Assets/Asset Types/SHAnimationAsset.h b/SHADE_Engine/src/Assets/Asset Types/SHAnimationAsset.h deleted file mode 100644 index b411a11e..00000000 --- a/SHADE_Engine/src/Assets/Asset Types/SHAnimationAsset.h +++ /dev/null @@ -1,30 +0,0 @@ -/*************************************************************************//** - * \file SHAnimationAsset.h - * \author Loh Xiao Qi - * \date October 2022 - * \brief - * - * 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 - -#include -#include -#include "SHAssetData.h" - -namespace SHADE -{ - struct SH_API SHAnimationAsset : SHAssetData - { - std::string name; - - std::vector nodeChannels; - std::vector meshChannels; - std::vector morphMeshChannels; - - double duration; - double ticksPerSecond; - }; -} \ No newline at end of file diff --git a/SHADE_Engine/src/Assets/Asset Types/SHAssetIncludes.h b/SHADE_Engine/src/Assets/Asset Types/SHAssetIncludes.h index f4fb49f0..eb656516 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 "SHModelAsset.h" +#include "Models/SHModelAsset.h" #include "SHTextureAsset.h" \ No newline at end of file diff --git a/SHADE_Engine/src/Assets/Libraries/Loaders/SHModelLoader.cpp b/SHADE_Engine/src/Assets/Libraries/Loaders/SHModelLoader.cpp index 74aa5350..1f825a97 100644 --- a/SHADE_Engine/src/Assets/Libraries/Loaders/SHModelLoader.cpp +++ b/SHADE_Engine/src/Assets/Libraries/Loaders/SHModelLoader.cpp @@ -24,7 +24,7 @@ namespace SHADE ); } - void SHModelLoader::ReadData(std::ifstream& file, SHMeshLoaderHeader const& header, SHMeshData& data) noexcept + void SHModelLoader::ReadData(std::ifstream& file, SHMeshLoaderHeader const& header, SHMeshAsset& data) noexcept { auto const vertexVec3Byte{ sizeof(SHVec3) * header.vertexCount }; auto const vertexVec2Byte{ sizeof(SHVec2) * header.vertexCount }; @@ -64,13 +64,13 @@ namespace SHADE ); std::vector headers(model.header.meshCount); - model.subMeshes.resize(model.header.meshCount); + model.meshes.resize(model.header.meshCount); for (auto i{ 0 }; i < model.header.meshCount; ++i) { - model.subMeshes[i] = new SHMeshData(); + model.meshes[i] = new SHMeshAsset(); ReadHeader(file, headers[i]); - ReadData(file, headers[i], *model.subMeshes[i]); + ReadData(file, headers[i], *model.meshes[i]); } file.close(); } diff --git a/SHADE_Engine/src/Assets/Libraries/Loaders/SHModelLoader.h b/SHADE_Engine/src/Assets/Libraries/Loaders/SHModelLoader.h index 35dc4514..2074169c 100644 --- a/SHADE_Engine/src/Assets/Libraries/Loaders/SHModelLoader.h +++ b/SHADE_Engine/src/Assets/Libraries/Loaders/SHModelLoader.h @@ -10,7 +10,7 @@ * of DigiPen Institute of Technology is prohibited. *****************************************************************************/ #pragma once -#include "Assets/Asset Types/SHModelAsset.h" +#include "Assets/Asset Types/Models/SHModelAsset.h" #include "SHAssetLoader.h" #include @@ -27,7 +27,7 @@ namespace SHADE void ReadHeader(std::ifstream& file, SHMeshLoaderHeader& header) noexcept; - void ReadData(std::ifstream& file, SHMeshLoaderHeader const& header, SHMeshData& data) noexcept; + void ReadData(std::ifstream& file, SHMeshLoaderHeader const& header, SHMeshAsset& data) noexcept; public: void LoadSHMesh(AssetPath path, SHModelAsset& model) noexcept; diff --git a/SHADE_Engine/src/Assets/SHAssetManager.cpp b/SHADE_Engine/src/Assets/SHAssetManager.cpp index 1569a13c..2695b2fa 100644 --- a/SHADE_Engine/src/Assets/SHAssetManager.cpp +++ b/SHADE_Engine/src/Assets/SHAssetManager.cpp @@ -530,7 +530,7 @@ namespace SHADE { assetData.emplace( parent.subAssets[i]->id, - parentModel->subMeshes[i] + parentModel->meshes[i] ); } } @@ -588,7 +588,7 @@ namespace SHADE SHModelAsset* const data = reinterpret_cast(LoadData(newAsset)); assetData.emplace(newAsset.id, data); - for(auto const& subMesh : data->subMeshes) + for(auto const& subMesh : data->meshes) { SHAsset subAsset{ .name = subMesh->header.name, diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHDebugDrawSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHDebugDrawSystem.cpp index 60262607..392590ed 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHDebugDrawSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHDebugDrawSystem.cpp @@ -14,7 +14,7 @@ of DigiPen Institute of Technology is prohibited. // STL Includes #include // Project Includes -#include "Assets/Asset Types/SHModelAsset.h" +#include "Assets/Asset Types/Models/SHModelAsset.h" #include "../Meshes/SHPrimitiveGenerator.h" #include "ECS_Base/Managers/SHSystemManager.h" #include "SHGraphicsSystem.h" @@ -321,7 +321,7 @@ namespace SHADE { spherePoints.clear(); // Generate - static const SHMeshData SPHERE = SHPrimitiveGenerator::Sphere(); + static const SHMeshAsset SPHERE = SHPrimitiveGenerator::Sphere(); for (const auto& idx : SPHERE.Indices) { spherePoints.emplace_back(SPHERE.VertexPositions[idx] * radius + pos); diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Meshes/SHPrimitiveGenerator.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Meshes/SHPrimitiveGenerator.cpp index 60decded..bf60c7df 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Meshes/SHPrimitiveGenerator.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Meshes/SHPrimitiveGenerator.cpp @@ -21,15 +21,15 @@ namespace SHADE /*-----------------------------------------------------------------------------------*/ /* Static Member Definitions */ /*-----------------------------------------------------------------------------------*/ - SHMeshData SHPrimitiveGenerator::cubeMesh; - SHMeshData SHPrimitiveGenerator::sphereMesh; + SHMeshAsset SHPrimitiveGenerator::cubeMesh; + SHMeshAsset SHPrimitiveGenerator::sphereMesh; /*-----------------------------------------------------------------------------------*/ /* Primitive Generation Functions */ /*-----------------------------------------------------------------------------------*/ - SHMeshData SHPrimitiveGenerator::Cube() noexcept + SHMeshAsset SHPrimitiveGenerator::Cube() noexcept { - SHMeshData mesh; + SHMeshAsset mesh; mesh.VertexPositions = { @@ -214,9 +214,9 @@ namespace SHADE return addMeshDataTo(cubeMesh, gfxSystem); } - SHADE::SHMeshData SHPrimitiveGenerator::Sphere() noexcept + SHADE::SHMeshAsset SHPrimitiveGenerator::Sphere() noexcept { - SHMeshData meshData; + SHMeshAsset meshData; const int LAT_SLICES = 12; const int LONG_SLICES = 12; @@ -284,7 +284,7 @@ namespace SHADE /*-----------------------------------------------------------------------------------*/ /* Helper Functions */ /*-----------------------------------------------------------------------------------*/ - SHADE::Handle SHPrimitiveGenerator::addMeshDataTo(const SHMeshData& meshData, SHMeshLibrary& meshLibrary) noexcept + SHADE::Handle SHPrimitiveGenerator::addMeshDataTo(const SHMeshAsset& meshData, SHMeshLibrary& meshLibrary) noexcept { return meshLibrary.AddMesh ( @@ -298,7 +298,7 @@ namespace SHADE ); } - SHADE::Handle SHPrimitiveGenerator::addMeshDataTo(const SHMeshData& meshData, SHGraphicsSystem& gfxSystem) noexcept + SHADE::Handle SHPrimitiveGenerator::addMeshDataTo(const SHMeshAsset& meshData, SHGraphicsSystem& gfxSystem) noexcept { return gfxSystem.AddMesh ( diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Meshes/SHPrimitiveGenerator.h b/SHADE_Engine/src/Graphics/MiddleEnd/Meshes/SHPrimitiveGenerator.h index 7719e4c3..7008ebb1 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Meshes/SHPrimitiveGenerator.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Meshes/SHPrimitiveGenerator.h @@ -13,7 +13,7 @@ of DigiPen Institute of Technology is prohibited. // Project Includes #include "Math/SHMath.h" -#include "Assets/Asset Types/SHModelAsset.h" +#include "Assets/Asset Types/Models/SHModelAsset.h" #include "Graphics/MiddleEnd/Interface/SHMeshLibrary.h" #include "SH_API.h" @@ -47,13 +47,13 @@ namespace SHADE /***********************************************************************************/ /*! \brief - Produces a cube and stores the data in a SHMeshData object. + Produces a cube and stores the data in a SHMeshAsset object. \return - SHMeshData object containing vertex data for the cube. + SHMeshAsset object containing vertex data for the cube. */ /***********************************************************************************/ - [[nodiscard]] static SHMeshData Cube() noexcept; + [[nodiscard]] static SHMeshAsset Cube() noexcept; /***********************************************************************************/ /*! \brief @@ -83,13 +83,13 @@ namespace SHADE /***********************************************************************************/ /*! \brief - Produces a sphere and stores the data in a SHMeshData object. + Produces a sphere and stores the data in a SHMeshAsset object. \return - SHMeshData object containing vertex data for the sphere. + SHMeshAsset object containing vertex data for the sphere. */ /***********************************************************************************/ - [[nodiscard]] static SHMeshData Sphere() noexcept; + [[nodiscard]] static SHMeshAsset Sphere() noexcept; /***********************************************************************************/ /*! \brief @@ -121,13 +121,13 @@ namespace SHADE /*---------------------------------------------------------------------------------*/ /* Helper Functions */ /*---------------------------------------------------------------------------------*/ - static Handle addMeshDataTo(const SHMeshData& meshData, SHMeshLibrary& meshLibrary) noexcept; - static Handle addMeshDataTo(const SHMeshData& meshData, SHGraphicsSystem& gfxSystem) noexcept; + static Handle addMeshDataTo(const SHMeshAsset& meshData, SHMeshLibrary& meshLibrary) noexcept; + static Handle addMeshDataTo(const SHMeshAsset& meshData, SHGraphicsSystem& gfxSystem) noexcept; /*---------------------------------------------------------------------------------*/ /* Data Members */ /*---------------------------------------------------------------------------------*/ - static SHMeshData cubeMesh; - static SHMeshData sphereMesh; + static SHMeshAsset cubeMesh; + static SHMeshAsset sphereMesh; }; } \ No newline at end of file diff --git a/SHADE_Engine/src/Resource/SHResourceManager.h b/SHADE_Engine/src/Resource/SHResourceManager.h index dae20f99..e008afad 100644 --- a/SHADE_Engine/src/Resource/SHResourceManager.h +++ b/SHADE_Engine/src/Resource/SHResourceManager.h @@ -17,7 +17,7 @@ of DigiPen Institute of Technology is prohibited. #include "SH_API.h" #include "SHResourceLibrary.h" #include "Assets/SHAssetMacros.h" -#include "Assets/Asset Types/SHModelAsset.h" +#include "Assets/Asset Types/Models/SHModelAsset.h" #include "Assets/Asset Types/SHTextureAsset.h" #include "Assets/Asset Types/SHShaderAsset.h" #include "Graphics/Shaders/SHVkShaderModule.h" @@ -42,7 +42,7 @@ namespace SHADE /// template struct SHResourceLoader { using AssetType = void; }; - template<> struct SHResourceLoader { using AssetType = SHMeshData; }; + template<> struct SHResourceLoader { using AssetType = SHMeshAsset; }; template<> struct SHResourceLoader { using AssetType = SHTextureAsset; }; template<> struct SHResourceLoader { using AssetType = SHShaderAsset; }; template<> struct SHResourceLoader { using AssetType = SHMaterialAsset; };