add Draw Helpers changed notification + physx draw helpers listens to it (#1456)
This commit is contained in:
@@ -210,6 +210,19 @@ namespace AzToolsFramework
|
||||
//! Type to inherit to implement ViewportInteractionRequests.
|
||||
using ViewportInteractionRequestBus = AZ::EBus<ViewportInteractionRequests, ViewportEBusTraits>;
|
||||
|
||||
//! An interface to notify when changes to viewport settings have happened.
|
||||
class ViewportSettingNotifications
|
||||
{
|
||||
public:
|
||||
virtual void OnGridSnappingChanged([[maybe_unused]] bool enabled) {}
|
||||
virtual void OnDrawHelpersChanged([[maybe_unused]] bool enabled) {}
|
||||
|
||||
protected:
|
||||
ViewportSettingNotifications() = default;
|
||||
};
|
||||
|
||||
using ViewportSettingsNotificationBus = AZ::EBus<ViewportSettingNotifications, ViewportEBusTraits>;
|
||||
|
||||
//! Requests to freeze the Viewport Input
|
||||
//! Added to prevent a bug with the legacy CryEngine Viewport code that would
|
||||
//! keep doing raycast tests even when no level is loaded, causing a crash.
|
||||
|
||||
@@ -45,6 +45,7 @@
|
||||
|
||||
#include <AzCore/std/algorithm.h>
|
||||
#include <AzCore/Casting/numeric_cast.h>
|
||||
#include <AzToolsFramework/Viewport/ViewportMessages.h>
|
||||
|
||||
AZ_PUSH_DISABLE_DLL_EXPORT_MEMBER_WARNING
|
||||
#include "ui_ViewportTitleDlg.h"
|
||||
@@ -57,13 +58,16 @@ inline namespace Helpers
|
||||
{
|
||||
void ToggleHelpers()
|
||||
{
|
||||
GetIEditor()->GetDisplaySettings()->DisplayHelpers(!GetIEditor()->GetDisplaySettings()->IsDisplayHelpers());
|
||||
const bool newValue = !GetIEditor()->GetDisplaySettings()->IsDisplayHelpers();
|
||||
GetIEditor()->GetDisplaySettings()->DisplayHelpers(newValue);
|
||||
GetIEditor()->Notify(eNotify_OnDisplayRenderUpdate);
|
||||
|
||||
if (GetIEditor()->GetDisplaySettings()->IsDisplayHelpers() == false)
|
||||
if (newValue == false)
|
||||
{
|
||||
GetIEditor()->GetObjectManager()->SendEvent(EVENT_HIDE_HELPER);
|
||||
}
|
||||
AzToolsFramework::ViewportInteraction::ViewportSettingsNotificationBus::Broadcast(
|
||||
&AzToolsFramework::ViewportInteraction::ViewportSettingNotifications::OnDrawHelpersChanged, newValue);
|
||||
}
|
||||
|
||||
bool IsHelpersShown()
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include <AzCore/Component/ComponentApplicationBus.h>
|
||||
#include <AzCore/Component/TickBus.h>
|
||||
#include <AzCore/Interface/Interface.h>
|
||||
#include <AzFramework/Entity/EntityDebugDisplayBus.h>
|
||||
#include <AzFramework/Physics/MaterialBus.h>
|
||||
#include <AzToolsFramework/API/ToolsApplicationAPI.h>
|
||||
#include <LyViewPaneNames.h>
|
||||
@@ -56,6 +57,15 @@ namespace PhysX
|
||||
return false;
|
||||
}
|
||||
|
||||
bool IsDrawColliderReadOnly()
|
||||
{
|
||||
bool helpersVisible = false;
|
||||
AzToolsFramework::EditorRequestBus::BroadcastResult(helpersVisible,
|
||||
&AzToolsFramework::EditorRequests::DisplayHelpersVisible);
|
||||
// if helpers are visible, draw colliders is NOT read only and can be changed.
|
||||
return !helpersVisible;
|
||||
}
|
||||
|
||||
static void BuildAABBVerts(const AZ::Aabb& aabb,
|
||||
AZStd::vector<AZ::Vector3>& verts,
|
||||
AZStd::vector<AZ::Vector3>& points,
|
||||
@@ -145,28 +155,42 @@ namespace PhysX
|
||||
"PhysX Collider Debug Draw", "Manages global and per-collider debug draw settings and logic")
|
||||
->DataElement(AZ::Edit::UIHandlers::CheckBox, &Collider::m_locallyEnabled, "Draw collider",
|
||||
"Shows the geometry for the collider in the viewport")
|
||||
->Attribute(AZ::Edit::Attributes::CheckboxTooltip,
|
||||
"If set, the geometry of this collider is visible in the viewport")
|
||||
->Attribute(AZ::Edit::Attributes::Visibility,
|
||||
VisibilityFunc{ []() { return IsGlobalColliderDebugCheck(GlobalCollisionDebugState::Manual); } })
|
||||
->Attribute(AZ::Edit::Attributes::CheckboxTooltip,
|
||||
"If set, the geometry of this collider is visible in the viewport. 'Draw Helpers' needs to be enabled to use.")
|
||||
->Attribute(AZ::Edit::Attributes::Visibility,
|
||||
VisibilityFunc{ []() { return IsGlobalColliderDebugCheck(GlobalCollisionDebugState::Manual); } })
|
||||
->Attribute(AZ::Edit::Attributes::ReadOnly, &IsDrawColliderReadOnly)
|
||||
->DataElement(AZ::Edit::UIHandlers::Button, &Collider::m_globalButtonState, "Draw collider",
|
||||
"Shows the geometry for the collider in the viewport")
|
||||
->Attribute(AZ::Edit::Attributes::ButtonText, "Global override")
|
||||
->Attribute(AZ::Edit::Attributes::ButtonTooltip,
|
||||
"A global setting is overriding this property (to disable the override, "
|
||||
"set the Global Collision Debug setting to \"Set manually\" in the PhysX Configuration)")
|
||||
->Attribute(AZ::Edit::Attributes::Visibility,
|
||||
VisibilityFunc{ []() { return !IsGlobalColliderDebugCheck(GlobalCollisionDebugState::Manual); } })
|
||||
->Attribute(AZ::Edit::Attributes::ChangeNotify, &OpenPhysXSettingsWindow)
|
||||
->Attribute(AZ::Edit::Attributes::ButtonText, "Global override")
|
||||
->Attribute(AZ::Edit::Attributes::ButtonTooltip,
|
||||
"A global setting is overriding this property (to disable the override, "
|
||||
"set the Global Collision Debug setting to \"Set manually\" in the PhysX Configuration)."
|
||||
"'Draw Helpers' needs to be enabled to use.")
|
||||
->Attribute(AZ::Edit::Attributes::Visibility,
|
||||
VisibilityFunc{ []() { return !IsGlobalColliderDebugCheck(GlobalCollisionDebugState::Manual); } })
|
||||
->Attribute(AZ::Edit::Attributes::ChangeNotify, &OpenPhysXSettingsWindow)
|
||||
->Attribute(AZ::Edit::Attributes::ReadOnly, &IsDrawColliderReadOnly)
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Collider::Collider()
|
||||
: m_debugDisplayDataChangedEvent(
|
||||
[this]([[maybe_unused]] const PhysX::Debug::DebugDisplayData& data)
|
||||
{
|
||||
this->RefreshTreeHelper();
|
||||
})
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Collider::Connect(AZ::EntityId entityId)
|
||||
{
|
||||
m_entityId = entityId;
|
||||
AzFramework::EntityDebugDisplayEventBus::Handler::BusConnect(m_entityId);
|
||||
AzToolsFramework::EntitySelectionEvents::Bus::Handler::BusConnect(m_entityId);
|
||||
}
|
||||
|
||||
void Collider::SetDisplayCallback(const DisplayCallback* callback)
|
||||
@@ -176,6 +200,11 @@ namespace PhysX
|
||||
|
||||
void Collider::Disconnect()
|
||||
{
|
||||
if (AzToolsFramework::ViewportInteraction::ViewportSettingsNotificationBus::Handler::BusIsConnected())
|
||||
{
|
||||
AzToolsFramework::ViewportInteraction::ViewportSettingsNotificationBus::Handler::BusDisconnect();
|
||||
}
|
||||
AzToolsFramework::EntitySelectionEvents::Bus::Handler::BusDisconnect();
|
||||
AzFramework::EntityDebugDisplayEventBus::Handler::BusDisconnect();
|
||||
m_displayCallback = nullptr;
|
||||
m_entityId = AZ::EntityId();
|
||||
@@ -731,6 +760,33 @@ namespace PhysX
|
||||
}
|
||||
}
|
||||
|
||||
void Collider::OnDrawHelpersChanged([[maybe_unused]] bool enabled)
|
||||
{
|
||||
RefreshTreeHelper();
|
||||
}
|
||||
|
||||
void Collider::OnSelected()
|
||||
{
|
||||
AzToolsFramework::ViewportInteraction::ViewportSettingsNotificationBus::Handler::BusConnect(
|
||||
AzFramework::g_defaultSceneEntityDebugDisplayId);
|
||||
if (auto* physXDebug = AZ::Interface<Debug::PhysXDebugInterface>::Get())
|
||||
{
|
||||
physXDebug->RegisterDebugDisplayDataChangedEvent(m_debugDisplayDataChangedEvent);
|
||||
}
|
||||
}
|
||||
|
||||
void Collider::OnDeselected()
|
||||
{
|
||||
AzToolsFramework::ViewportInteraction::ViewportSettingsNotificationBus::Handler::BusDisconnect();
|
||||
m_debugDisplayDataChangedEvent.Disconnect();
|
||||
}
|
||||
|
||||
void Collider::RefreshTreeHelper()
|
||||
{
|
||||
AzToolsFramework::ToolsApplicationEvents::Bus::Broadcast(
|
||||
&AzToolsFramework::ToolsApplicationEvents::Bus::Events::InvalidatePropertyDisplay, AzToolsFramework::Refresh_AttributesAndValues);
|
||||
}
|
||||
|
||||
AZStd::string Collider::GetEntityName() const
|
||||
{
|
||||
AZStd::string entityName;
|
||||
|
||||
@@ -15,8 +15,11 @@
|
||||
#include <AzFramework/Entity/EntityDebugDisplayBus.h>
|
||||
#include <AzFramework/Physics/ShapeConfiguration.h>
|
||||
#include <AzFramework/Physics/Shape.h>
|
||||
#include <AzToolsFramework/API/ToolsApplicationAPI.h>
|
||||
#include <AzToolsFramework/Viewport/ViewportMessages.h>
|
||||
#include <PhysX/MeshAsset.h>
|
||||
#include <PhysX/Debug/PhysXDebugConfiguration.h>
|
||||
#include <PhysX/Debug/PhysXDebugInterface.h>
|
||||
|
||||
namespace PhysX
|
||||
{
|
||||
@@ -40,13 +43,15 @@ namespace PhysX
|
||||
|
||||
class Collider
|
||||
: protected AzFramework::EntityDebugDisplayEventBus::Handler
|
||||
, protected AzToolsFramework::ViewportInteraction::ViewportSettingsNotificationBus::Handler
|
||||
, protected AzToolsFramework::EntitySelectionEvents::Bus::Handler
|
||||
{
|
||||
public:
|
||||
AZ_CLASS_ALLOCATOR(Collider, AZ::SystemAllocator, 0);
|
||||
AZ_RTTI(Collider, "{7DE9CA01-DF1E-4D72-BBF4-76C9136BE6A2}");
|
||||
static void Reflect(AZ::ReflectContext* context);
|
||||
|
||||
Collider() = default;
|
||||
Collider();
|
||||
|
||||
void Connect(AZ::EntityId entityId);
|
||||
void SetDisplayCallback(const DisplayCallback* callback);
|
||||
@@ -109,11 +114,20 @@ namespace PhysX
|
||||
const AZStd::vector<AZ::u32>& GetIndices(AZ::u32 geomIndex) const;
|
||||
|
||||
protected:
|
||||
// AzFramework::EntityDebugDisplayEventBus
|
||||
// AzFramework::EntityDebugDisplayEventBus overrides ...
|
||||
void DisplayEntityViewport(
|
||||
const AzFramework::ViewportInfo& viewportInfo,
|
||||
AzFramework::DebugDisplayRequests& debugDisplay) override;
|
||||
|
||||
// AzToolsFramework::ViewportInteraction::ViewportSettingsNotificationBus::Handler overrides ...
|
||||
void OnDrawHelpersChanged(bool enabled) override;
|
||||
|
||||
// AzToolsFramework::EntitySelectionEvents::Bus::Handler overrides ...
|
||||
void OnSelected() override;
|
||||
void OnDeselected() override;
|
||||
|
||||
void RefreshTreeHelper();
|
||||
|
||||
// Internal mesh drawing subroutines
|
||||
void DrawTriangleMesh(
|
||||
AzFramework::DebugDisplayRequests& debugDisplay, const Physics::ColliderConfiguration& colliderConfig, AZ::u32 geomIndex,
|
||||
@@ -143,6 +157,8 @@ namespace PhysX
|
||||
};
|
||||
|
||||
mutable AZStd::vector<GeometryData> m_geometry;
|
||||
|
||||
PhysX::Debug::DebugDisplayDataChangedEvent::Handler m_debugDisplayDataChangedEvent;
|
||||
};
|
||||
} // namespace DebugDraw
|
||||
} // namespace PhysX
|
||||
|
||||
Reference in New Issue
Block a user