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
|
||||
|
||||
#include "SHMeshAsset.h"
|
||||
#include "SHModelAsset.h"
|
||||
#include "SHTextureAsset.h"
|
|
@ -28,21 +28,21 @@ namespace SHADE
|
|||
struct SHMeshData
|
||||
{
|
||||
std::string name;
|
||||
std::vector<SHVec3> vertexPosition;
|
||||
std::vector<SHVec3> vertexTangent;
|
||||
std::vector<SHVec3> vertexNormal;
|
||||
std::vector<SHVec2> texCoords;
|
||||
std::vector<SHVec3> vertexPositions;
|
||||
std::vector<SHVec3> vertexTangents;
|
||||
std::vector<SHVec3> vertexNormals;
|
||||
std::vector<SHVec2> vertexTexCoords;
|
||||
std::vector<uint32_t> indices;
|
||||
};
|
||||
|
||||
struct SHMeshAssetHeader
|
||||
struct SHModelAssetHeader
|
||||
{
|
||||
size_t meshCount;
|
||||
};
|
||||
|
||||
struct SH_API SHMeshAsset : SHAssetData
|
||||
struct SH_API SHModelAsset : SHAssetData
|
||||
{
|
||||
SHMeshAssetHeader header;
|
||||
SHModelAssetHeader header;
|
||||
std::vector<SHMeshDataHeader> headers;
|
||||
std::vector<SHMeshData> meshes;
|
||||
};
|
|
@ -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 <fstream>
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
void SHMeshLoader::ReadHeader(std::ifstream& file, SHMeshDataHeader& header) noexcept
|
||||
void SHModelLoader::ReadHeader(std::ifstream& file, SHMeshDataHeader& header) noexcept
|
||||
{
|
||||
file.read(
|
||||
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 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<char*>(data.vertexPosition.data()), vertexVec3Byte);
|
||||
file.read(reinterpret_cast<char*>(data.vertexTangent.data()), vertexVec3Byte);
|
||||
file.read(reinterpret_cast<char*>(data.vertexNormal.data()), vertexVec3Byte);
|
||||
file.read(reinterpret_cast<char*>(data.texCoords.data()), vertexVec2Byte);
|
||||
file.read(reinterpret_cast<char*>(data.vertexPositions.data()), vertexVec3Byte);
|
||||
file.read(reinterpret_cast<char*>(data.vertexTangents.data()), vertexVec3Byte);
|
||||
file.read(reinterpret_cast<char*>(data.vertexNormals.data()), vertexVec3Byte);
|
||||
file.read(reinterpret_cast<char*>(data.vertexTexCoords.data()), vertexVec2Byte);
|
||||
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 };
|
||||
if (!file.is_open())
|
||||
|
@ -58,31 +58,31 @@ namespace SHADE
|
|||
file.seekg(0);
|
||||
|
||||
file.read(
|
||||
reinterpret_cast<char *>(&mesh.header),
|
||||
sizeof(SHMeshAssetHeader)
|
||||
reinterpret_cast<char *>(&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)
|
||||
{
|
||||
|
||||
}
|
|
@ -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 <fstream>
|
||||
|
||||
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;
|
||||
};
|
|
@ -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;
|
||||
|
||||
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<uint32_t>(meshData.VertexPositions.size()),
|
||||
meshData.VertexPositions.data(),
|
||||
meshData.VertexTexCoords.data(),
|
||||
meshData.VertexTangents.data(),
|
||||
meshData.VertexNormals.data(),
|
||||
static_cast<uint32_t>(meshData.Indices.size()),
|
||||
meshData.Indices.data()
|
||||
static_cast<uint32_t>(meshData.vertexPositions.size()),
|
||||
meshData.vertexPositions.data(),
|
||||
meshData.vertexTexCoords.data(),
|
||||
meshData.vertexTangents.data(),
|
||||
meshData.vertexNormals.data(),
|
||||
static_cast<uint32_t>(meshData.indices.size()),
|
||||
meshData.indices.data()
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -211,13 +211,13 @@ namespace SHADE
|
|||
static SHMeshData meshData = Cube();
|
||||
return gfxSystem.AddMesh
|
||||
(
|
||||
static_cast<uint32_t>(meshData.VertexPositions.size()),
|
||||
meshData.VertexPositions.data(),
|
||||
meshData.VertexTexCoords.data(),
|
||||
meshData.VertexTangents.data(),
|
||||
meshData.VertexNormals.data(),
|
||||
static_cast<uint32_t>(meshData.Indices.size()),
|
||||
meshData.Indices.data()
|
||||
static_cast<uint32_t>(meshData.vertexPositions.size()),
|
||||
meshData.vertexPositions.data(),
|
||||
meshData.vertexTexCoords.data(),
|
||||
meshData.vertexTangents.data(),
|
||||
meshData.vertexNormals.data(),
|
||||
static_cast<uint32_t>(meshData.indices.size()),
|
||||
meshData.indices.data()
|
||||
);
|
||||
}
|
||||
}
|
|
@ -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
|
||||
|
|
|
@ -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<SHMeshAsset>(assetId);
|
||||
const SHModelAsset* assetData = SHAssetManager::GetData<SHModelAsset>(assetId);
|
||||
if (assetData == nullptr)
|
||||
{
|
||||
SHLog::Warning("[SHResourceManager] Attempted to load an asset with an invalid Asset ID.");
|
||||
|
|
Loading…
Reference in New Issue