EditorWhiteBoxTransformMode.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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 "EditorWhiteBoxComponentMode.h"
  10. #include "EditorWhiteBoxComponentModeTypes.h"
  11. #include "Viewport/WhiteBoxManipulatorViews.h"
  12. #include <AzCore/Math/Quaternion.h>
  13. #include <AzCore/std/containers/variant.h>
  14. #include <AzCore/std/containers/vector.h>
  15. #include <AzCore/std/optional.h>
  16. #include <AzCore/std/smart_ptr/shared_ptr.h>
  17. #include <SubComponentModes/EditorWhiteBoxTransformModeBus.h>
  18. #include <WhiteBox/WhiteBoxToolApi.h>
  19. namespace AZ
  20. {
  21. class Color;
  22. class Transform;
  23. class EntityComponentIdPair;
  24. } // namespace AZ
  25. namespace AzFramework
  26. {
  27. struct ViewportInfo;
  28. }
  29. namespace AzToolsFramework
  30. {
  31. namespace ViewportInteraction
  32. {
  33. struct MouseInteractionEvent;
  34. }
  35. struct ActionOverride;
  36. } // namespace AzToolsFramework
  37. namespace WhiteBox
  38. {
  39. struct IntersectionAndRenderData;
  40. class TransformMode
  41. : public EditorWhiteBoxTransformModeRequestBus::Handler
  42. {
  43. public:
  44. AZ_CLASS_ALLOCATOR_DECL
  45. constexpr static const char* const ManipulatorModeClusterTranslateTooltip = "Switch to translate mode";
  46. constexpr static const char* const ManipulatorModeClusterRotateTooltip = "Switch to rotate mode";
  47. constexpr static const char* const ManipulatorModeClusterScaleTooltip = "Switch to scale mode";
  48. using IntersectionSelection = AZStd::variant<PolygonIntersection, EdgeIntersection, VertexIntersection, AZStd::monostate>;
  49. TransformMode(const AZ::EntityComponentIdPair& entityComponentIdPair);
  50. ~TransformMode();
  51. static void RegisterActionUpdaters();
  52. static void RegisterActions();
  53. static void BindActionsToModes(const AZStd::string& modeIdentifier);
  54. static void BindActionsToMenus();
  55. void Refresh();
  56. AZStd::vector<AzToolsFramework::ActionOverride> PopulateActions(const AZ::EntityComponentIdPair& entityComponentIdPair);
  57. void Display(
  58. const AZ::EntityComponentIdPair& entityComponentIdPair,
  59. const AZ::Transform& worldFromLocal,
  60. const IntersectionAndRenderData& renderData,
  61. const AzFramework::ViewportInfo& viewportInfo,
  62. AzFramework::DebugDisplayRequests& debugDisplay);
  63. bool HandleMouseInteraction(
  64. const AzToolsFramework::ViewportInteraction::MouseInteractionEvent& mouseInteraction,
  65. const AZ::EntityComponentIdPair& entityComponentIdPair,
  66. const AZStd::optional<EdgeIntersection>& edgeIntersection,
  67. const AZStd::optional<PolygonIntersection>& polygonIntersection,
  68. const AZStd::optional<VertexIntersection>& vertexIntersection);
  69. // EditorWhiteBoxTransformModeRequestBus overrides ...
  70. void ChangeTransformType(TransformType subModeType) override;
  71. private:
  72. //! shared data that is used between the different transformation modes Translation/Rotation/Scale.
  73. struct VertexTransformSelection
  74. {
  75. AZ::Vector3 m_localPosition = AZ::Vector3::CreateZero();
  76. AZ::Quaternion m_localRotation = AZ::Quaternion::CreateIdentity();
  77. AZStd::vector<AZ::Vector3> m_vertexPositions;
  78. Api::VertexHandles m_vertexHandles;
  79. IntersectionSelection m_selection;
  80. };
  81. void CreateTranslationManipulators();
  82. void CreateRotationManipulators();
  83. void CreateScaleManipulators();
  84. void UpdateTransformHandles(WhiteBoxMesh* mesh);
  85. void RefreshManipulator();
  86. void DestroyManipulators();
  87. AZ::EntityComponentIdPair m_entityComponentIdPair; //!< The entity and component id this modifier is associated with.
  88. AZStd::shared_ptr<AzToolsFramework::Manipulators> m_manipulator = nullptr;
  89. AZStd::shared_ptr<VertexTransformSelection> m_whiteBoxSelection = nullptr;
  90. AZStd::optional<PolygonIntersection> m_polygonIntersection = AZStd::nullopt;
  91. AZStd::optional<EdgeIntersection> m_edgeIntersection = AZStd::nullopt;
  92. AZStd::optional<VertexIntersection> m_vertexIntersection = AZStd::nullopt;
  93. TransformType m_transformType = TransformType::Translation;
  94. AzToolsFramework::ViewportUi::ClusterId m_transformClusterId;
  95. AzToolsFramework::ViewportUi::ButtonId m_transformTranslateButtonId;
  96. AzToolsFramework::ViewportUi::ButtonId m_transformRotateButtonId;
  97. AzToolsFramework::ViewportUi::ButtonId m_transformScaleButtonId;
  98. AZ::Event<AzToolsFramework::ViewportUi::ButtonId>::Handler m_transformSelectionHandler;
  99. };
  100. } // namespace WhiteBox