WhiteBoxVertexTranslationModifier.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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/Component/ComponentBus.h>
  11. #include <AzCore/Component/TickBus.h>
  12. #include <AzCore/Memory/Memory.h>
  13. #include <AzCore/std/smart_ptr/shared_ptr.h>
  14. #include <AzFramework/Entity/EntityDebugDisplayBus.h>
  15. #include <WhiteBox/WhiteBoxToolApi.h>
  16. namespace AzToolsFramework
  17. {
  18. class ManipulatorViewSphere;
  19. class MultiLinearManipulator;
  20. namespace ViewportInteraction
  21. {
  22. struct MouseInteraction;
  23. }
  24. } // namespace AzToolsFramework
  25. namespace WhiteBox
  26. {
  27. //! VertexTranslationModifier provides the ability to translate a single vertex in the viewport.
  28. class VertexTranslationModifier
  29. : private AzFramework::ViewportDebugDisplayEventBus::Handler
  30. , private AZ::TickBus::Handler
  31. {
  32. public:
  33. AZ_CLASS_ALLOCATOR_DECL
  34. using HandleType = Api::VertexHandle;
  35. VertexTranslationModifier(
  36. const AZ::EntityComponentIdPair& entityComponentIdPair, Api::VertexHandle vertexHandle,
  37. const AZ::Vector3& intersectionPoint);
  38. ~VertexTranslationModifier();
  39. bool MouseOver() const;
  40. void ForwardMouseOverEvent(const AzToolsFramework::ViewportInteraction::MouseInteraction& interaction);
  41. Api::VertexHandle GetHandle() const; // Generic context version
  42. Api::VertexHandle GetVertexHandle() const;
  43. void SetVertexHandle(Api::VertexHandle vertexHandle);
  44. void SetColor(const AZ::Color& color);
  45. void Refresh();
  46. void CreateView();
  47. bool PerformingAction() const;
  48. static const int InvalidAxisIndex = -1;
  49. private:
  50. void CreateManipulator();
  51. void DestroyManipulator();
  52. // ViewportDebugDisplayEventBus ...
  53. void DisplayViewport(
  54. const AzFramework::ViewportInfo& viewportInfo, AzFramework::DebugDisplayRequests& debugDisplay) override;
  55. // TickBis ...
  56. void OnTick(float deltaTime, AZ::ScriptTimePoint time) override;
  57. Api::VertexHandle m_vertexHandle; //!< The vertex handle this modifier is currently associated with.
  58. AZ::EntityComponentIdPair
  59. m_entityComponentIdPair; //!< The entity and component id this modifier is associated with.
  60. AZStd::shared_ptr<AzToolsFramework::MultiLinearManipulator>
  61. m_translationManipulator; //!< Manipulator for performing vertex translation.
  62. AZStd::shared_ptr<AzToolsFramework::ManipulatorViewSphere>
  63. m_vertexView; //!< Manipulator view used to represent a mesh vertex for selection.
  64. AZ::Color m_color = ed_whiteBoxVertexHover; //!< The current color of the vertex.
  65. AZ::Vector3
  66. m_localPositionAtMouseDown; //!< The position of the modifier in local space at the time of mouse down.
  67. int m_actionIndex = InvalidAxisIndex; //!< Which action (axis) are we moving along for the given vertex.
  68. float m_pressTime = 0.0f; //!< Duration of press and hold of modifier.
  69. };
  70. inline Api::VertexHandle VertexTranslationModifier::GetHandle() const
  71. {
  72. return GetVertexHandle();
  73. }
  74. inline Api::VertexHandle VertexTranslationModifier::GetVertexHandle() const
  75. {
  76. return m_vertexHandle;
  77. }
  78. inline void VertexTranslationModifier::SetVertexHandle(const Api::VertexHandle vertexHandle)
  79. {
  80. m_vertexHandle = vertexHandle;
  81. }
  82. inline void VertexTranslationModifier::SetColor(const AZ::Color& color)
  83. {
  84. m_color = color;
  85. }
  86. } // namespace WhiteBox