DebugOutput.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #include <SceneAPI/SceneCore/SceneCoreConfiguration.h>
  10. #include <SceneAPI/SceneCore/DataTypes/MatrixType.h>
  11. #include <SceneAPI/SceneCore/Utilities/HashHelper.h>
  12. #include <AzCore/std/string/string.h>
  13. #include <AzCore/std/containers/vector.h>
  14. #include <AzCore/std/optional.h>
  15. #include <cinttypes>
  16. #include <AzCore/std/any.h>
  17. namespace AZ
  18. {
  19. namespace SceneAPI
  20. {
  21. namespace Containers
  22. {
  23. class Scene;
  24. }
  25. namespace Events
  26. {
  27. struct ExportProduct;
  28. class ExportProductList;
  29. }
  30. }
  31. }
  32. namespace AZ::SceneAPI::Utilities
  33. {
  34. constexpr int SceneGraphVersion = 1;
  35. //! IsDebugEnabled - returns true if additional debug output is desired from scene processing.
  36. SCENE_CORE_API bool IsDebugEnabled();
  37. struct DebugNode
  38. {
  39. AZ_TYPE_INFO(DebugNode, "{490B9D4C-1847-46EB-BEBC-49812E104626}");
  40. AZStd::string m_name;
  41. AZStd::string m_path;
  42. AZStd::string m_type;
  43. DebugNode() = default;
  44. DebugNode(AZStd::string name, AZStd::string path, AZStd::string type)
  45. : m_name(AZStd::move(name)),
  46. m_path(AZStd::move(path)),
  47. m_type(AZStd::move(type))
  48. {
  49. }
  50. static void Reflect(AZ::ReflectContext* context);
  51. using DataItem = AZStd::pair<AZStd::string, AZStd::any>;
  52. AZStd::vector<DataItem> m_data;
  53. };
  54. struct DebugSceneGraph
  55. {
  56. AZ_TYPE_INFO(DebugSceneGraph, "{375F6558-5709-409F-881E-8ED575D56C92}");
  57. int m_version = SceneGraphVersion;
  58. AZStd::string m_productName;
  59. AZStd::string m_sceneName;
  60. AZStd::vector<DebugNode> m_nodes;
  61. static void Reflect(AZ::ReflectContext* context);
  62. };
  63. class DebugOutput
  64. {
  65. public:
  66. DebugOutput(DebugNode node) : m_currentNode(AZStd::move(node)){}
  67. template<typename T>
  68. void Write(const char* name, const AZStd::vector<T>& data);
  69. template<typename T>
  70. void Write(const char* name, const AZStd::vector<AZStd::vector<T>>& data);
  71. template<typename T>
  72. void AddToNode(const char* name, const T& data)
  73. {
  74. if (!m_pauseNodeData)
  75. {
  76. m_currentNode.m_data.emplace_back(name, AZStd::make_any<AZStd::decay_t<T>>(data));
  77. }
  78. }
  79. SCENE_CORE_API void Write(const char* name, const char* data);
  80. SCENE_CORE_API void WriteArray(const char* name, const unsigned int* data, int size);
  81. SCENE_CORE_API void Write(const char* name, const AZStd::string& data);
  82. SCENE_CORE_API void Write(const char* name, double data);
  83. SCENE_CORE_API void Write(const char* name, uint64_t data);
  84. SCENE_CORE_API void Write(const char* name, int64_t data);
  85. SCENE_CORE_API void Write(const char* name, const DataTypes::MatrixType& data);
  86. SCENE_CORE_API void Write(const char* name, bool data);
  87. SCENE_CORE_API void Write(const char* name, Vector3 data);
  88. SCENE_CORE_API void Write(const char* name, AZStd::optional<bool> data);
  89. SCENE_CORE_API void Write(const char* name, AZStd::optional<float> data);
  90. SCENE_CORE_API void Write(const char* name, AZStd::optional<AZ::Vector3> data);
  91. SCENE_CORE_API const AZStd::string& GetOutput() const;
  92. SCENE_CORE_API DebugNode GetDebugNode() const;
  93. 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);
  94. protected:
  95. AZStd::string m_output;
  96. DebugSceneGraph m_graph;
  97. DebugNode m_currentNode;
  98. bool m_pauseNodeData = false; // If true, don't append any data to the DebugNode. Useful when a Write function calls other Write functions
  99. };
  100. }
  101. #include "DebugOutput.inl"