Added SHPrimitiveGenerator

This commit is contained in:
Kah Wei 2022-09-18 23:11:08 +08:00
parent 28a5f8e4e5
commit 41daaaba9c
3 changed files with 302 additions and 0 deletions

View File

@ -0,0 +1,36 @@
/************************************************************************************//*!
\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;
};
}

View File

@ -0,0 +1,206 @@
/************************************************************************************//*!
\file SHPrimitiveGenerator.cpp
\author Tng Kah Wei, kahwei.tng, 390009620
\par email: kahwei.tng\@digipen.edu
\date Aug 30, 2022
\brief Contains definitions for all of the functions of the classes that deal
with storage and management of vertex and index buffers of meshes.
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.
*//*************************************************************************************/
#include "SHpch.h"
#include "SHPrimitiveGenerator.h"
namespace SHADE
{
SHMeshData SHPrimitiveGenerator::Cube() noexcept
{
SHMeshData mesh;
mesh.VertexPositions =
{
// front
SHVec3(-0.5f, -0.5f, 0.5f),
SHVec3( 0.5f, -0.5f, 0.5f),
SHVec3( 0.5f, 0.5f, 0.5f),
SHVec3(-0.5f, 0.5f, 0.5f),
// back
SHVec3(-0.5f, -0.5f, -0.5f),
SHVec3(-0.5f, 0.5f, -0.5f),
SHVec3( 0.5f, 0.5f, -0.5f),
SHVec3( 0.5f, -0.5f, -0.5f),
// top
SHVec3(-0.5f, 0.5f, -0.5f),
SHVec3(-0.5f, 0.5f, 0.5f),
SHVec3( 0.5f, 0.5f, 0.5f),
SHVec3( 0.5f, 0.5f, -0.5f),
// bottom
SHVec3(-0.5f, -0.5f, -0.5f),
SHVec3( 0.5f, -0.5f, -0.5f),
SHVec3( 0.5f, -0.5f, 0.5f),
SHVec3(-0.5f, -0.5f, 0.5f),
// right
SHVec3(0.5f, -0.5f, -0.5f),
SHVec3(0.5f, 0.5f, -0.5f),
SHVec3(0.5f, 0.5f, 0.5f),
SHVec3(0.5f, -0.5f, 0.5f),
// left
SHVec3(-0.5f, -0.5f, -0.5f),
SHVec3(-0.5f, -0.5f, 0.5f),
SHVec3(-0.5f, 0.5f, 0.5f),
SHVec3(-0.5f, 0.5f, -0.5f)
};
mesh.VertexTexCoords =
{
SHVec2(0.0f, 1.0f),
SHVec2(1.0f, 1.0f),
SHVec2(1.0f, 0.0f),
SHVec2(0.0f, 0.0f),
SHVec2(0.0f, 1.0f),
SHVec2(1.0f, 1.0f),
SHVec2(1.0f, 0.0f),
SHVec2(0.0f, 0.0f),
SHVec2(0.0f, 1.0f),
SHVec2(1.0f, 1.0f),
SHVec2(1.0f, 0.0f),
SHVec2(0.0f, 0.0f),
SHVec2(0.0f, 1.0f),
SHVec2(1.0f, 1.0f),
SHVec2(1.0f, 0.0f),
SHVec2(0.0f, 0.0f),
SHVec2(0.0f, 1.0f),
SHVec2(1.0f, 1.0f),
SHVec2(1.0f, 0.0f),
SHVec2(0.0f, 0.0f),
SHVec2(0.0f, 1.0f),
SHVec2(1.0f, 1.0f),
SHVec2(1.0f, 0.0f),
SHVec2(0.0f, 0.0f)
};
mesh.VertexTangents =
{
// front
SHVec3(1.0f, 0.0f, 0.0f),
SHVec3(1.0f, 0.0f, 0.0f),
SHVec3(1.0f, 0.0f, 0.0f),
SHVec3(1.0f, 0.0f, 0.0f),
// back
SHVec3(-1.0f, 0.0f, 0.0f),
SHVec3(-1.0f, 0.0f, 0.0f),
SHVec3(-1.0f, 0.0f, 0.0f),
SHVec3(-1.0f, 0.0f, 0.0f),
// top
SHVec3(1.0f, 0.0f, 0.0f),
SHVec3(1.0f, 0.0f, 0.0f),
SHVec3(1.0f, 0.0f, 0.0f),
SHVec3(1.0f, 0.0f, 0.0f),
// bottom
SHVec3(1.0f, 0.0f, 0.0f),
SHVec3(1.0f, 0.0f, 0.0f),
SHVec3(1.0f, 0.0f, 0.0f),
SHVec3(1.0f, 0.0f, 0.0f),
// right
SHVec3(0.0f, 0.0f, -1.0f),
SHVec3(0.0f, 0.0f, -1.0f),
SHVec3(0.0f, 0.0f, -1.0f),
SHVec3(0.0f, 0.0f, -1.0f),
// left
SHVec3(0.0f, 0.0f, 1.0f),
SHVec3(0.0f, 0.0f, 1.0f),
SHVec3(0.0f, 0.0f, 1.0f),
SHVec3(0.0f, 0.0f, 1.0f)
};
mesh.VertexNormals =
{
// front
SHVec3(0.0f, 0.0f, 1.0f),
SHVec3(0.0f, 0.0f, 1.0f),
SHVec3(0.0f, 0.0f, 1.0f),
SHVec3(0.0f, 0.0f, 1.0f),
//back
SHVec3(0.0f, 0.0f, -1.0f),
SHVec3(0.0f, 0.0f, -1.0f),
SHVec3(0.0f, 0.0f, -1.0f),
SHVec3(0.0f, 0.0f, -1.0f),
// top
SHVec3(0.0f, 1.0f, 0.0f),
SHVec3(0.0f, 1.0f, 0.0f),
SHVec3(0.0f, 1.0f, 0.0f),
SHVec3(0.0f, 1.0f, 0.0f),
// bottom
SHVec3(0.0f, -1.0f, 0.0f),
SHVec3(0.0f, -1.0f, 0.0f),
SHVec3(0.0f, -1.0f, 0.0f),
SHVec3(0.0f, -1.0f, 0.0f),
// right
SHVec3(1.0f, 0.0f, 0.0f),
SHVec3(1.0f, 0.0f, 0.0f),
SHVec3(1.0f, 0.0f, 0.0f),
SHVec3(1.0f, 0.0f, 0.0f),
// left
SHVec3(-1.0f, 0.0f, 0.0f),
SHVec3(-1.0f, 0.0f, 0.0f),
SHVec3(-1.0f, 0.0f, 0.0f),
SHVec3(-1.0f, 0.0f, 0.0f)
};
mesh.Indices =
{
0, 1, 2, 0, 2, 3,
4, 5, 6, 4, 6, 7,
8, 9, 10, 8, 10, 11,
12, 13, 14, 12, 14, 15,
16, 17, 18, 16, 18, 19,
20, 21, 22, 20, 22, 23
};
return mesh;
}
Handle<SHMesh> SHPrimitiveGenerator::Cube(SHMeshLibrary& meshLibrary) noexcept
{
SHMeshData meshData = Cube();
return meshLibrary.AddMesh
(
meshData.VertexPositions.size(),
meshData.VertexPositions.data(),
meshData.VertexTexCoords.data(),
meshData.VertexTangents.data(),
meshData.VertexNormals.data(),
meshData.Indices.size(),
meshData.Indices.data()
);
}
}

View File

@ -0,0 +1,60 @@
/************************************************************************************//*!
\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
// Project Includes
#include "Math/SHMath.h"
#include "SHMeshData.h"
namespace SHADE
{
/*************************************************************************************/
/*!
\brief
Static class that contains functions for generating 3D primitives.
*/
/*************************************************************************************/
class SHPrimitiveGenerator
{
/*---------------------------------------------------------------------------------*/
/* Constructors */
/*---------------------------------------------------------------------------------*/
SHPrimitiveGenerator() = delete;
/*---------------------------------------------------------------------------------*/
/* Primitive Generation Functions */
/*---------------------------------------------------------------------------------*/
/***********************************************************************************/
/*!
\brief
Produces a cube and stores the data in a SHMeshData object.
\return
SHMeshData object containing vertex data for the cube.
*/
/***********************************************************************************/
[[nodiscard]] static SHMeshData Cube() noexcept;
/***********************************************************************************/
/*!
\brief
Produces a cube and constructs a SHMesh using the SHMeshLibrary provided.
\param meshLibrary
Reference to the SHMeshLibrary to procude and store a cube mesh in.
\return
SHMesh object that points to the generated cube mesh in the SHMeshLibrary.
*/
/***********************************************************************************/
[[nodiscard]] static Handle<SHMesh> Cube(SHMeshLibrary& meshLibrary) noexcept;
};
}