Add serialized output version (xml) of debug scene graph (#3437)
* Add serialized output version (xml) of debug scene graph Signed-off-by: amzn-mike <80125227+amzn-mike@users.noreply.github.com> * Fix line endings Signed-off-by: amzn-mike <80125227+amzn-mike@users.noreply.github.com> * Fix line endings Signed-off-by: amzn-mike <80125227+amzn-mike@users.noreply.github.com> * Update fbx unit tests to check for dbgsg.xml file Signed-off-by: amzn-mike <80125227+amzn-mike@users.noreply.github.com> * Add dbgsg.xml comparison Signed-off-by: amzn-mike <80125227+amzn-mike@users.noreply.github.com> * Move dbgsg files to SceneDebug sub folder Signed-off-by: amzn-mike <80125227+amzn-mike@users.noreply.github.com> * Add shaderball.dbgsg.xml and multiple_mesh_multiple_material_override.dbgsg.xml Signed-off-by: amzn-mike <80125227+amzn-mike@users.noreply.github.com> * Add shaderball dbgsg.xml product. Update code to look in SceneDebug for dbgsg files Fix extension concatenation Signed-off-by: amzn-mike <80125227+amzn-mike@users.noreply.github.com> * Remove unnecessary dbgsg.xml file Signed-off-by: amzn-mike <80125227+amzn-mike@users.noreply.github.com>
This commit is contained in:
@@ -187,6 +187,7 @@ namespace AZ
|
||||
|
||||
// Register utilities
|
||||
AZ::SceneAPI::SceneCore::PatternMatcher::Reflect(context);
|
||||
AZ::SceneAPI::Utilities::DebugSceneGraph::Reflect(context);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <AzCore/std/optional.h>
|
||||
|
||||
#include <AzCore/IO/SystemFile.h>
|
||||
#include <AzCore/Serialization/Utils.h>
|
||||
#include <AzFramework/StringFunc/StringFunc.h>
|
||||
#include <SceneAPI/SceneCore/Containers/Scene.h>
|
||||
#include <SceneAPI/SceneCore/Containers/Views/PairIterator.h>
|
||||
@@ -20,6 +21,36 @@
|
||||
|
||||
namespace AZ::SceneAPI::Utilities
|
||||
{
|
||||
void DebugNode::Reflect(AZ::ReflectContext* context)
|
||||
{
|
||||
AZ::SerializeContext* serialize = azrtti_cast<AZ::SerializeContext*>(context);
|
||||
|
||||
if (serialize)
|
||||
{
|
||||
serialize->Class<DebugNode>()
|
||||
->Field("Name", &DebugNode::m_name)
|
||||
->Field("Path", &DebugNode::m_path)
|
||||
->Field("Type", &DebugNode::m_type)
|
||||
->Field("Data", &DebugNode::m_data);
|
||||
}
|
||||
}
|
||||
|
||||
void DebugSceneGraph::Reflect(AZ::ReflectContext* context)
|
||||
{
|
||||
DebugNode::Reflect(context);
|
||||
|
||||
AZ::SerializeContext* serialize = azrtti_cast<AZ::SerializeContext*>(context);
|
||||
|
||||
if (serialize)
|
||||
{
|
||||
serialize->Class<DebugSceneGraph>()
|
||||
->Field("Version", &DebugSceneGraph::m_version)
|
||||
->Field("ProductName", &DebugSceneGraph::m_productName)
|
||||
->Field("SceneName", &DebugSceneGraph::m_sceneName)
|
||||
->Field("Nodes", &DebugSceneGraph::m_nodes);
|
||||
}
|
||||
}
|
||||
|
||||
void DebugOutput::Write(const char* name, const char* data)
|
||||
{
|
||||
m_output += AZStd::string::format("\t%s: %s\n", name, data);
|
||||
@@ -38,21 +69,29 @@ namespace AZ::SceneAPI::Utilities
|
||||
void DebugOutput::Write(const char* name, const AZStd::string& data)
|
||||
{
|
||||
Write(name, data.c_str());
|
||||
|
||||
AddToNode(name, data);
|
||||
}
|
||||
|
||||
void DebugOutput::Write(const char* name, double data)
|
||||
{
|
||||
m_output += AZStd::string::format("\t%s: %f\n", name, data);
|
||||
|
||||
AddToNode(name, data);
|
||||
}
|
||||
|
||||
void DebugOutput::Write(const char* name, uint64_t data)
|
||||
{
|
||||
m_output += AZStd::string::format("\t%s: %" PRIu64 "\n", name, data);
|
||||
|
||||
AddToNode(name, data);
|
||||
}
|
||||
|
||||
void DebugOutput::Write(const char* name, int64_t data)
|
||||
{
|
||||
m_output += AZStd::string::format("\t%s: %" PRId64 "\n", name, data);
|
||||
|
||||
AddToNode(name, data);
|
||||
}
|
||||
|
||||
void DebugOutput::Write(const char* name, const DataTypes::MatrixType& data)
|
||||
@@ -63,6 +102,7 @@ namespace AZ::SceneAPI::Utilities
|
||||
AZ::Vector3 translation{};
|
||||
data.GetBasisAndTranslation(&basisX, &basisY, &basisZ, &translation);
|
||||
|
||||
m_pauseNodeData = true;
|
||||
m_output += AZStd::string::format("\t%s:\n", name);
|
||||
|
||||
m_output += "\t";
|
||||
@@ -76,16 +116,23 @@ namespace AZ::SceneAPI::Utilities
|
||||
|
||||
m_output += "\t";
|
||||
Write("Transl", translation);
|
||||
m_pauseNodeData = false;
|
||||
|
||||
AddToNode(name, data);
|
||||
}
|
||||
|
||||
void DebugOutput::Write(const char* name, bool data)
|
||||
{
|
||||
m_output += AZStd::string::format("\t%s: %s\n", name, data ? "true" : "false");
|
||||
|
||||
AddToNode(name, data);
|
||||
}
|
||||
|
||||
void DebugOutput::Write(const char* name, Vector3 data)
|
||||
{
|
||||
m_output += AZStd::string::format("\t%s: <% f, % f, % f>\n", name, data.GetX(), data.GetY(), data.GetZ());
|
||||
|
||||
AddToNode(name, data);
|
||||
}
|
||||
|
||||
void DebugOutput::Write(const char* name, AZStd::optional<bool> data)
|
||||
@@ -128,6 +175,11 @@ namespace AZ::SceneAPI::Utilities
|
||||
return m_output;
|
||||
}
|
||||
|
||||
DebugNode DebugOutput::GetDebugNode() const
|
||||
{
|
||||
return m_currentNode;
|
||||
}
|
||||
|
||||
void WriteAndLog(AZ::IO::SystemFile& dbgFile, const char* strToWrite)
|
||||
{
|
||||
AZ_TracePrintf(AZ::SceneAPI::Utilities::LogWindow, "%s", strToWrite);
|
||||
@@ -137,7 +189,6 @@ namespace AZ::SceneAPI::Utilities
|
||||
|
||||
void DebugOutput::BuildDebugSceneGraph(const char* outputFolder, AZ::SceneAPI::Events::ExportProductList& productList, const AZStd::shared_ptr<AZ::SceneAPI::Containers::Scene>& scene, AZStd::string productName)
|
||||
{
|
||||
const int debugSceneGraphVersion = 1;
|
||||
AZStd::string debugSceneFile;
|
||||
|
||||
AzFramework::StringFunc::Path::ConstructFull(outputFolder, productName.c_str(), debugSceneFile);
|
||||
@@ -147,7 +198,7 @@ namespace AZ::SceneAPI::Utilities
|
||||
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, AZStd::string::format("debugSceneGraphVersion: %d", SceneGraphVersion).c_str());
|
||||
WriteAndLog(dbgFile, scene->GetName().c_str());
|
||||
|
||||
const AZ::SceneAPI::Containers::SceneGraph& sceneGraph = scene->GetGraph();
|
||||
@@ -158,6 +209,11 @@ namespace AZ::SceneAPI::Utilities
|
||||
AZ::SceneAPI::Containers::Views::BreadthFirst>(
|
||||
sceneGraph, sceneGraph.GetRoot(), pairView.cbegin(), true);
|
||||
|
||||
DebugSceneGraph debugSceneGraph;
|
||||
debugSceneGraph.m_version = SceneGraphVersion;
|
||||
debugSceneGraph.m_productName = productName;
|
||||
debugSceneGraph.m_sceneName = scene->GetName().c_str();
|
||||
|
||||
for (auto&& viewIt : view)
|
||||
{
|
||||
if (viewIt.second == nullptr)
|
||||
@@ -170,20 +226,31 @@ namespace AZ::SceneAPI::Utilities
|
||||
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;
|
||||
|
||||
AZ::SceneAPI::Utilities::DebugOutput debugOutput(
|
||||
DebugNode(viewIt.first.GetName(), viewIt.first.GetPath(), graphObject->RTTI_GetTypeName()));
|
||||
|
||||
viewIt.second->GetDebugOutput(debugOutput);
|
||||
|
||||
if (!debugOutput.GetOutput().empty())
|
||||
{
|
||||
WriteAndLog(dbgFile, debugOutput.GetOutput().c_str());
|
||||
}
|
||||
|
||||
debugSceneGraph.m_nodes.push_back(debugOutput.GetDebugNode());
|
||||
}
|
||||
dbgFile.Close();
|
||||
|
||||
Utils::SaveObjectToFile((debugSceneFile + ".xml").c_str(), DataStream::StreamType::ST_XML, &debugSceneGraph);
|
||||
|
||||
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);
|
||||
|
||||
static const AZ::Data::AssetType dbgSceneGraphXmlAssetType("{51F37614-0D77-4F36-9AC6-7ED70A0AC868}");
|
||||
productList.AddProduct(
|
||||
(productName + ".xml"), AZ::Uuid::CreateName((productName + ".xml").c_str()), dbgSceneGraphXmlAssetType,
|
||||
AZStd::nullopt, AZStd::nullopt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include <AzCore/std/containers/vector.h>
|
||||
#include <AzCore/std/optional.h>
|
||||
#include <cinttypes>
|
||||
#include <AzCore/std/any.h>
|
||||
|
||||
namespace AZ
|
||||
{
|
||||
@@ -34,15 +35,63 @@ namespace AZ
|
||||
|
||||
namespace AZ::SceneAPI::Utilities
|
||||
{
|
||||
constexpr int SceneGraphVersion = 1;
|
||||
|
||||
struct DebugNode
|
||||
{
|
||||
AZ_TYPE_INFO(DebugNode, "{490B9D4C-1847-46EB-BEBC-49812E104626}");
|
||||
|
||||
AZStd::string m_name;
|
||||
AZStd::string m_path;
|
||||
AZStd::string m_type;
|
||||
|
||||
DebugNode() = default;
|
||||
|
||||
DebugNode(AZStd::string name, AZStd::string path, AZStd::string type)
|
||||
: m_name(AZStd::move(name)),
|
||||
m_path(AZStd::move(path)),
|
||||
m_type(AZStd::move(type))
|
||||
{
|
||||
}
|
||||
|
||||
static void Reflect(AZ::ReflectContext* context);
|
||||
|
||||
using DataItem = AZStd::pair<AZStd::string, AZStd::any>;
|
||||
AZStd::vector<DataItem> m_data;
|
||||
};
|
||||
|
||||
struct DebugSceneGraph
|
||||
{
|
||||
AZ_TYPE_INFO(DebugSceneGraph, "{375F6558-5709-409F-881E-8ED575D56C92}");
|
||||
|
||||
int m_version = SceneGraphVersion;
|
||||
AZStd::string m_productName;
|
||||
AZStd::string m_sceneName;
|
||||
AZStd::vector<DebugNode> m_nodes;
|
||||
|
||||
static void Reflect(AZ::ReflectContext* context);
|
||||
};
|
||||
|
||||
class DebugOutput
|
||||
{
|
||||
public:
|
||||
DebugOutput(DebugNode node) : m_currentNode(AZStd::move(node)){}
|
||||
|
||||
template<typename T>
|
||||
void Write(const char* name, const AZStd::vector<T>& data);
|
||||
|
||||
template<typename T>
|
||||
void Write(const char* name, const AZStd::vector<AZStd::vector<T>>& data);
|
||||
|
||||
template<typename T>
|
||||
void AddToNode(const char* name, const T& data)
|
||||
{
|
||||
if (!m_pauseNodeData)
|
||||
{
|
||||
m_currentNode.m_data.emplace_back(name, AZStd::make_any<AZStd::decay_t<T>>(data));
|
||||
}
|
||||
}
|
||||
|
||||
SCENE_CORE_API void Write(const char* name, const char* data);
|
||||
SCENE_CORE_API void WriteArray(const char* name, const unsigned int* data, int size);
|
||||
SCENE_CORE_API void Write(const char* name, const AZStd::string& data);
|
||||
@@ -57,11 +106,15 @@ namespace AZ::SceneAPI::Utilities
|
||||
SCENE_CORE_API void Write(const char* name, AZStd::optional<AZ::Vector3> data);
|
||||
|
||||
SCENE_CORE_API const AZStd::string& GetOutput() const;
|
||||
SCENE_CORE_API DebugNode GetDebugNode() const;
|
||||
|
||||
SCENE_CORE_API static void BuildDebugSceneGraph(const char* outputFolder, AZ::SceneAPI::Events::ExportProductList& productList, const AZStd::shared_ptr<AZ::SceneAPI::Containers::Scene>& scene, AZStd::string productName);
|
||||
|
||||
protected:
|
||||
AZStd::string m_output;
|
||||
DebugSceneGraph m_graph;
|
||||
DebugNode m_currentNode;
|
||||
bool m_pauseNodeData = false; // If true, don't append any data to the DebugNode. Useful when a Write function calls other Write functions
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,11 @@ namespace AZ::SceneAPI::Utilities
|
||||
template <typename T>
|
||||
void DebugOutput::Write(const char* name, const AZStd::vector<T>& data)
|
||||
{
|
||||
m_output += AZStd::string::format("\t%s: Count %zu. Hash: %zu\n", name, data.size(), AZStd::hash_range(data.begin(), data.end()));
|
||||
size_t hash = AZStd::hash_range(data.begin(), data.end());
|
||||
m_output += AZStd::string::format("\t%s: Count %zu. Hash: %zu\n", name, data.size(), hash);
|
||||
|
||||
AddToNode(AZStd::string::format("%s - Count", name).c_str(), data.size());
|
||||
AddToNode(AZStd::string::format("%s - Hash", name).c_str(), hash);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
@@ -27,5 +31,9 @@ namespace AZ::SceneAPI::Utilities
|
||||
}
|
||||
|
||||
m_output += AZStd::string::format("\t%s: Count %zu. Hash: %zu\n", name, data.size(), hash);
|
||||
|
||||
AddToNode(AZStd::string::format("%s - Count", name).c_str(), data.size());
|
||||
AddToNode(AZStd::string::format("%s - Hash", name).c_str(), hash);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user