Removed SHMeshData declaration/definition in graphics middle end
Renamed some data members in SHMeshData Replaced calls and references to mesh data in Primitive Generator
This commit is contained in:
parent
2beae24924
commit
d1f624b2eb
|
@ -1,4 +1,4 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "SHMeshAsset.h"
|
#include "SHModelAsset.h"
|
||||||
#include "SHTextureAsset.h"
|
#include "SHTextureAsset.h"
|
|
@ -28,21 +28,21 @@ namespace SHADE
|
||||||
struct SHMeshData
|
struct SHMeshData
|
||||||
{
|
{
|
||||||
std::string name;
|
std::string name;
|
||||||
std::vector<SHVec3> vertexPosition;
|
std::vector<SHVec3> vertexPositions;
|
||||||
std::vector<SHVec3> vertexTangent;
|
std::vector<SHVec3> vertexTangents;
|
||||||
std::vector<SHVec3> vertexNormal;
|
std::vector<SHVec3> vertexNormals;
|
||||||
std::vector<SHVec2> texCoords;
|
std::vector<SHVec2> vertexTexCoords;
|
||||||
std::vector<uint32_t> indices;
|
std::vector<uint32_t> indices;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SHMeshAssetHeader
|
struct SHModelAssetHeader
|
||||||
{
|
{
|
||||||
size_t meshCount;
|
size_t meshCount;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SH_API SHMeshAsset : SHAssetData
|
struct SH_API SHModelAsset : SHAssetData
|
||||||
{
|
{
|
||||||
SHMeshAssetHeader header;
|
SHModelAssetHeader header;
|
||||||
std::vector<SHMeshDataHeader> headers;
|
std::vector<SHMeshDataHeader> headers;
|
||||||
std::vector<SHMeshData> meshes;
|
std::vector<SHMeshData> meshes;
|
||||||
};
|
};
|
|
@ -1,5 +1,5 @@
|
||||||
/*************************************************************************//**
|
/*************************************************************************//**
|
||||||
* \file SHMeshLoader.cpp
|
* \file SHModelLoader.cpp
|
||||||
* \author Loh Xiao Qi
|
* \author Loh Xiao Qi
|
||||||
* \date 30 September 2022
|
* \date 30 September 2022
|
||||||
* \brief Implementation for Mesh loader. Accounts for custom binary format
|
* \brief Implementation for Mesh loader. Accounts for custom binary format
|
||||||
|
@ -11,12 +11,12 @@
|
||||||
* of DigiPen Institute of Technology is prohibited.
|
* of DigiPen Institute of Technology is prohibited.
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
#include "SHpch.h"
|
#include "SHpch.h"
|
||||||
#include "SHMeshLoader.h"
|
#include "SHModelLoader.h"
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
{
|
{
|
||||||
void SHMeshLoader::ReadHeader(std::ifstream& file, SHMeshDataHeader& header) noexcept
|
void SHModelLoader::ReadHeader(std::ifstream& file, SHMeshDataHeader& header) noexcept
|
||||||
{
|
{
|
||||||
file.read(
|
file.read(
|
||||||
reinterpret_cast<char*>(&header),
|
reinterpret_cast<char*>(&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 vertexVec3Byte{ sizeof(SHVec3) * header.vertexCount };
|
||||||
auto const vertexVec2Byte{ sizeof(SHVec2) * header.indexCount };
|
auto const vertexVec2Byte{ sizeof(SHVec2) * header.indexCount };
|
||||||
|
|
||||||
data.vertexPosition.resize(header.vertexCount);
|
data.vertexPositions.resize(header.vertexCount);
|
||||||
data.vertexTangent.resize(header.vertexCount);
|
data.vertexTangents.resize(header.vertexCount);
|
||||||
data.vertexNormal.resize(header.vertexCount);
|
data.vertexNormals.resize(header.vertexCount);
|
||||||
data.texCoords.resize(header.vertexCount);
|
data.vertexTexCoords.resize(header.vertexCount);
|
||||||
data.indices.resize(header.indexCount);
|
data.indices.resize(header.indexCount);
|
||||||
|
|
||||||
file.read(data.name.data(), header.charCount);
|
file.read(data.name.data(), header.charCount);
|
||||||
file.read(reinterpret_cast<char*>(data.vertexPosition.data()), vertexVec3Byte);
|
file.read(reinterpret_cast<char*>(data.vertexPositions.data()), vertexVec3Byte);
|
||||||
file.read(reinterpret_cast<char*>(data.vertexTangent.data()), vertexVec3Byte);
|
file.read(reinterpret_cast<char*>(data.vertexTangents.data()), vertexVec3Byte);
|
||||||
file.read(reinterpret_cast<char*>(data.vertexNormal.data()), vertexVec3Byte);
|
file.read(reinterpret_cast<char*>(data.vertexNormals.data()), vertexVec3Byte);
|
||||||
file.read(reinterpret_cast<char*>(data.texCoords.data()), vertexVec2Byte);
|
file.read(reinterpret_cast<char*>(data.vertexTexCoords.data()), vertexVec2Byte);
|
||||||
file.read(reinterpret_cast<char*>(data.indices.data()), sizeof(uint32_t) * header.indexCount);
|
file.read(reinterpret_cast<char*>(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 };
|
std::ifstream file{ path.string(), std::ios::in | std::ios::binary };
|
||||||
if (!file.is_open())
|
if (!file.is_open())
|
||||||
|
@ -58,31 +58,31 @@ namespace SHADE
|
||||||
file.seekg(0);
|
file.seekg(0);
|
||||||
|
|
||||||
file.read(
|
file.read(
|
||||||
reinterpret_cast<char *>(&mesh.header),
|
reinterpret_cast<char *>(&model.header),
|
||||||
sizeof(SHMeshAssetHeader)
|
sizeof(SHModelAssetHeader)
|
||||||
);
|
);
|
||||||
|
|
||||||
mesh.headers.resize(mesh.header.meshCount);
|
model.headers.resize(model.header.meshCount);
|
||||||
mesh.meshes.resize(mesh.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]);
|
ReadHeader(file, model.headers[i]);
|
||||||
ReadData(file, mesh.headers[i], mesh.meshes[i]);
|
ReadData(file, model.headers[i], model.meshes[i]);
|
||||||
}
|
}
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
SHAssetData* SHMeshLoader::Load(AssetPath path)
|
SHAssetData* SHModelLoader::Load(AssetPath path)
|
||||||
{
|
{
|
||||||
auto result = new SHMeshAsset();
|
auto result = new SHModelAsset();
|
||||||
|
|
||||||
LoadSHMesh(path, *result);
|
LoadSHMesh(path, *result);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SHMeshLoader::Write(SHAssetData const* data, AssetPath path)
|
void SHModelLoader::Write(SHAssetData const* data, AssetPath path)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
/*************************************************************************//**
|
/*************************************************************************//**
|
||||||
* \file SHMeshLoader.h
|
* \file SHModelLoader.h
|
||||||
* \author Loh Xiao Qi
|
* \author Loh Xiao Qi
|
||||||
* \date 30 September 2022
|
* \date 30 September 2022
|
||||||
* \brief Library to load gltf mesh files and custom binary format
|
* \brief Library to load gltf mesh files and custom binary format
|
||||||
|
@ -10,19 +10,19 @@
|
||||||
* of DigiPen Institute of Technology is prohibited.
|
* of DigiPen Institute of Technology is prohibited.
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "Assets/Asset Types/SHMeshAsset.h"
|
#include "Assets/Asset Types/SHModelAsset.h"
|
||||||
#include "SHAssetLoader.h"
|
#include "SHAssetLoader.h"
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
{
|
{
|
||||||
class SHMeshLoader : public SHAssetLoader
|
class SHModelLoader : public SHAssetLoader
|
||||||
{
|
{
|
||||||
void ReadHeader(std::ifstream& file, SHMeshDataHeader& header) noexcept;
|
void ReadHeader(std::ifstream& file, SHMeshDataHeader& header) noexcept;
|
||||||
void ReadData(std::ifstream& file, SHMeshDataHeader const& header, SHMeshData& data) noexcept;
|
void ReadData(std::ifstream& file, SHMeshDataHeader const& header, SHMeshData& data) noexcept;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void LoadSHMesh(AssetPath path, SHMeshAsset& meshes) noexcept;
|
void LoadSHMesh(AssetPath path, SHModelAsset& model) noexcept;
|
||||||
SHAssetData* Load(AssetPath path) override;
|
SHAssetData* Load(AssetPath path) override;
|
||||||
void Write(SHAssetData const* data, AssetPath path) override;
|
void Write(SHAssetData const* data, AssetPath path) override;
|
||||||
};
|
};
|
|
@ -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 <vector>
|
|
||||||
// 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<SHMesh::VertexPosition> VertexPositions;
|
|
||||||
std::vector<SHMesh::VertexTexCoord> VertexTexCoords;
|
|
||||||
std::vector<SHMesh::VertexTangent> VertexTangents;
|
|
||||||
std::vector<SHMesh::VertexNormal> VertexNormals;
|
|
||||||
std::vector<SHMesh::Index> Indices;
|
|
||||||
};
|
|
||||||
}
|
|
|
@ -22,7 +22,7 @@ namespace SHADE
|
||||||
{
|
{
|
||||||
SHMeshData mesh;
|
SHMeshData mesh;
|
||||||
|
|
||||||
mesh.VertexPositions =
|
mesh.vertexPositions =
|
||||||
{
|
{
|
||||||
// front
|
// front
|
||||||
SHVec3(-0.5f, -0.5f, 0.5f),
|
SHVec3(-0.5f, -0.5f, 0.5f),
|
||||||
|
@ -61,7 +61,7 @@ namespace SHADE
|
||||||
SHVec3(-0.5f, 0.5f, -0.5f)
|
SHVec3(-0.5f, 0.5f, -0.5f)
|
||||||
};
|
};
|
||||||
|
|
||||||
mesh.VertexTexCoords =
|
mesh.vertexTexCoords =
|
||||||
{
|
{
|
||||||
SHVec2(0.0f, 1.0f),
|
SHVec2(0.0f, 1.0f),
|
||||||
SHVec2(1.0f, 1.0f),
|
SHVec2(1.0f, 1.0f),
|
||||||
|
@ -99,7 +99,7 @@ namespace SHADE
|
||||||
SHVec2(0.0f, 0.0f)
|
SHVec2(0.0f, 0.0f)
|
||||||
};
|
};
|
||||||
|
|
||||||
mesh.VertexTangents =
|
mesh.vertexTangents =
|
||||||
{
|
{
|
||||||
// front
|
// front
|
||||||
SHVec3(1.0f, 0.0f, 0.0f),
|
SHVec3(1.0f, 0.0f, 0.0f),
|
||||||
|
@ -139,7 +139,7 @@ namespace SHADE
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
mesh.VertexNormals =
|
mesh.vertexNormals =
|
||||||
{
|
{
|
||||||
// front
|
// front
|
||||||
SHVec3(0.0f, 0.0f, 1.0f),
|
SHVec3(0.0f, 0.0f, 1.0f),
|
||||||
|
@ -178,7 +178,7 @@ namespace SHADE
|
||||||
SHVec3(-1.0f, 0.0f, 0.0f)
|
SHVec3(-1.0f, 0.0f, 0.0f)
|
||||||
};
|
};
|
||||||
|
|
||||||
mesh.Indices =
|
mesh.indices =
|
||||||
{
|
{
|
||||||
0, 1, 2, 0, 2, 3,
|
0, 1, 2, 0, 2, 3,
|
||||||
4, 5, 6, 4, 6, 7,
|
4, 5, 6, 4, 6, 7,
|
||||||
|
@ -196,13 +196,13 @@ namespace SHADE
|
||||||
static SHMeshData meshData = Cube();
|
static SHMeshData meshData = Cube();
|
||||||
return meshLibrary.AddMesh
|
return meshLibrary.AddMesh
|
||||||
(
|
(
|
||||||
static_cast<uint32_t>(meshData.VertexPositions.size()),
|
static_cast<uint32_t>(meshData.vertexPositions.size()),
|
||||||
meshData.VertexPositions.data(),
|
meshData.vertexPositions.data(),
|
||||||
meshData.VertexTexCoords.data(),
|
meshData.vertexTexCoords.data(),
|
||||||
meshData.VertexTangents.data(),
|
meshData.vertexTangents.data(),
|
||||||
meshData.VertexNormals.data(),
|
meshData.vertexNormals.data(),
|
||||||
static_cast<uint32_t>(meshData.Indices.size()),
|
static_cast<uint32_t>(meshData.indices.size()),
|
||||||
meshData.Indices.data()
|
meshData.indices.data()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -211,13 +211,13 @@ namespace SHADE
|
||||||
static SHMeshData meshData = Cube();
|
static SHMeshData meshData = Cube();
|
||||||
return gfxSystem.AddMesh
|
return gfxSystem.AddMesh
|
||||||
(
|
(
|
||||||
static_cast<uint32_t>(meshData.VertexPositions.size()),
|
static_cast<uint32_t>(meshData.vertexPositions.size()),
|
||||||
meshData.VertexPositions.data(),
|
meshData.vertexPositions.data(),
|
||||||
meshData.VertexTexCoords.data(),
|
meshData.vertexTexCoords.data(),
|
||||||
meshData.VertexTangents.data(),
|
meshData.vertexTangents.data(),
|
||||||
meshData.VertexNormals.data(),
|
meshData.vertexNormals.data(),
|
||||||
static_cast<uint32_t>(meshData.Indices.size()),
|
static_cast<uint32_t>(meshData.indices.size()),
|
||||||
meshData.Indices.data()
|
meshData.indices.data()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -13,7 +13,8 @@ of DigiPen Institute of Technology is prohibited.
|
||||||
|
|
||||||
// Project Includes
|
// Project Includes
|
||||||
#include "Math/SHMath.h"
|
#include "Math/SHMath.h"
|
||||||
#include "SHMeshData.h"
|
#include "Assets/Asset Types/SHModelAsset.h"
|
||||||
|
#include "Graphics/MiddleEnd/Interface/SHMeshLibrary.h"
|
||||||
#include "SH_API.h"
|
#include "SH_API.h"
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
|
|
|
@ -49,7 +49,7 @@ namespace SHADE
|
||||||
throw std::runtime_error("[SHResourceManager] Attempted to load graphics resource without a SHGraphicsSystem installed.");
|
throw std::runtime_error("[SHResourceManager] Attempted to load graphics resource without a SHGraphicsSystem installed.");
|
||||||
|
|
||||||
// Load
|
// Load
|
||||||
const SHMeshAsset* assetData = SHAssetManager::GetData<SHMeshAsset>(assetId);
|
const SHModelAsset* assetData = SHAssetManager::GetData<SHModelAsset>(assetId);
|
||||||
if (assetData == nullptr)
|
if (assetData == nullptr)
|
||||||
{
|
{
|
||||||
SHLog::Warning("[SHResourceManager] Attempted to load an asset with an invalid Asset ID.");
|
SHLog::Warning("[SHResourceManager] Attempted to load an asset with an invalid Asset ID.");
|
||||||
|
|
Loading…
Reference in New Issue