diff --git a/Assets/Scripts/RaccoonShowcase.cs b/Assets/Scripts/RaccoonShowcase.cs index 3c767f7f..1da191fd 100644 --- a/Assets/Scripts/RaccoonShowcase.cs +++ b/Assets/Scripts/RaccoonShowcase.cs @@ -23,7 +23,9 @@ public class RaccoonShowcase : Script [Range(-5, 5)] public List intList = new List(new int[] { 2, 8, 2, 6, 8, 0, 1 }); public List enumList = new List(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() { Transform = GetComponent(); diff --git a/SHADE_Engine/src/Editor/SHEditorUI.cpp b/SHADE_Engine/src/Editor/SHEditorUI.cpp index 9fdcbde7..b9783020 100644 --- a/SHADE_Engine/src/Editor/SHEditorUI.cpp +++ b/SHADE_Engine/src/Editor/SHEditorUI.cpp @@ -15,8 +15,10 @@ of DigiPen Institute of Technology is prohibited. #include "SHEditorUI.h" // External Dependencies #include +// Project Includes #include "SHEditorWidgets.hpp" #include "ECS_Base/Managers/SHEntityManager.h" +#include "Assets/SHAssetManager.h" namespace SHADE { @@ -351,6 +353,53 @@ namespace SHADE 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(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& enumNames, bool* isHovered) { // Clamp input value diff --git a/SHADE_Engine/src/Editor/SHEditorUI.h b/SHADE_Engine/src/Editor/SHEditorUI.h index f450ac0d..cd87f46b 100644 --- a/SHADE_Engine/src/Editor/SHEditorUI.h +++ b/SHADE_Engine/src/Editor/SHEditorUI.h @@ -19,6 +19,7 @@ of DigiPen Institute of Technology is prohibited. #include "Math/Vector/SHVec3.h" #include "Math/Vector/SHVec4.h" #include "Math/SHMatrix.h" +#include "Assets/SHAssetMacros.h" namespace SHADE { @@ -298,7 +299,7 @@ namespace SHADE /// True if the value was changed. static bool InputTextField(const std::string& label, std::string& value, bool* isHovered = nullptr); /// - /// Creates a drag field widget for int input. + /// Creates a drag field widget for GameObject input. /// /// Label used to identify this widget. /// Reference to the variable to store the result. @@ -310,6 +311,13 @@ namespace SHADE /// True if the value was changed. static bool InputGameObjectField(const std::string& label, uint32_t& value, bool* isHovered = nullptr, bool alwaysNull = false); /// + /// Creates a drag field widget for Asset input. + /// + /// Label used to identify this widget. + /// Reference to the variable to store the result. + /// The type of enum to input. diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderable.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderable.cpp index e22de5ab..c7578137 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderable.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderable.cpp @@ -76,6 +76,12 @@ namespace SHADE sharedMaterial = materialInstance; } + void SHRenderable::SetMaterial(Handle material) + { + SHGraphicsSystem* gfxSystem = SHSystemManager::GetSystem(); + SetMaterial(gfxSystem->AddOrGetBaseMaterialInstance(material)); + } + Handle SHRenderable::GetMaterial() const { if (material) diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderable.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderable.h index f1455ef4..39132ca0 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderable.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderable.h @@ -48,6 +48,7 @@ namespace SHADE /*-------------------------------------------------------------------------------*/ /* Material Functions */ /*-------------------------------------------------------------------------------*/ + void SetMaterial(Handle material); void SetMaterial(Handle materialInstance); Handle GetMaterial() const; Handle GetModifiableMaterial(); diff --git a/SHADE_Engine/src/Resource/SHResourceManager.h b/SHADE_Engine/src/Resource/SHResourceManager.h index 6afdf2b0..5b98ffc3 100644 --- a/SHADE_Engine/src/Resource/SHResourceManager.h +++ b/SHADE_Engine/src/Resource/SHResourceManager.h @@ -49,7 +49,8 @@ namespace SHADE template<> struct SHResourceLoader { using AssetType = SHMaterialAsset; }; template<> struct SHResourceLoader { using AssetType = SHMaterialSpec; }; template<> struct SHResourceLoader { using AssetType = SHFontAsset; }; -/// + + /// /// Static class responsible for loading and caching runtime resources from their /// serialised Asset IDs. /// diff --git a/SHADE_Engine/src/Resource/SHResourceManagerInterface.cpp b/SHADE_Engine/src/Resource/SHResourceManagerInterface.cpp new file mode 100644 index 00000000..d89a7b16 --- /dev/null +++ b/SHADE_Engine/src/Resource/SHResourceManagerInterface.cpp @@ -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 SHResourceManagerInterface::LoadOrGetMesh(AssetID assetId) + { + return SHResourceManager::LoadOrGet(assetId); + } + Handle SHResourceManagerInterface::LoadOrGetTexture(AssetID assetId) + { + return SHResourceManager::LoadOrGet(assetId); + } + Handle SHResourceManagerInterface::LoadOrGetShaderModule(AssetID assetId) + { + return SHResourceManager::LoadOrGet(assetId); + } + Handle SHResourceManagerInterface::LoadOrGetMaterialSpec(AssetID assetId) + { + return SHResourceManager::LoadOrGet(assetId); + } + Handle SHResourceManagerInterface::LoadOrGetMaterial(AssetID assetId) + { + return SHResourceManager::LoadOrGet(assetId); + } + Handle SHResourceManagerInterface::LoadOrGetFont(AssetID assetId) + { + return SHResourceManager::LoadOrGet(assetId); + } + + /*-----------------------------------------------------------------------------------*/ + /* Query Functions */ + /*-----------------------------------------------------------------------------------*/ + std::optional SHResourceManagerInterface::GetAssetID(Handle handle) + { + return SHResourceManager::GetAssetID(handle); + } + + std::optional SHResourceManagerInterface::GetAssetName(Handle handle) + { + return SHResourceManager::GetAssetName(handle); + } +} diff --git a/SHADE_Engine/src/Resource/SHResourceManagerInterface.h b/SHADE_Engine/src/Resource/SHResourceManagerInterface.h new file mode 100644 index 00000000..359bd7c8 --- /dev/null +++ b/SHADE_Engine/src/Resource/SHResourceManagerInterface.h @@ -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 +// 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 */ + /*-----------------------------------------------------------------------------------*/ + /// + /// Static class providing access to non-templated functions of SHResourceManager for + /// SHADE_Managed. + /// + class SH_API SHResourceManagerInterface + { + public: + /*---------------------------------------------------------------------------------*/ + /* Loading Functions */ + /*---------------------------------------------------------------------------------*/ + + /// + /// Wrapper for SHResourceManager::LoadOrGet(). + /// + /// Asset ID of the resource to load. + /// Handle to the resource to retrieve. + static Handle LoadOrGetMesh(AssetID assetId); + /// + /// Wrapper for SHResourceManager::LoadOrGet(). + /// + /// + /// Handle to the resource to retrieve. + static Handle LoadOrGetTexture(AssetID assetId); + /// + /// Wrapper for SHResourceManager::LoadOrGet(). + /// + /// Asset ID of the resource to load. + /// Handle to the resource to retrieve. + static Handle LoadOrGetShaderModule(AssetID assetId); + /// + /// Wrapper for SHResourceManager::LoadOrGet(). + /// + /// Asset ID of the resource to load. + /// Handle to the resource to retrieve. + static Handle LoadOrGetMaterialSpec (AssetID assetId); + /// + /// Wrapper for SHResourceManager::LoadOrGet(). + /// + /// Asset ID of the resource to load. + /// Handle to the resource to retrieve. + static Handle LoadOrGetMaterial(AssetID assetId); + /// + /// Wrapper for SHResourceManager::LoadOrGet(). + /// + /// Asset ID of the resource to load. + /// Handle to the resource to retrieve. + static Handle LoadOrGetFont(AssetID assetId); + + /*---------------------------------------------------------------------------------*/ + /* Query Functions */ + /*---------------------------------------------------------------------------------*/ + /// + /// 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. + /// + /// Handle to get the AssetID of. + /// + /// AssetID for the specified Handle. If the Handle is invalid, there will be no + /// value. + /// + static std::optional GetAssetID(Handle handle); + /// + /// 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. + /// + /// Handle to get the name of. + /// + /// Name for the specified Handle. If the Handle is invalid, there will be no + /// value. + /// + static std::optional GetAssetName(Handle handle); + }; +} \ No newline at end of file diff --git a/SHADE_Managed/src/Assets/Font.cxx b/SHADE_Managed/src/Assets/Font.cxx deleted file mode 100644 index 782b0688..00000000 --- a/SHADE_Managed/src/Assets/Font.cxx +++ /dev/null @@ -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; - - /*---------------------------------------------------------------------------------*/ - /* Constructors/Destructor */ - /*---------------------------------------------------------------------------------*/ - Font::Font(Handle font) - : NativeAsset { font } - {} -} diff --git a/SHADE_Managed/src/Assets/Font.hxx b/SHADE_Managed/src/Assets/Font.hxx deleted file mode 100644 index fd194d1a..00000000 --- a/SHADE_Managed/src/Assets/Font.hxx +++ /dev/null @@ -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 -{ - /// - /// Managed counterpart of the native Font object that can be fed to TextRenderables - /// for rendering. - /// - public ref class Font : public NativeAsset - { - internal: - /*-----------------------------------------------------------------------------*/ - /* Constructors/Destructor */ - /*-----------------------------------------------------------------------------*/ - /// - /// Constructor for the Font. - /// - /// Handle to the font object. - Font(Handle font); - }; -} diff --git a/SHADE_Managed/src/Assets/FontAsset.cxx b/SHADE_Managed/src/Assets/FontAsset.cxx new file mode 100644 index 00000000..19d256cb --- /dev/null +++ b/SHADE_Managed/src/Assets/FontAsset.cxx @@ -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 FontAsset::NativeObject::get() + try + { + return SHResourceManagerInterface::LoadOrGetFont(asset.NativeAssetID); + } + catch (const BadHandleCastException&) + { + return Handle(); + } + 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); + } +} diff --git a/SHADE_Managed/src/Assets/FontAsset.hxx b/SHADE_Managed/src/Assets/FontAsset.hxx new file mode 100644 index 00000000..89239224 --- /dev/null +++ b/SHADE_Managed/src/Assets/FontAsset.hxx @@ -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 +{ + /// + /// Managed counterpart of the native Font object that can be fed to TextRenderables + /// for rendering. + /// + public value struct FontAsset + { + internal: + /*-----------------------------------------------------------------------------*/ + /* Properties */ + /*-----------------------------------------------------------------------------*/ + /// + /// Copy of the Handle to the native object. + /// + property Handle NativeObject + { + Handle get(); + } + /// + /// The raw asset ID of the asset. + /// + property AssetID NativeAssetID + { + AssetID get(); + } + + /*-----------------------------------------------------------------------------*/ + /* Constructors/Destructor */ + /*-----------------------------------------------------------------------------*/ + /// + /// Constructor for the Font. + /// + /// AssetID to the font asset. + FontAsset(AssetID fontId); + + /*-----------------------------------------------------------------------------*/ + /* Operator Overloads */ + /*-----------------------------------------------------------------------------*/ + /// + /// Implicit conversion operator to enable checking if a Font is valid. + /// + /// Asset to check. + /// True if the Asset is valid. + static operator bool(FontAsset asset); + + /*-----------------------------------------------------------------------------*/ + /* Conversion Operators */ + /*-----------------------------------------------------------------------------*/ + /// + /// Conversion operator to enable casting from a Font to an Asset. + /// + /// Vector3 to convert from. + static explicit operator Asset(FontAsset nativeAsset); + /// + /// Conversion operator to enable casting from a Asset to a Font. + /// + /// + static explicit operator FontAsset(Asset asset); + + protected: + /*-----------------------------------------------------------------------------*/ + /* Data Members */ + /*-----------------------------------------------------------------------------*/ + Asset asset; + }; +} diff --git a/SHADE_Managed/src/Assets/MaterialAsset.cxx b/SHADE_Managed/src/Assets/MaterialAsset.cxx new file mode 100644 index 00000000..48cbfd83 --- /dev/null +++ b/SHADE_Managed/src/Assets/MaterialAsset.cxx @@ -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 MaterialAsset::NativeObject::get() + try + { + return SHResourceManagerInterface::LoadOrGetMaterial(asset.NativeAssetID); + } + catch (const BadHandleCastException&) + { + return Handle(); + } + 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); + } +} diff --git a/SHADE_Managed/src/Assets/MaterialAsset.hxx b/SHADE_Managed/src/Assets/MaterialAsset.hxx new file mode 100644 index 00000000..5380b286 --- /dev/null +++ b/SHADE_Managed/src/Assets/MaterialAsset.hxx @@ -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 +{ + /// + /// Managed counterpart of the native Material object that can be fed to TextRenderables + /// for rendering. + /// + public value struct MaterialAsset + { + internal: + /*-----------------------------------------------------------------------------*/ + /* Properties */ + /*-----------------------------------------------------------------------------*/ + /// + /// Copy of the Handle to the native object. + /// + property Handle NativeObject + { + Handle get(); + } + /// + /// The raw asset ID of the asset. + /// + property AssetID NativeAssetID + { + AssetID get(); + } + + /*-----------------------------------------------------------------------------*/ + /* Constructors/Destructor */ + /*-----------------------------------------------------------------------------*/ + /// + /// Constructor for the Material. + /// + /// AssetID to the Material asset. + MaterialAsset(AssetID MaterialId); + + /*-----------------------------------------------------------------------------*/ + /* Operator Overloads */ + /*-----------------------------------------------------------------------------*/ + /// + /// Implicit conversion operator to enable checking if a Material is valid. + /// + /// Asset to check. + /// True if the Asset is valid. + static operator bool(MaterialAsset asset); + + /*-----------------------------------------------------------------------------*/ + /* Conversion Operators */ + /*-----------------------------------------------------------------------------*/ + /// + /// Conversion operator to enable casting from a Material to an Asset. + /// + /// Vector3 to convert from. + static explicit operator Asset(MaterialAsset nativeAsset); + /// + /// Conversion operator to enable casting from a Asset to a Material. + /// + /// + static explicit operator MaterialAsset(Asset asset); + + protected: + /*-----------------------------------------------------------------------------*/ + /* Data Members */ + /*-----------------------------------------------------------------------------*/ + Asset asset; + }; +} diff --git a/SHADE_Managed/src/Assets/Mesh.cxx b/SHADE_Managed/src/Assets/Mesh.cxx deleted file mode 100644 index 95a61ff6..00000000 --- a/SHADE_Managed/src/Assets/Mesh.cxx +++ /dev/null @@ -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; - - /*---------------------------------------------------------------------------------*/ - /* Constructors/Destructor */ - /*---------------------------------------------------------------------------------*/ - Mesh::Mesh(Handle mesh) - : NativeAsset { mesh } - {} -} diff --git a/SHADE_Managed/src/Assets/Mesh.hxx b/SHADE_Managed/src/Assets/Mesh.hxx deleted file mode 100644 index 8cd356ba..00000000 --- a/SHADE_Managed/src/Assets/Mesh.hxx +++ /dev/null @@ -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 -{ - /// - /// Managed counterpart of the native Mesh object containing vertex data that can - /// be fed to Renderables for rendering. - /// - public ref class Mesh : public NativeAsset - { - internal: - /*-----------------------------------------------------------------------------*/ - /* Constructors/Destructor */ - /*-----------------------------------------------------------------------------*/ - /// - /// Constructor for the Mesh - /// - /// Handle to the mesh object. - Mesh(Handle mesh); - }; -} diff --git a/SHADE_Managed/src/Assets/MeshAsset.cxx b/SHADE_Managed/src/Assets/MeshAsset.cxx new file mode 100644 index 00000000..6301fcee --- /dev/null +++ b/SHADE_Managed/src/Assets/MeshAsset.cxx @@ -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 MeshAsset::NativeObject::get() + try + { + return SHResourceManagerInterface::LoadOrGetMesh(asset.NativeAssetID); + } + catch (const BadHandleCastException&) + { + return Handle(); + } + 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); + } +} diff --git a/SHADE_Managed/src/Assets/MeshAsset.hxx b/SHADE_Managed/src/Assets/MeshAsset.hxx new file mode 100644 index 00000000..26625c1a --- /dev/null +++ b/SHADE_Managed/src/Assets/MeshAsset.hxx @@ -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 +{ + /// + /// Managed counterpart of the native Mesh object containing vertex data that can + /// be fed to Renderables for rendering. + /// + public value struct MeshAsset + { + internal: + /*-----------------------------------------------------------------------------*/ + /* Properties */ + /*-----------------------------------------------------------------------------*/ + /// + /// Copy of the Handle to the native object. + /// + property Handle NativeObject + { + Handle get(); + } + /// + /// The raw asset ID of the asset. + /// + property AssetID NativeAssetID + { + AssetID get(); + } + + /*-----------------------------------------------------------------------------*/ + /* Constructors/Destructor */ + /*-----------------------------------------------------------------------------*/ + /// + /// Constructor for the Mesh. + /// + /// AssetID to the Mesh asset. + MeshAsset(AssetID meshId); + + /*-----------------------------------------------------------------------------*/ + /* Operator Overloads */ + /*-----------------------------------------------------------------------------*/ + /// + /// Implicit conversion operator to enable checking if a Mesh is valid. + /// + /// Asset to check. + /// True if the Asset is valid. + static operator bool(MeshAsset asset); + + /*-----------------------------------------------------------------------------*/ + /* Conversion Operators */ + /*-----------------------------------------------------------------------------*/ + /// + /// Conversion operator to enable casting from a Mesh to an Asset. + /// + /// Vector3 to convert from. + static explicit operator Asset(MeshAsset nativeAsset); + /// + /// Conversion operator to enable casting from a Asset to a Mesh. + /// + /// + static explicit operator MeshAsset(Asset asset); + + protected: + /*-----------------------------------------------------------------------------*/ + /* Data Members */ + /*-----------------------------------------------------------------------------*/ + Asset asset; + }; +} diff --git a/SHADE_Managed/src/Assets/NativeAsset.cxx b/SHADE_Managed/src/Assets/NativeAsset.cxx index 9cdb1840..9480b02a 100644 --- a/SHADE_Managed/src/Assets/NativeAsset.cxx +++ b/SHADE_Managed/src/Assets/NativeAsset.cxx @@ -17,21 +17,30 @@ of DigiPen Institute of Technology is prohibited. #include "NativeAsset.hxx" // Project Includes #include "Engine/GenericHandle.hxx" +#include "Utility/Convert.hxx" namespace SHADE { /*---------------------------------------------------------------------------------*/ /* Properties */ /*---------------------------------------------------------------------------------*/ - GenericHandle Asset::NativeObjectHandle::get() + AssetID Asset::NativeAssetID::get() { - return nativeObjHandle; + return assetId; } /*---------------------------------------------------------------------------------*/ /* Constructors */ /*---------------------------------------------------------------------------------*/ - Asset::Asset(Handle nativeHandle) - : nativeObjHandle { Convert::ToCLI(Handle(nativeHandle)) } + Asset::Asset(AssetID id) + : assetId { id } {} + + /*---------------------------------------------------------------------------------*/ + /* Operator Overloads */ + /*---------------------------------------------------------------------------------*/ + Asset::operator bool(Asset asset) + { + return asset.NativeAssetID != INVALID_ASSET_ID; + } } \ No newline at end of file diff --git a/SHADE_Managed/src/Assets/NativeAsset.h++ b/SHADE_Managed/src/Assets/NativeAsset.h++ deleted file mode 100644 index 05be83b4..00000000 --- a/SHADE_Managed/src/Assets/NativeAsset.h++ +++ /dev/null @@ -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 - Handle NativeAsset::NativeObject::get() - try - { - return Handle(Convert::ToNative(nativeObjHandle)); - } - catch (const BadHandleCastException&) - { - return Handle(); // Null handle - } - - /*---------------------------------------------------------------------------------*/ - /* Constructors */ - /*---------------------------------------------------------------------------------*/ - template - NativeAsset::NativeAsset(Handle nativeObj) - : Asset { Handle(nativeObj) } - {} -} diff --git a/SHADE_Managed/src/Assets/NativeAsset.hxx b/SHADE_Managed/src/Assets/NativeAsset.hxx index 4d53ce6b..40f7e628 100644 --- a/SHADE_Managed/src/Assets/NativeAsset.hxx +++ b/SHADE_Managed/src/Assets/NativeAsset.hxx @@ -14,25 +14,28 @@ of DigiPen Institute of Technology is prohibited. *//*************************************************************************************/ #pragma once +// External Dependencies +#include "Assets/SHAssetMacros.h" +// Project Includes #include "Engine/GenericHandle.hxx" namespace SHADE { /// - /// Abstract base class that all Native Assets will inherit from. + /// Struct that contains native asset information. /// - public ref class Asset abstract + public value struct Asset { internal: /*-----------------------------------------------------------------------------*/ /* Properties */ /*-----------------------------------------------------------------------------*/ /// - /// Generic handle for the native object + /// The raw asset ID of the asset. /// - property GenericHandle NativeObjectHandle + property AssetID NativeAssetID { - GenericHandle get(); + AssetID get(); } /*-----------------------------------------------------------------------------*/ @@ -41,46 +44,23 @@ namespace SHADE /// /// Constructor for the asset. /// - /// Native asset object handle. - Asset(Handle nativeHandle); + /// Native asset ID to construct this asset from. + explicit Asset(AssetID id); + + /*-----------------------------------------------------------------------------*/ + /* Operator Overloads */ + /*-----------------------------------------------------------------------------*/ + /// + /// Implicit conversion operator to enable checking if a Asset is valid. + /// + /// Asset to check. + /// True if the Asset is valid. + static operator bool(Asset asset); protected: /*-----------------------------------------------------------------------------*/ /* Data Members */ /*-----------------------------------------------------------------------------*/ - GenericHandle nativeObjHandle; - }; - - /// - /// Generalised template class for a managed representation of a native asset - /// - /// - /// The type of the asset's native representation. - /// - template - public ref class NativeAsset abstract : Asset - { - internal: - /*-----------------------------------------------------------------------------*/ - /* Properties */ - /*-----------------------------------------------------------------------------*/ - /// - /// Copy of the Handle to the native object. - /// - property Handle NativeObject - { - Handle get(); - } - - /*-----------------------------------------------------------------------------*/ - /* Constructors/Destructor */ - /*-----------------------------------------------------------------------------*/ - /// - /// Constructor for the native asset - /// - /// Native asset object handle. - NativeAsset(Handle ptr); + AssetID assetId; }; } - -#include "NativeAsset.h++" diff --git a/SHADE_Managed/src/Components/Renderable.cxx b/SHADE_Managed/src/Components/Renderable.cxx index bc01bc03..819760e6 100644 --- a/SHADE_Managed/src/Components/Renderable.cxx +++ b/SHADE_Managed/src/Components/Renderable.cxx @@ -30,11 +30,11 @@ namespace SHADE /*---------------------------------------------------------------------------------*/ /* 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) { @@ -42,7 +42,7 @@ namespace SHADE } else { - GetNativeComponent()->SetMesh(Handle(Convert::ToNative(value->NativeObjectHandle))); + GetNativeComponent()->SetMesh(value->NativeObject); } } SHADE::Material^ Renderable::Material::get() @@ -64,4 +64,12 @@ namespace SHADE { return GetNativeComponent()->GetLightLayer(); } + + /*---------------------------------------------------------------------------------*/ + /* Properties */ + /*---------------------------------------------------------------------------------*/ + void Renderable::SetMaterial(MaterialAsset materialAsset) + { + GetNativeComponent()->SetMaterial(materialAsset.NativeObject); + } } diff --git a/SHADE_Managed/src/Components/Renderable.hxx b/SHADE_Managed/src/Components/Renderable.hxx index e8f11ef6..d52a01e5 100644 --- a/SHADE_Managed/src/Components/Renderable.hxx +++ b/SHADE_Managed/src/Components/Renderable.hxx @@ -20,8 +20,9 @@ of DigiPen Institute of Technology is prohibited. #include "Math/Quaternion.hxx" // External Dependencies #include "Graphics/MiddleEnd/Interface/SHRenderable.h" -#include "Assets/Mesh.hxx" -#include "Assets/Material.hxx" +#include "Assets/MeshAsset.hxx" +#include "Graphics/Material.hxx" +#include "Assets/MaterialAsset.hxx" namespace SHADE { @@ -48,10 +49,10 @@ namespace SHADE /// /// Mesh used to render this Renderable. /// - property SHADE::Mesh^ Mesh + property SHADE::MeshAsset^ Mesh { - SHADE::Mesh^ get(); - void set(SHADE::Mesh^ value); + SHADE::MeshAsset^ get(); + void set(SHADE::MeshAsset^ value); } /// /// Material used to render this Renderable. @@ -68,6 +69,16 @@ namespace SHADE { System::Byte get(); } + + /*-----------------------------------------------------------------------------*/ + /* Usage functions */ + /*-----------------------------------------------------------------------------*/ + /// + /// Sets the Material used by this Renderable to be an instance of the specified + /// base MaterialAsset. + /// + /// Material to set. + void SetMaterial(MaterialAsset materialAsset); }; } diff --git a/SHADE_Managed/src/Components/TextRenderable.cxx b/SHADE_Managed/src/Components/TextRenderable.cxx index c5859854..88e43823 100644 --- a/SHADE_Managed/src/Components/TextRenderable.cxx +++ b/SHADE_Managed/src/Components/TextRenderable.cxx @@ -39,11 +39,11 @@ namespace SHADE { 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) { @@ -51,7 +51,7 @@ namespace SHADE } else { - GetNativeComponent()->SetFont(Handle(Convert::ToNative(value->NativeObjectHandle))); + GetNativeComponent()->SetFont(value->NativeObject); } } } diff --git a/SHADE_Managed/src/Components/TextRenderable.hxx b/SHADE_Managed/src/Components/TextRenderable.hxx index 5418b6e5..bcd99bcf 100644 --- a/SHADE_Managed/src/Components/TextRenderable.hxx +++ b/SHADE_Managed/src/Components/TextRenderable.hxx @@ -20,7 +20,7 @@ of DigiPen Institute of Technology is prohibited. #include "Components/Component.hxx" #include "Math/Vector3.hxx" #include "Math/Quaternion.hxx" -#include "Assets/Font.hxx" +#include "Assets/FontAsset.hxx" namespace SHADE { @@ -55,10 +55,10 @@ namespace SHADE /// /// Font to use to render using this TextRenderable. /// - property SHADE::Font^ Font + property SHADE::FontAsset^ Font { - SHADE::Font^ get(); - void set(SHADE::Font^ value); + SHADE::FontAsset^ get(); + void set(SHADE::FontAsset^ value); } }; } diff --git a/SHADE_Managed/src/Editor/Editor.cxx b/SHADE_Managed/src/Editor/Editor.cxx index beb667e3..29e3da36 100644 --- a/SHADE_Managed/src/Editor/Editor.cxx +++ b/SHADE_Managed/src/Editor/Editor.cxx @@ -176,7 +176,10 @@ namespace SHADE renderSpecificField(field, object, SHEditorUI::InputVec3 , &isHovered) || renderSpecificField(field, object, nullptr , &isHovered) || renderSpecificField(field, object, nullptr , &isHovered) || - renderSpecificField(field, object, nullptr , &isHovered); + renderSpecificField(field, object, nullptr , &isHovered) || + renderSpecificField(field, object, nullptr , &isHovered) || + renderSpecificField(field, object, nullptr , &isHovered) || + renderSpecificField(field, object, nullptr , &isHovered); if (!MODIFIED_PRIMITIVE) { @@ -319,7 +322,10 @@ namespace SHADE renderFieldEditor(fieldName, object, SHEditorUI::InputVec3 , nullptr, rangeAttrib, modified) || renderFieldEditor(fieldName, object, nullptr , nullptr, rangeAttrib, modified) || renderFieldEditor(fieldName, object, nullptr , nullptr, rangeAttrib, modified) || - renderFieldEditor(fieldName, object, nullptr , nullptr, rangeAttrib, modified); + renderFieldEditor(fieldName, object, nullptr , nullptr, rangeAttrib, modified) || + renderFieldEditor(fieldName, object, nullptr , nullptr, rangeAttrib, modified) || + renderFieldEditor(fieldName, object, nullptr , nullptr, rangeAttrib, modified) || + renderFieldEditor(fieldName, object, nullptr , nullptr, rangeAttrib, modified); return modified; } diff --git a/SHADE_Managed/src/Editor/Editor.h++ b/SHADE_Managed/src/Editor/Editor.h++ index a186d7ea..352431fd 100644 --- a/SHADE_Managed/src/Editor/Editor.h++ +++ b/SHADE_Managed/src/Editor/Editor.h++ @@ -20,6 +20,9 @@ of DigiPen Institute of Technology is prohibited. #include "Editor/SHEditorUI.h" // Project Includes #include "Utility/Convert.hxx" +#include "Assets/FontAsset.hxx" +#include "Assets/MeshAsset.hxx" +#include "Assets/MaterialAsset.hxx" namespace SHADE { @@ -198,6 +201,42 @@ namespace SHADE return true; } + return false; + } + template<> + bool Editor::renderFieldEditorInternal(const std::string& fieldName, interior_ptr managedValPtr, EditorFieldFunc, 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(const std::string& fieldName, interior_ptr managedValPtr, EditorFieldFunc, 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(const std::string& fieldName, interior_ptr managedValPtr, EditorFieldFunc, bool* isHovered, RangeAttribute^) + { + uint32_t assetId = managedValPtr->NativeAssetID; + if (SHEditorUI::InputAssetField(fieldName, assetId, AssetType::MATERIAL, isHovered, !(*managedValPtr))) + { + *managedValPtr = MaterialAsset(assetId); + return true; + } + return false; } } diff --git a/SHADE_Managed/src/Assets/Material.cxx b/SHADE_Managed/src/Graphics/Material.cxx similarity index 86% rename from SHADE_Managed/src/Assets/Material.cxx rename to SHADE_Managed/src/Graphics/Material.cxx index f4262c2a..e646b34d 100644 --- a/SHADE_Managed/src/Assets/Material.cxx +++ b/SHADE_Managed/src/Graphics/Material.cxx @@ -20,6 +20,7 @@ of DigiPen Institute of Technology is prohibited. #include // Project Includes #include "Utility/Convert.hxx" +#include "Resource/SHResourceManagerInterface.h" namespace SHADE { @@ -53,15 +54,31 @@ namespace SHADE } /*---------------------------------------------------------------------------------*/ - /* Explicit Template Instantiation */ + /* Properties */ /*---------------------------------------------------------------------------------*/ - template ref class NativeAsset; + Handle Material::NativeObject::get() + try + { + return Handle(Convert::ToNative(matInstHandle)); + } + catch (const BadHandleCastException&) + { + return Handle(); + } + GenericHandle Material::NativeObjectHandle::get() + { + return matInstHandle; + } + AssetID Material::NativeAssetID::get() + { + return SHResourceManagerInterface::GetAssetID(Convert::ToNative(matInstHandle)).value_or(INVALID_ASSET_ID); + } /*---------------------------------------------------------------------------------*/ /* Constructors/Destructor */ /*---------------------------------------------------------------------------------*/ Material::Material(Handle material) - : NativeAsset{ material } + : matInstHandle{ Handle(material) } {} /*---------------------------------------------------------------------------------*/ @@ -116,4 +133,12 @@ namespace SHADE throw gcnew System::ArgumentException("Attempted to retrieve an invalid property on a material."); } + + /*---------------------------------------------------------------------------------*/ + /* Operator Overloads */ + /*---------------------------------------------------------------------------------*/ + Material::operator bool(Material materialInstance) + { + return materialInstance; + } } diff --git a/SHADE_Managed/src/Assets/Material.hxx b/SHADE_Managed/src/Graphics/Material.hxx similarity index 66% rename from SHADE_Managed/src/Assets/Material.hxx rename to SHADE_Managed/src/Graphics/Material.hxx index 25cc96a6..12664658 100644 --- a/SHADE_Managed/src/Assets/Material.hxx +++ b/SHADE_Managed/src/Graphics/Material.hxx @@ -16,8 +16,8 @@ of DigiPen Institute of Technology is prohibited. // External Dependencies #include "Resource/SHHandle.h" #include "Graphics/MiddleEnd/Interface/SHMaterialInstance.h" +#include "Assets/SHAssetMacros.h" // Project Includes -#include "NativeAsset.hxx" #include "Engine/GenericHandle.hxx" namespace SHADE @@ -26,9 +26,34 @@ namespace SHADE /// Managed counterpart of the native MaterialInstance object containing material /// data that can be fed to Renderables for rendering. /// - public ref class Material : public NativeAsset + public value struct Material { internal: + /*-----------------------------------------------------------------------------*/ + /* Properties */ + /*-----------------------------------------------------------------------------*/ + /// + /// Copy of the Handle to the native object. + /// + property Handle NativeObject + { + Handle get(); + } + /// + /// Generic handle for the native object + /// + property GenericHandle NativeObjectHandle + { + GenericHandle get(); + } + /// + /// The raw asset ID of the asset. + /// + property AssetID NativeAssetID + { + AssetID get(); + } + /*-----------------------------------------------------------------------------*/ /* Constructors/Destructor */ /*-----------------------------------------------------------------------------*/ @@ -77,5 +102,21 @@ namespace SHADE /// generic T GetProperty(System::String^ name); + + /*-----------------------------------------------------------------------------*/ + /* Operator Overloads */ + /*-----------------------------------------------------------------------------*/ + /// + /// Implicit conversion operator to enable checking if a Material is valid. + /// + /// Asset to check. + /// True if the Asset is valid. + static operator bool(Material asset); + + protected: + /*-----------------------------------------------------------------------------*/ + /* Data Members */ + /*-----------------------------------------------------------------------------*/ + GenericHandle matInstHandle; }; } diff --git a/SHADE_Managed/src/Scripts/Script.cxx b/SHADE_Managed/src/Scripts/Script.cxx index 2ee7dbf7..294f4096 100644 --- a/SHADE_Managed/src/Scripts/Script.cxx +++ b/SHADE_Managed/src/Scripts/Script.cxx @@ -258,6 +258,14 @@ namespace SHADE Script::Script() : OnGizmosDrawOverriden { false } {} + + /*---------------------------------------------------------------------------------*/ + /* Manipulation Functions */ + /*---------------------------------------------------------------------------------*/ + void Script::SetEnabledWithoutEvents(bool enable) + { + enabled = enable; + } /*---------------------------------------------------------------------------------*/ /* Virtual "All-Time" Lifecycle Functions */ diff --git a/SHADE_Managed/src/Scripts/Script.hxx b/SHADE_Managed/src/Scripts/Script.hxx index 62c5015c..8fc36544 100644 --- a/SHADE_Managed/src/Scripts/Script.hxx +++ b/SHADE_Managed/src/Scripts/Script.hxx @@ -326,6 +326,15 @@ namespace SHADE /// Information on the collision event. void OnTriggerExit(CollisionInfo collision); + /*-----------------------------------------------------------------------------*/ + /* Manipulation Functions */ + /*-----------------------------------------------------------------------------*/ + /// + /// Function to set the enabled state of this script without triggering events. + /// + /// Whether to enable or disable the script. + void SetEnabledWithoutEvents(bool enable); + protected: /*-----------------------------------------------------------------------------*/ /* Constructors */ diff --git a/SHADE_Managed/src/Scripts/ScriptStore.cxx b/SHADE_Managed/src/Scripts/ScriptStore.cxx index 96eb7361..d3d989cc 100644 --- a/SHADE_Managed/src/Scripts/ScriptStore.cxx +++ b/SHADE_Managed/src/Scripts/ScriptStore.cxx @@ -744,7 +744,7 @@ namespace SHADE for (YAML::Node& node : *yamlNode) { // Get the name of the script - if (!node["Type"]) + if (!node["Type"].IsDefined()) { Debug::LogWarning("[ScriptStore] Script with no type detected, skipping."); continue; diff --git a/SHADE_Managed/src/Serialisation/SerialisationUtilities.cxx b/SHADE_Managed/src/Serialisation/SerialisationUtilities.cxx index cfa94540..2bf05bc5 100644 --- a/SHADE_Managed/src/Serialisation/SerialisationUtilities.cxx +++ b/SHADE_Managed/src/Serialisation/SerialisationUtilities.cxx @@ -18,11 +18,16 @@ of DigiPen Institute of Technology is prohibited. #include "Serialisation/SerialisationUtilities.hxx" // Project Includes #include "ReflectionUtilities.hxx" +#include "Assets/FontAsset.hxx" +#include "Assets/MaterialAsset.hxx" +#include "Assets/MeshAsset.hxx" +#include "Scripts/Script.hxx" /*-------------------------------------------------------------------------------------*/ /* File-Level Constants */ /*-------------------------------------------------------------------------------------*/ static const std::string_view SCRIPT_TYPE_YAMLTAG = "Type"; +static const std::string_view SCRIPT_ENABLED_YAMLTAG = "Enabled"; /*-------------------------------------------------------------------------------------*/ /* Function Definitions */ @@ -36,10 +41,19 @@ namespace SHADE { using namespace System::Reflection; + // Obtain script + Script^ script = safe_cast(object); + if (script == nullptr) + { + Debug::LogWarning("[SerialisationUtilities] Attempted to serialise an object that is not a script!"); + return; + } + // Create YAML object YAML::Node scriptNode; scriptNode.SetStyle(YAML::EmitterStyle::Block); scriptNode[SCRIPT_TYPE_YAMLTAG.data()] = Convert::ToNative(object->GetType()->FullName); + scriptNode[SCRIPT_ENABLED_YAMLTAG.data()] = script->Enabled; // Get all fields System::Collections::Generic::IEnumerable^ fields = ReflectionUtilities::GetInstanceFields(object); @@ -69,7 +83,7 @@ namespace SHADE { using namespace System::Reflection; - // Load the YAML + // Error Checking if (!yamlNode.IsMap()) { // Invalid @@ -80,6 +94,21 @@ namespace SHADE ); return; } + + // Get the script + Script^ script = safe_cast(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()); + } + // Get all fields System::Collections::Generic::IEnumerable^ fields = ReflectionUtilities::GetInstanceFields(object); for each (FieldInfo^ field in fields) @@ -92,7 +121,7 @@ namespace SHADE // Deserialise const std::string FIELD_NAME = Convert::ToNative(field->Name); - if (yamlNode[FIELD_NAME]) + if (yamlNode[FIELD_NAME].IsDefined()) { writeYamlIntoField(field, object, yamlNode[FIELD_NAME]); } @@ -129,7 +158,10 @@ namespace SHADE fieldInsertYaml(fieldInfo, object, fieldNode) || fieldInsertYaml(fieldInfo, object, fieldNode) || fieldInsertYaml(fieldInfo, object, fieldNode) || - fieldInsertYaml(fieldInfo, object, fieldNode); + fieldInsertYaml(fieldInfo, object, fieldNode) || + fieldInsertYaml(fieldInfo, object, fieldNode) || + fieldInsertYaml(fieldInfo, object, fieldNode) || + fieldInsertYaml(fieldInfo, object, fieldNode); // Serialization of more complex types if (!PRIMITIVE_SERIALIZED) @@ -190,7 +222,10 @@ namespace SHADE varInsertYamlInternal(object, fieldNode) || varInsertYamlInternal(object, fieldNode) || varInsertYamlInternal(object, fieldNode) || - varInsertYamlInternal(object, fieldNode); + varInsertYamlInternal(object, fieldNode) || + varInsertYamlInternal(object, fieldNode) || + varInsertYamlInternal(object, fieldNode) || + varInsertYamlInternal(object, fieldNode); return INSERTED; } @@ -214,7 +249,10 @@ namespace SHADE fieldAssignYaml(fieldInfo, object, node) || fieldAssignYaml (fieldInfo, object, node) || fieldAssignYaml (fieldInfo, object, node) || - fieldAssignYaml (fieldInfo, object, node); + fieldAssignYaml (fieldInfo, object, node) || + fieldAssignYaml (fieldInfo, object, node) || + fieldAssignYaml (fieldInfo, object, node) || + fieldAssignYaml (fieldInfo, object, node); if (!ASSIGNED) { if (ReflectionUtilities::FieldIsList(fieldInfo)) @@ -277,7 +315,10 @@ namespace SHADE varAssignYamlInternal(object, node) || varAssignYamlInternal (object, node) || varAssignYamlInternal (object, node) || - varAssignYamlInternal (object, node); + varAssignYamlInternal (object, node) || + varAssignYamlInternal (object, node) || + varAssignYamlInternal (object, node) || + varAssignYamlInternal (object, node); return DESERIALISED; } } diff --git a/SHADE_Managed/src/Serialisation/SerialisationUtilities.h++ b/SHADE_Managed/src/Serialisation/SerialisationUtilities.h++ index 2c943452..04c87ef4 100644 --- a/SHADE_Managed/src/Serialisation/SerialisationUtilities.h++ +++ b/SHADE_Managed/src/Serialisation/SerialisationUtilities.h++ @@ -60,6 +60,12 @@ namespace SHADE { fieldNode = MAX_EID; } + else if constexpr (std::is_same_v || + std::is_same_v || + std::is_same_v) + { + fieldNode = INVALID_ASSET_ID; + } else { fieldNode = FieldType(); @@ -122,6 +128,17 @@ namespace SHADE return true; } } + else if constexpr (std::is_same_v || + std::is_same_v || + std::is_same_v) + { + if (object->GetType() == FieldType::typeid) + { + FieldType asset = safe_cast(object); + fieldNode = asset.NativeAssetID; + return true; + } + } else { if (object->GetType() == FieldType::typeid) @@ -229,6 +246,16 @@ namespace SHADE const uint32_t EID = node.as(); object = (EID == MAX_EID ? GameObject() : GameObject(EID)); } + else if constexpr (std::is_same_v || + std::is_same_v || + std::is_same_v) + { + if (object->GetType() == FieldType::typeid) + { + object = FieldType(node.as()); + return true; + } + } else { object = node.as();