SceneGraphSelector.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #pragma once
  2. /*
  3. * Copyright (c) Contributors to the Open 3D Engine Project.
  4. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  5. *
  6. * SPDX-License-Identifier: Apache-2.0 OR MIT
  7. *
  8. */
  9. #include <AzCore/std/functional.h>
  10. #include <AzCore/std/string/string.h>
  11. #include <AzCore/std/containers/set.h>
  12. #include <AzCore/std/containers/unordered_set.h>
  13. #include <SceneAPI/SceneCore/Containers/SceneGraph.h>
  14. namespace AZ::SceneAPI::DataTypes {
  15. class ISceneNodeSelectionList;
  16. class ISceneNodeGroup;
  17. }
  18. namespace AZ::SceneAPI::Utilities
  19. {
  20. inline constexpr AZStd::string_view OptimizedMeshSuffix = "_optimized";
  21. inline constexpr AZStd::string_view OptimizedMeshPropertyMapKey = "o3de_optimized_mesh_node";
  22. inline constexpr AZStd::string_view OriginalUnoptimizedMeshPropertyMapKey = "o3de_original_unoptimized_mesh_node";
  23. // SceneGraphSelector provides utilities including converting selected and unselected node lists
  24. // in the MeshGroup into the final target node list.
  25. class SceneGraphSelector
  26. {
  27. public:
  28. using NodeFilterFunction = bool(const Containers::SceneGraph& graph, Containers::SceneGraph::NodeIndex& index);
  29. using NodeRemapFunction = Containers::SceneGraph::NodeIndex(const Containers::SceneGraph& graph, const Containers::SceneGraph::NodeIndex& index);
  30. SCENE_CORE_API static AZStd::vector<AZStd::string> GenerateTargetNodes(
  31. const Containers::SceneGraph& graph,
  32. const DataTypes::ISceneNodeSelectionList& list,
  33. NodeFilterFunction nodeFilter,
  34. NodeRemapFunction nodeRemap = NoRemap);
  35. SCENE_CORE_API static void SelectAll(const Containers::SceneGraph& graph, DataTypes::ISceneNodeSelectionList& list);
  36. SCENE_CORE_API static void UnselectAll(const Containers::SceneGraph& graph, DataTypes::ISceneNodeSelectionList& list);
  37. SCENE_CORE_API static void UpdateNodeSelection(const Containers::SceneGraph& graph, DataTypes::ISceneNodeSelectionList& list);
  38. SCENE_CORE_API static void UpdateTargetNodes(const Containers::SceneGraph& graph, DataTypes::ISceneNodeSelectionList& list,
  39. const AZStd::unordered_set<AZStd::string>& targetNodes, NodeFilterFunction nodeFilter);
  40. SCENE_CORE_API static bool IsTreeViewType(const Containers::SceneGraph& graph, Containers::SceneGraph::NodeIndex& index);
  41. SCENE_CORE_API static bool IsMesh(const Containers::SceneGraph& graph, Containers::SceneGraph::NodeIndex& index);
  42. SCENE_CORE_API static bool IsMeshObject(const AZStd::shared_ptr<const DataTypes::IGraphObject>& object);
  43. //! Returns the index that is passed in without remapping it.
  44. //! GenerateTargetNodes takes a NodeRemapFunction as input. NoRemap is used as the default
  45. //! if you want to call GenerateTargetNodes without doing any re-mapping
  46. SCENE_CORE_API static Containers::SceneGraph::NodeIndex NoRemap(
  47. [[maybe_unused]] const Containers::SceneGraph& /*graph*/,
  48. const Containers::SceneGraph::NodeIndex& index)
  49. {
  50. return index;
  51. }
  52. //! Remaps unoptimizedMeshNodeIndex to the optimized version of the mesh, if it exists.
  53. //! @param graph The scene graph
  54. //! @param unoptimizedMeshNodeIndex The node index of the unoptimized mesh
  55. //! @return Returns the node index of the optimized mesh if it exists, or unoptimizedMeshNodeIndex if it doesn't exist
  56. SCENE_CORE_API static Containers::SceneGraph::NodeIndex RemapToOptimizedMesh(
  57. const Containers::SceneGraph& graph, const Containers::SceneGraph::NodeIndex& unoptimizedMeshNodeIndex);
  58. //! Remap optimizedMeshNodeIndex to the original unoptimized version of the mesh, if it exists
  59. //! @param graph The scene graph
  60. //! @param optimizedMeshNodeIndex The node index of the optimized mesh
  61. //! @return Returns the node index of the original unoptimized mesh if it exists. Returns optimizedMeshNodeIndex if it doesn't exist.
  62. SCENE_CORE_API static Containers::SceneGraph::NodeIndex RemapToOriginalUnoptimizedMesh(
  63. const Containers::SceneGraph& graph, const Containers::SceneGraph::NodeIndex& optimizedMeshNodeIndex);
  64. //! Look for a ICustomPropertyData child node. If it exists, use the property map
  65. //! to look for an entry that matches customPropertyKey, and return the result
  66. //! @param graph The scene graph
  67. //! @param index The node index that is being remapped
  68. //! @param customPropertyKey The key to use to look up the remapped index in the property map
  69. //! @return Returns the remapped node index if one matching customPropertyKey is found. Returns the input index if it doesn't exist.
  70. SCENE_CORE_API static Containers::SceneGraph::NodeIndex RemapNodeIndex(
  71. const Containers::SceneGraph& graph,
  72. const Containers::SceneGraph::NodeIndex& index,
  73. const AZStd::string_view customPropertyKey);
  74. //! Generate a name for an optimized mesh node based on the name of the original node and the mesh group it belongs to
  75. SCENE_CORE_API static AZStd::string GenerateOptimizedMeshNodeName(
  76. const Containers::SceneGraph& graph,
  77. const Containers::SceneGraph::NodeIndex& unoptimizedMeshNodeIndex,
  78. const DataTypes::ISceneNodeGroup& meshGroup);
  79. private:
  80. static void CopySelectionToSet(
  81. AZStd::unordered_set<AZStd::string>& selected, AZStd::unordered_set<AZStd::string>& unselected,
  82. const DataTypes::ISceneNodeSelectionList& list);
  83. static void CorrectRootNode(
  84. const Containers::SceneGraph& graph,
  85. AZStd::unordered_set<AZStd::string>& selected, AZStd::unordered_set<AZStd::string>& unselected);
  86. };
  87. }