1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- /*
- * Copyright (c) Contributors to the Open 3D Engine Project.
- * For complete copyright and license terms please see the LICENSE at the root of this distribution.
- *
- * SPDX-License-Identifier: Apache-2.0 OR MIT
- *
- */
- #include <AzCore/Component/TransformBus.h>
- #include <AzCore/Math/IntersectSegment.h>
- #include <AzCore/Serialization/EditContext.h>
- #include <AzCore/Serialization/SerializeContext.h>
- #include <AzToolsFramework/ViewportSelection/EditorSelectionUtil.h>
- #include <Source/EditorFixedJointComponent.h>
- #include <Editor/Source/ComponentModes/Joints/JointsComponentMode.h>
- #include <Source/FixedJointComponent.h>
- namespace PhysX
- {
- void EditorFixedJointComponent::Reflect(AZ::ReflectContext* context)
- {
- if (auto* serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
- {
- serializeContext->Class<EditorFixedJointComponent, EditorJointComponent>()
- ->Version(2)
- ->Field("Component Mode", &EditorFixedJointComponent::m_componentModeDelegate)
- ;
- if (auto* editContext = serializeContext->GetEditContext())
- {
- editContext->Class<EditorFixedJointComponent>(
- "PhysX Fixed Joint",
- "A dynamic joint constraint that constrains a rigid body to the joint with no free translation or rotation on any axis.")
- ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
- ->Attribute(AZ::Edit::Attributes::Category, "PhysX")
- ->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC_CE("Game"))
- ->Attribute(AZ::Edit::Attributes::HelpPageURL, "https://www.o3de.org/docs/user-guide/components/reference/physx/fixed-joint/")
- ->Attribute(AZ::Edit::Attributes::AutoExpand, true)
- ->DataElement(AZ::Edit::UIHandlers::Default, &EditorFixedJointComponent::m_componentModeDelegate, "Component Mode", "Fixed Joint Component Mode.")
- ->Attribute(AZ::Edit::Attributes::Visibility, AZ::Edit::PropertyVisibility::ShowChildrenOnly)
- ;
- }
- }
- }
- void EditorFixedJointComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
- {
- provided.push_back(AZ_CRC_CE("PhysicsJointService"));
- }
- void EditorFixedJointComponent::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
- {
- required.push_back(AZ_CRC_CE("TransformService"));
- required.push_back(AZ_CRC_CE("PhysicsDynamicRigidBodyService"));
- }
- void EditorFixedJointComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
- {
- incompatible.push_back(AZ_CRC_CE("NonUniformScaleService"));
- }
- void EditorFixedJointComponent::Activate()
- {
- EditorJointComponent::Activate();
- const AZ::EntityId entityId = GetEntityId();
- AzToolsFramework::EditorComponentSelectionRequestsBus::Handler::BusConnect(entityId);
- AzToolsFramework::EditorComponentSelectionNotificationsBus::Handler::BusConnect(entityId);
- AzToolsFramework::EditorComponentSelectionRequestsBus::Handler* selection = this;
- m_componentModeDelegate.ConnectWithSingleComponentMode<EditorFixedJointComponent, JointsComponentMode>(
- AZ::EntityComponentIdPair(entityId, GetId()), selection);
- PhysX::EditorJointRequestBus::Handler::BusConnect(AZ::EntityComponentIdPair(entityId, GetId()));
- }
- void EditorFixedJointComponent::Deactivate()
- {
- PhysX::EditorJointRequestBus::Handler::BusDisconnect();
- m_componentModeDelegate.Disconnect();
- AzToolsFramework::EditorComponentSelectionNotificationsBus::Handler::BusDisconnect();
- AzToolsFramework::EditorComponentSelectionRequestsBus::Handler::BusDisconnect();
- EditorJointComponent::Deactivate();
- }
- void EditorFixedJointComponent::BuildGameEntity(AZ::Entity* gameEntity)
- {
- m_config.m_followerEntity = GetEntityId(); // joint is always in the same entity as the follower body.
- gameEntity->CreateComponent<FixedJointComponent>(m_config.ToGameTimeConfig(), m_config.ToGenericProperties());
- }
- AZStd::vector<JointsComponentModeCommon::SubModeParameterState> EditorFixedJointComponent::GetSubComponentModesState()
- {
- return EditorJointComponent::GetSubComponentModesState();
- }
- }
|