diff --git a/Source/Core/Loader/ERS_ModelLoader/ERS_CLASS_ModelLoader.cpp b/Source/Core/Loader/ERS_ModelLoader/ERS_CLASS_ModelLoader.cpp index 20c4d6d235..d3f387b854 100644 --- a/Source/Core/Loader/ERS_ModelLoader/ERS_CLASS_ModelLoader.cpp +++ b/Source/Core/Loader/ERS_ModelLoader/ERS_CLASS_ModelLoader.cpp @@ -132,6 +132,10 @@ void ERS_CLASS_ModelLoader::ProcessNewModels(ERS_STRUCT_Scene* ActiveScene) { } +void ERS_CLASS_ModelLoader::AddModelToLoadingQueue(std::shared_ptr Model) { + AddModelToLoadingQueue(Model->AssetID, Model); +} + void ERS_CLASS_ModelLoader::AddModelToLoadingQueue(long AssetID, std::shared_ptr Model) { // Log Addition diff --git a/Source/Core/Loader/ERS_ModelLoader/ERS_CLASS_ModelLoader.h b/Source/Core/Loader/ERS_ModelLoader/ERS_CLASS_ModelLoader.h index 9689d2afbe..b00d78aa83 100644 --- a/Source/Core/Loader/ERS_ModelLoader/ERS_CLASS_ModelLoader.h +++ b/Source/Core/Loader/ERS_ModelLoader/ERS_CLASS_ModelLoader.h @@ -200,6 +200,7 @@ class ERS_CLASS_ModelLoader { * @param FlipTextures */ void AddModelToLoadingQueue(long AssetID, std::shared_ptr Model); + void AddModelToLoadingQueue(std::shared_ptr Model); diff --git a/Source/Core/Loader/ERS_SceneLoader/CMakeLists.txt b/Source/Core/Loader/ERS_SceneLoader/CMakeLists.txt index c0e4acc623..16fd395363 100644 --- a/Source/Core/Loader/ERS_SceneLoader/CMakeLists.txt +++ b/Source/Core/Loader/ERS_SceneLoader/CMakeLists.txt @@ -8,9 +8,19 @@ add_library(ERS_SceneLoader # Add Source Files (.cpp) "ERS_SceneLoader.cpp" + "ERS_FUNCTION_YAMLHelpers.cpp" + "ERS_FUNCTION_SceneDecoderManager.cpp" + "ERS_FUNCTION_SceneDecoderV1.cpp" + "ERS_FUNCTION_SceneDecoderV2.cpp" + "ERS_FUNCTION_SceneDecoderV3.cpp" # Add Header Files (.h) "ERS_SceneLoader.h" + "ERS_FUNCTION_YAMLHelpers.h" + "ERS_FUNCTION_SceneDecoderManager.h" + "ERS_FUNCTION_SceneDecoderV1.h" + "ERS_FUNCTION_SceneDecoderV2.h" + "ERS_FUNCTION_SceneDecoderV3.h" ${BACKWARD_ENABLE} ) diff --git a/Source/Core/Loader/ERS_SceneLoader/ERS_FUNCTION_SceneDecoderManager.cpp b/Source/Core/Loader/ERS_SceneLoader/ERS_FUNCTION_SceneDecoderManager.cpp new file mode 100644 index 0000000000..78529b2248 --- /dev/null +++ b/Source/Core/Loader/ERS_SceneLoader/ERS_FUNCTION_SceneDecoderManager.cpp @@ -0,0 +1,39 @@ +//======================================================================// +// This file is part of the BrainGenix-ERS Environment Rendering System // +//======================================================================// + +#include + + + + +bool ERS_FUNCTION_DecodeScene(YAML::Node SceneData, ERS_STRUCT_Scene *Scene, ERS_STRUCT_SystemUtils *SystemUtils, ERS_CLASS_ModelLoader* ModelLoader, bool LogEnable) { + + SystemUtils->Logger_->Log("Decoding ERS Scene", 5, LogEnable); + + // Extract Current Version + int Version = 0; + SystemUtils->Logger_->Log("Identifying Scene Format Version", 4, LogEnable); + if (SceneData["SceneFormatVersion"]) { + Version = SceneData["SceneFormatVersion"].as(); + } else { + SystemUtils->Logger_->Log("Unable To Find Metadata Tag For 'SceneFormatVersion', Unable To Identify Version", 9); + return false; + } + + // Attempt Decoding With Known Decoding Systems + if (Version == 1) { + SystemUtils->Logger_->Log("Detected Scene Format To Be Version 1, Starting Decoding Process", 4, LogEnable); + return ERS_FUNCTION_DecodeSceneV1(SceneData, Scene, SystemUtils, ModelLoader, LogEnable); + } else if (Version == 2) { + SystemUtils->Logger_->Log("Detected Scene Format To Be Version 2, Starting Decoding Process", 4, LogEnable); + return ERS_FUNCTION_DecodeSceneV2(SceneData, Scene, SystemUtils, ModelLoader, LogEnable); + } else if (Version == 3) { + SystemUtils->Logger_->Log("Detected Scene Format To Be Version 3, Starting Decoding Process", 4, LogEnable); + return ERS_FUNCTION_DecodeSceneV3(SceneData, Scene, SystemUtils, ModelLoader, LogEnable); + } else { + SystemUtils->Logger_->Log("Scene Format Has Unknown Version, Aborting Load", 8); + return false; + } + +} \ No newline at end of file diff --git a/Source/Core/Loader/ERS_SceneLoader/ERS_FUNCTION_SceneDecoderManager.h b/Source/Core/Loader/ERS_SceneLoader/ERS_FUNCTION_SceneDecoderManager.h new file mode 100644 index 0000000000..6ffc668bd4 --- /dev/null +++ b/Source/Core/Loader/ERS_SceneLoader/ERS_FUNCTION_SceneDecoderManager.h @@ -0,0 +1,35 @@ +//======================================================================// +// This file is part of the BrainGenix-ERS Environment Rendering System // +//======================================================================// + +#pragma once + +// Standard Libraries (BG convention: use <> instead of "") +#include +#include + +// Third-Party Libraries (BG convention: use <> instead of "") +#include + +// Internal Libraries (BG convention: use <> instead of "") +#include +#include + +#include + +#include +#include +#include + + +/** + * @brief Attempts to decode the scene data passed in. Will check against known format versions and decode if it's a known format. + * + * @param SceneData YAML::Node containing the scene data. + * @param Scene Pointer to the scene to be updated. + * @param SystemUtils Pointer to the systemutils struct. + * @param LogEnable Enable or disable information log messages. + * @return true Loading completed without errors. + * @return false Loading failed. + */ +bool ERS_FUNCTION_DecodeScene(YAML::Node SceneData, ERS_STRUCT_Scene *Scene, ERS_STRUCT_SystemUtils *SystemUtils, ERS_CLASS_ModelLoader* ModelLoader, bool LogEnable = true); \ No newline at end of file diff --git a/Source/Core/Loader/ERS_SceneLoader/ERS_FUNCTION_SceneDecoderV1.cpp b/Source/Core/Loader/ERS_SceneLoader/ERS_FUNCTION_SceneDecoderV1.cpp new file mode 100644 index 0000000000..e52e184403 --- /dev/null +++ b/Source/Core/Loader/ERS_SceneLoader/ERS_FUNCTION_SceneDecoderV1.cpp @@ -0,0 +1,107 @@ +//======================================================================// +// This file is part of the BrainGenix-ERS Environment Rendering System // +//======================================================================// + +#include + + + +bool ERS_FUNCTION_DecodeSceneV1(YAML::Node SceneData, ERS_STRUCT_Scene *Scene, ERS_STRUCT_SystemUtils *SystemUtils, ERS_CLASS_ModelLoader* ModelLoader, bool LogEnable) { + + // Init + bool Success = true; + SystemUtils->Logger_->Log(std::string("Processing Scene '") + Scene->SceneName + "' With Decoder Version 1", 3, LogEnable); + ERS_CLASS_LoggingSystem* Logger = SystemUtils->Logger_.get(); + + // Grab Metadata + std::vector SceneItems; + Success &= ERS_FUNCTION_GetLong (Logger, SceneData, "SceneFormatVersion", Scene->SceneFormatVersion ); + Success &= ERS_FUNCTION_GetString (Logger, SceneData, "SceneName", Scene->SceneName ); + Success &= ERS_FUNCTION_GetNodeVector (Logger, SceneData, "SceneData", SceneItems ); + + // Iterate Through Vector To Add Each Asset To Loading Queue Of Requested Type + for (long i = 0; (long)i < (long)SceneItems.size(); i++) { + + // Get Asset Information + YAML::Node Item = SceneItems[i]; + std::string AssetName, AssetType; + Success &= ERS_FUNCTION_GetString(Logger, Item, "AssetName", AssetName); + Success &= ERS_FUNCTION_GetString(Logger, Item, "AssetType", AssetType); + + + if (AssetType == "Model") { + + ERS_STRUCT_Model Model; + Success &= ERS_FUNCTION_GetLong (Logger, Item, "AssetID", Model.AssetID ); + Success &= ERS_FUNCTION_GetVec3 (Logger, Item, "AssetPosition", Model.ModelPosition ); + Success &= ERS_FUNCTION_GetVec3 (Logger, Item, "AssetRotation", Model.ModelRotation ); + Success &= ERS_FUNCTION_GetVec3 (Logger, Item, "AssetScale", Model.ModelScale ); + Success &= ERS_FUNCTION_GetBool (Logger, Item, "CastDynamicShadows", Model.CastDynamicShadows_ ); + Success &= ERS_FUNCTION_GetBool (Logger, Item, "CastStaticShadows", Model.CastStaticShadows_ ); + Success &= ERS_FUNCTION_GetBool (Logger, Item, "ReceiveShadows", Model.ReceiveShadows_ ); + Success &= ERS_FUNCTION_GetLong (Logger, Item, "ShaderOverrideIndex", Model.ShaderOverrideIndex_ ); + Success &= ERS_FUNCTION_GetString (Logger, Item, "AssetName", Model.Name ); + Success &= ERS_FUNCTION_GetLongVector (Logger, Item, "AttachedScripts", Model.AttachedScriptIndexes_ ); + + Scene->Models.push_back(std::make_shared(Model)); + ModelLoader->AddModelToLoadingQueue(Scene->Models[Scene->Models.size()-1]); + Scene->Models[Scene->Models.size()-1]->ApplyTransformations(); + + } else if (AssetType == std::string("DirectionalLight")) { + + ERS_STRUCT_DirectionalLight Light; + Success &= ERS_FUNCTION_GetString (Logger, Item, "AssetName", Light.UserDefinedName ); + Success &= ERS_FUNCTION_GetVec3Color (Logger, Item, "Color", Light.Color ); + Success &= ERS_FUNCTION_GetVec3 (Logger, Item, "Pos", Light.Pos ); + Success &= ERS_FUNCTION_GetVec3 (Logger, Item, "Rot", Light.Rot ); + Success &= ERS_FUNCTION_GetFloat (Logger, Item, "Intensity", Light.Intensity ); + Success &= ERS_FUNCTION_GetFloat (Logger, Item, "MaxDistance", Light.MaxDistance ); + Success &= ERS_FUNCTION_GetBool (Logger, Item, "CastShadows", Light.CastsShadows_ ); + Success &= ERS_FUNCTION_GetLongVector (Logger, Item, "AttachedScripts", Light.AttachedScriptIndexes_ ); + Scene->DirectionalLights.push_back(std::make_shared(Light)); + + } else if (AssetType == std::string("PointLight")) { + + ERS_STRUCT_PointLight Light; + Success &= ERS_FUNCTION_GetString (Logger, Item, "AssetName", Light.UserDefinedName ); + Success &= ERS_FUNCTION_GetVec3Color (Logger, Item, "Color", Light.Color ); + Success &= ERS_FUNCTION_GetVec3 (Logger, Item, "Pos", Light.Pos ); + Success &= ERS_FUNCTION_GetFloat (Logger, Item, "Intensity", Light.Intensity ); + Success &= ERS_FUNCTION_GetFloat (Logger, Item, "MaxDistance", Light.MaxDistance ); + Success &= ERS_FUNCTION_GetBool (Logger, Item, "CastShadows", Light.CastsShadows_ ); + Success &= ERS_FUNCTION_GetLongVector (Logger, Item, "AttachedScripts", Light.AttachedScriptIndexes_ ); + Scene->PointLights.push_back(std::make_shared(Light)); + + } else if (AssetType == std::string("SpotLight")) { + + ERS_STRUCT_SpotLight Light; + Success &= ERS_FUNCTION_GetString (Logger, Item, "AssetName", Light.UserDefinedName ); + Success &= ERS_FUNCTION_GetVec3Color (Logger, Item, "Color", Light.Color ); + Success &= ERS_FUNCTION_GetVec3 (Logger, Item, "Pos", Light.Pos ); + Success &= ERS_FUNCTION_GetVec3 (Logger, Item, "Rot", Light.Rot ); + Success &= ERS_FUNCTION_GetFloat (Logger, Item, "Intensity", Light.Intensity ); + Success &= ERS_FUNCTION_GetFloat (Logger, Item, "MaxDistance", Light.MaxDistance ); + Success &= ERS_FUNCTION_GetFloat (Logger, Item, "CutOff", Light.CutOff ); + Success &= ERS_FUNCTION_GetFloat (Logger, Item, "RollOff", Light.Rolloff ); + Success &= ERS_FUNCTION_GetBool (Logger, Item, "CastShadows", Light.CastsShadows_ ); + Success &= ERS_FUNCTION_GetLongVector (Logger, Item, "AttachedScripts", Light.AttachedScriptIndexes_ ); + Scene->SpotLights.push_back(std::make_shared(Light)); + + } else { + SystemUtils->Logger_->Log(std::string("Unsupported/Unknown Asset Type: ") + AssetType, 9); + } + + } + + // Indicate Scene Is Loaded + if (!Success) { + SystemUtils->Logger_->Log("Scene Decoding Failed", 8); + } else { + SystemUtils->Logger_->Log("Finished Decoding Scene", 4); + } + Scene->IsSceneLoaded = Success; + return Success; + +} + + diff --git a/Source/Core/Loader/ERS_SceneLoader/ERS_FUNCTION_SceneDecoderV1.h b/Source/Core/Loader/ERS_SceneLoader/ERS_FUNCTION_SceneDecoderV1.h new file mode 100644 index 0000000000..386a783666 --- /dev/null +++ b/Source/Core/Loader/ERS_SceneLoader/ERS_FUNCTION_SceneDecoderV1.h @@ -0,0 +1,40 @@ +//======================================================================// +// This file is part of the BrainGenix-ERS Environment Rendering System // +//======================================================================// + +#pragma once + +// Standard Libraries (BG convention: use <> instead of "") +#include +#include + +// Third-Party Libraries (BG convention: use <> instead of "") +#include + +// Internal Libraries (BG convention: use <> instead of "") +#include +#include +#include +#include +#include +#include +#include + +#include + +#include + + + + +/** + * @brief Decodes the specified version of the scene format. + * + * @param SceneData YAML::Node containing the scene data. + * @param Scene Pointer to the scene to be updated. + * @param SystemUtils Pointer to the systemutils struct. + * @param LogEnable Enable or disable information log messages. + * @return true Loading completed without errors. + * @return false Loading failed. + */ +bool ERS_FUNCTION_DecodeSceneV1(YAML::Node SceneData, ERS_STRUCT_Scene *Scene, ERS_STRUCT_SystemUtils *SystemUtils, ERS_CLASS_ModelLoader* ModelLoader, bool LogEnable = true); \ No newline at end of file diff --git a/Source/Core/Loader/ERS_SceneLoader/ERS_FUNCTION_SceneDecoderV2.cpp b/Source/Core/Loader/ERS_SceneLoader/ERS_FUNCTION_SceneDecoderV2.cpp new file mode 100644 index 0000000000..fab207f9a6 --- /dev/null +++ b/Source/Core/Loader/ERS_SceneLoader/ERS_FUNCTION_SceneDecoderV2.cpp @@ -0,0 +1,127 @@ +//======================================================================// +// This file is part of the BrainGenix-ERS Environment Rendering System // +//======================================================================// + +#include + + +//======================================================================// +// This file is part of the BrainGenix-ERS Environment Rendering System // +//======================================================================// + +#include + + + +bool ERS_FUNCTION_DecodeSceneV2(YAML::Node SceneData, ERS_STRUCT_Scene *Scene, ERS_STRUCT_SystemUtils *SystemUtils, ERS_CLASS_ModelLoader* ModelLoader, bool LogEnable) { + + // Init + bool Success = true; + SystemUtils->Logger_->Log(std::string("Processing Scene '") + Scene->SceneName + "' With Decoder Version 2", 3, LogEnable); + ERS_CLASS_LoggingSystem* Logger = SystemUtils->Logger_.get(); + + // Grab Metadata + std::vector SceneItems; + Success &= ERS_FUNCTION_GetLong (Logger, SceneData, "SceneFormatVersion", Scene->SceneFormatVersion ); + Success &= ERS_FUNCTION_GetString (Logger, SceneData, "SceneName", Scene->SceneName ); + Success &= ERS_FUNCTION_GetInt (Logger, SceneData, "ActiveCameraIndex", Scene->ActiveSceneCameraIndex ); + Success &= ERS_FUNCTION_GetNodeVector (Logger, SceneData, "SceneData", SceneItems ); + + // Iterate Through Vector To Add Each Asset To Loading Queue Of Requested Type + for (long i = 0; (long)i < (long)SceneItems.size(); i++) { + + // Get Asset Information + YAML::Node Item = SceneItems[i]; + std::string AssetName, AssetType; + Success &= ERS_FUNCTION_GetString(Logger, Item, "AssetName", AssetName); + Success &= ERS_FUNCTION_GetString(Logger, Item, "AssetType", AssetType); + + + if (AssetType == "Model") { + + ERS_STRUCT_Model Model; + Success &= ERS_FUNCTION_GetLong (Logger, Item, "AssetID", Model.AssetID ); + Success &= ERS_FUNCTION_GetVec3 (Logger, Item, "AssetPosition", Model.ModelPosition ); + Success &= ERS_FUNCTION_GetVec3 (Logger, Item, "AssetRotation", Model.ModelRotation ); + Success &= ERS_FUNCTION_GetVec3 (Logger, Item, "AssetScale", Model.ModelScale ); + Success &= ERS_FUNCTION_GetBool (Logger, Item, "CastDynamicShadows", Model.CastDynamicShadows_ ); + Success &= ERS_FUNCTION_GetBool (Logger, Item, "CastStaticShadows", Model.CastStaticShadows_ ); + Success &= ERS_FUNCTION_GetBool (Logger, Item, "ReceiveShadows", Model.ReceiveShadows_ ); + Success &= ERS_FUNCTION_GetLong (Logger, Item, "ShaderOverrideIndex", Model.ShaderOverrideIndex_ ); + Success &= ERS_FUNCTION_GetString (Logger, Item, "AssetName", Model.Name ); + Success &= ERS_FUNCTION_GetLongVector (Logger, Item, "AttachedScripts", Model.AttachedScriptIndexes_ ); + + Scene->Models.push_back(std::make_shared(Model)); + ModelLoader->AddModelToLoadingQueue(Scene->Models[Scene->Models.size()-1]); + Scene->Models[Scene->Models.size()-1]->ApplyTransformations(); + + } else if (AssetType == std::string("DirectionalLight")) { + + ERS_STRUCT_DirectionalLight Light; + Success &= ERS_FUNCTION_GetString (Logger, Item, "AssetName", Light.UserDefinedName ); + Success &= ERS_FUNCTION_GetVec3Color (Logger, Item, "Color", Light.Color ); + Success &= ERS_FUNCTION_GetVec3 (Logger, Item, "Pos", Light.Pos ); + Success &= ERS_FUNCTION_GetVec3 (Logger, Item, "Rot", Light.Rot ); + Success &= ERS_FUNCTION_GetFloat (Logger, Item, "Intensity", Light.Intensity ); + Success &= ERS_FUNCTION_GetFloat (Logger, Item, "MaxDistance", Light.MaxDistance ); + Success &= ERS_FUNCTION_GetBool (Logger, Item, "CastShadows", Light.CastsShadows_ ); + Success &= ERS_FUNCTION_GetLongVector (Logger, Item, "AttachedScripts", Light.AttachedScriptIndexes_ ); + Scene->DirectionalLights.push_back(std::make_shared(Light)); + + } else if (AssetType == std::string("PointLight")) { + + ERS_STRUCT_PointLight Light; + Success &= ERS_FUNCTION_GetString (Logger, Item, "AssetName", Light.UserDefinedName ); + Success &= ERS_FUNCTION_GetVec3Color (Logger, Item, "Color", Light.Color ); + Success &= ERS_FUNCTION_GetVec3 (Logger, Item, "Pos", Light.Pos ); + Success &= ERS_FUNCTION_GetFloat (Logger, Item, "Intensity", Light.Intensity ); + Success &= ERS_FUNCTION_GetFloat (Logger, Item, "MaxDistance", Light.MaxDistance ); + Success &= ERS_FUNCTION_GetBool (Logger, Item, "CastShadows", Light.CastsShadows_ ); + Success &= ERS_FUNCTION_GetLongVector (Logger, Item, "AttachedScripts", Light.AttachedScriptIndexes_ ); + Scene->PointLights.push_back(std::make_shared(Light)); + + } else if (AssetType == std::string("SpotLight")) { + + ERS_STRUCT_SpotLight Light; + Success &= ERS_FUNCTION_GetString (Logger, Item, "AssetName", Light.UserDefinedName ); + Success &= ERS_FUNCTION_GetVec3Color (Logger, Item, "Color", Light.Color ); + Success &= ERS_FUNCTION_GetVec3 (Logger, Item, "Pos", Light.Pos ); + Success &= ERS_FUNCTION_GetVec3 (Logger, Item, "Rot", Light.Rot ); + Success &= ERS_FUNCTION_GetFloat (Logger, Item, "Intensity", Light.Intensity ); + Success &= ERS_FUNCTION_GetFloat (Logger, Item, "MaxDistance", Light.MaxDistance ); + Success &= ERS_FUNCTION_GetFloat (Logger, Item, "CutOff", Light.CutOff ); + Success &= ERS_FUNCTION_GetFloat (Logger, Item, "RollOff", Light.Rolloff ); + Success &= ERS_FUNCTION_GetBool (Logger, Item, "CastShadows", Light.CastsShadows_ ); + Success &= ERS_FUNCTION_GetLongVector (Logger, Item, "AttachedScripts", Light.AttachedScriptIndexes_ ); + Scene->SpotLights.push_back(std::make_shared(Light)); + + } else if (AssetType == std::string("SceneCamera")) { + + ERS_STRUCT_SceneCamera Camera; + Success &= ERS_FUNCTION_GetString (Logger, Item, "AssetName", Camera.UserDefinedName_ ); + Success &= ERS_FUNCTION_GetVec3 (Logger, Item, "Pos", Camera.Pos_ ); + Success &= ERS_FUNCTION_GetVec3 (Logger, Item, "Rot", Camera.Rot_ ); + Success &= ERS_FUNCTION_GetFloat (Logger, Item, "NearClip", Camera.NearClip_ ); + Success &= ERS_FUNCTION_GetFloat (Logger, Item, "FarClip", Camera.FarClip_ ); + Success &= ERS_FUNCTION_GetFloat (Logger, Item, "FOV", Camera.FOV_ ); + Success &= ERS_FUNCTION_GetBool (Logger, Item, "EnforceAspectRatio", Camera.EnforceAspectRatio_ ); + Success &= ERS_FUNCTION_GetFloat (Logger, Item, "AspectRatio", Camera.AspectRatio_ ); + Success &= ERS_FUNCTION_GetInt (Logger, Item, "StreamingPriority", Camera.StreamingPriority_ ); + Success &= ERS_FUNCTION_GetLongVector (Logger, Item, "AttachedScripts", Camera.AttachedScriptIndexes_ ); + Scene->SceneCameras.push_back(std::make_shared(Camera)); + + } else { + SystemUtils->Logger_->Log(std::string("Unsupported/Unknown Asset Type: ") + AssetType, 9); + } + + } + + // Indicate Scene Is Loaded + if (!Success) { + SystemUtils->Logger_->Log("Scene Decoding Failed", 8); + } else { + SystemUtils->Logger_->Log("Finished Decoding Scene", 4); + } + Scene->IsSceneLoaded = Success; + return Success; +} \ No newline at end of file diff --git a/Source/Core/Loader/ERS_SceneLoader/ERS_FUNCTION_SceneDecoderV2.h b/Source/Core/Loader/ERS_SceneLoader/ERS_FUNCTION_SceneDecoderV2.h new file mode 100644 index 0000000000..c8901ddd19 --- /dev/null +++ b/Source/Core/Loader/ERS_SceneLoader/ERS_FUNCTION_SceneDecoderV2.h @@ -0,0 +1,40 @@ +//======================================================================// +// This file is part of the BrainGenix-ERS Environment Rendering System // +//======================================================================// + +#pragma once + +// Standard Libraries (BG convention: use <> instead of "") +#include +#include + +// Third-Party Libraries (BG convention: use <> instead of "") +#include + +// Internal Libraries (BG convention: use <> instead of "") +#include +#include +#include +#include +#include +#include +#include + +#include + +#include + + + + +/** + * @brief Decodes the specified version of the scene format. + * + * @param SceneData YAML::Node containing the scene data. + * @param Scene Pointer to the scene to be updated. + * @param SystemUtils Pointer to the systemutils struct. + * @param LogEnable Enable or disable information log messages. + * @return true Loading completed without errors. + * @return false Loading failed. + */ +bool ERS_FUNCTION_DecodeSceneV2(YAML::Node SceneData, ERS_STRUCT_Scene *Scene, ERS_STRUCT_SystemUtils *SystemUtils, ERS_CLASS_ModelLoader* ModelLoader, bool LogEnable = true); \ No newline at end of file diff --git a/Source/Core/Loader/ERS_SceneLoader/ERS_FUNCTION_SceneDecoderV3.cpp b/Source/Core/Loader/ERS_SceneLoader/ERS_FUNCTION_SceneDecoderV3.cpp new file mode 100644 index 0000000000..d7cfda3758 --- /dev/null +++ b/Source/Core/Loader/ERS_SceneLoader/ERS_FUNCTION_SceneDecoderV3.cpp @@ -0,0 +1,126 @@ +//======================================================================// +// This file is part of the BrainGenix-ERS Environment Rendering System // +//======================================================================// + +#include + + +bool ERS_FUNCTION_DecodeSceneV3(YAML::Node SceneData, ERS_STRUCT_Scene *Scene, ERS_STRUCT_SystemUtils *SystemUtils, ERS_CLASS_ModelLoader* ModelLoader, bool LogEnable) { + + // Init + bool Success = true; + SystemUtils->Logger_->Log(std::string("Processing Scene '") + Scene->SceneName + "' With Decoder Version 3", 3, LogEnable); + ERS_CLASS_LoggingSystem* Logger = SystemUtils->Logger_.get(); + + // Grab Metadata + std::vector Models, PointLights, SpotLights, DirectionalLights, SceneCameras; + Success &= ERS_FUNCTION_GetLong (Logger, SceneData, "SceneFormatVersion", Scene->SceneFormatVersion ); + Success &= ERS_FUNCTION_GetString (Logger, SceneData, "SceneName", Scene->SceneName ); + Success &= ERS_FUNCTION_GetInt (Logger, SceneData, "ActiveCameraIndex", Scene->ActiveSceneCameraIndex ); + Success &= ERS_FUNCTION_GetNodeVector (Logger, SceneData, "Models", Models ); + Success &= ERS_FUNCTION_GetNodeVector (Logger, SceneData, "PointLights", PointLights ); + Success &= ERS_FUNCTION_GetNodeVector (Logger, SceneData, "SpotLights", SpotLights ); + Success &= ERS_FUNCTION_GetNodeVector (Logger, SceneData, "DirectionalLights", DirectionalLights ); + Success &= ERS_FUNCTION_GetNodeVector (Logger, SceneData, "SceneCameras", SceneCameras ); + + + for (unsigned int i = 0; i < Models.size(); i++) { + + YAML::Node Item = Models[i]; + ERS_STRUCT_Model Model; + Success &= ERS_FUNCTION_GetLong (Logger, Item, "AssetID", Model.AssetID ); + Success &= ERS_FUNCTION_GetVec3 (Logger, Item, "AssetPosition", Model.ModelPosition ); + Success &= ERS_FUNCTION_GetVec3 (Logger, Item, "AssetRotation", Model.ModelRotation ); + Success &= ERS_FUNCTION_GetVec3 (Logger, Item, "AssetScale", Model.ModelScale ); + Success &= ERS_FUNCTION_GetBool (Logger, Item, "CastDynamicShadows", Model.CastDynamicShadows_ ); + Success &= ERS_FUNCTION_GetBool (Logger, Item, "CastStaticShadows", Model.CastStaticShadows_ ); + Success &= ERS_FUNCTION_GetBool (Logger, Item, "ReceiveShadows", Model.ReceiveShadows_ ); + Success &= ERS_FUNCTION_GetLong (Logger, Item, "ShaderOverrideIndex", Model.ShaderOverrideIndex_ ); + Success &= ERS_FUNCTION_GetString (Logger, Item, "AssetName", Model.Name ); + Success &= ERS_FUNCTION_GetLongVector (Logger, Item, "AttachedScripts", Model.AttachedScriptIndexes_ ); + + Scene->Models.push_back(std::make_shared(Model)); + ModelLoader->AddModelToLoadingQueue(Scene->Models[Scene->Models.size()-1]); + Scene->Models[Scene->Models.size()-1]->ApplyTransformations(); + + } + + for (unsigned int i = 0; i < PointLights.size(); i++) { + + YAML::Node Item = Models[i]; + ERS_STRUCT_PointLight Light; + Success &= ERS_FUNCTION_GetString (Logger, Item, "AssetName", Light.UserDefinedName ); + Success &= ERS_FUNCTION_GetVec3Color (Logger, Item, "Color", Light.Color ); + Success &= ERS_FUNCTION_GetVec3 (Logger, Item, "Pos", Light.Pos ); + Success &= ERS_FUNCTION_GetFloat (Logger, Item, "Intensity", Light.Intensity ); + Success &= ERS_FUNCTION_GetFloat (Logger, Item, "MaxDistance", Light.MaxDistance ); + Success &= ERS_FUNCTION_GetBool (Logger, Item, "CastShadows", Light.CastsShadows_ ); + Success &= ERS_FUNCTION_GetLongVector (Logger, Item, "AttachedScripts", Light.AttachedScriptIndexes_ ); + Scene->PointLights.push_back(std::make_shared(Light)); + } + + for (unsigned int i = 0; i < SpotLights.size(); i++) { + + YAML::Node Item = Models[i]; + ERS_STRUCT_SpotLight Light; + Success &= ERS_FUNCTION_GetString (Logger, Item, "AssetName", Light.UserDefinedName ); + Success &= ERS_FUNCTION_GetVec3Color (Logger, Item, "Color", Light.Color ); + Success &= ERS_FUNCTION_GetVec3 (Logger, Item, "Pos", Light.Pos ); + Success &= ERS_FUNCTION_GetVec3 (Logger, Item, "Rot", Light.Rot ); + Success &= ERS_FUNCTION_GetFloat (Logger, Item, "Intensity", Light.Intensity ); + Success &= ERS_FUNCTION_GetFloat (Logger, Item, "MaxDistance", Light.MaxDistance ); + Success &= ERS_FUNCTION_GetFloat (Logger, Item, "CutOff", Light.CutOff ); + Success &= ERS_FUNCTION_GetFloat (Logger, Item, "RollOff", Light.Rolloff ); + Success &= ERS_FUNCTION_GetBool (Logger, Item, "CastShadows", Light.CastsShadows_ ); + Success &= ERS_FUNCTION_GetLongVector (Logger, Item, "AttachedScripts", Light.AttachedScriptIndexes_ ); + Scene->SpotLights.push_back(std::make_shared(Light)); + + } + + for (unsigned int i = 0; i < DirectionalLights.size(); i++) { + + YAML::Node Item = Models[i]; + ERS_STRUCT_DirectionalLight Light; + Success &= ERS_FUNCTION_GetString (Logger, Item, "AssetName", Light.UserDefinedName ); + Success &= ERS_FUNCTION_GetVec3Color (Logger, Item, "Color", Light.Color ); + Success &= ERS_FUNCTION_GetVec3 (Logger, Item, "Pos", Light.Pos ); + Success &= ERS_FUNCTION_GetVec3 (Logger, Item, "Rot", Light.Rot ); + Success &= ERS_FUNCTION_GetFloat (Logger, Item, "Intensity", Light.Intensity ); + Success &= ERS_FUNCTION_GetFloat (Logger, Item, "MaxDistance", Light.MaxDistance ); + Success &= ERS_FUNCTION_GetBool (Logger, Item, "CastShadows", Light.CastsShadows_ ); + Success &= ERS_FUNCTION_GetLongVector (Logger, Item, "AttachedScripts", Light.AttachedScriptIndexes_ ); + Scene->DirectionalLights.push_back(std::make_shared(Light)); + + } + + for (unsigned int i = 0; i < SceneCameras.size(); i++) { + + YAML::Node Item = Models[i]; + ERS_STRUCT_SceneCamera Camera; + Success &= ERS_FUNCTION_GetString (Logger, Item, "AssetName", Camera.UserDefinedName_ ); + Success &= ERS_FUNCTION_GetVec3 (Logger, Item, "Pos", Camera.Pos_ ); + Success &= ERS_FUNCTION_GetVec3 (Logger, Item, "Rot", Camera.Rot_ ); + Success &= ERS_FUNCTION_GetFloat (Logger, Item, "NearClip", Camera.NearClip_ ); + Success &= ERS_FUNCTION_GetFloat (Logger, Item, "FarClip", Camera.FarClip_ ); + Success &= ERS_FUNCTION_GetFloat (Logger, Item, "FOV", Camera.FOV_ ); + Success &= ERS_FUNCTION_GetBool (Logger, Item, "EnforceAspectRatio", Camera.EnforceAspectRatio_ ); + Success &= ERS_FUNCTION_GetFloat (Logger, Item, "AspectRatio", Camera.AspectRatio_ ); + Success &= ERS_FUNCTION_GetInt (Logger, Item, "StreamingPriority", Camera.StreamingPriority_ ); + Success &= ERS_FUNCTION_GetLongVector (Logger, Item, "AttachedScripts", Camera.AttachedScriptIndexes_ ); + Scene->SceneCameras.push_back(std::make_shared(Camera)); + + } + + + + // Indicate Scene Is Loaded + if (!Success) { + SystemUtils->Logger_->Log("Scene Decoding Failed", 8); + } else { + SystemUtils->Logger_->Log("Finished Decoding Scene", 4); + } + Scene->IsSceneLoaded = Success; + return Success; +} + + diff --git a/Source/Core/Loader/ERS_SceneLoader/ERS_FUNCTION_SceneDecoderV3.h b/Source/Core/Loader/ERS_SceneLoader/ERS_FUNCTION_SceneDecoderV3.h new file mode 100644 index 0000000000..8cbef93290 --- /dev/null +++ b/Source/Core/Loader/ERS_SceneLoader/ERS_FUNCTION_SceneDecoderV3.h @@ -0,0 +1,40 @@ +//======================================================================// +// This file is part of the BrainGenix-ERS Environment Rendering System // +//======================================================================// + +#pragma once + +// Standard Libraries (BG convention: use <> instead of "") +#include +#include + +// Third-Party Libraries (BG convention: use <> instead of "") +#include + +// Internal Libraries (BG convention: use <> instead of "") +#include +#include +#include +#include +#include +#include +#include + +#include + +#include + + + + +/** + * @brief Decodes the specified version of the scene format. + * + * @param SceneData YAML::Node containing the scene data. + * @param Scene Pointer to the scene to be updated. + * @param SystemUtils Pointer to the systemutils struct. + * @param LogEnable Enable or disable information log messages. + * @return true Loading completed without errors. + * @return false Loading failed. + */ +bool ERS_FUNCTION_DecodeSceneV3(YAML::Node SceneData, ERS_STRUCT_Scene *Scene, ERS_STRUCT_SystemUtils *SystemUtils, ERS_CLASS_ModelLoader* ModelLoader, bool LogEnable = true); \ No newline at end of file diff --git a/Source/Core/Loader/ERS_SceneLoader/ERS_FUNCTION_YAMLHelpers.cpp b/Source/Core/Loader/ERS_SceneLoader/ERS_FUNCTION_YAMLHelpers.cpp new file mode 100644 index 0000000000..ce42fa6247 --- /dev/null +++ b/Source/Core/Loader/ERS_SceneLoader/ERS_FUNCTION_YAMLHelpers.cpp @@ -0,0 +1,223 @@ +//======================================================================// +// This file is part of the BrainGenix-ERS Environment Rendering System // +//======================================================================// + +#include + +// Standart Type Helper Functions +bool ERS_FUNCTION_GetInt(ERS_CLASS_LoggingSystem* Logger, YAML::Node Data, std::string Name, int &Target) { + try { + Target = Data[Name].as(); + return true; + } catch (YAML::TypedBadConversion&) { + Logger->Log(std::string("Failed To Cast Parameter '") + Name + "' To Type 'int'", 8); + return false; + } catch (YAML::KeyNotFound&) { + Logger->Log(std::string("Failed To Find Parameter '") + Name + "'", 7); + return false; + } +} +bool ERS_FUNCTION_GetFloat(ERS_CLASS_LoggingSystem* Logger, YAML::Node Data, std::string Name, float &Target) { + try { + Target = Data[Name].as(); + return true; + } catch (YAML::TypedBadConversion&) { + Logger->Log(std::string("Failed To Cast Parameter '") + Name + "' To Type 'float'", 8); + return false; + } catch (YAML::KeyNotFound&) { + Logger->Log(std::string("Failed To Find Parameter '") + Name + "'", 7); + return false; + } +} +bool ERS_FUNCTION_GetBool(ERS_CLASS_LoggingSystem* Logger, YAML::Node Data, std::string Name, bool &Target) { + try { + Target = Data[Name].as(); + return true; + } catch (YAML::TypedBadConversion&) { + Logger->Log(std::string("Failed To Cast Parameter '") + Name + "' To Type 'bool'", 8); + return false; + } catch (YAML::KeyNotFound&) { + Logger->Log(std::string("Failed To Find Parameter '") + Name + "'", 7); + return false; + } +} +bool ERS_FUNCTION_GetLong(ERS_CLASS_LoggingSystem* Logger, YAML::Node Data, std::string Name, long &Target) { + try { + Target = Data[Name].as(); + return true; + } catch (YAML::TypedBadConversion&) { + Logger->Log(std::string("Failed To Cast Parameter '") + Name + "' To Type 'long'", 8); + return false; + } catch (YAML::KeyNotFound&) { + Logger->Log(std::string("Failed To Find Parameter '") + Name + "'", 7); + return false; + } +} +bool ERS_FUNCTION_GetDouble(ERS_CLASS_LoggingSystem* Logger, YAML::Node Data, std::string Name, double &Target) { + try { + Target = Data[Name].as(); + return true; + } catch (YAML::TypedBadConversion&) { + Logger->Log(std::string("Failed To Cast Parameter '") + Name + "' To Type 'double'", 8); + return false; + } catch (YAML::KeyNotFound&) { + Logger->Log(std::string("Failed To Find Parameter '") + Name + "'", 7); + return false; + } +} +bool ERS_FUNCTION_GetUnsignedInt(ERS_CLASS_LoggingSystem* Logger, YAML::Node Data, std::string Name, unsigned int &Target) { + try { + Target = Data[Name].as(); + return true; + } catch (YAML::TypedBadConversion&) { + Logger->Log(std::string("Failed To Cast Parameter '") + Name + "' To Type 'unsigned int'", 8); + return false; + } catch (YAML::KeyNotFound&) { + Logger->Log(std::string("Failed To Find Parameter '") + Name + "'", 7); + return false; + } +} +bool ERS_FUNCTION_GetBool(ERS_CLASS_LoggingSystem* Logger, YAML::Node Data, std::string Name, unsigned long &Target) { + try { + Target = Data[Name].as(); + return true; + } catch (YAML::TypedBadConversion&) { + Logger->Log(std::string("Failed To Cast Parameter '") + Name + "' To Type 'unsigned long'", 8); + return false; + } catch (YAML::KeyNotFound&) { + Logger->Log(std::string("Failed To Find Parameter '") + Name + "'", 7); + return false; + } +} +bool ERS_FUNCTION_GetLongLong(ERS_CLASS_LoggingSystem* Logger, YAML::Node Data, std::string Name, long long &Target) { + try { + Target = Data[Name].as(); + return true; + } catch (YAML::TypedBadConversion&) { + Logger->Log(std::string("Failed To Cast Parameter '") + Name + "' To Type 'long long'", 8); + return false; + } catch (YAML::KeyNotFound&) { + Logger->Log(std::string("Failed To Find Parameter '") + Name + "'", 7); + return false; + } +} +bool ERS_FUNCTION_GetUnsignedLongLong(ERS_CLASS_LoggingSystem* Logger, YAML::Node Data, std::string Name, unsigned long long &Target) { + try { + Target = Data[Name].as(); + return true; + } catch (YAML::TypedBadConversion&) { + Logger->Log(std::string("Failed To Cast Parameter '") + Name + "' To Type 'unsigned long long'", 8); + return false; + } catch (YAML::KeyNotFound&) { + Logger->Log(std::string("Failed To Find Parameter '") + Name + "'", 7); + return false; + } +} +bool ERS_FUNCTION_GetString(ERS_CLASS_LoggingSystem* Logger, YAML::Node Data, std::string Name, std::string &Target) { + try { + Target = Data[Name].as(); + return true; + } catch (YAML::TypedBadConversion&) { + Logger->Log(std::string("Failed To Cast Parameter '") + Name + "' To Type 'std::string'", 8); + return false; + } catch (YAML::KeyNotFound&) { + Logger->Log(std::string("Failed To Find Parameter '") + Name + "'", 7); + return false; + } +} +bool ERS_FUNCTION_GetNode(ERS_CLASS_LoggingSystem* Logger, YAML::Node Data, std::string Name, YAML::Node &Target) { + try { + Target = Data[Name]; + return true; + } catch (YAML::KeyNotFound&) { + Logger->Log(std::string("Failed To Find Parameter '") + Name + "'", 7); + return false; + } +} + + +// Vector Helpers +bool ERS_FUNCTION_GetStringVector(ERS_CLASS_LoggingSystem* Logger, YAML::Node Data, std::string Name, std::vector &Target) { + try { + YAML::Node TargetNode = Data[Name]; + for (YAML::const_iterator it=TargetNode.begin(); it!=TargetNode.end(); ++it) { + Target.push_back(it->second.as()); + } + return true; + } catch (YAML::TypedBadConversion&) { + Logger->Log(std::string("Failed To Cast Parameter '") + Name + "' To Type 'std::string'", 8); + return false; + } catch (YAML::KeyNotFound&) { + Logger->Log(std::string("Failed To Find Parameter '") + Name + "'", 7); + return false; + } +} +bool ERS_FUNCTION_GetIntVector(ERS_CLASS_LoggingSystem* Logger, YAML::Node Data, std::string Name, std::vector &Target) { + try { + YAML::Node TargetNode = Data[Name]; + for (YAML::const_iterator it=TargetNode.begin(); it!=TargetNode.end(); ++it) { + Target.push_back(it->second.as()); + } + return true; + } catch (YAML::TypedBadConversion&) { + Logger->Log(std::string("Failed To Cast Parameter '") + Name + "' To Type 'int'", 8); + return false; + } catch (YAML::KeyNotFound&) { + Logger->Log(std::string("Failed To Find Parameter '") + Name + "'", 7); + return false; + } +} +bool ERS_FUNCTION_GetLongVector(ERS_CLASS_LoggingSystem* Logger, YAML::Node Data, std::string Name, std::vector &Target) { + try { + YAML::Node TargetNode = Data[Name]; + for (YAML::const_iterator it=TargetNode.begin(); it!=TargetNode.end(); ++it) { + Target.push_back(it->second.as()); + } + return true; + } catch (YAML::TypedBadConversion&) { + Logger->Log(std::string("Failed To Cast Parameter '") + Name + "' To Type 'long'", 8); + return false; + } catch (YAML::KeyNotFound&) { + Logger->Log(std::string("Failed To Find Parameter '") + Name + "'", 7); + return false; + } +} +bool ERS_FUNCTION_GetNodeVector(ERS_CLASS_LoggingSystem* Logger, YAML::Node Data, std::string Name, std::vector &Target) { + try { + YAML::Node TargetNode = Data[Name]; + for (YAML::const_iterator it=TargetNode.begin(); it!=TargetNode.end(); ++it) { + Target.push_back(it->second); + } + return true; + } catch (YAML::KeyNotFound&) { + Logger->Log(std::string("Failed To Find Parameter '") + Name + "'", 7); + return false; + } +} + + +// GLM Helper Functions +bool ERS_FUNCTION_GetVec3(ERS_CLASS_LoggingSystem* Logger, YAML::Node Data, std::string NameBase, glm::vec3 &Target) { + + float X,Y,Z = 0.0f; + bool Status = true; + + Status &= ERS_FUNCTION_GetFloat(Logger, Data, NameBase + "X", X); + Status &= ERS_FUNCTION_GetFloat(Logger, Data, NameBase + "Y", Y); + Status &= ERS_FUNCTION_GetFloat(Logger, Data, NameBase + "Z", Z); + + Target = glm::vec3(X,Y,Z); + return Status; + +} +bool ERS_FUNCTION_GetVec3Color(ERS_CLASS_LoggingSystem* Logger, YAML::Node Data, std::string NameBase, glm::vec3 &Target) { + float X,Y,Z = 0.0f; + bool Status = true; + + Status &= ERS_FUNCTION_GetFloat(Logger, Data, NameBase + "Red", X); + Status &= ERS_FUNCTION_GetFloat(Logger, Data, NameBase + "Green", Y); + Status &= ERS_FUNCTION_GetFloat(Logger, Data, NameBase + "Blue", Z); + + Target = glm::vec3(X,Y,Z); + return Status; +} diff --git a/Source/Core/Loader/ERS_SceneLoader/ERS_FUNCTION_YAMLHelpers.h b/Source/Core/Loader/ERS_SceneLoader/ERS_FUNCTION_YAMLHelpers.h new file mode 100644 index 0000000000..fe05385bf7 --- /dev/null +++ b/Source/Core/Loader/ERS_SceneLoader/ERS_FUNCTION_YAMLHelpers.h @@ -0,0 +1,247 @@ +//======================================================================// +// This file is part of the BrainGenix-ERS Environment Rendering System // +//======================================================================// + +#pragma once + +// Standard Libraries (BG convention: use <> instead of "") +#include +#include + +// Third-Party Libraries (BG convention: use <> instead of "") +#include + +#include + +// Internal Libraries (BG convention: use <> instead of "") +#include + + + +/** + * @brief Helper function to the YAML::CPP Library that helps catch errors and other problems. + * Returns true on success, false on fail. + * + * @param Logger Pointer to ERS Logging system, used to log errors. + * @param Data YAML::Node containing the target data + * @param Name Name of the parameter in the yaml node + * @param Target Reference to the variable to be set to the decoded value + * @return true + * @return false + */ +bool ERS_FUNCTION_GetInt(ERS_CLASS_LoggingSystem* Logger, YAML::Node Data, std::string Name, int &Target); + +/** + * @brief Helper function to the YAML::CPP Library that helps catch errors and other problems. + * Returns true on success, false on fail. + * + * @param Logger Pointer to ERS Logging system, used to log errors. + * @param Data YAML::Node containing the target data + * @param Name Name of the parameter in the yaml node + * @param Target Reference to the variable to be set to the decoded value + * @return true + * @return false + */ +bool ERS_FUNCTION_GetFloat(ERS_CLASS_LoggingSystem* Logger, YAML::Node Data, std::string Name, float &Target); + +/** + * @brief Helper function to the YAML::CPP Library that helps catch errors and other problems. + * Returns true on success, false on fail. + * + * @param Logger Pointer to ERS Logging system, used to log errors. + * @param Data YAML::Node containing the target data + * @param Name Name of the parameter in the yaml node + * @param Target Reference to the variable to be set to the decoded value + * @return true + * @return false + */ +bool ERS_FUNCTION_GetBool(ERS_CLASS_LoggingSystem* Logger, YAML::Node Data, std::string Name, bool &Target); + +/** + * @brief Helper function to the YAML::CPP Library that helps catch errors and other problems. + * Returns true on success, false on fail. + * + * @param Logger Pointer to ERS Logging system, used to log errors. + * @param Data YAML::Node containing the target data + * @param Name Name of the parameter in the yaml node + * @param Target Reference to the variable to be set to the decoded value + * @return true + * @return false + */ +bool ERS_FUNCTION_GetLong(ERS_CLASS_LoggingSystem* Logger, YAML::Node Data, std::string Name, long &Target); + + +/** + * @brief Helper function to the YAML::CPP Library that helps catch errors and other problems. + * Returns true on success, false on fail. + * + * @param Logger Pointer to ERS Logging system, used to log errors. + * @param Data YAML::Node containing the target data + * @param Name Name of the parameter in the yaml node + * @param Target Reference to the variable to be set to the decoded value + * @return true + * @return false + */ +bool ERS_FUNCTION_GetDouble(ERS_CLASS_LoggingSystem* Logger, YAML::Node Data, std::string Name, double &Target); + +/** + * @brief Helper function to the YAML::CPP Library that helps catch errors and other problems. + * Returns true on success, false on fail. + * + * @param Logger Pointer to ERS Logging system, used to log errors. + * @param Data YAML::Node containing the target data + * @param Name Name of the parameter in the yaml node + * @param Target Reference to the variable to be set to the decoded value + * @return true + * @return false + */ +bool ERS_FUNCTION_GetUnsignedInt(ERS_CLASS_LoggingSystem* Logger, YAML::Node Data, std::string Name, unsigned int &Target); + +/** + * @brief Helper function to the YAML::CPP Library that helps catch errors and other problems. + * Returns true on success, false on fail. + * + * @param Logger Pointer to ERS Logging system, used to log errors. + * @param Data YAML::Node containing the target data + * @param Name Name of the parameter in the yaml node + * @param Target Reference to the variable to be set to the decoded value + * @return true + * @return false + */ +bool ERS_FUNCTION_GetUnsignedLong(ERS_CLASS_LoggingSystem* Logger, YAML::Node Data, std::string Name, unsigned long &Target); + +/** + * @brief Helper function to the YAML::CPP Library that helps catch errors and other problems. + * Returns true on success, false on fail. + * + * @param Logger Pointer to ERS Logging system, used to log errors. + * @param Data YAML::Node containing the target data + * @param Name Name of the parameter in the yaml node + * @param Target Reference to the variable to be set to the decoded value + * @return true + * @return false + */ +bool ERS_FUNCTION_GetLongLong(ERS_CLASS_LoggingSystem* Logger, YAML::Node Data, std::string Name, long long &Target); + +/** + * @brief Helper function to the YAML::CPP Library that helps catch errors and other problems. + * Returns true on success, false on fail. + * + * @param Logger Pointer to ERS Logging system, used to log errors. + * @param Data YAML::Node containing the target data + * @param Name Name of the parameter in the yaml node + * @param Target Reference to the variable to be set to the decoded value + * @return true + * @return false + */ +bool ERS_FUNCTION_GetUnsignedLongLong(ERS_CLASS_LoggingSystem* Logger, YAML::Node Data, std::string Name, unsigned long long &Target); + +/** + * @brief Helper function to the YAML::CPP Library that helps catch errors and other problems. + * Returns true on success, false on fail. + * + * @param Logger Pointer to ERS Logging system, used to log errors. + * @param Data YAML::Node containing the target data + * @param Name Name of the parameter in the yaml node + * @param Target Reference to the variable to be set to the decoded value + * @return true + * @return false + */ +bool ERS_FUNCTION_GetString(ERS_CLASS_LoggingSystem* Logger, YAML::Node Data, std::string Name, std::string &Target); + +/** + * @brief Helper function to the YAML::CPP Library that helps catch errors and other problems. + * Returns true on success, false on fail. + * + * @param Logger Pointer to ERS Logging system, used to log errors. + * @param Data YAML::Node containing the target data + * @param Name Name of the parameter in the yaml node + * @param Target Reference to the variable to be set to the decoded value + * @return true + * @return false + */ +bool ERS_FUNCTION_GetNode(ERS_CLASS_LoggingSystem* Logger, YAML::Node Data, std::string NameBase, YAML::Node &Target); + + + +/** + * @brief Helper function to the YAML::CPP Library that helps catch errors and other problems. + * Returns true on success, false on fail. + * + * @param Logger Pointer to ERS Logging system, used to log errors. + * @param Data YAML::Node containing the target data + * @param Name Name of the parameter in the yaml node + * @param Target Reference to the variable to be set to the decoded value + * @return true + * @return false + */ +bool ERS_FUNCTION_GetStringVector(ERS_CLASS_LoggingSystem* Logger, YAML::Node Data, std::string NameBase, std::vector &Target); + +/** + * @brief Helper function to the YAML::CPP Library that helps catch errors and other problems. + * Returns true on success, false on fail. + * + * @param Logger Pointer to ERS Logging system, used to log errors. + * @param Data YAML::Node containing the target data + * @param Name Name of the parameter in the yaml node + * @param Target Reference to the variable to be set to the decoded value + * @return true + * @return false + */ +bool ERS_FUNCTION_GetIntVector(ERS_CLASS_LoggingSystem* Logger, YAML::Node Data, std::string NameBase, std::vector &Target); + +/** + * @brief Helper function to the YAML::CPP Library that helps catch errors and other problems. + * Returns true on success, false on fail. + * + * @param Logger Pointer to ERS Logging system, used to log errors. + * @param Data YAML::Node containing the target data + * @param Name Name of the parameter in the yaml node + * @param Target Reference to the variable to be set to the decoded value + * @return true + * @return false + */ +bool ERS_FUNCTION_GetLongVector(ERS_CLASS_LoggingSystem* Logger, YAML::Node Data, std::string NameBase, std::vector &Target); + +/** + * @brief Helper function to the YAML::CPP Library that helps catch errors and other problems. + * Returns true on success, false on fail. + * + * @param Logger Pointer to ERS Logging system, used to log errors. + * @param Data YAML::Node containing the target data + * @param Name Name of the parameter in the yaml node + * @param Target Reference to the variable to be set to the decoded value + * @return true + * @return false + */ +bool ERS_FUNCTION_GetNodeVector(ERS_CLASS_LoggingSystem* Logger, YAML::Node Data, std::string NameBase, std::vector &Target); + + + +/** + * @brief Helper function to the YAML::CPP Library that helps catch errors and other problems. + * Returns true on success, false on fail. + * Will append X,Y,Z to get the three components of the vector. + * + * @param Logger Pointer to ERS Logging system, used to log errors. + * @param Data YAML::Node containing the target data + * @param Name Name of the parameter in the yaml node + * @param Target Reference to the variable to be set to the decoded value + * @return true + * @return false + */ +bool ERS_FUNCTION_GetVec3(ERS_CLASS_LoggingSystem* Logger, YAML::Node Data, std::string NameBase, glm::vec3 &Target); + +/** + * @brief Helper function to the YAML::CPP Library that helps catch errors and other problems. + * Returns true on success, false on fail. + * Will append Red,Green,Blue to get the three components of the vector. + * + * @param Logger Pointer to ERS Logging system, used to log errors. + * @param Data YAML::Node containing the target data + * @param Name Name of the parameter in the yaml node + * @param Target Reference to the variable to be set to the decoded value + * @return true + * @return false + */ +bool ERS_FUNCTION_GetVec3Color(ERS_CLASS_LoggingSystem* Logger, YAML::Node Data, std::string NameBase, glm::vec3 &Target); \ No newline at end of file diff --git a/Source/Core/Loader/ERS_SceneLoader/ERS_SceneLoader.cpp b/Source/Core/Loader/ERS_SceneLoader/ERS_SceneLoader.cpp index f25df516a4..827519b528 100644 --- a/Source/Core/Loader/ERS_SceneLoader/ERS_SceneLoader.cpp +++ b/Source/Core/Loader/ERS_SceneLoader/ERS_SceneLoader.cpp @@ -42,269 +42,10 @@ ERS_STRUCT_Scene ERS_CLASS_SceneLoader::ProcessScene(YAML::Node RawSceneData, lo // Create Scene Instance ERS_STRUCT_Scene Scene; - - // Grab Metadata - Scene.SceneFormatVersion = RawSceneData["SceneFormatVersion"].as(); - Scene.SceneName = RawSceneData["SceneName"].as(); Scene.ScenePath = AssetID; - if (RawSceneData["ActiveCameraIndex"]) { - Scene.ActiveSceneCameraIndex = RawSceneData["ActiveCameraIndex"].as(); - } - - // Log Scene Processing - SystemUtils_->Logger_->Log(std::string(std::string("Processing Scene: ") + std::string(Scene.SceneName)).c_str(), 3); - - // Create Vector Of YAML::Nodes - std::vector SceneItems; - - // Populate Vector With Elements From SceneData - YAML::Node SceneDataNode = RawSceneData["SceneData"]; - for (YAML::const_iterator it=SceneDataNode.begin(); it!=SceneDataNode.end(); ++it) { - SceneItems.push_back(it->second); - } - - - // Iterate Through Vector To Add Each Asset To Loading Queue Of Requested Type - for (long i = 0; (long)i < (long)SceneDataNode.size(); i++) { - - // Get Asset Information - std::string AssetName = SceneDataNode[i]["AssetName"].as(); - std::string AssetType = SceneDataNode[i]["AssetType"].as(); - - // If type Is Model - if (AssetType == std::string("Model")) { - - long AssetID = SceneDataNode[i]["AssetID"].as(); - - // Get Asset LocRotScale - float PosX = SceneDataNode[i]["AssetPositionX"].as(); - float PosY = SceneDataNode[i]["AssetPositionY"].as(); - float PosZ = SceneDataNode[i]["AssetPositionZ"].as(); - - float RotX = SceneDataNode[i]["AssetRotationX"].as(); - float RotY = SceneDataNode[i]["AssetRotationY"].as(); - float RotZ = SceneDataNode[i]["AssetRotationZ"].as(); - - float ScaleX = SceneDataNode[i]["AssetScaleX"].as(); - float ScaleY = SceneDataNode[i]["AssetScaleY"].as(); - float ScaleZ = SceneDataNode[i]["AssetScaleZ"].as(); - - //Load Model - Scene.Models.push_back(std::make_shared()); - int CurrentSize = Scene.Models.size(); - ModelLoader_->AddModelToLoadingQueue(AssetID, Scene.Models[CurrentSize-1]); - - // Add Instance To Models Vector - Scene.Models[CurrentSize-1]->IsTemplateModel = false; - Scene.Models[CurrentSize-1]->SetLocRotScale(glm::vec3(PosX, PosY, PosZ), glm::vec3(RotX, RotY, RotZ), glm::vec3(ScaleX, ScaleY, ScaleZ)); - Scene.Models[CurrentSize-1]->ApplyTransformations(); - Scene.Models[CurrentSize-1]->AssetID = AssetID; - Scene.Models[CurrentSize-1]->Name = AssetName; - - - // Load Attached Scripts - if (SceneDataNode[i]["AttachedScripts"]) { - YAML::Node Scripts = SceneDataNode[i]["AttachedScripts"]; - for (YAML::const_iterator it=Scripts.begin(); it!=Scripts.end(); ++it) { - Scene.Models[CurrentSize-1]->AttachedScriptIndexes_.push_back(it->second.as()); - } - } - - - // Load Shadow Configuration - if (SceneDataNode[i]["CastDynamicShadows"]) { - Scene.Models[CurrentSize-1]->CastDynamicShadows_ = SceneDataNode[i]["CastDynamicShadows"].as(); - } - - if (SceneDataNode[i]["CastStaticShadows"]) { - Scene.Models[CurrentSize-1]->CastStaticShadows_ = SceneDataNode[i]["CastStaticShadows"].as(); - } - - if (SceneDataNode[i]["ReceiveShadows"]) { - Scene.Models[CurrentSize-1]->ReceiveShadows_ = SceneDataNode[i]["ReceiveShadows"].as(); - } - - if (SceneDataNode[i]["ShaderOverrideIndex"]) { - Scene.Models[CurrentSize-1]->ShaderOverrideIndex_ = SceneDataNode[i]["ShaderOverrideIndex"].as(); - } - - - } else if (AssetType == std::string("DirectionalLight")) { - - // Setup Model Pointer In Scene To Work On - Scene.DirectionalLights.push_back(std::make_shared()); - int LightIndex = Scene.DirectionalLights.size() - 1; - - Scene.DirectionalLights[LightIndex]->UserDefinedName = AssetName; - - if (SceneDataNode[i]["ColorRed"] && SceneDataNode[i]["ColorGreen"] && SceneDataNode[i]["ColorBlue"]) { - Scene.DirectionalLights[LightIndex]->Color = glm::vec3( - SceneDataNode[i]["ColorRed"].as(), - SceneDataNode[i]["ColorGreen"].as(), - SceneDataNode[i]["ColorBlue"].as() - ); - } - - if (SceneDataNode[i]["Intensity"]) { - Scene.DirectionalLights[LightIndex]->Intensity = SceneDataNode[i]["Intensity"].as(); - } - - if (SceneDataNode[i]["MaxDistance"]) { - Scene.DirectionalLights[LightIndex]->MaxDistance = SceneDataNode[i]["MaxDistance"].as(); - } - - Scene.DirectionalLights[LightIndex]->Pos = glm::vec3( - SceneDataNode[i]["PosX"].as(), - SceneDataNode[i]["PosY"].as(), - SceneDataNode[i]["PosZ"].as() - ); - Scene.DirectionalLights[LightIndex]->Rot = glm::vec3( - SceneDataNode[i]["RotX"].as(), - SceneDataNode[i]["RotY"].as(), - SceneDataNode[i]["RotZ"].as() - ); - - - if (SceneDataNode[i]["CastShadows"]) { - Scene.DirectionalLights[LightIndex]->CastsShadows_ = SceneDataNode[i]["CastShadows"].as(); - } - - // Load Attached Scripts - if (SceneDataNode[i]["AttachedScripts"]) { - YAML::Node Scripts = SceneDataNode[i]["AttachedScripts"]; - for (YAML::const_iterator it=Scripts.begin(); it!=Scripts.end(); ++it) { - Scene.DirectionalLights[LightIndex]->AttachedScriptIndexes_.push_back(it->second.as()); - } - } - - } else if (AssetType == std::string("PointLight")) { - - // Setup Model Pointer In Scene To Work On - Scene.PointLights.push_back(std::make_shared()); - int LightIndex = Scene.PointLights.size() - 1; - - Scene.PointLights[LightIndex]->UserDefinedName = AssetName; - if (SceneDataNode[i]["Intensity"]) { - Scene.PointLights[LightIndex]->Intensity = SceneDataNode[i]["Intensity"].as(); - } - if (SceneDataNode[i]["MaxDistance"]) { - Scene.PointLights[LightIndex]->MaxDistance = SceneDataNode[i]["MaxDistance"].as(); - } - - - if (SceneDataNode[i]["ColorRed"] && SceneDataNode[i]["ColorGreen"] && SceneDataNode[i]["ColorBlue"]) { - Scene.PointLights[LightIndex]->Color = glm::vec3( - SceneDataNode[i]["ColorRed"].as(), - SceneDataNode[i]["ColorGreen"].as(), - SceneDataNode[i]["ColorBlue"].as() - ); - } - - Scene.PointLights[LightIndex]->Pos = glm::vec3( - SceneDataNode[i]["PosX"].as(), - SceneDataNode[i]["PosY"].as(), - SceneDataNode[i]["PosZ"].as() - ); - - if (SceneDataNode[i]["CastShadows"]) { - Scene.PointLights[LightIndex]->CastsShadows_ = SceneDataNode[i]["CastShadows"].as(); - } - - // Load Attached Scripts - if (SceneDataNode[i]["AttachedScripts"]) { - YAML::Node Scripts = SceneDataNode[i]["AttachedScripts"]; - for (YAML::const_iterator it=Scripts.begin(); it!=Scripts.end(); ++it) { - Scene.PointLights[LightIndex]->AttachedScriptIndexes_.push_back(it->second.as()); - } - } - - } else if (AssetType == std::string("SpotLight")) { - - // Setup Model Pointer In Scene To Work On - Scene.SpotLights.push_back(std::make_shared()); - int LightIndex = Scene.SpotLights.size() - 1; - - Scene.SpotLights[LightIndex]->UserDefinedName = AssetName; - - if (SceneDataNode[i]["Intensity"]) { - Scene.SpotLights[LightIndex]->Intensity = SceneDataNode[i]["Intensity"].as(); - } - if (SceneDataNode[i]["MaxDistance"]) { - Scene.SpotLights[LightIndex]->MaxDistance = SceneDataNode[i]["MaxDistance"].as(); - } - Scene.SpotLights[LightIndex]->CutOff = SceneDataNode[i]["CutOff"].as(); - - if (SceneDataNode[i]["RollOff"]) { - Scene.SpotLights[LightIndex]->Rolloff = SceneDataNode[i]["RollOff"].as(); - } - if (SceneDataNode[i]["ColorRed"] && SceneDataNode[i]["ColorGreen"] && SceneDataNode[i]["ColorBlue"]) { - Scene.SpotLights[LightIndex]->Color = glm::vec3( - SceneDataNode[i]["ColorRed"].as(), - SceneDataNode[i]["ColorGreen"].as(), - SceneDataNode[i]["ColorBlue"].as() - ); - } - - - Scene.SpotLights[LightIndex]->Pos = glm::vec3( - SceneDataNode[i]["PosX"].as(), - SceneDataNode[i]["PosY"].as(), - SceneDataNode[i]["PosZ"].as() - ); - Scene.SpotLights[LightIndex]->Rot = glm::vec3( - SceneDataNode[i]["RotX"].as(), - SceneDataNode[i]["RotY"].as(), - SceneDataNode[i]["RotZ"].as() - ); - - - if (SceneDataNode[i]["CastShadows"]) { - Scene.SpotLights[LightIndex]->CastsShadows_ = SceneDataNode[i]["CastShadows"].as(); - } - - // Load Attached Scripts - if (SceneDataNode[i]["AttachedScripts"]) { - YAML::Node Scripts = SceneDataNode[i]["AttachedScripts"]; - for (YAML::const_iterator it=Scripts.begin(); it!=Scripts.end(); ++it) { - Scene.SpotLights[LightIndex]->AttachedScriptIndexes_.push_back(it->second.as()); - } - } - - } else if (AssetType == std::string("SceneCamera")) { - - // Setup Model Pointer In Scene To Work On - Scene.SceneCameras.push_back(std::make_shared()); - int SceneCameraIndex = Scene.SceneCameras.size() - 1; - - Scene.SceneCameras[SceneCameraIndex]->UserDefinedName_ = AssetName; - Scene.SceneCameras[SceneCameraIndex]->Pos_ = glm::vec3( - SceneDataNode[i]["PosX"].as(), - SceneDataNode[i]["PosY"].as(), - SceneDataNode[i]["PosZ"].as() - ); - Scene.SceneCameras[SceneCameraIndex]->Rot_ = glm::vec3( - SceneDataNode[i]["RotX"].as(), - SceneDataNode[i]["RotY"].as(), - SceneDataNode[i]["RotZ"].as() - ); - - // Load Attached Scripts - if (SceneDataNode[i]["AttachedScripts"]) { - YAML::Node Scripts = SceneDataNode[i]["AttachedScripts"]; - for (YAML::const_iterator it=Scripts.begin(); it!=Scripts.end(); ++it) { - Scene.SceneCameras[SceneCameraIndex]->AttachedScriptIndexes_.push_back(it->second.as()); - } - } - - } else { - SystemUtils_->Logger_->Log(std::string("Unsupported/Unknown Asset Type: ") + AssetType, 9); - } - - } - - // Indicate Scene Is Loaded - Scene.IsSceneLoaded = true; + // Decode + ERS_FUNCTION_DecodeScene(RawSceneData, &Scene, SystemUtils_, ModelLoader_); // Return Scene return Scene; diff --git a/Source/Core/Loader/ERS_SceneLoader/ERS_SceneLoader.h b/Source/Core/Loader/ERS_SceneLoader/ERS_SceneLoader.h index bdb0f4b4f7..74f1f26752 100644 --- a/Source/Core/Loader/ERS_SceneLoader/ERS_SceneLoader.h +++ b/Source/Core/Loader/ERS_SceneLoader/ERS_SceneLoader.h @@ -14,6 +14,8 @@ #include #include +#include + #include #include #include diff --git a/Source/Core/Structures/ERS_STRUCT_Camera/ERS_STRUCT_Camera.h b/Source/Core/Structures/ERS_STRUCT_Camera/ERS_STRUCT_Camera.h index 4a08384ef4..85d8174289 100644 --- a/Source/Core/Structures/ERS_STRUCT_Camera/ERS_STRUCT_Camera.h +++ b/Source/Core/Structures/ERS_STRUCT_Camera/ERS_STRUCT_Camera.h @@ -247,94 +247,8 @@ struct ERS_STRUCT_Camera { // Asset Streaming Settings - int StreamingPriority_ = 1; /**< Higher this is, the more the system will try and load assets for this camera. Should be in range (1-10)*/ + int StreamingPriority_ = 1; /**< Higher this is, the more the system will try and load assets for this camera. Should be in range (1-10)*/ }; - - - - - - - -// struct ERS_STRUCT_Camera { -// private: -// void Rotate(float angle, const glm::vec3 &axis); - -// glm::mat4 PerspectiveMatrix_; -// glm::mat4 ViewMatrix_; - -// float AspectRatio_; -// float NearClip_; -// float FarClip_; - -// public: - -// // Asset Streaming Config -// int Priority_ = 1; // Higher this is, the more the system will try and load assets for this camera. Should be in range (1-10) - -// float FOV_; -// float zoom; -// float zoomDelta = glm::radians(1.0f); - - - -// glm::vec3 Position_; - -// glm::quat orientation; // store rotation and orientation data - -// glm::vec3 mousePosition; // use to calculate the yaw and pitch rotation. -// float mouseSenstivitiy = 0.0009f; // slow down the rate in which the camera rotate - -// // play around with those two values until you get a roll speed that you like. -// const float ROLL_ANGLE = 0.009f; // we're using this because roll depends on the mouse scroll. -// float rollDamp = 0.95f; // we're using this because roll depends on the mouse scroll. - -// float damp = 0.8f; // a value to damp the camera rotational speed - -// // the angles to rotate the camera by. -// float Yaw_ = 0.0f; // rotate about the y axis -// float Pitch_ = 0.0f; // rotate about the x axis -// float Roll_ = 0.0f; // rotate about the z axis -// float twoPI = glm::two_pi(); // check radian bound - -// float MovementSpeed_ = 0.2f; // the linear travel speed of the camera - - -// glm::vec3 xAxis = glm::vec3(1.0f, 0.0f, 0.0f); -// glm::vec3 yAxis = glm::vec3(0.0f, 1.0f, 0.0f); -// glm::vec3 zAxis = glm::vec3(0.0f, 0.0f, 1.0f); - - -// //ERS_STRUCT_Camera() = delete; - -// ///The vertical Field of View. In radians -// ///The width of the display window -// ///The height of the display window -// ///The near-clipping plane -// ///The far-clipping plane -// ///The Position_ of the camera -// ERS_STRUCT_Camera(float fov, int width, int height, float near, float far); -// ERS_STRUCT_Camera(float fov, int width, int height, float near, float far, glm::vec3 Position); -// ERS_STRUCT_Camera(glm::vec3 Position = glm::vec3(0.0f, 0.0f, 0.0f)); - - -// // Done -// void ProcessKeyboard(CameraMovement Direction, float DeltaTime); -// void ProcessMouseMovement(float XOffset, float YOffset); // control pitch and yaw -// void ProcessMouseScroll(float YOffset); // control Roll_ -// void SetRotation(glm::vec3 Rotation); -// void SetAspectRatio(float AspectRatio); -// void Update(); - -// // Todo -// void Zoom(ZoomState z); - - -// void SetMousePosition(float x, float y); -// void GetMatrices(glm::mat4& perspective, glm::mat4& view); -// //void GetDirectionVectors(glm::vec3 &Front, glm::vec3 &Right, glm::vec3 &Up); - -// }; diff --git a/Source/Core/Writers/ERS_SceneWriter/ERS_SceneWriter.cpp b/Source/Core/Writers/ERS_SceneWriter/ERS_SceneWriter.cpp index 601f31bce4..309b86054f 100644 --- a/Source/Core/Writers/ERS_SceneWriter/ERS_SceneWriter.cpp +++ b/Source/Core/Writers/ERS_SceneWriter/ERS_SceneWriter.cpp @@ -50,19 +50,17 @@ std::string SceneWriter::ProcessScene(ERS_STRUCT_Scene* InputScene) { // Write Metadata Output << YAML::Key << "SceneName" << YAML::Value << InputScene->SceneName; - Output << YAML::Key << "SceneFormatVersion" << YAML::Value << InputScene->SceneFormatVersion; + Output << YAML::Key << "SceneFormatVersion" << YAML::Value << 3; Output << YAML::Key << "ActiveCameraIndex" << YAML::Value << InputScene->ActiveSceneCameraIndex; - // Write SceneData - Output << YAML::Key << "SceneData"; - Output << YAML::Key << YAML::BeginMap; - long AssetIndex = 0; - //---- Write Models ----// + Output << YAML::Key << "Models"; + Output << YAML::Key << YAML::BeginMap; for (int i = 0; (long)i < (long)InputScene->Models.size(); i++) { - Output << YAML::Key << AssetIndex; + + Output << YAML::Key << i; Output << YAML::BeginMap; @@ -101,13 +99,16 @@ std::string SceneWriter::ProcessScene(ERS_STRUCT_Scene* InputScene) { Output << YAML::EndMap; - AssetIndex++; } + Output << YAML::EndMap; + //---- Write Directional Lights ----// + Output << YAML::Key << "DirectionalLights"; + Output << YAML::Key << YAML::BeginMap; for (int i = 0; (long)i < (long)InputScene->DirectionalLights.size(); i++) { - Output << YAML::Key << AssetIndex; + Output << YAML::Key << i; Output << YAML::BeginMap; @@ -141,13 +142,15 @@ std::string SceneWriter::ProcessScene(ERS_STRUCT_Scene* InputScene) { Output<PointLights.size(); i++) { - Output << YAML::Key << AssetIndex; + Output << YAML::Key << i; Output << YAML::BeginMap; @@ -181,13 +184,15 @@ std::string SceneWriter::ProcessScene(ERS_STRUCT_Scene* InputScene) { Output << YAML::EndMap; - AssetIndex++; } + Output << YAML::EndMap; //---- Write Spot Lights ----// + Output << YAML::Key << "SpotLights"; + Output << YAML::Key << YAML::BeginMap; for (int i = 0; (long)i < (long)InputScene->SpotLights.size(); i++) { - Output << YAML::Key << AssetIndex; + Output << YAML::Key << i; Output << YAML::BeginMap; @@ -229,46 +234,51 @@ std::string SceneWriter::ProcessScene(ERS_STRUCT_Scene* InputScene) { Output << YAML::EndMap; - AssetIndex++; } - + Output << YAML::EndMap; //---- Write Scene Cameras ----// + Output << YAML::Key << "SceneCameras"; + Output << YAML::Key << YAML::BeginMap; for (int i = 0; (long)i < (long)InputScene->SceneCameras.size(); i++) { - Output << YAML::Key << AssetIndex; - Output << YAML::BeginMap; + ERS_STRUCT_SceneCamera* SceneCamera = InputScene->SceneCameras[i].get(); - Output << YAML::Key << "AssetName" << YAML::Value << InputScene->SceneCameras[i]->UserDefinedName_; - Output << YAML::Key << "AssetType" << YAML::Value << "SceneCamera"; + Output << YAML::Key << i; + Output << YAML::BeginMap; - Output << YAML::Key << "PosX" << YAML::Value << InputScene->SceneCameras[i]->Pos_[0]; - Output << YAML::Key << "PosY" << YAML::Value << InputScene->SceneCameras[i]->Pos_[1]; - Output << YAML::Key << "PosZ" << YAML::Value << InputScene->SceneCameras[i]->Pos_[2]; + Output << YAML::Key << "AssetName" << YAML::Value << SceneCamera->UserDefinedName_; + Output << YAML::Key << "AssetType" << YAML::Value << "SceneCamera"; - Output << YAML::Key << "RotX" << YAML::Value << InputScene->SceneCameras[i]->Rot_[0]; - Output << YAML::Key << "RotY" << YAML::Value << InputScene->SceneCameras[i]->Rot_[1]; - Output << YAML::Key << "RotZ" << YAML::Value << InputScene->SceneCameras[i]->Rot_[2]; + Output << YAML::Key << "PosX" << YAML::Value << SceneCamera->Pos_[0]; + Output << YAML::Key << "PosY" << YAML::Value << SceneCamera->Pos_[1]; + Output << YAML::Key << "PosZ" << YAML::Value << SceneCamera->Pos_[2]; + Output << YAML::Key << "RotX" << YAML::Value << SceneCamera->Rot_[0]; + Output << YAML::Key << "RotY" << YAML::Value << SceneCamera->Rot_[1]; + Output << YAML::Key << "RotZ" << YAML::Value << SceneCamera->Rot_[2]; + Output << YAML::Key << "NearClip" << YAML::Value << SceneCamera->NearClip_; + Output << YAML::Key << "FarClip" << YAML::Value << SceneCamera->FarClip_; + Output << YAML::Key << "FOV" << YAML::Value << SceneCamera->FOV_; + Output << YAML::Key << "EnforceAspectRatio" << YAML::Value << SceneCamera->EnforceAspectRatio_; + Output << YAML::Key << "AspectRatio" << YAML::Value << SceneCamera->AspectRatio_; + Output << YAML::Key << "StreamingPriority" << YAML::Value << SceneCamera->StreamingPriority_; Output<SceneCameras[i]->AttachedScriptIndexes_.size(); x++) { - Output<SceneCameras[i]->AttachedScriptIndexes_[x]; + for (unsigned long x = 0; x < SceneCamera->AttachedScriptIndexes_.size(); x++) { + Output<AttachedScriptIndexes_[x]; } Output<