Skip to content

Commit

Permalink
Merge pull request #283 from carboncopies/281-update-scenewriterloade…
Browse files Browse the repository at this point in the history
…r-with-viewport-camera

281 update scenewriterloader with viewport camera
  • Loading branch information
datacrystals authored Aug 13, 2022
2 parents f54a490 + 11c3796 commit 90b63c7
Show file tree
Hide file tree
Showing 17 changed files with 1,085 additions and 379 deletions.
4 changes: 4 additions & 0 deletions Source/Core/Loader/ERS_ModelLoader/ERS_CLASS_ModelLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ void ERS_CLASS_ModelLoader::ProcessNewModels(ERS_STRUCT_Scene* ActiveScene) {

}

void ERS_CLASS_ModelLoader::AddModelToLoadingQueue(std::shared_ptr<ERS_STRUCT_Model> Model) {
AddModelToLoadingQueue(Model->AssetID, Model);
}

void ERS_CLASS_ModelLoader::AddModelToLoadingQueue(long AssetID, std::shared_ptr<ERS_STRUCT_Model> Model) {

// Log Addition
Expand Down
1 change: 1 addition & 0 deletions Source/Core/Loader/ERS_ModelLoader/ERS_CLASS_ModelLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ class ERS_CLASS_ModelLoader {
* @param FlipTextures
*/
void AddModelToLoadingQueue(long AssetID, std::shared_ptr<ERS_STRUCT_Model> Model);
void AddModelToLoadingQueue(std::shared_ptr<ERS_STRUCT_Model> Model);



Expand Down
10 changes: 10 additions & 0 deletions Source/Core/Loader/ERS_SceneLoader/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//======================================================================//
// This file is part of the BrainGenix-ERS Environment Rendering System //
//======================================================================//

#include <ERS_FUNCTION_SceneDecoderManager.h>




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<int>();
} 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;
}

}
Original file line number Diff line number Diff line change
@@ -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 <string>
#include <vector>

// Third-Party Libraries (BG convention: use <> instead of "")
#include <yaml-cpp/yaml.h>

// Internal Libraries (BG convention: use <> instead of "")
#include <ERS_STRUCT_SystemUtils.h>
#include <ERS_STRUCT_Scene.h>

#include <ERS_CLASS_ModelLoader.h>

#include <ERS_FUNCTION_SceneDecoderV1.h>
#include <ERS_FUNCTION_SceneDecoderV2.h>
#include <ERS_FUNCTION_SceneDecoderV3.h>


/**
* @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);
107 changes: 107 additions & 0 deletions Source/Core/Loader/ERS_SceneLoader/ERS_FUNCTION_SceneDecoderV1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
//======================================================================//
// This file is part of the BrainGenix-ERS Environment Rendering System //
//======================================================================//

#include <ERS_FUNCTION_SceneDecoderV1.h>



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<YAML::Node> 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<ERS_STRUCT_Model>(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<ERS_STRUCT_DirectionalLight>(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<ERS_STRUCT_PointLight>(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<ERS_STRUCT_SpotLight>(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;

}


40 changes: 40 additions & 0 deletions Source/Core/Loader/ERS_SceneLoader/ERS_FUNCTION_SceneDecoderV1.h
Original file line number Diff line number Diff line change
@@ -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 <string>
#include <vector>

// Third-Party Libraries (BG convention: use <> instead of "")
#include <yaml-cpp/yaml.h>

// Internal Libraries (BG convention: use <> instead of "")
#include <ERS_STRUCT_SystemUtils.h>
#include <ERS_STRUCT_Scene.h>
#include <ERS_STRUCT_Model.h>
#include <ERS_STRUCT_SceneCamera.h>
#include <ERS_STRUCT_SpotLight.h>
#include <ERS_STRUCT_PointLight.h>
#include <ERS_STRUCT_DirectionalLight.h>

#include <ERS_CLASS_ModelLoader.h>

#include <ERS_FUNCTION_YAMLHelpers.h>




/**
* @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);
Loading

0 comments on commit 90b63c7

Please sign in to comment.