Added C# Assets System and Serialization of Script Enabled State #247
|
@ -23,7 +23,9 @@ public class RaccoonShowcase : Script
|
||||||
[Range(-5, 5)]
|
[Range(-5, 5)]
|
||||||
public List<int> intList = new List<int>(new int[] { 2, 8, 2, 6, 8, 0, 1 });
|
public List<int> intList = new List<int>(new int[] { 2, 8, 2, 6, 8, 0, 1 });
|
||||||
public List<Light.Type> enumList = new List<Light.Type>(new Light.Type[] { Light.Type.Point, Light.Type.Directional, Light.Type.Ambient });
|
public List<Light.Type> enumList = new List<Light.Type>(new Light.Type[] { Light.Type.Point, Light.Type.Directional, Light.Type.Ambient });
|
||||||
|
public FontAsset fontAsset;
|
||||||
|
public MeshAsset mesh;
|
||||||
|
public MaterialAsset matAsset;
|
||||||
protected override void awake()
|
protected override void awake()
|
||||||
{
|
{
|
||||||
Transform = GetComponent<Transform>();
|
Transform = GetComponent<Transform>();
|
||||||
|
|
|
@ -15,8 +15,10 @@ of DigiPen Institute of Technology is prohibited.
|
||||||
#include "SHEditorUI.h"
|
#include "SHEditorUI.h"
|
||||||
// External Dependencies
|
// External Dependencies
|
||||||
#include <imgui.h>
|
#include <imgui.h>
|
||||||
|
// Project Includes
|
||||||
#include "SHEditorWidgets.hpp"
|
#include "SHEditorWidgets.hpp"
|
||||||
#include "ECS_Base/Managers/SHEntityManager.h"
|
#include "ECS_Base/Managers/SHEntityManager.h"
|
||||||
|
#include "Assets/SHAssetManager.h"
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
{
|
{
|
||||||
|
@ -351,6 +353,53 @@ namespace SHADE
|
||||||
return changed;
|
return changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool SHEditorUI::InputAssetField(const std::string& label, AssetID& value, AssetType type, bool* isHovered)
|
||||||
|
{
|
||||||
|
// Label
|
||||||
|
if (!label.empty())
|
||||||
|
{
|
||||||
|
ImGui::Text(label.c_str());
|
||||||
|
ImGui::SameLine();
|
||||||
|
}
|
||||||
|
// Hover tracking
|
||||||
|
if (isHovered)
|
||||||
|
*isHovered = ImGui::IsItemHovered();
|
||||||
|
ImGui::SameLine();
|
||||||
|
|
||||||
|
// Attempt to get the asset's data for rendering editor
|
||||||
|
auto asset = SHAssetManager::GetAsset(value);
|
||||||
|
std::string assetName;
|
||||||
|
if (asset.has_value())
|
||||||
|
{
|
||||||
|
assetName = asset.value().name;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Editor
|
||||||
|
bool changed = ImGui::InputText("##", &assetName, ImGuiInputTextFlags_ReadOnly);
|
||||||
|
if (SHDragDrop::BeginTarget())
|
||||||
|
{
|
||||||
|
if (AssetID* payload = SHDragDrop::AcceptPayload<AssetID>(SHDragDrop::DRAG_RESOURCE))
|
||||||
|
{
|
||||||
|
// Check if type matches
|
||||||
|
auto draggedAsset = SHAssetManager::GetAsset(*payload);
|
||||||
|
if (draggedAsset.has_value() && draggedAsset.value().type == type)
|
||||||
|
{
|
||||||
|
value = draggedAsset.value().id;
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
SHDragDrop::EndTarget();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ImGui::SameLine();
|
||||||
|
if (ImGui::Button("Clear"))
|
||||||
|
{
|
||||||
|
value = INVALID_ASSET_ID;
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return changed;
|
||||||
|
}
|
||||||
|
|
||||||
bool SHEditorUI::InputEnumCombo(const std::string& label, int& v, const std::vector<std::string>& enumNames, bool* isHovered)
|
bool SHEditorUI::InputEnumCombo(const std::string& label, int& v, const std::vector<std::string>& enumNames, bool* isHovered)
|
||||||
{
|
{
|
||||||
// Clamp input value
|
// Clamp input value
|
||||||
|
|
|
@ -19,6 +19,7 @@ of DigiPen Institute of Technology is prohibited.
|
||||||
#include "Math/Vector/SHVec3.h"
|
#include "Math/Vector/SHVec3.h"
|
||||||
#include "Math/Vector/SHVec4.h"
|
#include "Math/Vector/SHVec4.h"
|
||||||
#include "Math/SHMatrix.h"
|
#include "Math/SHMatrix.h"
|
||||||
|
#include "Assets/SHAssetMacros.h"
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
{
|
{
|
||||||
|
@ -298,7 +299,7 @@ namespace SHADE
|
||||||
/// <returns>True if the value was changed.</returns>
|
/// <returns>True if the value was changed.</returns>
|
||||||
static bool InputTextField(const std::string& label, std::string& value, bool* isHovered = nullptr);
|
static bool InputTextField(const std::string& label, std::string& value, bool* isHovered = nullptr);
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a drag field widget for int input.
|
/// Creates a drag field widget for GameObject input.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="label">Label used to identify this widget.</param>
|
/// <param name="label">Label used to identify this widget.</param>
|
||||||
/// <param name="value">Reference to the variable to store the result.</param>
|
/// <param name="value">Reference to the variable to store the result.</param>
|
||||||
|
@ -310,6 +311,13 @@ namespace SHADE
|
||||||
/// <returns>True if the value was changed.</returns>
|
/// <returns>True if the value was changed.</returns>
|
||||||
static bool InputGameObjectField(const std::string& label, uint32_t& value, bool* isHovered = nullptr, bool alwaysNull = false);
|
static bool InputGameObjectField(const std::string& label, uint32_t& value, bool* isHovered = nullptr, bool alwaysNull = false);
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
/// Creates a drag field widget for Asset input.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="label">Label used to identify this widget.</param>
|
||||||
|
/// <param name="value">Reference to the variable to store the result.</param>
|
||||||
|
/// <param name="isHovered>If set, stores the hover state of this widget.</param>
|
||||||
|
static bool InputAssetField(const std::string& label, AssetID& value, AssetType type, bool* isHovered = nullptr);
|
||||||
|
/// <summary>
|
||||||
/// Creates a combo box for enumeration input.
|
/// Creates a combo box for enumeration input.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="Enum">The type of enum to input.</typeparam>
|
/// <typeparam name="Enum">The type of enum to input.</typeparam>
|
||||||
|
|
|
@ -76,6 +76,12 @@ namespace SHADE
|
||||||
sharedMaterial = materialInstance;
|
sharedMaterial = materialInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SHRenderable::SetMaterial(Handle<SHMaterial> material)
|
||||||
|
{
|
||||||
|
SHGraphicsSystem* gfxSystem = SHSystemManager::GetSystem<SHGraphicsSystem>();
|
||||||
|
SetMaterial(gfxSystem->AddOrGetBaseMaterialInstance(material));
|
||||||
|
}
|
||||||
|
|
||||||
Handle<SHMaterialInstance> SHRenderable::GetMaterial() const
|
Handle<SHMaterialInstance> SHRenderable::GetMaterial() const
|
||||||
{
|
{
|
||||||
if (material)
|
if (material)
|
||||||
|
|
|
@ -48,6 +48,7 @@ namespace SHADE
|
||||||
/*-------------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------------*/
|
||||||
/* Material Functions */
|
/* Material Functions */
|
||||||
/*-------------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------------*/
|
||||||
|
void SetMaterial(Handle<SHMaterial> material);
|
||||||
void SetMaterial(Handle<SHMaterialInstance> materialInstance);
|
void SetMaterial(Handle<SHMaterialInstance> materialInstance);
|
||||||
Handle<SHMaterialInstance> GetMaterial() const;
|
Handle<SHMaterialInstance> GetMaterial() const;
|
||||||
Handle<SHMaterialInstance> GetModifiableMaterial();
|
Handle<SHMaterialInstance> GetModifiableMaterial();
|
||||||
|
|
|
@ -49,7 +49,8 @@ namespace SHADE
|
||||||
template<> struct SHResourceLoader<SHMaterialSpec> { using AssetType = SHMaterialAsset; };
|
template<> struct SHResourceLoader<SHMaterialSpec> { using AssetType = SHMaterialAsset; };
|
||||||
template<> struct SHResourceLoader<SHMaterial> { using AssetType = SHMaterialSpec; };
|
template<> struct SHResourceLoader<SHMaterial> { using AssetType = SHMaterialSpec; };
|
||||||
template<> struct SHResourceLoader<SHFont> { using AssetType = SHFontAsset; };
|
template<> struct SHResourceLoader<SHFont> { using AssetType = SHFontAsset; };
|
||||||
/// <summary>
|
|
||||||
|
/// <summary>
|
||||||
/// Static class responsible for loading and caching runtime resources from their
|
/// Static class responsible for loading and caching runtime resources from their
|
||||||
/// serialised Asset IDs.
|
/// serialised Asset IDs.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -0,0 +1,59 @@
|
||||||
|
/************************************************************************************//*!
|
||||||
|
\file SHResourceManagerInterface.cpp
|
||||||
|
\author Tng Kah Wei, kahwei.tng, 390009620
|
||||||
|
\par email: kahwei.tng\@digipen.edu
|
||||||
|
\date Nov 22, 2022
|
||||||
|
\brief Contains the definition of the functions of the
|
||||||
|
SHResourceManagerInterface static class.
|
||||||
|
|
||||||
|
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 Header
|
||||||
|
#include "SHpch.h"
|
||||||
|
// Primary Include
|
||||||
|
#include "SHResourceManagerInterface.h"
|
||||||
|
// Project Includes
|
||||||
|
#include "SHResourceManager.h"
|
||||||
|
|
||||||
|
namespace SHADE
|
||||||
|
{
|
||||||
|
Handle<SHMesh> SHResourceManagerInterface::LoadOrGetMesh(AssetID assetId)
|
||||||
|
{
|
||||||
|
return SHResourceManager::LoadOrGet<SHMesh>(assetId);
|
||||||
|
}
|
||||||
|
Handle<SHTexture> SHResourceManagerInterface::LoadOrGetTexture(AssetID assetId)
|
||||||
|
{
|
||||||
|
return SHResourceManager::LoadOrGet<SHTexture>(assetId);
|
||||||
|
}
|
||||||
|
Handle<SHVkShaderModule> SHResourceManagerInterface::LoadOrGetShaderModule(AssetID assetId)
|
||||||
|
{
|
||||||
|
return SHResourceManager::LoadOrGet<SHVkShaderModule>(assetId);
|
||||||
|
}
|
||||||
|
Handle<SHMaterialSpec> SHResourceManagerInterface::LoadOrGetMaterialSpec(AssetID assetId)
|
||||||
|
{
|
||||||
|
return SHResourceManager::LoadOrGet<SHMaterialSpec>(assetId);
|
||||||
|
}
|
||||||
|
Handle<SHMaterial> SHResourceManagerInterface::LoadOrGetMaterial(AssetID assetId)
|
||||||
|
{
|
||||||
|
return SHResourceManager::LoadOrGet<SHMaterial>(assetId);
|
||||||
|
}
|
||||||
|
Handle<SHFont> SHResourceManagerInterface::LoadOrGetFont(AssetID assetId)
|
||||||
|
{
|
||||||
|
return SHResourceManager::LoadOrGet<SHFont>(assetId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
/* Query Functions */
|
||||||
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
std::optional<AssetID> SHResourceManagerInterface::GetAssetID(Handle<void> handle)
|
||||||
|
{
|
||||||
|
return SHResourceManager::GetAssetID(handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::optional<std::string> SHResourceManagerInterface::GetAssetName(Handle<void> handle)
|
||||||
|
{
|
||||||
|
return SHResourceManager::GetAssetName(handle);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,111 @@
|
||||||
|
/************************************************************************************//*!
|
||||||
|
\file SHResourceManagerInterface.h
|
||||||
|
\author Tng Kah Wei, kahwei.tng, 390009620
|
||||||
|
\par email: kahwei.tng\@digipen.edu
|
||||||
|
\date Nov 22, 2022
|
||||||
|
\brief Contains the definition of the SHResourceManagerInterface static class.
|
||||||
|
|
||||||
|
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 <optional>
|
||||||
|
// Project Includes
|
||||||
|
#include "SH_API.h"
|
||||||
|
#include "Resource/SHHandle.h"
|
||||||
|
#include "Assets/SHAssetMacros.h"
|
||||||
|
|
||||||
|
namespace SHADE
|
||||||
|
{
|
||||||
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
/* Forward Declarations */
|
||||||
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
class SHMesh;
|
||||||
|
class SHTexture;
|
||||||
|
class SHVkShaderModule;
|
||||||
|
struct SHMaterialSpec;
|
||||||
|
class SHMaterial;
|
||||||
|
class SHFont;
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
/* Type Definitions */
|
||||||
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
/// <summary>
|
||||||
|
/// Static class providing access to non-templated functions of SHResourceManager for
|
||||||
|
/// SHADE_Managed.
|
||||||
|
/// </summary>
|
||||||
|
class SH_API SHResourceManagerInterface
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* Loading Functions */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Wrapper for SHResourceManager::LoadOrGet<SHMesh>().
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="assetId">Asset ID of the resource to load.</param>
|
||||||
|
/// <returns>Handle to the resource to retrieve.</returns>
|
||||||
|
static Handle<SHMesh> LoadOrGetMesh(AssetID assetId);
|
||||||
|
/// <summary>
|
||||||
|
/// Wrapper for SHResourceManager::LoadOrGet<SHTexture>().
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="assetId"></param>
|
||||||
|
/// <returns>Handle to the resource to retrieve.</returns>
|
||||||
|
static Handle<SHTexture> LoadOrGetTexture(AssetID assetId);
|
||||||
|
/// <summary>
|
||||||
|
/// Wrapper for SHResourceManager::LoadOrGet<SHVkShaderModule>().
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="assetId">Asset ID of the resource to load.</param>
|
||||||
|
/// <returns>Handle to the resource to retrieve.</returns>
|
||||||
|
static Handle<SHVkShaderModule> LoadOrGetShaderModule(AssetID assetId);
|
||||||
|
/// <summary>
|
||||||
|
/// Wrapper for SHResourceManager::LoadOrGet<SHMaterialSpec>().
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="assetId">Asset ID of the resource to load.</param>
|
||||||
|
/// <returns>Handle to the resource to retrieve.</returns>
|
||||||
|
static Handle<SHMaterialSpec> LoadOrGetMaterialSpec (AssetID assetId);
|
||||||
|
/// <summary>
|
||||||
|
/// Wrapper for SHResourceManager::LoadOrGet<SHMaterial>().
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="assetId">Asset ID of the resource to load.</param>
|
||||||
|
/// <returns>Handle to the resource to retrieve.</returns>
|
||||||
|
static Handle<SHMaterial> LoadOrGetMaterial(AssetID assetId);
|
||||||
|
/// <summary>
|
||||||
|
/// Wrapper for SHResourceManager::LoadOrGet<SHFont>().
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="assetId">Asset ID of the resource to load.</param>
|
||||||
|
/// <returns>Handle to the resource to retrieve.</returns>
|
||||||
|
static Handle<SHFont> LoadOrGetFont(AssetID assetId);
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* Query Functions */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/// <summary>
|
||||||
|
/// Retrieves the AssetID associated with a specified Handle.
|
||||||
|
/// Compared to the templated version, this function is slower as it requires
|
||||||
|
/// searching through the storage of all resource types.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="handle">Handle to get the AssetID of.</param>
|
||||||
|
/// <return>
|
||||||
|
/// AssetID for the specified Handle. If the Handle is invalid, there will be no
|
||||||
|
/// value.
|
||||||
|
/// </return>
|
||||||
|
static std::optional<AssetID> GetAssetID(Handle<void> handle);
|
||||||
|
/// <summary>
|
||||||
|
/// Retrieves the name associated with the AssetID that is associated with the
|
||||||
|
/// specified Handle.
|
||||||
|
/// Compared to the templated version, this function is slower as it requires
|
||||||
|
/// searching through the storage of all resource types.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="handle">Handle to get the name of.</param>
|
||||||
|
/// <return>
|
||||||
|
/// Name for the specified Handle. If the Handle is invalid, there will be no
|
||||||
|
/// value.
|
||||||
|
/// </return>
|
||||||
|
static std::optional<std::string> GetAssetName(Handle<void> handle);
|
||||||
|
};
|
||||||
|
}
|
|
@ -1,32 +0,0 @@
|
||||||
/************************************************************************************//*!
|
|
||||||
\file Font.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 Font 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 "Font.hxx"
|
|
||||||
|
|
||||||
namespace SHADE
|
|
||||||
{
|
|
||||||
/*---------------------------------------------------------------------------------*/
|
|
||||||
/* Explicit Template Instantiation */
|
|
||||||
/*---------------------------------------------------------------------------------*/
|
|
||||||
template ref class NativeAsset<SHFont>;
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------------*/
|
|
||||||
/* Constructors/Destructor */
|
|
||||||
/*---------------------------------------------------------------------------------*/
|
|
||||||
Font::Font(Handle<SHFont> font)
|
|
||||||
: NativeAsset<SHFont> { font }
|
|
||||||
{}
|
|
||||||
}
|
|
|
@ -1,41 +0,0 @@
|
||||||
/************************************************************************************//*!
|
|
||||||
\file Font.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 Font 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/TextRendering/SHFont.h"
|
|
||||||
// Project Includes
|
|
||||||
#include "NativeAsset.hxx"
|
|
||||||
#include "Engine/GenericHandle.hxx"
|
|
||||||
|
|
||||||
namespace SHADE
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Managed counterpart of the native Font object that can be fed to TextRenderables
|
|
||||||
/// for rendering.
|
|
||||||
/// </summary>
|
|
||||||
public ref class Font : public NativeAsset<SHFont>
|
|
||||||
{
|
|
||||||
internal:
|
|
||||||
/*-----------------------------------------------------------------------------*/
|
|
||||||
/* Constructors/Destructor */
|
|
||||||
/*-----------------------------------------------------------------------------*/
|
|
||||||
/// <summary>
|
|
||||||
/// Constructor for the Font.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="font">Handle to the font object.</param>
|
|
||||||
Font(Handle<SHFont> font);
|
|
||||||
};
|
|
||||||
}
|
|
|
@ -0,0 +1,69 @@
|
||||||
|
/************************************************************************************//*!
|
||||||
|
\file Font.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 Font 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 "FontAsset.hxx"
|
||||||
|
// External Dependencies
|
||||||
|
#include "Resource/SHResourceManagerInterface.h"
|
||||||
|
// Project Headers
|
||||||
|
#include "Utility/Convert.hxx"
|
||||||
|
|
||||||
|
namespace SHADE
|
||||||
|
{
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* Properties */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
Handle<SHFont> FontAsset::NativeObject::get()
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return SHResourceManagerInterface::LoadOrGetFont(asset.NativeAssetID);
|
||||||
|
}
|
||||||
|
catch (const BadHandleCastException&)
|
||||||
|
{
|
||||||
|
return Handle<SHFont>();
|
||||||
|
}
|
||||||
|
AssetID FontAsset::NativeAssetID::get()
|
||||||
|
{
|
||||||
|
return asset.NativeAssetID;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* Constructors/Destructor */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
FontAsset::FontAsset(AssetID fontId)
|
||||||
|
: asset { fontId }
|
||||||
|
{}
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* Operator Overloads */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
FontAsset::operator bool(FontAsset asset)
|
||||||
|
{
|
||||||
|
return asset.asset;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* Conversion Operators */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
FontAsset::operator Asset(FontAsset nativeAsset)
|
||||||
|
{
|
||||||
|
return nativeAsset.asset;
|
||||||
|
}
|
||||||
|
|
||||||
|
FontAsset::operator FontAsset(Asset asset)
|
||||||
|
{
|
||||||
|
return FontAsset(asset.NativeAssetID);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,89 @@
|
||||||
|
/************************************************************************************//*!
|
||||||
|
\file Font.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 Font 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/TextRendering/SHFont.h"
|
||||||
|
// Project Includes
|
||||||
|
#include "NativeAsset.hxx"
|
||||||
|
#include "Engine/GenericHandle.hxx"
|
||||||
|
|
||||||
|
namespace SHADE
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Managed counterpart of the native Font object that can be fed to TextRenderables
|
||||||
|
/// for rendering.
|
||||||
|
/// </summary>
|
||||||
|
public value struct FontAsset
|
||||||
|
{
|
||||||
|
internal:
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/* Properties */
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/// <summary>
|
||||||
|
/// Copy of the Handle to the native object.
|
||||||
|
/// </summary>
|
||||||
|
property Handle<SHFont> NativeObject
|
||||||
|
{
|
||||||
|
Handle<SHFont> get();
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// The raw asset ID of the asset.
|
||||||
|
/// </summary>
|
||||||
|
property AssetID NativeAssetID
|
||||||
|
{
|
||||||
|
AssetID get();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/* Constructors/Destructor */
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor for the Font.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="fontId">AssetID to the font asset.</param>
|
||||||
|
FontAsset(AssetID fontId);
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/* Operator Overloads */
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/// <summary>
|
||||||
|
/// Implicit conversion operator to enable checking if a Font is valid.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="gameObj">Asset to check.</param>
|
||||||
|
/// <returns>True if the Asset is valid.</returns>
|
||||||
|
static operator bool(FontAsset asset);
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/* Conversion Operators */
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/// <summary>
|
||||||
|
/// Conversion operator to enable casting from a Font to an Asset.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="vec">Vector3 to convert from.</param>
|
||||||
|
static explicit operator Asset(FontAsset nativeAsset);
|
||||||
|
/// <summary>
|
||||||
|
/// Conversion operator to enable casting from a Asset to a Font.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="asset"></param>
|
||||||
|
static explicit operator FontAsset(Asset asset);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/* Data Members */
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
Asset asset;
|
||||||
|
};
|
||||||
|
}
|
|
@ -0,0 +1,70 @@
|
||||||
|
/************************************************************************************//*!
|
||||||
|
\file MaterialAsset.cxx
|
||||||
|
\author Tng Kah Wei, kahwei.tng, 390009620
|
||||||
|
\par email: kahwei.tng\@digipen.edu
|
||||||
|
\date Nov 22, 2022
|
||||||
|
\brief Contains the implementation of the functions of the managed Material
|
||||||
|
struct.
|
||||||
|
|
||||||
|
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 "MaterialAsset.hxx"
|
||||||
|
// External Dependencies
|
||||||
|
#include "Resource/SHResourceManagerInterface.h"
|
||||||
|
// Project Headers
|
||||||
|
#include "Utility/Convert.hxx"
|
||||||
|
|
||||||
|
namespace SHADE
|
||||||
|
{
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* Properties */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
Handle<SHMaterial> MaterialAsset::NativeObject::get()
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return SHResourceManagerInterface::LoadOrGetMaterial(asset.NativeAssetID);
|
||||||
|
}
|
||||||
|
catch (const BadHandleCastException&)
|
||||||
|
{
|
||||||
|
return Handle<SHMaterial>();
|
||||||
|
}
|
||||||
|
AssetID MaterialAsset::NativeAssetID::get()
|
||||||
|
{
|
||||||
|
return asset.NativeAssetID;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* Constructors/Destructor */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
MaterialAsset::MaterialAsset(AssetID MaterialId)
|
||||||
|
: asset { MaterialId }
|
||||||
|
{}
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* Operator Overloads */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
MaterialAsset::operator bool(MaterialAsset asset)
|
||||||
|
{
|
||||||
|
return asset.asset;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* Conversion Operators */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
MaterialAsset::operator Asset(MaterialAsset nativeAsset)
|
||||||
|
{
|
||||||
|
return nativeAsset.asset;
|
||||||
|
}
|
||||||
|
|
||||||
|
MaterialAsset::operator MaterialAsset(Asset asset)
|
||||||
|
{
|
||||||
|
return MaterialAsset(asset.NativeAssetID);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,89 @@
|
||||||
|
/************************************************************************************//*!
|
||||||
|
\file MaterialAsset.hxx
|
||||||
|
\author Tng Kah Wei, kahwei.tng, 390009620
|
||||||
|
\par email: kahwei.tng\@digipen.edu
|
||||||
|
\date Nov 22, 2022
|
||||||
|
\brief Contains the definition of the managed MaterialAsset struct.
|
||||||
|
|
||||||
|
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/SHMaterial.h"
|
||||||
|
// Project Includes
|
||||||
|
#include "NativeAsset.hxx"
|
||||||
|
#include "Engine/GenericHandle.hxx"
|
||||||
|
|
||||||
|
namespace SHADE
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Managed counterpart of the native Material object that can be fed to TextRenderables
|
||||||
|
/// for rendering.
|
||||||
|
/// </summary>
|
||||||
|
public value struct MaterialAsset
|
||||||
|
{
|
||||||
|
internal:
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/* Properties */
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/// <summary>
|
||||||
|
/// Copy of the Handle to the native object.
|
||||||
|
/// </summary>
|
||||||
|
property Handle<SHMaterial> NativeObject
|
||||||
|
{
|
||||||
|
Handle<SHMaterial> get();
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// The raw asset ID of the asset.
|
||||||
|
/// </summary>
|
||||||
|
property AssetID NativeAssetID
|
||||||
|
{
|
||||||
|
AssetID get();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/* Constructors/Destructor */
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor for the Material.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="MaterialId">AssetID to the Material asset.</param>
|
||||||
|
MaterialAsset(AssetID MaterialId);
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/* Operator Overloads */
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/// <summary>
|
||||||
|
/// Implicit conversion operator to enable checking if a Material is valid.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="gameObj">Asset to check.</param>
|
||||||
|
/// <returns>True if the Asset is valid.</returns>
|
||||||
|
static operator bool(MaterialAsset asset);
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/* Conversion Operators */
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/// <summary>
|
||||||
|
/// Conversion operator to enable casting from a Material to an Asset.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="vec">Vector3 to convert from.</param>
|
||||||
|
static explicit operator Asset(MaterialAsset nativeAsset);
|
||||||
|
/// <summary>
|
||||||
|
/// Conversion operator to enable casting from a Asset to a Material.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="asset"></param>
|
||||||
|
static explicit operator MaterialAsset(Asset asset);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/* Data Members */
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
Asset asset;
|
||||||
|
};
|
||||||
|
}
|
|
@ -1,34 +0,0 @@
|
||||||
/************************************************************************************//*!
|
|
||||||
\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 }
|
|
||||||
{}
|
|
||||||
}
|
|
|
@ -1,41 +0,0 @@
|
||||||
/************************************************************************************//*!
|
|
||||||
\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);
|
|
||||||
};
|
|
||||||
}
|
|
|
@ -0,0 +1,69 @@
|
||||||
|
/************************************************************************************//*!
|
||||||
|
\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 "MeshAsset.hxx"
|
||||||
|
// External Dependencies
|
||||||
|
#include "Resource/SHResourceManagerInterface.h"
|
||||||
|
// Project Headers
|
||||||
|
#include "Utility/Convert.hxx"
|
||||||
|
|
||||||
|
namespace SHADE
|
||||||
|
{
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* Properties */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
Handle<SHMesh> MeshAsset::NativeObject::get()
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return SHResourceManagerInterface::LoadOrGetMesh(asset.NativeAssetID);
|
||||||
|
}
|
||||||
|
catch (const BadHandleCastException&)
|
||||||
|
{
|
||||||
|
return Handle<SHMesh>();
|
||||||
|
}
|
||||||
|
AssetID MeshAsset::NativeAssetID::get()
|
||||||
|
{
|
||||||
|
return asset.NativeAssetID;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* Constructors/Destructor */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
MeshAsset::MeshAsset(AssetID meshId)
|
||||||
|
: asset{ meshId }
|
||||||
|
{}
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* Operator Overloads */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
MeshAsset::operator bool(MeshAsset asset)
|
||||||
|
{
|
||||||
|
return asset.asset;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* Conversion Operators */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
MeshAsset::operator Asset(MeshAsset nativeAsset)
|
||||||
|
{
|
||||||
|
return nativeAsset.asset;
|
||||||
|
}
|
||||||
|
|
||||||
|
MeshAsset::operator MeshAsset(Asset asset)
|
||||||
|
{
|
||||||
|
return MeshAsset(asset.NativeAssetID);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,89 @@
|
||||||
|
/************************************************************************************//*!
|
||||||
|
\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 value struct MeshAsset
|
||||||
|
{
|
||||||
|
internal:
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/* Properties */
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/// <summary>
|
||||||
|
/// Copy of the Handle to the native object.
|
||||||
|
/// </summary>
|
||||||
|
property Handle<SHMesh> NativeObject
|
||||||
|
{
|
||||||
|
Handle<SHMesh> get();
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// The raw asset ID of the asset.
|
||||||
|
/// </summary>
|
||||||
|
property AssetID NativeAssetID
|
||||||
|
{
|
||||||
|
AssetID get();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/* Constructors/Destructor */
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor for the Mesh.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="meshId">AssetID to the Mesh asset.</param>
|
||||||
|
MeshAsset(AssetID meshId);
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/* Operator Overloads */
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/// <summary>
|
||||||
|
/// Implicit conversion operator to enable checking if a Mesh is valid.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="gameObj">Asset to check.</param>
|
||||||
|
/// <returns>True if the Asset is valid.</returns>
|
||||||
|
static operator bool(MeshAsset asset);
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/* Conversion Operators */
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/// <summary>
|
||||||
|
/// Conversion operator to enable casting from a Mesh to an Asset.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="vec">Vector3 to convert from.</param>
|
||||||
|
static explicit operator Asset(MeshAsset nativeAsset);
|
||||||
|
/// <summary>
|
||||||
|
/// Conversion operator to enable casting from a Asset to a Mesh.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="asset"></param>
|
||||||
|
static explicit operator MeshAsset(Asset asset);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/* Data Members */
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
Asset asset;
|
||||||
|
};
|
||||||
|
}
|
|
@ -17,21 +17,30 @@ of DigiPen Institute of Technology is prohibited.
|
||||||
#include "NativeAsset.hxx"
|
#include "NativeAsset.hxx"
|
||||||
// Project Includes
|
// Project Includes
|
||||||
#include "Engine/GenericHandle.hxx"
|
#include "Engine/GenericHandle.hxx"
|
||||||
|
#include "Utility/Convert.hxx"
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
{
|
{
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
/* Properties */
|
/* Properties */
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
GenericHandle Asset::NativeObjectHandle::get()
|
AssetID Asset::NativeAssetID::get()
|
||||||
{
|
{
|
||||||
return nativeObjHandle;
|
return assetId;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
/* Constructors */
|
/* Constructors */
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
Asset::Asset(Handle<void> nativeHandle)
|
Asset::Asset(AssetID id)
|
||||||
: nativeObjHandle { Convert::ToCLI(Handle<void>(nativeHandle)) }
|
: assetId { id }
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* Operator Overloads */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
Asset::operator bool(Asset asset)
|
||||||
|
{
|
||||||
|
return asset.NativeAssetID != INVALID_ASSET_ID;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -1,44 +0,0 @@
|
||||||
/************************************************************************************//*!
|
|
||||||
\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"
|
|
||||||
#include "Utility/Convert.hxx"
|
|
||||||
|
|
||||||
namespace SHADE
|
|
||||||
{
|
|
||||||
/*---------------------------------------------------------------------------------*/
|
|
||||||
/* Properties */
|
|
||||||
/*---------------------------------------------------------------------------------*/
|
|
||||||
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)
|
|
||||||
: Asset { Handle<void>(nativeObj) }
|
|
||||||
{}
|
|
||||||
}
|
|
|
@ -14,25 +14,28 @@ of DigiPen Institute of Technology is prohibited.
|
||||||
*//*************************************************************************************/
|
*//*************************************************************************************/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
// External Dependencies
|
||||||
|
#include "Assets/SHAssetMacros.h"
|
||||||
|
// Project Includes
|
||||||
#include "Engine/GenericHandle.hxx"
|
#include "Engine/GenericHandle.hxx"
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Abstract base class that all Native Assets will inherit from.
|
/// Struct that contains native asset information.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ref class Asset abstract
|
public value struct Asset
|
||||||
{
|
{
|
||||||
internal:
|
internal:
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
/* Properties */
|
/* Properties */
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Generic handle for the native object
|
/// The raw asset ID of the asset.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
property GenericHandle NativeObjectHandle
|
property AssetID NativeAssetID
|
||||||
{
|
{
|
||||||
GenericHandle get();
|
AssetID get();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
@ -41,46 +44,23 @@ namespace SHADE
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Constructor for the asset.
|
/// Constructor for the asset.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="ptr">Native asset object handle.</param>
|
/// <param name="id">Native asset ID to construct this asset from.</param>
|
||||||
Asset(Handle<void> nativeHandle);
|
explicit Asset(AssetID id);
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/* Operator Overloads */
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/// <summary>
|
||||||
|
/// Implicit conversion operator to enable checking if a Asset is valid.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="gameObj">Asset to check.</param>
|
||||||
|
/// <returns>True if the Asset is valid.</returns>
|
||||||
|
static operator bool(Asset asset);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
/* Data Members */
|
/* Data Members */
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
GenericHandle nativeObjHandle;
|
AssetID assetId;
|
||||||
};
|
|
||||||
|
|
||||||
/// <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 abstract : Asset
|
|
||||||
{
|
|
||||||
internal:
|
|
||||||
/*-----------------------------------------------------------------------------*/
|
|
||||||
/* Properties */
|
|
||||||
/*-----------------------------------------------------------------------------*/
|
|
||||||
/// <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 handle.</param>
|
|
||||||
NativeAsset(Handle<NativeAssetType> ptr);
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "NativeAsset.h++"
|
|
||||||
|
|
|
@ -30,11 +30,11 @@ namespace SHADE
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
/* Properties */
|
/* Properties */
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
SHADE::Mesh^ Renderable::Mesh::get()
|
SHADE::MeshAsset^ Renderable::Mesh::get()
|
||||||
{
|
{
|
||||||
return gcnew SHADE::Mesh(GetNativeComponent()->GetMesh());
|
return gcnew SHADE::MeshAsset(GetNativeComponent()->GetMesh());
|
||||||
}
|
}
|
||||||
void Renderable::Mesh::set(SHADE::Mesh^ value)
|
void Renderable::Mesh::set(SHADE::MeshAsset^ value)
|
||||||
{
|
{
|
||||||
if (value == nullptr)
|
if (value == nullptr)
|
||||||
{
|
{
|
||||||
|
@ -42,7 +42,7 @@ namespace SHADE
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
GetNativeComponent()->SetMesh(Handle<SHMesh>(Convert::ToNative(value->NativeObjectHandle)));
|
GetNativeComponent()->SetMesh(value->NativeObject);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SHADE::Material^ Renderable::Material::get()
|
SHADE::Material^ Renderable::Material::get()
|
||||||
|
@ -64,4 +64,12 @@ namespace SHADE
|
||||||
{
|
{
|
||||||
return GetNativeComponent()->GetLightLayer();
|
return GetNativeComponent()->GetLightLayer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* Properties */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
void Renderable::SetMaterial(MaterialAsset materialAsset)
|
||||||
|
{
|
||||||
|
GetNativeComponent()->SetMaterial(materialAsset.NativeObject);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,8 +20,9 @@ of DigiPen Institute of Technology is prohibited.
|
||||||
#include "Math/Quaternion.hxx"
|
#include "Math/Quaternion.hxx"
|
||||||
// External Dependencies
|
// External Dependencies
|
||||||
#include "Graphics/MiddleEnd/Interface/SHRenderable.h"
|
#include "Graphics/MiddleEnd/Interface/SHRenderable.h"
|
||||||
#include "Assets/Mesh.hxx"
|
#include "Assets/MeshAsset.hxx"
|
||||||
#include "Assets/Material.hxx"
|
#include "Graphics/Material.hxx"
|
||||||
|
#include "Assets/MaterialAsset.hxx"
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
{
|
{
|
||||||
|
@ -48,10 +49,10 @@ namespace SHADE
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Mesh used to render this Renderable.
|
/// Mesh used to render this Renderable.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
property SHADE::Mesh^ Mesh
|
property SHADE::MeshAsset^ Mesh
|
||||||
{
|
{
|
||||||
SHADE::Mesh^ get();
|
SHADE::MeshAsset^ get();
|
||||||
void set(SHADE::Mesh^ value);
|
void set(SHADE::MeshAsset^ value);
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Material used to render this Renderable.
|
/// Material used to render this Renderable.
|
||||||
|
@ -68,6 +69,16 @@ namespace SHADE
|
||||||
{
|
{
|
||||||
System::Byte get();
|
System::Byte get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/* Usage functions */
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the Material used by this Renderable to be an instance of the specified
|
||||||
|
/// base MaterialAsset.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="asset">Material to set.</param>
|
||||||
|
void SetMaterial(MaterialAsset materialAsset);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,11 +39,11 @@ namespace SHADE
|
||||||
{
|
{
|
||||||
GetNativeComponent()->SetText(Convert::ToNative(value));
|
GetNativeComponent()->SetText(Convert::ToNative(value));
|
||||||
}
|
}
|
||||||
SHADE::Font^ TextRenderable::Font::get()
|
SHADE::FontAsset^ TextRenderable::Font::get()
|
||||||
{
|
{
|
||||||
return gcnew SHADE::Font(GetNativeComponent()->GetFont());
|
return gcnew SHADE::FontAsset(GetNativeComponent()->GetFont());
|
||||||
}
|
}
|
||||||
void TextRenderable::Font::set(SHADE::Font^ value)
|
void TextRenderable::Font::set(SHADE::FontAsset^ value)
|
||||||
{
|
{
|
||||||
if (value == nullptr)
|
if (value == nullptr)
|
||||||
{
|
{
|
||||||
|
@ -51,7 +51,7 @@ namespace SHADE
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
GetNativeComponent()->SetFont(Handle<SHFont>(Convert::ToNative(value->NativeObjectHandle)));
|
GetNativeComponent()->SetFont(value->NativeObject);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ of DigiPen Institute of Technology is prohibited.
|
||||||
#include "Components/Component.hxx"
|
#include "Components/Component.hxx"
|
||||||
#include "Math/Vector3.hxx"
|
#include "Math/Vector3.hxx"
|
||||||
#include "Math/Quaternion.hxx"
|
#include "Math/Quaternion.hxx"
|
||||||
#include "Assets/Font.hxx"
|
#include "Assets/FontAsset.hxx"
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
{
|
{
|
||||||
|
@ -55,10 +55,10 @@ namespace SHADE
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Font to use to render using this TextRenderable.
|
/// Font to use to render using this TextRenderable.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
property SHADE::Font^ Font
|
property SHADE::FontAsset^ Font
|
||||||
{
|
{
|
||||||
SHADE::Font^ get();
|
SHADE::FontAsset^ get();
|
||||||
void set(SHADE::Font^ value);
|
void set(SHADE::FontAsset^ value);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -176,7 +176,10 @@ namespace SHADE
|
||||||
renderSpecificField<SHVec3 , Vector3 >(field, object, SHEditorUI::InputVec3 , &isHovered) ||
|
renderSpecificField<SHVec3 , Vector3 >(field, object, SHEditorUI::InputVec3 , &isHovered) ||
|
||||||
renderSpecificField<uint32_t , GameObject >(field, object, nullptr , &isHovered) ||
|
renderSpecificField<uint32_t , GameObject >(field, object, nullptr , &isHovered) ||
|
||||||
renderSpecificField<std::string, System::String^>(field, object, nullptr , &isHovered) ||
|
renderSpecificField<std::string, System::String^>(field, object, nullptr , &isHovered) ||
|
||||||
renderSpecificField<int , System::Enum >(field, object, nullptr , &isHovered);
|
renderSpecificField<int , System::Enum >(field, object, nullptr , &isHovered) ||
|
||||||
|
renderSpecificField<AssetID , FontAsset >(field, object, nullptr , &isHovered) ||
|
||||||
|
renderSpecificField<AssetID , MeshAsset >(field, object, nullptr , &isHovered) ||
|
||||||
|
renderSpecificField<AssetID , MaterialAsset >(field, object, nullptr , &isHovered);
|
||||||
|
|
||||||
if (!MODIFIED_PRIMITIVE)
|
if (!MODIFIED_PRIMITIVE)
|
||||||
{
|
{
|
||||||
|
@ -319,7 +322,10 @@ namespace SHADE
|
||||||
renderFieldEditor<SHVec3 , Vector3 >(fieldName, object, SHEditorUI::InputVec3 , nullptr, rangeAttrib, modified) ||
|
renderFieldEditor<SHVec3 , Vector3 >(fieldName, object, SHEditorUI::InputVec3 , nullptr, rangeAttrib, modified) ||
|
||||||
renderFieldEditor<uint32_t , GameObject >(fieldName, object, nullptr , nullptr, rangeAttrib, modified) ||
|
renderFieldEditor<uint32_t , GameObject >(fieldName, object, nullptr , nullptr, rangeAttrib, modified) ||
|
||||||
renderFieldEditor<std::string, System::String^>(fieldName, object, nullptr , nullptr, rangeAttrib, modified) ||
|
renderFieldEditor<std::string, System::String^>(fieldName, object, nullptr , nullptr, rangeAttrib, modified) ||
|
||||||
renderFieldEditor<int , System::Enum >(fieldName, object, nullptr , nullptr, rangeAttrib, modified);
|
renderFieldEditor<int , System::Enum >(fieldName, object, nullptr , nullptr, rangeAttrib, modified) ||
|
||||||
|
renderFieldEditor<AssetID , FontAsset >(fieldName, object, nullptr , nullptr, rangeAttrib, modified) ||
|
||||||
|
renderFieldEditor<AssetID , MeshAsset >(fieldName, object, nullptr , nullptr, rangeAttrib, modified) ||
|
||||||
|
renderFieldEditor<AssetID , MaterialAsset >(fieldName, object, nullptr , nullptr, rangeAttrib, modified);
|
||||||
|
|
||||||
return modified;
|
return modified;
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,9 @@ of DigiPen Institute of Technology is prohibited.
|
||||||
#include "Editor/SHEditorUI.h"
|
#include "Editor/SHEditorUI.h"
|
||||||
// Project Includes
|
// Project Includes
|
||||||
#include "Utility/Convert.hxx"
|
#include "Utility/Convert.hxx"
|
||||||
|
#include "Assets/FontAsset.hxx"
|
||||||
|
#include "Assets/MeshAsset.hxx"
|
||||||
|
#include "Assets/MaterialAsset.hxx"
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
{
|
{
|
||||||
|
@ -198,6 +201,42 @@ namespace SHADE
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
template<>
|
||||||
|
bool Editor::renderFieldEditorInternal<AssetID, FontAsset>(const std::string& fieldName, interior_ptr<FontAsset> managedValPtr, EditorFieldFunc<uint32_t>, bool* isHovered, RangeAttribute^)
|
||||||
|
{
|
||||||
|
uint32_t assetId = managedValPtr->NativeAssetID;
|
||||||
|
if (SHEditorUI::InputAssetField(fieldName, assetId, AssetType::FONT, isHovered, !(*managedValPtr)))
|
||||||
|
{
|
||||||
|
*managedValPtr = FontAsset(assetId);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
template<>
|
||||||
|
bool Editor::renderFieldEditorInternal<AssetID, MeshAsset>(const std::string& fieldName, interior_ptr<MeshAsset> managedValPtr, EditorFieldFunc<uint32_t>, bool* isHovered, RangeAttribute^)
|
||||||
|
{
|
||||||
|
uint32_t assetId = managedValPtr->NativeAssetID;
|
||||||
|
if (SHEditorUI::InputAssetField(fieldName, assetId, AssetType::MESH, isHovered, !(*managedValPtr)))
|
||||||
|
{
|
||||||
|
*managedValPtr = MeshAsset(assetId);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
template<>
|
||||||
|
bool Editor::renderFieldEditorInternal<AssetID, MaterialAsset>(const std::string& fieldName, interior_ptr<MaterialAsset> managedValPtr, EditorFieldFunc<uint32_t>, bool* isHovered, RangeAttribute^)
|
||||||
|
{
|
||||||
|
uint32_t assetId = managedValPtr->NativeAssetID;
|
||||||
|
if (SHEditorUI::InputAssetField(fieldName, assetId, AssetType::MATERIAL, isHovered, !(*managedValPtr)))
|
||||||
|
{
|
||||||
|
*managedValPtr = MaterialAsset(assetId);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@ of DigiPen Institute of Technology is prohibited.
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
// Project Includes
|
// Project Includes
|
||||||
#include "Utility/Convert.hxx"
|
#include "Utility/Convert.hxx"
|
||||||
|
#include "Resource/SHResourceManagerInterface.h"
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
{
|
{
|
||||||
|
@ -53,15 +54,31 @@ namespace SHADE
|
||||||
}
|
}
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
/* Explicit Template Instantiation */
|
/* Properties */
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
template ref class NativeAsset<SHMaterialInstance>;
|
Handle<SHMaterialInstance> Material::NativeObject::get()
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return Handle<SHMaterialInstance>(Convert::ToNative(matInstHandle));
|
||||||
|
}
|
||||||
|
catch (const BadHandleCastException&)
|
||||||
|
{
|
||||||
|
return Handle<SHMaterialInstance>();
|
||||||
|
}
|
||||||
|
GenericHandle Material::NativeObjectHandle::get()
|
||||||
|
{
|
||||||
|
return matInstHandle;
|
||||||
|
}
|
||||||
|
AssetID Material::NativeAssetID::get()
|
||||||
|
{
|
||||||
|
return SHResourceManagerInterface::GetAssetID(Convert::ToNative(matInstHandle)).value_or(INVALID_ASSET_ID);
|
||||||
|
}
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
/* Constructors/Destructor */
|
/* Constructors/Destructor */
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
Material::Material(Handle<SHMaterialInstance> material)
|
Material::Material(Handle<SHMaterialInstance> material)
|
||||||
: NativeAsset<SHMaterialInstance>{ material }
|
: matInstHandle{ Handle<void>(material) }
|
||||||
{}
|
{}
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
@ -116,4 +133,12 @@ namespace SHADE
|
||||||
|
|
||||||
throw gcnew System::ArgumentException("Attempted to retrieve an invalid property on a material.");
|
throw gcnew System::ArgumentException("Attempted to retrieve an invalid property on a material.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* Operator Overloads */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
Material::operator bool(Material materialInstance)
|
||||||
|
{
|
||||||
|
return materialInstance;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -16,8 +16,8 @@ of DigiPen Institute of Technology is prohibited.
|
||||||
// External Dependencies
|
// External Dependencies
|
||||||
#include "Resource/SHHandle.h"
|
#include "Resource/SHHandle.h"
|
||||||
#include "Graphics/MiddleEnd/Interface/SHMaterialInstance.h"
|
#include "Graphics/MiddleEnd/Interface/SHMaterialInstance.h"
|
||||||
|
#include "Assets/SHAssetMacros.h"
|
||||||
// Project Includes
|
// Project Includes
|
||||||
#include "NativeAsset.hxx"
|
|
||||||
#include "Engine/GenericHandle.hxx"
|
#include "Engine/GenericHandle.hxx"
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
|
@ -26,9 +26,34 @@ namespace SHADE
|
||||||
/// Managed counterpart of the native MaterialInstance object containing material
|
/// Managed counterpart of the native MaterialInstance object containing material
|
||||||
/// data that can be fed to Renderables for rendering.
|
/// data that can be fed to Renderables for rendering.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ref class Material : public NativeAsset<SHMaterialInstance>
|
public value struct Material
|
||||||
{
|
{
|
||||||
internal:
|
internal:
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/* Properties */
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/// <summary>
|
||||||
|
/// Copy of the Handle to the native object.
|
||||||
|
/// </summary>
|
||||||
|
property Handle<SHMaterialInstance> NativeObject
|
||||||
|
{
|
||||||
|
Handle<SHMaterialInstance> get();
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Generic handle for the native object
|
||||||
|
/// </summary>
|
||||||
|
property GenericHandle NativeObjectHandle
|
||||||
|
{
|
||||||
|
GenericHandle get();
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// The raw asset ID of the asset.
|
||||||
|
/// </summary>
|
||||||
|
property AssetID NativeAssetID
|
||||||
|
{
|
||||||
|
AssetID get();
|
||||||
|
}
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
/* Constructors/Destructor */
|
/* Constructors/Destructor */
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
@ -77,5 +102,21 @@ namespace SHADE
|
||||||
/// </exception>
|
/// </exception>
|
||||||
generic<typename T>
|
generic<typename T>
|
||||||
T GetProperty(System::String^ name);
|
T GetProperty(System::String^ name);
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/* Operator Overloads */
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/// <summary>
|
||||||
|
/// Implicit conversion operator to enable checking if a Material is valid.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="gameObj">Asset to check.</param>
|
||||||
|
/// <returns>True if the Asset is valid.</returns>
|
||||||
|
static operator bool(Material asset);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/* Data Members */
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
GenericHandle matInstHandle;
|
||||||
};
|
};
|
||||||
}
|
}
|
|
@ -259,6 +259,14 @@ namespace SHADE
|
||||||
: OnGizmosDrawOverriden { false }
|
: OnGizmosDrawOverriden { false }
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* Manipulation Functions */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
void Script::SetEnabledWithoutEvents(bool enable)
|
||||||
|
{
|
||||||
|
enabled = enable;
|
||||||
|
}
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
/* Virtual "All-Time" Lifecycle Functions */
|
/* Virtual "All-Time" Lifecycle Functions */
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
|
|
@ -326,6 +326,15 @@ namespace SHADE
|
||||||
/// <param name="collision">Information on the collision event.</param>
|
/// <param name="collision">Information on the collision event.</param>
|
||||||
void OnTriggerExit(CollisionInfo collision);
|
void OnTriggerExit(CollisionInfo collision);
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/* Manipulation Functions */
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/// <summary>
|
||||||
|
/// Function to set the enabled state of this script without triggering events.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="enable">Whether to enable or disable the script.</param>
|
||||||
|
void SetEnabledWithoutEvents(bool enable);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
/* Constructors */
|
/* Constructors */
|
||||||
|
|
|
@ -744,7 +744,7 @@ namespace SHADE
|
||||||
for (YAML::Node& node : *yamlNode)
|
for (YAML::Node& node : *yamlNode)
|
||||||
{
|
{
|
||||||
// Get the name of the script
|
// Get the name of the script
|
||||||
if (!node["Type"])
|
if (!node["Type"].IsDefined())
|
||||||
{
|
{
|
||||||
Debug::LogWarning("[ScriptStore] Script with no type detected, skipping.");
|
Debug::LogWarning("[ScriptStore] Script with no type detected, skipping.");
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -18,11 +18,16 @@ of DigiPen Institute of Technology is prohibited.
|
||||||
#include "Serialisation/SerialisationUtilities.hxx"
|
#include "Serialisation/SerialisationUtilities.hxx"
|
||||||
// Project Includes
|
// Project Includes
|
||||||
#include "ReflectionUtilities.hxx"
|
#include "ReflectionUtilities.hxx"
|
||||||
|
#include "Assets/FontAsset.hxx"
|
||||||
|
#include "Assets/MaterialAsset.hxx"
|
||||||
|
#include "Assets/MeshAsset.hxx"
|
||||||
|
#include "Scripts/Script.hxx"
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------------------*/
|
||||||
/* File-Level Constants */
|
/* File-Level Constants */
|
||||||
/*-------------------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------------------*/
|
||||||
static const std::string_view SCRIPT_TYPE_YAMLTAG = "Type";
|
static const std::string_view SCRIPT_TYPE_YAMLTAG = "Type";
|
||||||
|
static const std::string_view SCRIPT_ENABLED_YAMLTAG = "Enabled";
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------------------*/
|
||||||
/* Function Definitions */
|
/* Function Definitions */
|
||||||
|
@ -36,10 +41,19 @@ namespace SHADE
|
||||||
{
|
{
|
||||||
using namespace System::Reflection;
|
using namespace System::Reflection;
|
||||||
|
|
||||||
|
// Obtain script
|
||||||
|
Script^ script = safe_cast<Script^>(object);
|
||||||
|
if (script == nullptr)
|
||||||
|
{
|
||||||
|
Debug::LogWarning("[SerialisationUtilities] Attempted to serialise an object that is not a script!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Create YAML object
|
// Create YAML object
|
||||||
YAML::Node scriptNode;
|
YAML::Node scriptNode;
|
||||||
scriptNode.SetStyle(YAML::EmitterStyle::Block);
|
scriptNode.SetStyle(YAML::EmitterStyle::Block);
|
||||||
scriptNode[SCRIPT_TYPE_YAMLTAG.data()] = Convert::ToNative(object->GetType()->FullName);
|
scriptNode[SCRIPT_TYPE_YAMLTAG.data()] = Convert::ToNative(object->GetType()->FullName);
|
||||||
|
scriptNode[SCRIPT_ENABLED_YAMLTAG.data()] = script->Enabled;
|
||||||
|
|
||||||
// Get all fields
|
// Get all fields
|
||||||
System::Collections::Generic::IEnumerable<FieldInfo^>^ fields = ReflectionUtilities::GetInstanceFields(object);
|
System::Collections::Generic::IEnumerable<FieldInfo^>^ fields = ReflectionUtilities::GetInstanceFields(object);
|
||||||
|
@ -69,7 +83,7 @@ namespace SHADE
|
||||||
{
|
{
|
||||||
using namespace System::Reflection;
|
using namespace System::Reflection;
|
||||||
|
|
||||||
// Load the YAML
|
// Error Checking
|
||||||
if (!yamlNode.IsMap())
|
if (!yamlNode.IsMap())
|
||||||
{
|
{
|
||||||
// Invalid
|
// Invalid
|
||||||
|
@ -80,6 +94,21 @@ namespace SHADE
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get the script
|
||||||
|
Script^ script = safe_cast<Script^>(object);
|
||||||
|
if (script == nullptr)
|
||||||
|
{
|
||||||
|
Debug::LogWarning("[SerialisationUtilities] Attempted to deserialise an object that is not a script!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set enabled state
|
||||||
|
if (yamlNode[SCRIPT_ENABLED_YAMLTAG.data()].IsDefined())
|
||||||
|
{
|
||||||
|
script->SetEnabledWithoutEvents(yamlNode[SCRIPT_ENABLED_YAMLTAG.data()].as<bool>());
|
||||||
|
}
|
||||||
|
|
||||||
// Get all fields
|
// Get all fields
|
||||||
System::Collections::Generic::IEnumerable<FieldInfo^>^ fields = ReflectionUtilities::GetInstanceFields(object);
|
System::Collections::Generic::IEnumerable<FieldInfo^>^ fields = ReflectionUtilities::GetInstanceFields(object);
|
||||||
for each (FieldInfo^ field in fields)
|
for each (FieldInfo^ field in fields)
|
||||||
|
@ -92,7 +121,7 @@ namespace SHADE
|
||||||
|
|
||||||
// Deserialise
|
// Deserialise
|
||||||
const std::string FIELD_NAME = Convert::ToNative(field->Name);
|
const std::string FIELD_NAME = Convert::ToNative(field->Name);
|
||||||
if (yamlNode[FIELD_NAME])
|
if (yamlNode[FIELD_NAME].IsDefined())
|
||||||
{
|
{
|
||||||
writeYamlIntoField(field, object, yamlNode[FIELD_NAME]);
|
writeYamlIntoField(field, object, yamlNode[FIELD_NAME]);
|
||||||
}
|
}
|
||||||
|
@ -129,7 +158,10 @@ namespace SHADE
|
||||||
fieldInsertYaml<System::String>(fieldInfo, object, fieldNode) ||
|
fieldInsertYaml<System::String>(fieldInfo, object, fieldNode) ||
|
||||||
fieldInsertYaml<Vector2 >(fieldInfo, object, fieldNode) ||
|
fieldInsertYaml<Vector2 >(fieldInfo, object, fieldNode) ||
|
||||||
fieldInsertYaml<Vector3 >(fieldInfo, object, fieldNode) ||
|
fieldInsertYaml<Vector3 >(fieldInfo, object, fieldNode) ||
|
||||||
fieldInsertYaml<GameObject >(fieldInfo, object, fieldNode);
|
fieldInsertYaml<GameObject >(fieldInfo, object, fieldNode) ||
|
||||||
|
fieldInsertYaml<FontAsset >(fieldInfo, object, fieldNode) ||
|
||||||
|
fieldInsertYaml<MaterialAsset >(fieldInfo, object, fieldNode) ||
|
||||||
|
fieldInsertYaml<MeshAsset >(fieldInfo, object, fieldNode);
|
||||||
|
|
||||||
// Serialization of more complex types
|
// Serialization of more complex types
|
||||||
if (!PRIMITIVE_SERIALIZED)
|
if (!PRIMITIVE_SERIALIZED)
|
||||||
|
@ -190,7 +222,10 @@ namespace SHADE
|
||||||
varInsertYamlInternal<System::String>(object, fieldNode) ||
|
varInsertYamlInternal<System::String>(object, fieldNode) ||
|
||||||
varInsertYamlInternal<Vector2 >(object, fieldNode) ||
|
varInsertYamlInternal<Vector2 >(object, fieldNode) ||
|
||||||
varInsertYamlInternal<Vector3 >(object, fieldNode) ||
|
varInsertYamlInternal<Vector3 >(object, fieldNode) ||
|
||||||
varInsertYamlInternal<GameObject >(object, fieldNode);
|
varInsertYamlInternal<GameObject >(object, fieldNode) ||
|
||||||
|
varInsertYamlInternal<FontAsset >(object, fieldNode) ||
|
||||||
|
varInsertYamlInternal<MaterialAsset >(object, fieldNode) ||
|
||||||
|
varInsertYamlInternal<MeshAsset >(object, fieldNode);
|
||||||
return INSERTED;
|
return INSERTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -214,7 +249,10 @@ namespace SHADE
|
||||||
fieldAssignYaml<System::String>(fieldInfo, object, node) ||
|
fieldAssignYaml<System::String>(fieldInfo, object, node) ||
|
||||||
fieldAssignYaml<Vector2> (fieldInfo, object, node) ||
|
fieldAssignYaml<Vector2> (fieldInfo, object, node) ||
|
||||||
fieldAssignYaml<Vector3> (fieldInfo, object, node) ||
|
fieldAssignYaml<Vector3> (fieldInfo, object, node) ||
|
||||||
fieldAssignYaml<GameObject> (fieldInfo, object, node);
|
fieldAssignYaml<GameObject> (fieldInfo, object, node) ||
|
||||||
|
fieldAssignYaml<FontAsset> (fieldInfo, object, node) ||
|
||||||
|
fieldAssignYaml<MaterialAsset> (fieldInfo, object, node) ||
|
||||||
|
fieldAssignYaml<MeshAsset> (fieldInfo, object, node);
|
||||||
if (!ASSIGNED)
|
if (!ASSIGNED)
|
||||||
{
|
{
|
||||||
if (ReflectionUtilities::FieldIsList(fieldInfo))
|
if (ReflectionUtilities::FieldIsList(fieldInfo))
|
||||||
|
@ -277,7 +315,10 @@ namespace SHADE
|
||||||
varAssignYamlInternal<System::String>(object, node) ||
|
varAssignYamlInternal<System::String>(object, node) ||
|
||||||
varAssignYamlInternal<Vector2> (object, node) ||
|
varAssignYamlInternal<Vector2> (object, node) ||
|
||||||
varAssignYamlInternal<Vector3> (object, node) ||
|
varAssignYamlInternal<Vector3> (object, node) ||
|
||||||
varAssignYamlInternal<GameObject> (object, node);
|
varAssignYamlInternal<GameObject> (object, node) ||
|
||||||
|
varAssignYamlInternal<FontAsset> (object, node) ||
|
||||||
|
varAssignYamlInternal<MaterialAsset> (object, node) ||
|
||||||
|
varAssignYamlInternal<MeshAsset> (object, node);
|
||||||
return DESERIALISED;
|
return DESERIALISED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,6 +60,12 @@ namespace SHADE
|
||||||
{
|
{
|
||||||
fieldNode = MAX_EID;
|
fieldNode = MAX_EID;
|
||||||
}
|
}
|
||||||
|
else if constexpr (std::is_same_v<FieldType, FontAsset> ||
|
||||||
|
std::is_same_v<FieldType, MaterialAsset> ||
|
||||||
|
std::is_same_v<FieldType, MeshAsset>)
|
||||||
|
{
|
||||||
|
fieldNode = INVALID_ASSET_ID;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
fieldNode = FieldType();
|
fieldNode = FieldType();
|
||||||
|
@ -122,6 +128,17 @@ namespace SHADE
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if constexpr (std::is_same_v<FieldType, FontAsset> ||
|
||||||
|
std::is_same_v<FieldType, MaterialAsset> ||
|
||||||
|
std::is_same_v<FieldType, MeshAsset>)
|
||||||
|
{
|
||||||
|
if (object->GetType() == FieldType::typeid)
|
||||||
|
{
|
||||||
|
FieldType asset = safe_cast<FieldType>(object);
|
||||||
|
fieldNode = asset.NativeAssetID;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (object->GetType() == FieldType::typeid)
|
if (object->GetType() == FieldType::typeid)
|
||||||
|
@ -229,6 +246,16 @@ namespace SHADE
|
||||||
const uint32_t EID = node.as<uint32_t>();
|
const uint32_t EID = node.as<uint32_t>();
|
||||||
object = (EID == MAX_EID ? GameObject() : GameObject(EID));
|
object = (EID == MAX_EID ? GameObject() : GameObject(EID));
|
||||||
}
|
}
|
||||||
|
else if constexpr (std::is_same_v<FieldType, FontAsset> ||
|
||||||
|
std::is_same_v<FieldType, MaterialAsset> ||
|
||||||
|
std::is_same_v<FieldType, MeshAsset>)
|
||||||
|
{
|
||||||
|
if (object->GetType() == FieldType::typeid)
|
||||||
|
{
|
||||||
|
object = FieldType(node.as<AssetID>());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
object = node.as<CastType>();
|
object = node.as<CastType>();
|
||||||
|
|
Loading…
Reference in New Issue