WhiteBoxEdgeScaleModifier.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 <AzCore/Component/ComponentBus.h>
  10. #include <AzToolsFramework/Manipulators/LinearManipulator.h>
  11. #include <WhiteBox/WhiteBoxToolApi.h>
  12. namespace WhiteBox
  13. {
  14. //! Provides manipulators for scaling an edge on a white box mesh.
  15. class EdgeScaleModifier
  16. {
  17. public:
  18. AZ_CLASS_ALLOCATOR_DECL
  19. EdgeScaleModifier(const Api::EdgeHandle& edgeHandle, const AZ::EntityComponentIdPair& entityComponentIdPair);
  20. ~EdgeScaleModifier();
  21. void Refresh();
  22. Api::EdgeHandle GetEdgeHandle() const;
  23. void SetEdgeHandle(Api::EdgeHandle edgeHandle);
  24. private:
  25. //! The scaling modes supported by this modifier.
  26. enum class ScaleMode
  27. {
  28. Uniform,
  29. NonUniform
  30. };
  31. void CreateManipulators();
  32. void DestroyManipulators();
  33. void InitializeScaleModifier(
  34. const WhiteBoxMesh* whiteBox, const AzToolsFramework::LinearManipulator::Action& action);
  35. static ScaleMode GetScaleModeFromModifierKey(
  36. const AzToolsFramework::ViewportInteraction::KeyboardModifiers& modifiers);
  37. AZ::EntityComponentIdPair
  38. m_entityComponentIdPair; //!< The entity and component id this modifier is associated with.
  39. Api::EdgeHandle m_edgeHandle; //!< The edge handle this modifier is responsible for.
  40. AZStd::array<AZStd::shared_ptr<AzToolsFramework::LinearManipulator>, 2>
  41. m_scaleManipulators; //!< Manipulators to handle each end of an edge.
  42. AZStd::array<AZ::Vector3, 2>
  43. m_initialVertexPositions; //!< The initial position of all vertices when scaling begins.
  44. AZ::Vector3 m_pivotPoint; //!< The pivot point for scaling.
  45. float m_startingDistance =
  46. 0.0f; //!< The distance a manipulator is from the pivot point when an interaction first begins.
  47. AZ::u32 m_selectedHandleIndex = 0; //!< The vertex that will be scaled for non-uniform scaling.
  48. ScaleMode m_scaleMode = ScaleMode::Uniform; //!< The current scale mode being applied.
  49. };
  50. inline Api::EdgeHandle EdgeScaleModifier::GetEdgeHandle() const
  51. {
  52. return m_edgeHandle;
  53. }
  54. inline void EdgeScaleModifier::SetEdgeHandle(Api::EdgeHandle edgeHandle)
  55. {
  56. m_edgeHandle = edgeHandle;
  57. }
  58. } // namespace WhiteBox