PhysicsSetupViewportUiCluster.h 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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/Math/Transform.h>
  10. #include <AzToolsFramework/ViewportUi/ViewportUiRequestBus.h>
  11. #include <Editor/Plugins/Ragdoll/PhysicsSetupManipulators.h>
  12. namespace EMotionFX
  13. {
  14. class Actor;
  15. class Node;
  16. class Transform;
  17. //! Provides UI in the viewport for manipulating physics configurations such as collider and joint limit settings.
  18. class PhysicsSetupViewportUiCluster
  19. {
  20. public:
  21. PhysicsSetupViewportUiCluster();
  22. void UpdateClusters(PhysicsSetupManipulatorData physicsSetupManipulatorData);
  23. void DestroyClusterIfExists();
  24. enum class SubMode : AZ::u32
  25. {
  26. Null,
  27. ColliderTranslation,
  28. ColliderRotation,
  29. ColliderDimensions,
  30. JointLimitParentRotation,
  31. JointLimitChildRotation,
  32. JointSwingLimits,
  33. JointTwistLimits,
  34. JointLimitOptimization,
  35. NumModes
  36. };
  37. //! Used to track the cluster that a specific button is a part of.
  38. struct ButtonData
  39. {
  40. AzToolsFramework::ViewportUi::ClusterId m_clusterId = AzToolsFramework::ViewportUi::InvalidClusterId;
  41. AzToolsFramework::ViewportUi::ButtonId m_buttonId = AzToolsFramework::ViewportUi::InvalidButtonId;
  42. };
  43. constexpr static const char* const ColliderTranslationTooltip = "Switch to collider translation mode";
  44. constexpr static const char* const ColliderRotationTooltip = "Switch to collider rotation mode";
  45. constexpr static const char* const ColliderDimensionsTooltip = "Switch to collider dimensions mode";
  46. constexpr static const char* const JointLimitParentRotationTooltip = "Switch to joint limit parent frame rotation mode";
  47. constexpr static const char* const JointLimitChildRotationTooltip = "Switch to joint limit child frame rotation mode";
  48. constexpr static const char* const JointLimitSwingTooltip = "Switch to joint swing limit mode";
  49. constexpr static const char* const JointLimitTwistTooltip = "Switch to joint twist limit mode";
  50. constexpr static const char* const JointLimitAutofitTooltip = "Automatic joint limit setup";
  51. private:
  52. void SetCurrentMode(SubMode mode);
  53. AZ::s32 GetViewportId() const;
  54. AzToolsFramework::ViewportUi::ClusterId m_colliderClusterId = AzToolsFramework::ViewportUi::InvalidClusterId;
  55. AzToolsFramework::ViewportUi::ClusterId m_jointLimitClusterId = AzToolsFramework::ViewportUi::InvalidClusterId;
  56. AZStd::vector<ButtonData> m_buttonData;
  57. AZStd::unordered_map<SubMode, AZStd::unique_ptr<PhysicsSetupManipulatorsBase>> m_subModes;
  58. SubMode m_subMode = SubMode::Null;
  59. AZ::Event<AzToolsFramework::ViewportUi::ButtonId>::Handler
  60. m_colliderModeSelectionHandler; //!< Event handler for sub mode changes in the collider cluster.
  61. AZ::Event<AzToolsFramework::ViewportUi::ButtonId>::Handler
  62. m_jointLimitModeSelectionHandler; //!< Event handler for sub mode changes in the joint limit cluster.
  63. PhysicsSetupManipulatorData m_physicsSetupManipulatorData;
  64. mutable AZStd::optional<AZ::s32> m_viewportId;
  65. bool m_hasColliders = false;
  66. bool m_hasCapsuleCollider = false;
  67. bool m_hasJointLimit = false;
  68. };
  69. } // namespace EMotionFX