diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Meshes/SHMeshData.h b/SHADE_Engine/src/Graphics/MiddleEnd/Meshes/SHMeshData.h new file mode 100644 index 00000000..2f7d320b --- /dev/null +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Meshes/SHMeshData.h @@ -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 +// 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 VertexPositions; + std::vector VertexTexCoords; + std::vector VertexTangents; + std::vector VertexNormals; + std::vector Indices; + }; +} \ No newline at end of file diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Meshes/SHPrimitiveGenerator.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Meshes/SHPrimitiveGenerator.cpp new file mode 100644 index 00000000..59f43712 --- /dev/null +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Meshes/SHPrimitiveGenerator.cpp @@ -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 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() + ); + } + +} \ No newline at end of file diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Meshes/SHPrimitiveGenerator.h b/SHADE_Engine/src/Graphics/MiddleEnd/Meshes/SHPrimitiveGenerator.h new file mode 100644 index 00000000..88b243f5 --- /dev/null +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Meshes/SHPrimitiveGenerator.h @@ -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 Cube(SHMeshLibrary& meshLibrary) noexcept; + }; +} \ No newline at end of file