LoggingGroup.cpp 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. #include <AzCore/Serialization/SerializeContext.h>
  9. #include <AzCore/Serialization/EditContext.h>
  10. #include <Groups/LoggingGroup.h>
  11. namespace SceneLoggingExample
  12. {
  13. const char* LoggingGroup::s_disabledOption = "No logging";
  14. LoggingGroup::LoggingGroup()
  15. : m_logProcessingEvents(true)
  16. {
  17. }
  18. // The data in groups will be saved to the manifest file and will be reflected in the Scene Settings
  19. // window. For those systems to do their work, the LoggingGroup needs to tell a bit more about itself
  20. // than the other classes in this example.
  21. void LoggingGroup::Reflect(AZ::ReflectContext* context)
  22. {
  23. // There are different kind of contexts, but for groups and rules, the only one that's
  24. // interesting is the SerializeContext. Check if the provided context is one.
  25. AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context);
  26. if (!serializeContext)
  27. {
  28. return;
  29. }
  30. // Next, specify the fields that need to be serialized to and from a manifest. This allows new
  31. // fields to be stored and loaded from the manifest (.assetinfo file). These are also needed
  32. // for the edit context below.
  33. serializeContext->Class<LoggingGroup, AZ::SceneAPI::DataTypes::IManifestObject>()->Version(1)
  34. ->Field("groupName", &LoggingGroup::m_groupName)
  35. ->Field("graphLogRoot", &LoggingGroup::m_graphLogRoot)
  36. ->Field("logProcessingEvents", &LoggingGroup::m_logProcessingEvents);
  37. // The EditContext allows you to add additional meta information to the previously registered fields.
  38. // This meta information will be used in the Scene Settings, which uses the Reflected Property Editor.
  39. AZ::EditContext* editContext = serializeContext->GetEditContext();
  40. if (editContext)
  41. {
  42. editContext->Class<LoggingGroup>("Logger", "Add additional logging to the SceneAPI.")
  43. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  44. ->Attribute("AutoExpand", true)
  45. ->Attribute(AZ::Edit::Attributes::NameLabelOverride, "")
  46. ->DataElement(AZ::Edit::UIHandlers::Default, &LoggingGroup::m_groupName,
  47. "Name", "The name of the group will be used in the log")
  48. // The Reflected Property Editor can pick a default editor for many types. However, for the string
  49. // that will store the selected node, a more specialized editor is needed. NodeListSelection is
  50. // one such editor and it is SceneGraph-aware. It allows the selection of a specific node from the
  51. // graph and the selectable items can be filtered. You can find other available editors in the
  52. // "RowWidgets"-folder of the SceneUI.
  53. ->DataElement(AZ_CRC("NodeListSelection", 0x45c54909), &LoggingGroup::m_graphLogRoot,
  54. "Graph log root", "Select the node in the graph to list children of to the log, or disable logging.")
  55. ->Attribute(AZ_CRC("DisabledOption", 0x6cd17278), s_disabledOption)
  56. // Nodes in the SceneGraph can be marked as endpoints. To the graph, this means that these nodes
  57. // are not allowed to have children. While not a true one-to-one mapping, endpoints often act as
  58. // attributes to a node. For example, a transform can be marked as an endpoint. This means that
  59. // it applies its transform to the parent object like an attribute. If the transform is not marked
  60. // as an endpoint, then it is the root transform for the group(s) that are its children.
  61. ->Attribute(AZ_CRC("ExcludeEndPoints", 0x53bd29cc), true)
  62. ->DataElement(AZ::Edit::UIHandlers::Default, &LoggingGroup::m_logProcessingEvents,
  63. "Log processing events", "Log processing events as they happen.");
  64. }
  65. }
  66. void LoggingGroup::SetName(const AZStd::string& name)
  67. {
  68. m_groupName = name;
  69. }
  70. void LoggingGroup::SetName(AZStd::string&& name)
  71. {
  72. m_groupName = AZStd::move(name);
  73. }
  74. const AZStd::string& LoggingGroup::GetName() const
  75. {
  76. return m_groupName;
  77. }
  78. // Groups need to provide a unique id that will be used to create the final sub id for the product
  79. // build using this group. While new groups created through the UI can remain fully random, it's
  80. // important that ids used for defaults are recreated the same way every time. It's recommended this
  81. // is done by using the source guid of the file and calling DataTypes::Utilities::CreateStableUuid.
  82. // If the id doesn't remain stable between updates this will cause the sub id to change which will in
  83. // turn cause the objects links to those products to break.
  84. //
  85. // As this example doesn't have a product, the id is not important so just always return the randomly
  86. // generated id.
  87. const AZ::Uuid& LoggingGroup::GetId() const
  88. {
  89. return m_id;
  90. }
  91. // Groups have the minimal amount of options to generate a working product in the cache and nothing more.
  92. // A group might not be perfect or contain all the data the user would expect, but it will load in the
  93. // engine and not crash. You can add additional settings to fine tune the exporting process in the form of
  94. // rules (or "modifiers" in the Scene Settings UI). Rules usually group a subset of settings together,
  95. // such as control of physics or level of detail. This approach keeps UI clutter to a minimum by only
  96. // presenting options that are relevant for the user's file, while still providing access to all available
  97. // settings.
  98. //
  99. // By using the "GetAvailableModifiers" in the ManifestMetaInfoHandler EBus, it's possible to filter out
  100. // any options that are not relevant to the group. For example, if a group only allows for a single instance
  101. // of a rule, it would no longer be added to this call if there is already one. Because the logging doesn't
  102. // require any rules, empty defaults are provided.
  103. AZ::SceneAPI::Containers::RuleContainer& LoggingGroup::GetRuleContainer()
  104. {
  105. return m_ruleContainer;
  106. }
  107. const AZ::SceneAPI::Containers::RuleContainer& LoggingGroup::GetRuleContainerConst() const
  108. {
  109. return m_ruleContainer;
  110. }
  111. const AZStd::string& LoggingGroup::GetGraphLogRoot() const
  112. {
  113. return m_graphLogRoot;
  114. }
  115. bool LoggingGroup::DoesLogGraph() const
  116. {
  117. return m_graphLogRoot.compare(s_disabledOption) != 0;
  118. }
  119. bool LoggingGroup::DoesLogProcessingEvents() const
  120. {
  121. return m_logProcessingEvents;
  122. }
  123. void LoggingGroup::ShouldLogProcessingEvents(bool state)
  124. {
  125. m_logProcessingEvents = state;
  126. }
  127. } // namespace SceneLoggingExample