From 933e9639506a6cb57ae526258cb3604a6763cf45 Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Tue, 31 Jan 2023 11:29:00 +0800 Subject: [PATCH] Added script inspector and serialization support for RigAsset and AnimationClipAsset --- SHADE_Managed/src/Editor/Editor.cxx | 80 ++++----- SHADE_Managed/src/Editor/Editor.h++ | 26 +++ .../Serialisation/SerialisationUtilities.cxx | 154 ++++++++++-------- .../Serialisation/SerialisationUtilities.h++ | 14 +- 4 files changed, 161 insertions(+), 113 deletions(-) diff --git a/SHADE_Managed/src/Editor/Editor.cxx b/SHADE_Managed/src/Editor/Editor.cxx index 8b53db1b..21db95c0 100644 --- a/SHADE_Managed/src/Editor/Editor.cxx +++ b/SHADE_Managed/src/Editor/Editor.cxx @@ -18,6 +18,7 @@ of DigiPen Institute of Technology is prohibited. #include "Editor/Editor.hxx" // STL Includes #include +#include // Project Headers #include "Components/Component.hxx" #include "Scripts/ScriptStore.hxx" @@ -30,7 +31,8 @@ of DigiPen Institute of Technology is prohibited. #include "RangeAttribute.hxx" #include "Math/Vector2.hxx" #include "Math/Vector3.hxx" -#include +#include "Assets/RigAsset.hxx" +#include "Assets/AnimationClipAsset.hxx" // Using Directives using namespace System; @@ -162,24 +164,26 @@ namespace SHADE bool isHovered = false; const bool MODIFIED_PRIMITIVE = - renderSpecificField(field, object, SHEditorUI::InputInt , &isHovered) || - renderSpecificField(field, object, SHEditorUI::InputInt , &isHovered) || - renderSpecificField(field, object, SHEditorUI::InputInt , &isHovered) || - renderSpecificField(field, object, SHEditorUI::InputInt , &isHovered) || - renderSpecificField(field, object, SHEditorUI::InputInt , &isHovered) || - renderSpecificField(field, object, SHEditorUI::InputInt , &isHovered) || - renderSpecificField(field, object, SHEditorUI::InputInt , &isHovered) || - renderSpecificField(field, object, SHEditorUI::InputCheckbox, &isHovered) || - renderSpecificField(field, object, SHEditorUI::InputFloat , &isHovered) || - renderSpecificField(field, object, SHEditorUI::InputDouble , &isHovered) || - renderSpecificField(field, object, SHEditorUI::InputVec2 , &isHovered) || - 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, SHEditorUI::InputInt , &isHovered) || + renderSpecificField(field, object, SHEditorUI::InputInt , &isHovered) || + renderSpecificField(field, object, SHEditorUI::InputInt , &isHovered) || + renderSpecificField(field, object, SHEditorUI::InputInt , &isHovered) || + renderSpecificField(field, object, SHEditorUI::InputInt , &isHovered) || + renderSpecificField(field, object, SHEditorUI::InputInt , &isHovered) || + renderSpecificField(field, object, SHEditorUI::InputInt , &isHovered) || + renderSpecificField(field, object, SHEditorUI::InputCheckbox, &isHovered) || + renderSpecificField(field, object, SHEditorUI::InputFloat , &isHovered) || + renderSpecificField(field, object, SHEditorUI::InputDouble , &isHovered) || + renderSpecificField(field, object, SHEditorUI::InputVec2 , &isHovered) || + 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) || + renderSpecificField(field, object, nullptr , &isHovered); if (!MODIFIED_PRIMITIVE) { @@ -323,24 +327,26 @@ namespace SHADE bool modified; const bool RENDERED = - renderFieldEditor(fieldName, object, SHEditorUI::InputInt , nullptr, rangeAttrib, modified) || - renderFieldEditor(fieldName, object, SHEditorUI::InputInt , nullptr, rangeAttrib, modified) || - renderFieldEditor(fieldName, object, SHEditorUI::InputInt , nullptr, rangeAttrib, modified) || - renderFieldEditor(fieldName, object, SHEditorUI::InputInt , nullptr, rangeAttrib, modified) || - renderFieldEditor(fieldName, object, SHEditorUI::InputInt , nullptr, rangeAttrib, modified) || - renderFieldEditor(fieldName, object, SHEditorUI::InputInt , nullptr, rangeAttrib, modified) || - renderFieldEditor(fieldName, object, SHEditorUI::InputInt , nullptr, rangeAttrib, modified) || - renderFieldEditor(fieldName, object, SHEditorUI::InputCheckbox, nullptr, rangeAttrib, modified) || - renderFieldEditor(fieldName, object, SHEditorUI::InputFloat , nullptr, rangeAttrib, modified) || - renderFieldEditor(fieldName, object, SHEditorUI::InputDouble , nullptr, rangeAttrib, modified) || - renderFieldEditor(fieldName, object, SHEditorUI::InputVec2 , nullptr, rangeAttrib, modified) || - 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, SHEditorUI::InputInt , nullptr, rangeAttrib, modified) || + renderFieldEditor(fieldName, object, SHEditorUI::InputInt , nullptr, rangeAttrib, modified) || + renderFieldEditor(fieldName, object, SHEditorUI::InputInt , nullptr, rangeAttrib, modified) || + renderFieldEditor(fieldName, object, SHEditorUI::InputInt , nullptr, rangeAttrib, modified) || + renderFieldEditor(fieldName, object, SHEditorUI::InputInt , nullptr, rangeAttrib, modified) || + renderFieldEditor(fieldName, object, SHEditorUI::InputInt , nullptr, rangeAttrib, modified) || + renderFieldEditor(fieldName, object, SHEditorUI::InputInt , nullptr, rangeAttrib, modified) || + renderFieldEditor(fieldName, object, SHEditorUI::InputCheckbox, nullptr, rangeAttrib, modified) || + renderFieldEditor(fieldName, object, SHEditorUI::InputFloat , nullptr, rangeAttrib, modified) || + renderFieldEditor(fieldName, object, SHEditorUI::InputDouble , nullptr, rangeAttrib, modified) || + renderFieldEditor(fieldName, object, SHEditorUI::InputVec2 , nullptr, rangeAttrib, modified) || + 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) || + 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 37d5c27d..6c2e6763 100644 --- a/SHADE_Managed/src/Editor/Editor.h++ +++ b/SHADE_Managed/src/Editor/Editor.h++ @@ -23,6 +23,8 @@ of DigiPen Institute of Technology is prohibited. #include "Assets/FontAsset.hxx" #include "Assets/MeshAsset.hxx" #include "Assets/MaterialAsset.hxx" +#include "Assets/RigAsset.hxx" +#include "Assets/AnimationClipAsset.hxx" namespace SHADE { @@ -237,6 +239,30 @@ 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::MODEL, isHovered)) + { + *managedValPtr = RigAsset(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::MODEL, isHovered)) + { + *managedValPtr = AnimationClipAsset(assetId); + return true; + } + return false; } } diff --git a/SHADE_Managed/src/Serialisation/SerialisationUtilities.cxx b/SHADE_Managed/src/Serialisation/SerialisationUtilities.cxx index 83da64b8..d6010b96 100644 --- a/SHADE_Managed/src/Serialisation/SerialisationUtilities.cxx +++ b/SHADE_Managed/src/Serialisation/SerialisationUtilities.cxx @@ -22,6 +22,8 @@ of DigiPen Institute of Technology is prohibited. #include "Assets/MaterialAsset.hxx" #include "Assets/MeshAsset.hxx" #include "Scripts/Script.hxx" +#include "Assets/RigAsset.hxx" +#include "Assets/AnimationClipAsset.hxx" /*-------------------------------------------------------------------------------------*/ /* File-Level Constants */ @@ -144,24 +146,26 @@ namespace SHADE YAML::Node fieldNode; // Retrieve string for the YAML - const bool PRIMITIVE_SERIALIZED = 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) || - 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) || - fieldInsertYaml(fieldInfo, object, fieldNode) || - fieldInsertYaml(fieldInfo, object, fieldNode); + const bool PRIMITIVE_SERIALIZED = 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) || + 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) || + fieldInsertYaml(fieldInfo, object, fieldNode) || + fieldInsertYaml(fieldInfo, object, fieldNode) || + fieldInsertYaml(fieldInfo, object, fieldNode) || + fieldInsertYaml(fieldInfo, object, fieldNode); // Serialization of more complex types if (!PRIMITIVE_SERIALIZED) @@ -208,24 +212,26 @@ namespace SHADE bool SerialisationUtilities::varInsertYaml(System::Object^ object, YAML::Node& fieldNode) { const bool INSERTED = - varInsertYamlInternal(object, fieldNode) || - varInsertYamlInternal(object, fieldNode) || - varInsertYamlInternal(object, fieldNode) || - varInsertYamlInternal(object, fieldNode) || - varInsertYamlInternal(object, fieldNode) || - varInsertYamlInternal(object, fieldNode) || - varInsertYamlInternal(object, fieldNode) || - varInsertYamlInternal(object, fieldNode) || - varInsertYamlInternal(object, fieldNode) || - varInsertYamlInternal(object, fieldNode) || - varInsertYamlInternal(object, fieldNode) || - varInsertYamlInternal(object, fieldNode) || - varInsertYamlInternal(object, fieldNode) || - varInsertYamlInternal(object, fieldNode) || - varInsertYamlInternal(object, fieldNode) || - varInsertYamlInternal(object, fieldNode) || - varInsertYamlInternal(object, fieldNode) || - varInsertYamlInternal(object, fieldNode); + varInsertYamlInternal(object, fieldNode) || + varInsertYamlInternal(object, fieldNode) || + varInsertYamlInternal(object, fieldNode) || + varInsertYamlInternal(object, fieldNode) || + varInsertYamlInternal(object, fieldNode) || + varInsertYamlInternal(object, fieldNode) || + varInsertYamlInternal(object, fieldNode) || + varInsertYamlInternal(object, fieldNode) || + varInsertYamlInternal(object, fieldNode) || + varInsertYamlInternal(object, fieldNode) || + varInsertYamlInternal(object, fieldNode) || + varInsertYamlInternal(object, fieldNode) || + 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; } @@ -235,24 +241,26 @@ namespace SHADE bool SerialisationUtilities::writeYamlIntoField(System::Reflection::FieldInfo^ fieldInfo, Object^ object, YAML::Node& node) { const bool ASSIGNED = - 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) || - 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) || - 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) || + 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) || + 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)) @@ -309,24 +317,26 @@ namespace SHADE bool SerialisationUtilities::varAssignYaml(System::Object^% object, YAML::Node& node) { const bool DESERIALISED = - varAssignYamlInternal (object, node) || - varAssignYamlInternal (object, node) || - varAssignYamlInternal (object, node) || - varAssignYamlInternal(object, node) || - varAssignYamlInternal(object, node) || - varAssignYamlInternal(object, node) || - varAssignYamlInternal (object, node) || - varAssignYamlInternal (object, node) || - varAssignYamlInternal (object, node) || - varAssignYamlInternal (object, node) || - varAssignYamlInternal (object, node) || - varAssignYamlInternal(object, node) || - varAssignYamlInternal (object, node) || - varAssignYamlInternal (object, node) || - varAssignYamlInternal (object, node) || - varAssignYamlInternal (object, node) || - varAssignYamlInternal (object, node) || - varAssignYamlInternal (object, node); + varAssignYamlInternal (object, node) || + varAssignYamlInternal (object, node) || + varAssignYamlInternal (object, node) || + varAssignYamlInternal (object, node) || + varAssignYamlInternal (object, node) || + varAssignYamlInternal (object, node) || + varAssignYamlInternal (object, node) || + varAssignYamlInternal (object, node) || + varAssignYamlInternal (object, node) || + varAssignYamlInternal (object, node) || + varAssignYamlInternal (object, node) || + varAssignYamlInternal (object, node) || + 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 d2043f6b..f93293de 100644 --- a/SHADE_Managed/src/Serialisation/SerialisationUtilities.h++ +++ b/SHADE_Managed/src/Serialisation/SerialisationUtilities.h++ @@ -60,9 +60,11 @@ namespace SHADE { fieldNode = MAX_EID; } - else if constexpr (std::is_same_v || + else if constexpr (std::is_same_v || std::is_same_v || - std::is_same_v) + std::is_same_v || + std::is_same_v || + std::is_same_v) { fieldNode = INVALID_ASSET_ID; } @@ -130,7 +132,9 @@ namespace SHADE } else if constexpr (std::is_same_v || std::is_same_v || - std::is_same_v) + std::is_same_v || + std::is_same_v || + std::is_same_v) { if (object->GetType() == FieldType::typeid) { @@ -256,7 +260,9 @@ namespace SHADE } else if constexpr (std::is_same_v || std::is_same_v || - std::is_same_v) + std::is_same_v || + std::is_same_v || + std::is_same_v) { if (object->GetType() == FieldType::typeid) {