WhiteBoxEdgeTranslationModifier.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 "Viewport/WhiteBoxViewportConstants.h"
  10. #include <AzCore/std/smart_ptr/shared_ptr.h>
  11. #include <AzCore/Component/ComponentBus.h>
  12. #include <WhiteBox/WhiteBoxToolApi.h>
  13. namespace AzToolsFramework
  14. {
  15. class PlanarManipulator;
  16. namespace ViewportInteraction
  17. {
  18. struct MouseInteraction;
  19. }
  20. } // namespace AzToolsFramework
  21. namespace WhiteBox
  22. {
  23. class ManipulatorViewEdge;
  24. //! EdgeTranslationModifier provides the ability to select and draw an edge in the viewport.
  25. class EdgeTranslationModifier
  26. {
  27. public:
  28. AZ_CLASS_ALLOCATOR_DECL
  29. using HandleType = Api::EdgeHandle;
  30. EdgeTranslationModifier(
  31. const AZ::EntityComponentIdPair& entityComponentIdPair, Api::EdgeHandle edgeHandle,
  32. const AZ::Vector3& intersectionPoint);
  33. ~EdgeTranslationModifier();
  34. bool MouseOver() const;
  35. void ForwardMouseOverEvent(const AzToolsFramework::ViewportInteraction::MouseInteraction& interaction);
  36. Api::EdgeHandle GetHandle() const; //!< Return the currently hovered edge (generic context version).
  37. Api::EdgeHandle GetEdgeHandle() const; //!< Return the currently hovered edge.
  38. Api::EdgeHandles::const_iterator EdgeHandlesBegin() const; //!< Return begin iterator to edge handles.
  39. Api::EdgeHandles::const_iterator EdgeHandlesEnd() const; //!< Return end iterator to edge handles.
  40. void SetEdgeHandle(Api::EdgeHandle edgeHandle);
  41. void SetColors(const AZ::Color& color, const AZ::Color& hoverColor);
  42. void SetWidths(float width, float hoverWidth);
  43. void Refresh();
  44. void CreateView();
  45. bool PerformingAction() const;
  46. private:
  47. void CreateManipulator();
  48. void DestroyManipulator();
  49. Api::EdgeHandles m_edgeHandles; //!< The edge handles this modifier is currently associated with (edge group).
  50. Api::EdgeHandle m_hoveredEdgeHandle; //!< The edge handle the mouse is currently over.
  51. //! The entity and component id this modifier is associated with.
  52. AZ::EntityComponentIdPair m_entityComponentIdPair;
  53. //! Manipulators for performing edge translations.
  54. AZStd::shared_ptr<AzToolsFramework::PlanarManipulator> m_translationManipulator;
  55. //! Manipulator views used to represent mesh edges for translation.
  56. AZStd::vector<AZStd::shared_ptr<ManipulatorViewEdge>> m_edgeViews;
  57. AZ::Color m_color = ed_whiteBoxEdgeDefault; //!< The color to use for the regular edge.
  58. AZ::Color m_hoverColor = ed_whiteBoxOutlineHover; //!< The color to use for the selected/highlighted edge.
  59. float m_width = cl_whiteBoxEdgeVisualWidth; //!< The width to use for the regular edge.
  60. //! The visible width to use for the selected/highlighted edge.
  61. float m_hoverWidth = cl_whiteBoxSelectedEdgeVisualWidth;
  62. };
  63. AZStd::array<AZ::Vector3, 2> GetEdgeNormalAxes(const AZ::Vector3& start, const AZ::Vector3& end);
  64. inline Api::EdgeHandle EdgeTranslationModifier::GetHandle() const
  65. {
  66. return GetEdgeHandle();
  67. }
  68. inline Api::EdgeHandle EdgeTranslationModifier::GetEdgeHandle() const
  69. {
  70. return m_hoveredEdgeHandle;
  71. }
  72. inline Api::EdgeHandles::const_iterator EdgeTranslationModifier::EdgeHandlesBegin() const
  73. {
  74. return m_edgeHandles.cbegin();
  75. }
  76. inline Api::EdgeHandles::const_iterator EdgeTranslationModifier::EdgeHandlesEnd() const
  77. {
  78. return m_edgeHandles.cend();
  79. }
  80. inline void EdgeTranslationModifier::SetEdgeHandle(const Api::EdgeHandle edgeHandle)
  81. {
  82. m_hoveredEdgeHandle = edgeHandle;
  83. }
  84. } // namespace WhiteBox