From 7164b64bb5810183d9bfd1b6cc0ac8f49c52184b Mon Sep 17 00:00:00 2001 From: amzn-victor <86271008+amzn-victor@users.noreply.github.com> Date: Wed, 18 Aug 2021 09:48:24 -0700 Subject: [PATCH] Move BuildDebugSceneGraph function out of SceneProcessing gem (#3290) Moved BuildDebugSceneGraph out of SceneProcessing gem and into DebugOutput class to allow the function to be shared, which ensures the same dbgsg format is outputted among any calls to the function. * Move BuildDebugSceneGraph function, update all calls to this function Signed-off-by: Victor Huang * Remove unused includes Signed-off-by: Victor Huang * Remove z Signed-off-by: Victor Huang --- .../SceneCore/Utilities/DebugOutput.cpp | 68 ++++++++++++++++++ .../SceneCore/Utilities/DebugOutput.h | 18 +++++ .../SceneBuilder/SceneBuilderWorker.cpp | 69 ++----------------- .../Source/SceneBuilder/SceneBuilderWorker.h | 3 - 4 files changed, 90 insertions(+), 68 deletions(-) diff --git a/Code/Tools/SceneAPI/SceneCore/Utilities/DebugOutput.cpp b/Code/Tools/SceneAPI/SceneCore/Utilities/DebugOutput.cpp index e688ebccd4..de727498fc 100644 --- a/Code/Tools/SceneAPI/SceneCore/Utilities/DebugOutput.cpp +++ b/Code/Tools/SceneAPI/SceneCore/Utilities/DebugOutput.cpp @@ -9,6 +9,15 @@ #include "DebugOutput.h" #include +#include +#include +#include +#include +#include +#include +#include +#include + namespace AZ::SceneAPI::Utilities { void DebugOutput::Write(const char* name, const char* data) @@ -118,4 +127,63 @@ namespace AZ::SceneAPI::Utilities { return m_output; } + + void WriteAndLog(AZ::IO::SystemFile& dbgFile, const char* strToWrite) + { + AZ_TracePrintf(AZ::SceneAPI::Utilities::LogWindow, "%s", strToWrite); + dbgFile.Write(strToWrite, strlen(strToWrite)); + dbgFile.Write("\n", strlen("\n")); + } + + void DebugOutput::BuildDebugSceneGraph(const char* outputFolder, AZ::SceneAPI::Events::ExportProductList& productList, const AZStd::shared_ptr& scene, AZStd::string productName) + { + const int debugSceneGraphVersion = 1; + AZStd::string debugSceneFile; + + AzFramework::StringFunc::Path::ConstructFull(outputFolder, productName.c_str(), debugSceneFile); + AZ_TracePrintf(AZ::SceneAPI::Utilities::LogWindow, "outputFolder %s, name %s.\n", outputFolder, productName.c_str()); + + AZ::IO::SystemFile dbgFile; + if (dbgFile.Open(debugSceneFile.c_str(), AZ::IO::SystemFile::SF_OPEN_CREATE | AZ::IO::SystemFile::SF_OPEN_WRITE_ONLY)) + { + WriteAndLog(dbgFile, AZStd::string::format("ProductName: %s", productName.c_str()).c_str()); + WriteAndLog(dbgFile, AZStd::string::format("debugSceneGraphVersion: %d", debugSceneGraphVersion).c_str()); + WriteAndLog(dbgFile, scene->GetName().c_str()); + + const AZ::SceneAPI::Containers::SceneGraph& sceneGraph = scene->GetGraph(); + auto names = sceneGraph.GetNameStorage(); + auto content = sceneGraph.GetContentStorage(); + auto pairView = AZ::SceneAPI::Containers::Views::MakePairView(names, content); + auto view = AZ::SceneAPI::Containers::Views::MakeSceneGraphDownwardsView< + AZ::SceneAPI::Containers::Views::BreadthFirst>( + sceneGraph, sceneGraph.GetRoot(), pairView.cbegin(), true); + + for (auto&& viewIt : view) + { + if (viewIt.second == nullptr) + { + continue; + } + + AZ::SceneAPI::DataTypes::IGraphObject* graphObject = const_cast(viewIt.second.get()); + + WriteAndLog(dbgFile, AZStd::string::format("Node Name: %s", viewIt.first.GetName()).c_str()); + WriteAndLog(dbgFile, AZStd::string::format("Node Path: %s", viewIt.first.GetPath()).c_str()); + WriteAndLog(dbgFile, AZStd::string::format("Node Type: %s", graphObject->RTTI_GetTypeName()).c_str()); + + AZ::SceneAPI::Utilities::DebugOutput debugOutput; + viewIt.second->GetDebugOutput(debugOutput); + + if (!debugOutput.GetOutput().empty()) + { + WriteAndLog(dbgFile, debugOutput.GetOutput().c_str()); + } + } + dbgFile.Close(); + + static const AZ::Data::AssetType dbgSceneGraphAssetType("{07F289D1-4DC7-4C40-94B4-0A53BBCB9F0B}"); + productList.AddProduct(productName, AZ::Uuid::CreateName(productName.c_str()), dbgSceneGraphAssetType, + AZStd::nullopt, AZStd::nullopt); + } + } } diff --git a/Code/Tools/SceneAPI/SceneCore/Utilities/DebugOutput.h b/Code/Tools/SceneAPI/SceneCore/Utilities/DebugOutput.h index 5fe5b98243..e05d10e2fa 100644 --- a/Code/Tools/SceneAPI/SceneCore/Utilities/DebugOutput.h +++ b/Code/Tools/SceneAPI/SceneCore/Utilities/DebugOutput.h @@ -16,6 +16,22 @@ #include #include +namespace AZ +{ + namespace SceneAPI + { + namespace Containers + { + class Scene; + } + namespace Events + { + struct ExportProduct; + class ExportProductList; + } + } +} + namespace AZ::SceneAPI::Utilities { class DebugOutput @@ -42,6 +58,8 @@ namespace AZ::SceneAPI::Utilities SCENE_CORE_API const AZStd::string& GetOutput() const; + SCENE_CORE_API static void BuildDebugSceneGraph(const char* outputFolder, AZ::SceneAPI::Events::ExportProductList& productList, const AZStd::shared_ptr& scene, AZStd::string productName); + protected: AZStd::string m_output; }; diff --git a/Gems/SceneProcessing/Code/Source/SceneBuilder/SceneBuilderWorker.cpp b/Gems/SceneProcessing/Code/Source/SceneBuilder/SceneBuilderWorker.cpp index 18ee0285b8..b4ae490e2c 100644 --- a/Gems/SceneProcessing/Code/Source/SceneBuilder/SceneBuilderWorker.cpp +++ b/Gems/SceneProcessing/Code/Source/SceneBuilder/SceneBuilderWorker.cpp @@ -10,9 +10,7 @@ #include #include #include -#include #include -#include #include #include #include @@ -306,7 +304,10 @@ namespace SceneBuilder if (itr != request.m_jobDescription.m_jobParameters.end() && itr->second == "true") { - BuildDebugSceneGraph(outputFolder.c_str(), productList, scene); + AZStd::string productName; + AzFramework::StringFunc::Path::GetFullFileName(scene->GetSourceFilename().c_str(), productName); + AzFramework::StringFunc::Path::ReplaceExtension(productName, "dbgsg"); + AZ::SceneAPI::Utilities::DebugOutput::BuildDebugSceneGraph(outputFolder.c_str(), productList, scene, productName); } AZ_TracePrintf(Utilities::LogWindow, "Collecting and registering products.\n"); @@ -371,66 +372,4 @@ namespace SceneBuilder return id; } - - void WriteAndLog(AZ::IO::SystemFile& dbgFile, const char* strToWrite) - { - AZ_TracePrintf(AZ::SceneAPI::Utilities::LogWindow, "%s", strToWrite); - dbgFile.Write(strToWrite, strlen(strToWrite)); - dbgFile.Write("\n", strlen("\n")); - - } - - void SceneBuilderWorker::BuildDebugSceneGraph(const char* outputFolder, AZ::SceneAPI::Events::ExportProductList& productList, const AZStd::shared_ptr& scene) const - { - const int debugSceneGraphVersion = 1; - AZStd::string productName, debugSceneFile; - - AzFramework::StringFunc::Path::GetFullFileName(scene->GetSourceFilename().c_str(), productName); - AzFramework::StringFunc::Path::ReplaceExtension(productName, "dbgsg"); - AzFramework::StringFunc::Path::ConstructFull(outputFolder, productName.c_str(), debugSceneFile); - AZ_TracePrintf(AZ::SceneAPI::Utilities::LogWindow, "outputFolder %s, name %s.\n", outputFolder, productName.c_str()); - - AZ::IO::SystemFile dbgFile; - if (dbgFile.Open(debugSceneFile.c_str(), AZ::IO::SystemFile::SF_OPEN_CREATE | AZ::IO::SystemFile::SF_OPEN_WRITE_ONLY)) - { - WriteAndLog(dbgFile, AZStd::string::format("ProductName: %s", productName.c_str()).c_str()); - WriteAndLog(dbgFile, AZStd::string::format("debugSceneGraphVersion: %d", debugSceneGraphVersion).c_str()); - WriteAndLog(dbgFile, scene->GetName().c_str()); - - const AZ::SceneAPI::Containers::SceneGraph& sceneGraph = scene->GetGraph(); - auto names = sceneGraph.GetNameStorage(); - auto content = sceneGraph.GetContentStorage(); - auto pairView = AZ::SceneAPI::Containers::Views::MakePairView(names, content); - auto view = AZ::SceneAPI::Containers::Views::MakeSceneGraphDownwardsView< - AZ::SceneAPI::Containers::Views::BreadthFirst>( - sceneGraph, sceneGraph.GetRoot(), pairView.cbegin(), true); - - for (auto&& viewIt : view) - { - if (viewIt.second == nullptr) - { - continue; - } - - AZ::SceneAPI::DataTypes::IGraphObject* graphObject = const_cast(viewIt.second.get()); - - WriteAndLog(dbgFile, AZStd::string::format("Node Name: %s", viewIt.first.GetName()).c_str()); - WriteAndLog(dbgFile, AZStd::string::format("Node Path: %s", viewIt.first.GetPath()).c_str()); - WriteAndLog(dbgFile, AZStd::string::format("Node Type: %s", graphObject->RTTI_GetTypeName()).c_str()); - - AZ::SceneAPI::Utilities::DebugOutput debugOutput; - viewIt.second->GetDebugOutput(debugOutput); - - if (!debugOutput.GetOutput().empty()) - { - WriteAndLog(dbgFile, debugOutput.GetOutput().c_str()); - } - } - dbgFile.Close(); - - static const AZ::Data::AssetType dbgSceneGraphAssetType("{07F289D1-4DC7-4C40-94B4-0A53BBCB9F0B}"); - productList.AddProduct(productName, AZ::Uuid::CreateName(productName.c_str()), dbgSceneGraphAssetType, - AZStd::nullopt, AZStd::nullopt); - } - } } // namespace SceneBuilder diff --git a/Gems/SceneProcessing/Code/Source/SceneBuilder/SceneBuilderWorker.h b/Gems/SceneProcessing/Code/Source/SceneBuilder/SceneBuilderWorker.h index 895bcf5672..3ecc657a3a 100644 --- a/Gems/SceneProcessing/Code/Source/SceneBuilder/SceneBuilderWorker.h +++ b/Gems/SceneProcessing/Code/Source/SceneBuilder/SceneBuilderWorker.h @@ -55,9 +55,6 @@ namespace SceneBuilder void PopulateProductDependencies(const AZ::SceneAPI::Events::ExportProduct& exportProduct, const char* watchFolder, AssetBuilderSDK::JobProduct& jobProduct) const; protected: - - void BuildDebugSceneGraph(const char* outputFolder, AZ::SceneAPI::Events::ExportProductList& productList, const AZStd::shared_ptr& scene) const; - bool LoadScene(AZStd::shared_ptr& result, const AssetBuilderSDK::ProcessJobRequest& request, AssetBuilderSDK::ProcessJobResponse& response);