Added NativeAsset, Material and Mesh representations along with a stub for Renderable

This commit is contained in:
Kah Wei 2022-10-28 19:23:40 +08:00
parent 7e5c819813
commit 9617ed3838
9 changed files with 506 additions and 0 deletions

View File

@ -0,0 +1,119 @@
/************************************************************************************//*!
\file Material.cxx
\author Tng Kah Wei, kahwei.tng, 390009620
\par email: kahwei.tng\@digipen.edu
\date Oct 28, 2022
\brief Contains the implementation of the functions of the managed Material
class.
Note: This file is written in C++17/CLI.
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.
*//*************************************************************************************/
// Precompiled Headers
#include "SHpch.h"
// Primary Header
#include "Material.hxx"
// Standard Library
#include <stdexcept>
// Project Includes
#include "Utility/Convert.hxx"
namespace SHADE
{
/*---------------------------------------------------------------------------------*/
/* Macro Definitions */
/*---------------------------------------------------------------------------------*/
#define SET_PROP(NATIVE_TYPE, MANAGED_TYPE) \
(T::typeid == MANAGED_TYPE::typeid) \
{ \
const NATIVE_TYPE VAL = safe_cast<NATIVE_TYPE>(System::Convert::ChangeType(value, MANAGED_TYPE::typeid)); \
NativeObject->SetProperty<NATIVE_TYPE>(PROP_NAME, VAL); \
} \
#define SET_PROP_CONVERT(NATIVE_TYPE, MANAGED_TYPE) \
(T::typeid == MANAGED_TYPE::typeid) \
{ \
const NATIVE_TYPE VAL = Convert::ToNative(safe_cast<MANAGED_TYPE>(System::Convert::ChangeType(value, MANAGED_TYPE::typeid))); \
NativeObject->SetProperty<NATIVE_TYPE>(PROP_NAME, VAL); \
} \
#define GET_PROP(NATIVE_TYPE, MANAGED_TYPE) \
(T::typeid == MANAGED_TYPE::typeid) \
{ \
return safe_cast<T>(NativeObject->GetProperty<NATIVE_TYPE>(PROP_NAME)); \
} \
#define GET_PROP_CONVERT(NATIVE_TYPE, MANAGED_TYPE) \
(T::typeid == MANAGED_TYPE::typeid) \
{ \
return safe_cast<T>(Convert::ToCLI(NativeObject->GetProperty<NATIVE_TYPE>(PROP_NAME))); \
}
/*---------------------------------------------------------------------------------*/
/* Explicit Template Instantiation */
/*---------------------------------------------------------------------------------*/
template ref class NativeAsset<SHMaterialInstance>;
/*---------------------------------------------------------------------------------*/
/* Constructors/Destructor */
/*---------------------------------------------------------------------------------*/
Material::Material(Handle<SHMaterialInstance> material)
: NativeAsset<SHMaterialInstance>{ material }
{}
/*---------------------------------------------------------------------------------*/
/* Material Properties Functions */
/*---------------------------------------------------------------------------------*/
generic<typename T>
void Material::SetProperty(System::String^ name, T value)
{
if (!NativeObject)
throw gcnew System::InvalidOperationException("Attempted to set property on an invalid material!");
// Call the correct one based on type
const std::string PROP_NAME = Convert::ToNative(name);
try
{
if SET_PROP (int, System::Int32)
else if SET_PROP (int, System::Int64)
else if SET_PROP (float, float)
else if SET_PROP (double, double)
else if SET_PROP_CONVERT(SHVec2, Vector2)
else if SET_PROP_CONVERT(SHVec3, Vector3)
// TODO: Vector4
}
catch (const std::invalid_argument&)
{
throw gcnew System::ArgumentException("Attempted to modify an invalid property on a material.");
}
}
generic<typename T>
T Material::GetProperty(System::String^ name)
{
if (!NativeObject)
throw gcnew System::InvalidOperationException("[Material] Attempted to get property of an invalid material!");
// Call the correct one based on type
const std::string PROP_NAME = Convert::ToNative(name);
try
{
if GET_PROP (int, System::Int32)
else if GET_PROP (int, System::Int64)
else if GET_PROP (float, float)
else if GET_PROP (double, double)
else if GET_PROP_CONVERT(SHVec2, Vector2)
else if GET_PROP_CONVERT(SHVec3, Vector3)
// TODO: Vector4
}
catch (const std::invalid_argument&)
{
throw gcnew System::ArgumentException("Attempted to retrieve a property on a material with an invalid type.");
}
throw gcnew System::ArgumentException("Attempted to retrieve an invalid property on a material.");
}
}

View File

@ -0,0 +1,81 @@
/************************************************************************************//*!
\file Material.hxx
\author Tng Kah Wei, kahwei.tng, 390009620
\par email: kahwei.tng\@digipen.edu
\date Oct 28, 2022
\brief Contains the definition of the managed Mesh class.
Note: This file is written in C++17/CLI.
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
// External Dependencies
#include "Resource/SHHandle.h"
#include "Graphics/MiddleEnd/Interface/SHMaterialInstance.h"
// Project Includes
#include "NativeAsset.hxx"
#include "Engine/GenericHandle.hxx"
namespace SHADE
{
/// <summary>
/// Managed counterpart of the native MaterialInstance object containing material
/// data that can be fed to Renderables for rendering.
/// </summary>
public ref class Material : public NativeAsset<SHMaterialInstance>
{
internal:
/*-----------------------------------------------------------------------------*/
/* Constructors/Destructor */
/*-----------------------------------------------------------------------------*/
/// <summary>
/// Constructor for the Material
/// </summary>
/// <param name="material">Handle to the native material object.</param>
Material(Handle<SHMaterialInstance> material);
public:
/*-----------------------------------------------------------------------------*/
/* Properties */
/*-----------------------------------------------------------------------------*/
// TODO: Change Shader
/*-----------------------------------------------------------------------------*/
/* Material Properties Functions */
/*-----------------------------------------------------------------------------*/
/// <summary>
/// Set the value of a specific property.
/// </summary>
/// <typeparam name="T">Type of property to set.</typeparam>
/// <param name="name">Name of the property to set.</param>
/// <param name="value">Value to set te property to.</param>
/// <exception cref="System.InvalidOperationException">
/// If this Material object is invalid.
/// </exception>
/// <exception cref="System.ArgumentException">
/// If the name or type was specified that does not match the material's shader's
/// defined properties.
/// </exception>
generic<typename T>
void SetProperty(System::String^ name, T value);
/// <summary>
/// Retrieves the value of a specified property on the material.
/// </summary>
/// <typeparam name="T">Type of property to get.</typeparam>
/// <param name="name">Name of the property to get.</param>
/// <returns>Value of that property on the material.</returns>
/// <exception cref="System.InvalidOperationException">
/// If this Material object is invalid.
/// </exception>
/// <exception cref="System.ArgumentException">
/// If the name or type was specified that does not match the material's shader's
/// defined properties.
/// </exception>
generic<typename T>
T GetProperty(System::String^ name);
};
}

View File

@ -0,0 +1,34 @@
/************************************************************************************//*!
\file Mesh.cxx
\author Tng Kah Wei, kahwei.tng, 390009620
\par email: kahwei.tng\@digipen.edu
\date Oct 28, 2022
\brief Contains the implementation of the functions of the managed Mesh class.
Note: This file is written in C++17/CLI.
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.
*//*************************************************************************************/
// Precompiled Headers
#include "SHpch.h"
// Primary Header
#include "Mesh.hxx"
// Project Headers
#include "Utility/Convert.hxx"
namespace SHADE
{
/*---------------------------------------------------------------------------------*/
/* Explicit Template Instantiation */
/*---------------------------------------------------------------------------------*/
template ref class NativeAsset<SHMesh>;
/*---------------------------------------------------------------------------------*/
/* Constructors/Destructor */
/*---------------------------------------------------------------------------------*/
Mesh::Mesh(Handle<SHMesh> mesh)
: NativeAsset<SHMesh> { mesh }
{}
}

View File

@ -0,0 +1,41 @@
/************************************************************************************//*!
\file Mesh.hxx
\author Tng Kah Wei, kahwei.tng, 390009620
\par email: kahwei.tng\@digipen.edu
\date Oct 28, 2022
\brief Contains the definition of the managed Mesh class.
Note: This file is written in C++17/CLI.
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
// External Dependencies
#include "Resource/SHHandle.h"
#include "Graphics/MiddleEnd/Interface/SHMeshLibrary.h"
// Project Includes
#include "NativeAsset.hxx"
#include "Engine/GenericHandle.hxx"
namespace SHADE
{
/// <summary>
/// Managed counterpart of the native Mesh object containing vertex data that can
/// be fed to Renderables for rendering.
/// </summary>
public ref class Mesh : public NativeAsset<SHMesh>
{
internal:
/*-----------------------------------------------------------------------------*/
/* Constructors/Destructor */
/*-----------------------------------------------------------------------------*/
/// <summary>
/// Constructor for the Mesh
/// </summary>
/// <param name="mesh">Handle to the mesh object.</param>
Mesh(Handle<SHMesh> mesh);
};
}

View File

@ -0,0 +1,26 @@
/************************************************************************************//*!
\file NativeAsset.cxx
\author Tng Kah Wei, kahwei.tng, 390009620
\par email: kahwei.tng\@digipen.edu
\date Oct 28, 2022
\brief Contains the explicit template instantiation for some types of the
templated managed NativeAsset class.
Note: This file is written in C++17/CLI.
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"
// Primary Include
#include "NativeAsset.hxx"
// Project Includes
#include "Engine/GenericHandle.hxx"
namespace SHADE
{
/*---------------------------------------------------------------------------------*/
/* Explicit Tempalte Instantiations */
/*---------------------------------------------------------------------------------*/
}

View File

@ -0,0 +1,49 @@
/************************************************************************************//*!
\file NativeAsset.h++
\author Tng Kah Wei, kahwei.tng, 390009620
\par email: kahwei.tng\@digipen.edu
\date Oct 28, 2022
\brief Contains the definition of templated functions for the managed
NativeAsset classes.
Note: This file is written in C++17/CLI.
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
// Primary Include
#include "NativeAsset.hxx"
namespace SHADE
{
/*---------------------------------------------------------------------------------*/
/* Properties */
/*---------------------------------------------------------------------------------*/
template <typename NativeAssetType>
GenericHandle NativeAsset<NativeAssetType>::NativeObjectHandle::get()
{
return nativeObjHandle;
}
template <typename NativeAssetType>
Handle<NativeAssetType> NativeAsset<NativeAssetType>::NativeObject::get()
try
{
return Handle<NativeAssetType>(Convert::ToNative(nativeObjHandle));
}
catch (const BadHandleCastException&)
{
return Handle<NativeAssetType>(); // Null handle
}
/*---------------------------------------------------------------------------------*/
/* Constructors */
/*---------------------------------------------------------------------------------*/
template <typename NativeAssetType>
NativeAsset<NativeAssetType>::NativeAsset(Handle<NativeAssetType> nativeObj)
: nativeObjHandle{ Convert::ToCLI(Handle<void>(nativeObj)) }
{}
}

View File

@ -0,0 +1,66 @@
/************************************************************************************//*!
\file NativeAsset.hxx
\author Tng Kah Wei, kahwei.tng, 390009620
\par email: kahwei.tng\@digipen.edu
\date Oct 28, 2022
\brief Contains the template definition of the managed class that represents
native assets with a pointer to the corresponding native object.
Note: This file is written in C++17/CLI.
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 "Engine/GenericHandle.hxx"
namespace SHADE
{
/// <summary>
/// Generalised template class for a managed representation of a native asset
/// </summary>
/// <typeparam name="NativeAssetType">
/// The type of the asset's native representation.
/// </typeparam>
template<typename NativeAssetType>
public ref class NativeAsset
{
internal:
/*-----------------------------------------------------------------------------*/
/* Properties */
/*-----------------------------------------------------------------------------*/
/// <summary>
/// Generic handle for the native object
/// </summary>
property GenericHandle NativeObjectHandle
{
GenericHandle get();
}
/// <summary>
/// Copy of the Handle to the native object.
/// </summary>
property Handle<NativeAssetType> NativeObject
{
Handle<NativeAssetType> get();
}
/*-----------------------------------------------------------------------------*/
/* Constructors/Destructor */
/*-----------------------------------------------------------------------------*/
/// <summary>
/// Constructor for the native asset
/// </summary>
/// <param name="ptr">Native asset object.</param>
NativeAsset(Handle<NativeAssetType> ptr);
protected:
/*-----------------------------------------------------------------------------*/
/* Data Members */
/*-----------------------------------------------------------------------------*/
GenericHandle nativeObjHandle;
};
}
#include "NativeAsset.h++"

View File

@ -0,0 +1,37 @@
/************************************************************************************//*!
\file Renderable.cxx
\author Tng Kah Wei, kahwei.tng, 390009620
\par email: kahwei.tng\@digipen.edu
\date Oct 28, 2022
\brief Contains the definition of the functions of the managed Renderable class.
Note: This file is written in C++17/CLI.
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.
*//*************************************************************************************/
// Precompiled Headers
#include "SHpch.h"
// Primary Header
#include "Renderable.hxx"
#include "Assets/NativeAsset.hxx"
namespace SHADE
{
/*---------------------------------------------------------------------------------*/
/* Properties */
/*---------------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------------*/
/* Constructors */
/*---------------------------------------------------------------------------------*/
Renderable::Renderable(Entity entity)
: Component(entity)
{}
/*---------------------------------------------------------------------------------*/
/* Usage Functions */
/*---------------------------------------------------------------------------------*/
}

View File

@ -0,0 +1,53 @@
/************************************************************************************//*!
\file Renderable.hxx
\author Tng Kah Wei, kahwei.tng, 390009620
\par email: kahwei.tng\@digipen.edu
\date Oct 28, 2022
\brief Contains the definition of the managed Renderable class with the
declaration of functions for working with it.
Note: This file is written in C++17/CLI.
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 "Components/Component.hxx"
#include "Math/Vector3.hxx"
#include "Math/Quaternion.hxx"
// External Dependencies
#include "Graphics/MiddleEnd/Interface/SHRenderable.h"
namespace SHADE
{
/// <summary>
/// CLR version of the SHADE Engine's SHRenderableComponent.
/// </summary>
public ref class Renderable : public Component<SHRenderable>
{
internal:
/*-----------------------------------------------------------------------------*/
/* Constructors */
/*-----------------------------------------------------------------------------*/
/// <summary>
/// Constructs a Renderable Component that represents a native Renderable
/// component tied to the specified Entity.
/// </summary>
/// <param name="entity">Entity that this Component will be tied to.</param>
Renderable(Entity entity);
public:
/*-----------------------------------------------------------------------------*/
/* Properties */
/*-----------------------------------------------------------------------------*/
/*-----------------------------------------------------------------------------*/
/* Usage Functions */
/*-----------------------------------------------------------------------------*/
};
}