You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
100 lines
4.5 KiB
C++
100 lines
4.5 KiB
C++
/*
|
|
* 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("Game", 0x232b318c))
|
|
->Attribute(AZ::Edit::Attributes::HelpPageURL, "https://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("PhysXJointService", 0x0d2f906f));
|
|
}
|
|
|
|
void EditorFixedJointComponent::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
|
|
{
|
|
required.push_back(AZ_CRC("TransformService", 0x8ee22c50));
|
|
required.push_back(AZ_CRC("PhysXColliderService", 0x4ff43f7c));
|
|
required.push_back(AZ_CRC("PhysXRigidBodyService", 0x1d4c64a8));
|
|
}
|
|
|
|
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::SubModeParamaterState> EditorFixedJointComponent::GetSubComponentModesState()
|
|
{
|
|
return EditorJointComponent::GetSubComponentModesState();
|
|
}
|
|
}
|