EditorFixedJointComponent.cpp 4.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. #include <AzCore/Component/TransformBus.h>
  9. #include <AzCore/Math/IntersectSegment.h>
  10. #include <AzCore/Serialization/EditContext.h>
  11. #include <AzCore/Serialization/SerializeContext.h>
  12. #include <AzToolsFramework/ViewportSelection/EditorSelectionUtil.h>
  13. #include <Source/EditorFixedJointComponent.h>
  14. #include <Editor/Source/ComponentModes/Joints/JointsComponentMode.h>
  15. #include <Source/FixedJointComponent.h>
  16. namespace PhysX
  17. {
  18. void EditorFixedJointComponent::Reflect(AZ::ReflectContext* context)
  19. {
  20. if (auto* serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  21. {
  22. serializeContext->Class<EditorFixedJointComponent, EditorJointComponent>()
  23. ->Version(2)
  24. ->Field("Component Mode", &EditorFixedJointComponent::m_componentModeDelegate)
  25. ;
  26. if (auto* editContext = serializeContext->GetEditContext())
  27. {
  28. editContext->Class<EditorFixedJointComponent>(
  29. "PhysX Fixed Joint",
  30. "A dynamic joint constraint that constrains a rigid body to the joint with no free translation or rotation on any axis.")
  31. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  32. ->Attribute(AZ::Edit::Attributes::Category, "PhysX")
  33. ->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC_CE("Game"))
  34. ->Attribute(AZ::Edit::Attributes::HelpPageURL, "https://www.o3de.org/docs/user-guide/components/reference/physx/fixed-joint/")
  35. ->Attribute(AZ::Edit::Attributes::AutoExpand, true)
  36. ->DataElement(AZ::Edit::UIHandlers::Default, &EditorFixedJointComponent::m_componentModeDelegate, "Component Mode", "Fixed Joint Component Mode.")
  37. ->Attribute(AZ::Edit::Attributes::Visibility, AZ::Edit::PropertyVisibility::ShowChildrenOnly)
  38. ;
  39. }
  40. }
  41. }
  42. void EditorFixedJointComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
  43. {
  44. provided.push_back(AZ_CRC_CE("PhysicsJointService"));
  45. }
  46. void EditorFixedJointComponent::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
  47. {
  48. required.push_back(AZ_CRC_CE("TransformService"));
  49. required.push_back(AZ_CRC_CE("PhysicsDynamicRigidBodyService"));
  50. }
  51. void EditorFixedJointComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
  52. {
  53. incompatible.push_back(AZ_CRC_CE("NonUniformScaleService"));
  54. }
  55. void EditorFixedJointComponent::Activate()
  56. {
  57. EditorJointComponent::Activate();
  58. const AZ::EntityId entityId = GetEntityId();
  59. AzToolsFramework::EditorComponentSelectionRequestsBus::Handler::BusConnect(entityId);
  60. AzToolsFramework::EditorComponentSelectionNotificationsBus::Handler::BusConnect(entityId);
  61. AzToolsFramework::EditorComponentSelectionRequestsBus::Handler* selection = this;
  62. m_componentModeDelegate.ConnectWithSingleComponentMode<EditorFixedJointComponent, JointsComponentMode>(
  63. AZ::EntityComponentIdPair(entityId, GetId()), selection);
  64. PhysX::EditorJointRequestBus::Handler::BusConnect(AZ::EntityComponentIdPair(entityId, GetId()));
  65. }
  66. void EditorFixedJointComponent::Deactivate()
  67. {
  68. PhysX::EditorJointRequestBus::Handler::BusDisconnect();
  69. m_componentModeDelegate.Disconnect();
  70. AzToolsFramework::EditorComponentSelectionNotificationsBus::Handler::BusDisconnect();
  71. AzToolsFramework::EditorComponentSelectionRequestsBus::Handler::BusDisconnect();
  72. EditorJointComponent::Deactivate();
  73. }
  74. void EditorFixedJointComponent::BuildGameEntity(AZ::Entity* gameEntity)
  75. {
  76. m_config.m_followerEntity = GetEntityId(); // joint is always in the same entity as the follower body.
  77. gameEntity->CreateComponent<FixedJointComponent>(m_config.ToGameTimeConfig(), m_config.ToGenericProperties());
  78. }
  79. AZStd::vector<JointsComponentModeCommon::SubModeParameterState> EditorFixedJointComponent::GetSubComponentModesState()
  80. {
  81. return EditorJointComponent::GetSubComponentModesState();
  82. }
  83. }