2
0

NodeSoftNameSetting.cpp 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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/EditContext.h>
  9. #include <SceneAPI/SceneCore/Containers/Scene.h>
  10. #include <SceneAPI/SceneCore/Containers/Views/SceneGraphUpwardsIterator.h>
  11. #include <Config/SettingsObjects/NodeSoftNameSetting.h>
  12. namespace AZ
  13. {
  14. namespace SceneProcessingConfig
  15. {
  16. NodeSoftNameSetting::NodeSoftNameSetting(const char* pattern, SceneAPI::SceneCore::PatternMatcher::MatchApproach approach,
  17. const char* virtualType, bool includeChildren)
  18. : SoftNameSetting(pattern, approach, virtualType)
  19. , m_includeChildren(includeChildren)
  20. {
  21. }
  22. void NodeSoftNameSetting::Reflect(ReflectContext* context)
  23. {
  24. SerializeContext* serialize = azrtti_cast<SerializeContext*>(context);
  25. if (serialize)
  26. {
  27. serialize->Class<NodeSoftNameSetting, SoftNameSetting>()
  28. ->Version(1)
  29. ->Field("includeChildren", &NodeSoftNameSetting::m_includeChildren);
  30. serialize->RegisterGenericType<AZStd::vector<AZStd::unique_ptr<NodeSoftNameSetting>>>();
  31. EditContext* editContext = serialize->GetEditContext();
  32. if (editContext)
  33. {
  34. editContext->Class<NodeSoftNameSetting>("Node name setting", "Applies the pattern to the name of the node.")
  35. ->ClassElement(Edit::ClassElements::EditorData, "")
  36. ->Attribute(Edit::Attributes::AutoExpand, true)
  37. ->DataElement(Edit::UIHandlers::Default, &NodeSoftNameSetting::m_includeChildren,
  38. "Include child nodes", "Whether or not the soft name only applies to the matching node or propagated to all its children as well.");
  39. }
  40. }
  41. }
  42. bool NodeSoftNameSetting::IsVirtualType(const SceneAPI::Containers::Scene& scene, SceneAPI::Containers::SceneGraph::NodeIndex node) const
  43. {
  44. const SceneAPI::Containers::SceneGraph& graph = scene.GetGraph();
  45. if (m_includeChildren)
  46. {
  47. auto upwardsView = SceneAPI::Containers::Views::MakeSceneGraphUpwardsView(graph, node, graph.GetNameStorage().begin(), true);
  48. for (const SceneAPI::Containers::SceneGraph::Name& name : upwardsView)
  49. {
  50. if (MatchesPattern(name))
  51. {
  52. return true;
  53. }
  54. }
  55. return false;
  56. }
  57. else
  58. {
  59. return MatchesPattern(graph.GetNodeName(node));
  60. }
  61. }
  62. const AZ::Uuid NodeSoftNameSetting::GetTypeId() const
  63. {
  64. return azrtti_typeid<NodeSoftNameSetting>();
  65. }
  66. bool NodeSoftNameSetting::MatchesPattern(const SceneAPI::Containers::SceneGraph::Name& name) const
  67. {
  68. switch (m_pattern.GetMatchApproach())
  69. {
  70. case SceneAPI::SceneCore::PatternMatcher::MatchApproach::PreFix:
  71. return m_pattern.MatchesPattern(name.GetName(), name.GetNameLength());
  72. case SceneAPI::SceneCore::PatternMatcher::MatchApproach::PostFix:
  73. return m_pattern.MatchesPattern(name.GetPath(), name.GetPathLength());
  74. case SceneAPI::SceneCore::PatternMatcher::MatchApproach::Regex:
  75. return m_pattern.MatchesPattern(name.GetPath(), name.GetPathLength());
  76. default:
  77. AZ_Assert(false, "Unknown option '%i' for pattern matcher.", m_pattern.GetMatchApproach());
  78. return false;
  79. }
  80. }
  81. } // namespace SceneProcessingConfig
  82. } // namespace AZ