Pārlūkot izejas kodu

Merge pull request #13890 from aws-lumberyard-dev/ahmadkrm/disallow-kinematic-and-ccd-enabled-at-the-same-time

Make CCD read only when kinematic is enabled and vice versa
Chris Galvan 2 gadi atpakaļ
vecāks
revīzija
a6943b6779

+ 38 - 0
Code/Framework/AzFramework/AzFramework/Physics/Configuration/RigidBodyConfiguration.cpp

@@ -12,6 +12,7 @@
 #include <AzCore/Serialization/EditContext.h>
 #include <AzCore/Serialization/SerializeContext.h>
 #include <AzFramework/Physics/Shape.h>
+#include <AzFramework/Physics/PhysicsSystem.h>
 
 namespace AzPhysics
 {
@@ -104,6 +105,24 @@ namespace AzPhysics
         }
     }
 
+    constexpr AZStd::string_view KinematicDescription =
+        "When active, the rigid body is not affected by gravity or other forces and is moved by script. ";
+
+    constexpr AZStd::string_view KinematicDescriptionReadOnly =
+        "When active, the rigid body is not affected by gravity or other forces and is moved by script. "
+        "<b>The rigid body cannot be set as Kinematic if CCD is enabled, disable CCD to allow changes to be made.</b>";
+
+    constexpr AZStd::string_view CcdDescription =
+        "When active, the rigid body has continuous collision detection (CCD). Use this to ensure accurate "
+        "collision detection, particularly for fast moving rigid bodies. CCD must be activated in the global PhysX "
+        "configuration. ";
+
+    constexpr AZStd::string_view CcdDescriptionReadOnly =
+        "When active, the rigid body has continuous collision detection (CCD). Use this to ensure accurate "
+        "collision detection, particularly for fast moving rigid bodies. CCD must be activated in the global PhysX "
+        "configuration. <b>CCD cannot be enabled if the rigid body is kinematic, set the rigid body as non-kinematic"
+        "to allow changes to be made.</b>";
+
     AZ_CLASS_ALLOCATOR_IMPL(RigidBodyConfiguration, AZ::SystemAllocator, 0);
 
     void RigidBodyConfiguration::Reflect(AZ::ReflectContext* context)
@@ -184,6 +203,25 @@ namespace AzPhysics
         return m_ccdEnabled;
     }
 
+    bool RigidBodyConfiguration::CcdReadOnly() const
+    {
+        if (auto* physicsSystem = AZ::Interface<AzPhysics::SystemInterface>::Get())
+        {
+            return !physicsSystem->GetDefaultSceneConfiguration().m_enableCcd || m_kinematic;
+        }
+        return m_kinematic;
+    }
+
+    AZStd::string_view RigidBodyConfiguration::GetCcdTooltip() const
+    {
+        return m_kinematic ? CcdDescriptionReadOnly : CcdDescription;
+    }
+
+    AZStd::string_view RigidBodyConfiguration::GetKinematicTooltip() const
+    {
+        return m_ccdEnabled ? KinematicDescriptionReadOnly : KinematicDescription;
+    }
+
     AZ::Crc32 RigidBodyConfiguration::GetInitialVelocitiesVisibility() const
     {
         return Internal::GetPropertyVisibility(m_propertyVisibilityFlags, RigidBodyConfiguration::PropertyVisibility::InitialVelocities);

+ 3 - 0
Code/Framework/AzFramework/AzFramework/Physics/Configuration/RigidBodyConfiguration.h

@@ -36,6 +36,9 @@ namespace AzPhysics
         void SetMassComputeFlags(MassComputeFlags flags);
 
         bool IsCcdEnabled() const;
+        bool CcdReadOnly() const;
+        AZStd::string_view GetCcdTooltip() const;
+        AZStd::string_view GetKinematicTooltip() const;
 
         // Basic initial settings.
         AZ::Vector3 m_initialLinearVelocity = AZ::Vector3::CreateZero();

+ 4 - 1
Gems/PhysX/Code/Source/EditorRigidBodyComponent.cpp

@@ -178,6 +178,8 @@ namespace PhysX
                     ->DataElement(AZ::Edit::UIHandlers::Default, &AzPhysics::RigidBodyConfiguration::m_kinematic,
                         "Kinematic", "When active, the rigid body is not affected by gravity or other forces and is moved by script.")
                         ->Attribute(AZ::Edit::Attributes::Visibility, &AzPhysics::RigidBodyConfiguration::GetKinematicVisibility)
+                        ->Attribute(AZ::Edit::Attributes::ReadOnly, &AzPhysics::RigidBodyConfiguration::m_ccdEnabled)
+                        ->Attribute(AZ::Edit::Attributes::DescriptionTextOverride, &AzPhysics::RigidBodyConfiguration::GetKinematicTooltip)
 
                     // Linear axis locking properties
                     ->ClassElement(AZ::Edit::ClassElements::Group, "Linear Axis Locking")
@@ -212,7 +214,8 @@ namespace PhysX
                         "CCD enabled", "When active, the rigid body has continuous collision detection (CCD). Use this to ensure accurate "
                         "collision detection, particularly for fast moving rigid bodies. CCD must be activated in the global PhysX configuration.")
                         ->Attribute(AZ::Edit::Attributes::Visibility, &AzPhysics::RigidBodyConfiguration::GetCcdVisibility)
-                    ->Attribute(AZ::Edit::Attributes::ReadOnly, &IsSceneCcdDisabled)
+                        ->Attribute(AZ::Edit::Attributes::DescriptionTextOverride, &AzPhysics::RigidBodyConfiguration::GetCcdTooltip)
+                        ->Attribute(AZ::Edit::Attributes::ReadOnly, &AzPhysics::RigidBodyConfiguration::CcdReadOnly)
                         ->Attribute(AZ::Edit::Attributes::ChangeNotify, AZ::Edit::PropertyRefreshLevels::EntireTree)
                     ->DataElement(AZ::Edit::UIHandlers::Default, &AzPhysics::RigidBodyConfiguration::m_ccdMinAdvanceCoefficient,
                         "Min advance coefficient", "Lower values reduce clipping but can affect simulation smoothness.")