SelectedEntityState.cpp 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 <Pass/State/SelectedEntityState.h>
  9. #include <Pass/Child/EditorModeOutlinePass.h>
  10. #include <AzToolsFramework/Entity/EditorEntityHelpers.h>
  11. #include <AzToolsFramework/Viewport/ViewportMessages.h>
  12. #include <AzToolsFramework/Entity/EditorEntityInfoBus.h>
  13. namespace AZ::Render
  14. {
  15. // Name of the mask for selected entities
  16. static constexpr const char* const SelectedEntityMaskName = "editormodeselectedmask";
  17. // Indices of child passes (a better way to do this will be to specifiy a pass template name/effect name pair for the
  18. // PassNameList so we can lookup child passes by their effect name rather than having to maintain parity between
  19. // their ordering in the PassNameList and in this enum but that is a problem that will be addressed in the next
  20. // version where we remove the CVARs and have the editor state effects configured via menus and registry, see the note
  21. // in UpdatePassData below)
  22. enum class SelectedEntityChildPass
  23. {
  24. EntityOutlinePass
  25. };
  26. // Helper function to construct the pass descriptor list for this editor state effect.
  27. static PassNameList CreateSelectedEntityChildPasses()
  28. {
  29. return PassNameList
  30. {
  31. // Outline effect for the entities in the selected entity mask
  32. AZ::Name("EditorModeOutlineTemplate")
  33. };
  34. }
  35. SelectedEntityState::SelectedEntityState()
  36. : EditorStateBase(EditorState::EntitySelection, "EntitySelection", CreateSelectedEntityChildPasses(), SelectedEntityMaskName)
  37. {
  38. }
  39. void SelectedEntityState::UpdatePassData([[maybe_unused]] RPI::ParentPass* parentPass)
  40. {
  41. // Note: this is an example of how the state passes configure their child passes to tailor the effects in response to
  42. // settigns menus etc. Right now they can't be set here as the temporary CVARS are hogging the pass configuration
  43. //auto* entityOutlinePass =
  44. // FindChildPass<EditorModeOutlinePass>(parentPass, static_cast<std::size_t>(SelectedEntityChildPass::EntityOutlinePass));
  45. //
  46. //if (entityOutlinePass)
  47. //{
  48. // entityOutlinePass->SetLineColor(AZ::Color::CreateFromRgba(0, 0, 255, 255));
  49. //}
  50. }
  51. AzToolsFramework::EntityIdList SelectedEntityState::GetMaskedEntities() const
  52. {
  53. AzToolsFramework::EntityIdList initialSelectedEntityList, selectedEntityList;
  54. AzToolsFramework::ToolsApplicationRequestBus::BroadcastResult(
  55. initialSelectedEntityList, &AzToolsFramework::ToolsApplicationRequests::GetSelectedEntities);
  56. // Drill down any entity hierarchies to select all children of the currently selected entities
  57. for (const auto& selectedEntityId : initialSelectedEntityList)
  58. {
  59. AZStd::queue<AZ::EntityId> entityIdQueue;
  60. entityIdQueue.push(selectedEntityId);
  61. while (!entityIdQueue.empty())
  62. {
  63. AZ::EntityId entityId = entityIdQueue.front();
  64. entityIdQueue.pop();
  65. if (entityId.IsValid())
  66. {
  67. selectedEntityList.push_back(entityId);
  68. }
  69. AzToolsFramework::EntityIdList children;
  70. AzToolsFramework::EditorEntityInfoRequestBus::EventResult(
  71. children, entityId, &AzToolsFramework::EditorEntityInfoRequestBus::Events::GetChildren);
  72. for (AZ::EntityId childEntityId : children)
  73. {
  74. entityIdQueue.push(childEntityId);
  75. }
  76. }
  77. }
  78. return selectedEntityList;
  79. }
  80. } // namespace AZ::Render