Initial commit, change of data structs containing data for model and animation assets.

Changed all other references to previous mode and mesh asset names
This commit is contained in:
Xiao Qi 2022-11-19 21:16:24 +08:00
parent 61acbdc34e
commit c4be9b1cba
13 changed files with 238 additions and 82 deletions

View File

@ -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 <vector>
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<SHAnimNodeInfo> nodeHeaders;
};
// Main data containers
struct SHAnimData
{
std::string name;
SHAnimationBehaviour pre;
SHAnimationBehaviour post;
std::vector<PositionKey> positionKeys;
std::vector<RotationKey> rotationKeys;
std::vector<ScaleKey> scaleKeys;
};
struct SH_API SHAnimAsset : SHAssetData
{
std::string name;
double duration;
double ticksPerSecond;
std::vector<SHAnimData> nodeChannels;
//std::vector<aiMeshAnim*> meshChannels;
//std::vector<aiMeshMorphAnim*> morphMeshChannels;
};
}

View File

@ -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 <vector>
#include <string>
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<BoneWeight> weights;
};
struct SH_API SHMeshAsset : SHAssetData
{
SHMeshDataHeader header;
std::vector<SHVec3> VertexPositions;
std::vector<SHVec3> VertexTangents;
std::vector<SHVec3> VertexNormals;
std::vector<SHVec2> VertexTexCoords;
std::vector<uint32_t> Indices;
std::vector<MeshBoneInfo> BonesInfo;
std::vector<MeshBone> Bones;
};
}

View File

@ -13,36 +13,26 @@
#pragma once #pragma once
#include <vector> #include <vector>
#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 namespace SHADE
{ {
struct SHMeshAssetHeader
{
uint32_t vertexCount;
uint32_t indexCount;
std::string name;
};
struct SHModelAssetHeader struct SHModelAssetHeader
{ {
size_t meshCount; size_t meshCount;
}; size_t animCount;
struct SH_API SHMeshData : SHAssetData
{
SHMeshAssetHeader header;
std::vector<SHVec3> VertexPositions;
std::vector<SHVec3> VertexTangents;
std::vector<SHVec3> VertexNormals;
std::vector<SHVec2> VertexTexCoords;
std::vector<uint32_t> Indices;
}; };
struct SH_API SHModelAsset : SHAssetData struct SH_API SHModelAsset : SHAssetData
{ {
SHModelAssetHeader header; SHModelAssetHeader header;
std::vector<SHMeshData*> subMeshes;
SHRigAsset rig;
std::vector<SHMeshAsset*> meshes;
std::vector<SHAnimAsset*> anims;
}; };
} }

View File

@ -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 <map>
namespace SHADE
{
struct RigDataHeader
{
uint32_t nodeCount;
std::vector<uint32_t> charCounts;
};
struct RigNodeData
{
std::string name;
SHMatrix transform;
};
struct RigNode
{
uint32_t idRef;
std::vector<RigNode*> children;
};
struct SH_API SHRigAsset : SHAssetData
{
~SHRigAsset()
{
delete root;
}
std::map<uint32_t, RigNodeData> nodeDataCollection;
RigNode* root;
};
}

View File

@ -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 <vector>
#include <assimp/anim.h>
#include "SHAssetData.h"
namespace SHADE
{
struct SH_API SHAnimationAsset : SHAssetData
{
std::string name;
std::vector<aiNodeAnim*> nodeChannels;
std::vector<aiMeshAnim*> meshChannels;
std::vector<aiMeshMorphAnim*> morphMeshChannels;
double duration;
double ticksPerSecond;
};
}

View File

@ -1,4 +1,4 @@
#pragma once #pragma once
#include "SHModelAsset.h" #include "Models/SHModelAsset.h"
#include "SHTextureAsset.h" #include "SHTextureAsset.h"

View File

@ -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 vertexVec3Byte{ sizeof(SHVec3) * header.vertexCount };
auto const vertexVec2Byte{ sizeof(SHVec2) * header.vertexCount }; auto const vertexVec2Byte{ sizeof(SHVec2) * header.vertexCount };
@ -64,13 +64,13 @@ namespace SHADE
); );
std::vector<SHMeshLoaderHeader> headers(model.header.meshCount); std::vector<SHMeshLoaderHeader> 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) for (auto i{ 0 }; i < model.header.meshCount; ++i)
{ {
model.subMeshes[i] = new SHMeshData(); model.meshes[i] = new SHMeshAsset();
ReadHeader(file, headers[i]); ReadHeader(file, headers[i]);
ReadData(file, headers[i], *model.subMeshes[i]); ReadData(file, headers[i], *model.meshes[i]);
} }
file.close(); file.close();
} }

View File

@ -10,7 +10,7 @@
* of DigiPen Institute of Technology is prohibited. * of DigiPen Institute of Technology is prohibited.
*****************************************************************************/ *****************************************************************************/
#pragma once #pragma once
#include "Assets/Asset Types/SHModelAsset.h" #include "Assets/Asset Types/Models/SHModelAsset.h"
#include "SHAssetLoader.h" #include "SHAssetLoader.h"
#include <fstream> #include <fstream>
@ -27,7 +27,7 @@ namespace SHADE
void ReadHeader(std::ifstream& file, SHMeshLoaderHeader& header) noexcept; 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: public:
void LoadSHMesh(AssetPath path, SHModelAsset& model) noexcept; void LoadSHMesh(AssetPath path, SHModelAsset& model) noexcept;

View File

@ -530,7 +530,7 @@ namespace SHADE
{ {
assetData.emplace( assetData.emplace(
parent.subAssets[i]->id, parent.subAssets[i]->id,
parentModel->subMeshes[i] parentModel->meshes[i]
); );
} }
} }
@ -588,7 +588,7 @@ namespace SHADE
SHModelAsset* const data = reinterpret_cast<SHModelAsset*>(LoadData(newAsset)); SHModelAsset* const data = reinterpret_cast<SHModelAsset*>(LoadData(newAsset));
assetData.emplace(newAsset.id, data); assetData.emplace(newAsset.id, data);
for(auto const& subMesh : data->subMeshes) for(auto const& subMesh : data->meshes)
{ {
SHAsset subAsset{ SHAsset subAsset{
.name = subMesh->header.name, .name = subMesh->header.name,

View File

@ -14,7 +14,7 @@ of DigiPen Institute of Technology is prohibited.
// STL Includes // STL Includes
#include <algorithm> #include <algorithm>
// Project Includes // Project Includes
#include "Assets/Asset Types/SHModelAsset.h" #include "Assets/Asset Types/Models/SHModelAsset.h"
#include "../Meshes/SHPrimitiveGenerator.h" #include "../Meshes/SHPrimitiveGenerator.h"
#include "ECS_Base/Managers/SHSystemManager.h" #include "ECS_Base/Managers/SHSystemManager.h"
#include "SHGraphicsSystem.h" #include "SHGraphicsSystem.h"
@ -321,7 +321,7 @@ namespace SHADE
{ {
spherePoints.clear(); spherePoints.clear();
// Generate // Generate
static const SHMeshData SPHERE = SHPrimitiveGenerator::Sphere(); static const SHMeshAsset SPHERE = SHPrimitiveGenerator::Sphere();
for (const auto& idx : SPHERE.Indices) for (const auto& idx : SPHERE.Indices)
{ {
spherePoints.emplace_back(SPHERE.VertexPositions[idx] * radius + pos); spherePoints.emplace_back(SPHERE.VertexPositions[idx] * radius + pos);

View File

@ -21,15 +21,15 @@ namespace SHADE
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
/* Static Member Definitions */ /* Static Member Definitions */
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
SHMeshData SHPrimitiveGenerator::cubeMesh; SHMeshAsset SHPrimitiveGenerator::cubeMesh;
SHMeshData SHPrimitiveGenerator::sphereMesh; SHMeshAsset SHPrimitiveGenerator::sphereMesh;
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
/* Primitive Generation Functions */ /* Primitive Generation Functions */
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
SHMeshData SHPrimitiveGenerator::Cube() noexcept SHMeshAsset SHPrimitiveGenerator::Cube() noexcept
{ {
SHMeshData mesh; SHMeshAsset mesh;
mesh.VertexPositions = mesh.VertexPositions =
{ {
@ -214,9 +214,9 @@ namespace SHADE
return addMeshDataTo(cubeMesh, gfxSystem); 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 LAT_SLICES = 12;
const int LONG_SLICES = 12; const int LONG_SLICES = 12;
@ -284,7 +284,7 @@ namespace SHADE
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
/* Helper Functions */ /* Helper Functions */
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
SHADE::Handle<SHADE::SHMesh> SHPrimitiveGenerator::addMeshDataTo(const SHMeshData& meshData, SHMeshLibrary& meshLibrary) noexcept SHADE::Handle<SHADE::SHMesh> SHPrimitiveGenerator::addMeshDataTo(const SHMeshAsset& meshData, SHMeshLibrary& meshLibrary) noexcept
{ {
return meshLibrary.AddMesh return meshLibrary.AddMesh
( (
@ -298,7 +298,7 @@ namespace SHADE
); );
} }
SHADE::Handle<SHADE::SHMesh> SHPrimitiveGenerator::addMeshDataTo(const SHMeshData& meshData, SHGraphicsSystem& gfxSystem) noexcept SHADE::Handle<SHADE::SHMesh> SHPrimitiveGenerator::addMeshDataTo(const SHMeshAsset& meshData, SHGraphicsSystem& gfxSystem) noexcept
{ {
return gfxSystem.AddMesh return gfxSystem.AddMesh
( (

View File

@ -13,7 +13,7 @@ of DigiPen Institute of Technology is prohibited.
// Project Includes // Project Includes
#include "Math/SHMath.h" #include "Math/SHMath.h"
#include "Assets/Asset Types/SHModelAsset.h" #include "Assets/Asset Types/Models/SHModelAsset.h"
#include "Graphics/MiddleEnd/Interface/SHMeshLibrary.h" #include "Graphics/MiddleEnd/Interface/SHMeshLibrary.h"
#include "SH_API.h" #include "SH_API.h"
@ -47,13 +47,13 @@ namespace SHADE
/***********************************************************************************/ /***********************************************************************************/
/*! /*!
\brief \brief
Produces a cube and stores the data in a SHMeshData object. Produces a cube and stores the data in a SHMeshAsset object.
\return \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 \brief
@ -83,13 +83,13 @@ namespace SHADE
/***********************************************************************************/ /***********************************************************************************/
/*! /*!
\brief \brief
Produces a sphere and stores the data in a SHMeshData object. Produces a sphere and stores the data in a SHMeshAsset object.
\return \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 \brief
@ -121,13 +121,13 @@ namespace SHADE
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
/* Helper Functions */ /* Helper Functions */
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
static Handle<SHMesh> addMeshDataTo(const SHMeshData& meshData, SHMeshLibrary& meshLibrary) noexcept; static Handle<SHMesh> addMeshDataTo(const SHMeshAsset& meshData, SHMeshLibrary& meshLibrary) noexcept;
static Handle<SHMesh> addMeshDataTo(const SHMeshData& meshData, SHGraphicsSystem& gfxSystem) noexcept; static Handle<SHMesh> addMeshDataTo(const SHMeshAsset& meshData, SHGraphicsSystem& gfxSystem) noexcept;
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
/* Data Members */ /* Data Members */
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
static SHMeshData cubeMesh; static SHMeshAsset cubeMesh;
static SHMeshData sphereMesh; static SHMeshAsset sphereMesh;
}; };
} }

View File

@ -17,7 +17,7 @@ of DigiPen Institute of Technology is prohibited.
#include "SH_API.h" #include "SH_API.h"
#include "SHResourceLibrary.h" #include "SHResourceLibrary.h"
#include "Assets/SHAssetMacros.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/SHTextureAsset.h"
#include "Assets/Asset Types/SHShaderAsset.h" #include "Assets/Asset Types/SHShaderAsset.h"
#include "Graphics/Shaders/SHVkShaderModule.h" #include "Graphics/Shaders/SHVkShaderModule.h"
@ -42,7 +42,7 @@ namespace SHADE
/// </summary> /// </summary>
template<typename T = void> template<typename T = void>
struct SHResourceLoader { using AssetType = void; }; struct SHResourceLoader { using AssetType = void; };
template<> struct SHResourceLoader<SHMesh> { using AssetType = SHMeshData; }; template<> struct SHResourceLoader<SHMesh> { using AssetType = SHMeshAsset; };
template<> struct SHResourceLoader<SHTexture> { using AssetType = SHTextureAsset; }; template<> struct SHResourceLoader<SHTexture> { using AssetType = SHTextureAsset; };
template<> struct SHResourceLoader<SHVkShaderModule> { using AssetType = SHShaderAsset; }; template<> struct SHResourceLoader<SHVkShaderModule> { using AssetType = SHShaderAsset; };
template<> struct SHResourceLoader<SHMaterialSpec> { using AssetType = SHMaterialAsset; }; template<> struct SHResourceLoader<SHMaterialSpec> { using AssetType = SHMaterialAsset; };