From a9c15ab34e267b76d8d80072494929b4e041a39a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20=C5=BBak?= Date: Thu, 5 Sep 2024 12:07:45 +0200 Subject: [PATCH 1/6] enable pointcloud bus for editor component MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mateusz Żak --- .../Source/Tools/Components/PointcloudEditorComponent.cpp | 4 ---- .../Code/Source/Tools/Components/PointcloudEditorComponent.h | 2 -- 2 files changed, 6 deletions(-) diff --git a/Gems/Pointcloud/Code/Source/Tools/Components/PointcloudEditorComponent.cpp b/Gems/Pointcloud/Code/Source/Tools/Components/PointcloudEditorComponent.cpp index 39f1603..e32b45e 100644 --- a/Gems/Pointcloud/Code/Source/Tools/Components/PointcloudEditorComponent.cpp +++ b/Gems/Pointcloud/Code/Source/Tools/Components/PointcloudEditorComponent.cpp @@ -61,10 +61,6 @@ namespace Pointcloud AzToolsFramework::EditorComponentSelectionRequestsBus::Handler::BusDisconnect(); AzFramework::BoundsRequestBus::Handler::BusDisconnect(); } - bool PointcloudEditorComponent::ShouldActivateController() const - { - return false; - } AZ::Aabb PointcloudEditorComponent::GetWorldBounds() { diff --git a/Gems/Pointcloud/Code/Source/Tools/Components/PointcloudEditorComponent.h b/Gems/Pointcloud/Code/Source/Tools/Components/PointcloudEditorComponent.h index c8a4b9c..28b2bae 100644 --- a/Gems/Pointcloud/Code/Source/Tools/Components/PointcloudEditorComponent.h +++ b/Gems/Pointcloud/Code/Source/Tools/Components/PointcloudEditorComponent.h @@ -17,7 +17,6 @@ #include #include #include -#include #include #include @@ -47,7 +46,6 @@ namespace Pointcloud // EditorComponentBase interface overrides ... void Activate() override; void Deactivate() override; - bool ShouldActivateController() const override; AZ::Aabb GetWorldBounds() override; AZ::Aabb GetLocalBounds() override; From 5338e0945c68e5db3d3be17ad4ac2f514a1117ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20=C5=BBak?= Date: Thu, 5 Sep 2024 12:39:46 +0200 Subject: [PATCH 2/6] clean up MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * add comments * clean up headers Signed-off-by: Mateusz Żak --- .../Components/PointcloudComponentController.cpp | 2 +- .../Components/PointcloudComponentController.h | 13 ++++--------- .../Components/PointcloudEditorComponent.cpp | 1 - .../Tools/Components/PointcloudEditorComponent.h | 15 ++++++--------- 4 files changed, 11 insertions(+), 20 deletions(-) diff --git a/Gems/Pointcloud/Code/Source/Tools/Components/PointcloudComponentController.cpp b/Gems/Pointcloud/Code/Source/Tools/Components/PointcloudComponentController.cpp index e77f72c..0c8f12f 100644 --- a/Gems/Pointcloud/Code/Source/Tools/Components/PointcloudComponentController.cpp +++ b/Gems/Pointcloud/Code/Source/Tools/Components/PointcloudComponentController.cpp @@ -153,7 +153,6 @@ namespace Pointcloud { if (m_featureProcessor) { - printf("Feature processor exists\n"); m_featureProcessor->ReleasePointcloud(m_config.m_pointcloudHandle); if (m_config.m_pointcloudAsset.GetId().IsValid()) { @@ -189,6 +188,7 @@ namespace Pointcloud { m_config.m_pointcloudAsset = asset; } + void PointcloudComponentController::SetPointSize(float pointSize) { m_config.m_pointSize = pointSize; diff --git a/Gems/Pointcloud/Code/Source/Tools/Components/PointcloudComponentController.h b/Gems/Pointcloud/Code/Source/Tools/Components/PointcloudComponentController.h index a512eef..f7b24ea 100644 --- a/Gems/Pointcloud/Code/Source/Tools/Components/PointcloudComponentController.h +++ b/Gems/Pointcloud/Code/Source/Tools/Components/PointcloudComponentController.h @@ -8,18 +8,12 @@ #pragma once -#include "AzCore/Math/Aabb.h" - #include #include #include -#include -#include -#include -#include +#include #include #include -#include namespace Pointcloud { @@ -37,7 +31,7 @@ namespace Pointcloud float m_pointSize = 1.0f; PointcloudFeatureProcessorInterface::PointcloudHandle m_pointcloudHandle = PointcloudFeatureProcessorInterface::InvalidPointcloudHandle; - AZ::Data::Asset m_pointcloudAsset; + AZ::Data::Asset m_pointcloudAsset = {}; }; class PointcloudComponentController @@ -61,7 +55,8 @@ namespace Pointcloud ////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// - void OnTransformChanged(const AZ::Transform& local, const AZ::Transform& world); + // AZ::TransformNotificationBus::Handler overrides ... + void OnTransformChanged(const AZ::Transform& local, const AZ::Transform& world) override; // AzToolsFramework::EditorEntityInfoNotificationBus overrides ... void OnEntityInfoUpdatedVisibility(AZ::EntityId entityId, bool visible); diff --git a/Gems/Pointcloud/Code/Source/Tools/Components/PointcloudEditorComponent.cpp b/Gems/Pointcloud/Code/Source/Tools/Components/PointcloudEditorComponent.cpp index e32b45e..acbacf5 100644 --- a/Gems/Pointcloud/Code/Source/Tools/Components/PointcloudEditorComponent.cpp +++ b/Gems/Pointcloud/Code/Source/Tools/Components/PointcloudEditorComponent.cpp @@ -1,7 +1,6 @@ #include "PointcloudEditorComponent.h" #include "Clients/PointcloudComponent.h" -#include #include #include #include diff --git a/Gems/Pointcloud/Code/Source/Tools/Components/PointcloudEditorComponent.h b/Gems/Pointcloud/Code/Source/Tools/Components/PointcloudEditorComponent.h index 28b2bae..77426a3 100644 --- a/Gems/Pointcloud/Code/Source/Tools/Components/PointcloudEditorComponent.h +++ b/Gems/Pointcloud/Code/Source/Tools/Components/PointcloudEditorComponent.h @@ -2,18 +2,12 @@ #include "PointcloudComponentController.h" -#include "../../Clients/PointcloudComponent.h" -#include - -#include +#include "Clients/PointcloudComponent.h" -#include -#include #include -#include #include -#include -#include +#include +#include #include #include #include @@ -47,9 +41,11 @@ namespace Pointcloud void Activate() override; void Deactivate() override; + // AzFramework::BoundsRequestBus overrides ... AZ::Aabb GetWorldBounds() override; AZ::Aabb GetLocalBounds() override; + // AzToolsFramework::EditorComponentSelectionRequestsBus overrides ... AZ::Aabb GetEditorSelectionBoundsViewport(const AzFramework::ViewportInfo& viewportInfo) override; bool EditorSelectionIntersectRayViewport( const AzFramework::ViewportInfo& viewportInfo, const AZ::Vector3& src, const AZ::Vector3& dir, float& distance) override; @@ -57,6 +53,7 @@ namespace Pointcloud bool SupportsEditorRayIntersect() override; bool SupportsEditorRayIntersectViewport(const AzFramework::ViewportInfo& viewportInfo) override; + // AzFramework::EntityDebugDisplayEventBus overrides ... void DisplayEntityViewport(const AzFramework::ViewportInfo& viewportInfo, AzFramework::DebugDisplayRequests& debugDisplay) override; private: From 96c623287e48ac53a3bcf1cbc909558580df6a09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20=C5=BBak?= Date: Thu, 5 Sep 2024 13:19:14 +0200 Subject: [PATCH 3/6] query for featureProcessor before enable attempt MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * this avoids flooding logs with warnings Signed-off-by: Mateusz Żak --- .../PointcloudComponentController.cpp | 28 +++++++++++-------- .../PointcloudComponentController.h | 1 - 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/Gems/Pointcloud/Code/Source/Tools/Components/PointcloudComponentController.cpp b/Gems/Pointcloud/Code/Source/Tools/Components/PointcloudComponentController.cpp index 0c8f12f..81ebf0e 100644 --- a/Gems/Pointcloud/Code/Source/Tools/Components/PointcloudComponentController.cpp +++ b/Gems/Pointcloud/Code/Source/Tools/Components/PointcloudComponentController.cpp @@ -28,14 +28,16 @@ namespace Pointcloud AZ::SystemTickBus::QueueFunction( [this]() { - m_scene = AZ::RPI::Scene::GetSceneForEntityId(m_config.m_editorEntityId); - if (m_scene) + m_featureProcessor = AZ::RPI::Scene::GetFeatureProcessorForEntity(m_config.m_editorEntityId); + if (!m_featureProcessor) { - m_featureProcessor = m_scene->EnableFeatureProcessor(); - - AZ_Assert(m_featureProcessor, "Failed to enable PointcloudFeatureProcessorInterface."); - OnAssetChanged(); + if (auto* scene = AZ::RPI::Scene::GetSceneForEntityId(m_config.m_editorEntityId)) + { + m_featureProcessor = scene->EnableFeatureProcessor(); + AZ_Assert(m_featureProcessor, "Failed to enable PointcloudFeatureProcessorInterface."); + } } + OnAssetChanged(); }); } @@ -119,14 +121,16 @@ namespace Pointcloud AZ::SystemTickBus::QueueFunction( [this]() { - m_scene = AZ::RPI::Scene::GetSceneForEntityId(m_config.m_editorEntityId); - if (m_scene) + m_featureProcessor = AZ::RPI::Scene::GetFeatureProcessorForEntity(m_config.m_editorEntityId); + if (!m_featureProcessor) { - m_featureProcessor = m_scene->EnableFeatureProcessor(); - - AZ_Assert(m_featureProcessor, "Failed to enable PointcloudFeatureProcessorInterface."); - OnAssetChanged(); + if (auto* scene = AZ::RPI::Scene::GetSceneForEntityId(m_config.m_editorEntityId)) + { + m_featureProcessor = scene->EnableFeatureProcessor(); + AZ_Assert(m_featureProcessor, "Failed to enable PointcloudFeatureProcessorInterface."); + } } + OnAssetChanged(); }); } diff --git a/Gems/Pointcloud/Code/Source/Tools/Components/PointcloudComponentController.h b/Gems/Pointcloud/Code/Source/Tools/Components/PointcloudComponentController.h index f7b24ea..4d9f4aa 100644 --- a/Gems/Pointcloud/Code/Source/Tools/Components/PointcloudComponentController.h +++ b/Gems/Pointcloud/Code/Source/Tools/Components/PointcloudComponentController.h @@ -72,7 +72,6 @@ namespace Pointcloud private: PointcloudFeatureProcessorInterface* m_featureProcessor = nullptr; - AZ::RPI::Scene* m_scene = nullptr; PointcloudComponentConfig m_config; bool visibility = true; }; From 856d22aaf19382d3ae124e63772e3e43cea4b0a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20=C5=BBak?= Date: Thu, 5 Sep 2024 13:20:11 +0200 Subject: [PATCH 4/6] do not apply transforms on invalid bounds MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * it will make them valid - but incorrect Signed-off-by: Mateusz Żak --- .../Tools/Components/PointcloudEditorComponent.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Gems/Pointcloud/Code/Source/Tools/Components/PointcloudEditorComponent.cpp b/Gems/Pointcloud/Code/Source/Tools/Components/PointcloudEditorComponent.cpp index acbacf5..e951be2 100644 --- a/Gems/Pointcloud/Code/Source/Tools/Components/PointcloudEditorComponent.cpp +++ b/Gems/Pointcloud/Code/Source/Tools/Components/PointcloudEditorComponent.cpp @@ -66,7 +66,10 @@ namespace Pointcloud AZ::Transform transform = AZ::Transform::CreateIdentity(); AZ::TransformBus::EventResult(transform, GetEntityId(), &AZ::TransformBus::Events::GetWorldTM); AZ::Aabb bounds = m_controller.GetBounds(); - bounds.ApplyTransform(transform); + if (bounds.IsValid()) + { + bounds.ApplyTransform(transform); + } return bounds; } @@ -75,7 +78,10 @@ namespace Pointcloud AZ::Transform transform = AZ::Transform::CreateIdentity(); AZ::TransformBus::EventResult(transform, GetEntityId(), &AZ::TransformBus::Events::GetLocalTM); AZ::Aabb bounds = m_controller.GetBounds(); - bounds.ApplyTransform(transform); + if (bounds.IsValid()) + { + bounds.ApplyTransform(transform); + } return bounds; } From 86b6162391ab177f097fab0ed9abefbe3131469c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20=C5=BBak?= Date: Fri, 6 Sep 2024 10:39:48 +0200 Subject: [PATCH 5/6] further cleanup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * shorten the Gems Bus header filename Signed-off-by: Mateusz Żak --- ...trollerConfigurationBus.h => PointcloudConfigurationBus.h} | 0 Gems/Pointcloud/Code/Source/Clients/PointcloudComponent.cpp | 4 ---- .../Source/Tools/Components/PointcloudComponentController.h | 2 +- 3 files changed, 1 insertion(+), 5 deletions(-) rename Gems/Pointcloud/Code/Include/Pointcloud/{PointcloudComponentControllerConfigurationBus.h => PointcloudConfigurationBus.h} (100%) diff --git a/Gems/Pointcloud/Code/Include/Pointcloud/PointcloudComponentControllerConfigurationBus.h b/Gems/Pointcloud/Code/Include/Pointcloud/PointcloudConfigurationBus.h similarity index 100% rename from Gems/Pointcloud/Code/Include/Pointcloud/PointcloudComponentControllerConfigurationBus.h rename to Gems/Pointcloud/Code/Include/Pointcloud/PointcloudConfigurationBus.h diff --git a/Gems/Pointcloud/Code/Source/Clients/PointcloudComponent.cpp b/Gems/Pointcloud/Code/Source/Clients/PointcloudComponent.cpp index 17c36de..572f0e4 100644 --- a/Gems/Pointcloud/Code/Source/Clients/PointcloudComponent.cpp +++ b/Gems/Pointcloud/Code/Source/Clients/PointcloudComponent.cpp @@ -8,11 +8,7 @@ #include "PointcloudComponent.h" #include -#include #include -#include -#include -#include namespace Pointcloud { diff --git a/Gems/Pointcloud/Code/Source/Tools/Components/PointcloudComponentController.h b/Gems/Pointcloud/Code/Source/Tools/Components/PointcloudComponentController.h index 4d9f4aa..04d7a4e 100644 --- a/Gems/Pointcloud/Code/Source/Tools/Components/PointcloudComponentController.h +++ b/Gems/Pointcloud/Code/Source/Tools/Components/PointcloudComponentController.h @@ -12,7 +12,7 @@ #include #include #include -#include +#include #include namespace Pointcloud From 76d856aec202f8a0179a2929c76f3677198bd2a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20=C5=BBak?= Date: Tue, 17 Sep 2024 11:04:24 +0200 Subject: [PATCH 6/6] Add ChangeEvent to PointcloudFeatureProcessor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * asset change should be signaled to the PointcloudController * currently the change is needed to update cached local bounds to fix selection Signed-off-by: Mateusz Żak --- .../PointcloudFeatureProcessorInterface.h | 4 ++++ .../Render/PointcloudFeatureProcessor.cpp | 9 +++++++++ .../Source/Render/PointcloudFeatureProcessor.h | 3 +++ .../PointcloudComponentController.cpp | 18 ++++++++++++++++++ .../Components/PointcloudComponentController.h | 3 +++ 5 files changed, 37 insertions(+) diff --git a/Gems/Pointcloud/Code/Include/Pointcloud/PointcloudFeatureProcessorInterface.h b/Gems/Pointcloud/Code/Include/Pointcloud/PointcloudFeatureProcessorInterface.h index 447d5fa..0872574 100644 --- a/Gems/Pointcloud/Code/Include/Pointcloud/PointcloudFeatureProcessorInterface.h +++ b/Gems/Pointcloud/Code/Include/Pointcloud/PointcloudFeatureProcessorInterface.h @@ -24,6 +24,7 @@ namespace Pointcloud { public: using PointcloudHandle = int; + using PointcloudChangedEvent = AZ::Event; constexpr static PointcloudHandle InvalidPointcloudHandle = -1; AZ_RTTI(PointcloudFeatureProcessorInterface, "{8597AF27-EB4E-4363-8889-3BFC2AF5D2EC}", AZ::RPI::FeatureProcessor); @@ -67,5 +68,8 @@ namespace Pointcloud //! Get the bounds of a pointcloud //! @param handle The handle of the pointcloud obtained from AcquirePointcloud virtual AZStd::optional GetBounds(const PointcloudHandle& handle) const = 0; + + //! Connects a handler to any changes to a Pointcloud. Changes include loading and reloading + virtual void ConnectChangeEventHandler(const PointcloudHandle& meshHandle, PointcloudChangedEvent::Handler& handler) = 0; }; } // namespace Pointcloud \ No newline at end of file diff --git a/Gems/Pointcloud/Code/Source/Render/PointcloudFeatureProcessor.cpp b/Gems/Pointcloud/Code/Source/Render/PointcloudFeatureProcessor.cpp index c65ff9b..682e627 100644 --- a/Gems/Pointcloud/Code/Source/Render/PointcloudFeatureProcessor.cpp +++ b/Gems/Pointcloud/Code/Source/Render/PointcloudFeatureProcessor.cpp @@ -128,6 +128,7 @@ namespace Pointcloud pcData.m_bounds = aabb; UpdateDrawPacket(); + m_pointcloudChangedEvent.Signal(PointcloudDataIndex); } PointcloudFeatureProcessorInterface::PointcloudHandle PointcloudFeatureProcessor::AcquirePointcloudFromAsset( @@ -366,4 +367,12 @@ namespace Pointcloud } return AZStd::nullopt; } + void PointcloudFeatureProcessor::ConnectChangeEventHandler( + const PointcloudHandle& pointcloudHandle, PointcloudChangedEvent::Handler& handler) + { + if (pointcloudHandle != InvalidPointcloudHandle) + { + handler.Connect(m_pointcloudChangedEvent); + } + } } // namespace Pointcloud \ No newline at end of file diff --git a/Gems/Pointcloud/Code/Source/Render/PointcloudFeatureProcessor.h b/Gems/Pointcloud/Code/Source/Render/PointcloudFeatureProcessor.h index 0e6f559..5387ee2 100644 --- a/Gems/Pointcloud/Code/Source/Render/PointcloudFeatureProcessor.h +++ b/Gems/Pointcloud/Code/Source/Render/PointcloudFeatureProcessor.h @@ -45,6 +45,8 @@ namespace Pointcloud uint32_t GetPointCount(const PointcloudHandle& handle) const override; AZStd::optional GetBounds(const PointcloudHandle& handle) const override; + void ConnectChangeEventHandler(const PointcloudHandle& meshHandle, PointcloudChangedEvent::Handler& handler) override; + protected: // RPI::SceneNotificationBus overrides void OnRenderPipelineChanged( @@ -101,5 +103,6 @@ namespace Pointcloud AZStd::unordered_map m_pointcloudData; //!< Map of pointcloud data PointcloudHandle m_currentPointcloudDataIndex = 0; //!< Index to the next pointcloud data to be created AZStd::unordered_map m_pointcloudAssets; + PointcloudChangedEvent m_pointcloudChangedEvent; }; } // namespace Pointcloud \ No newline at end of file diff --git a/Gems/Pointcloud/Code/Source/Tools/Components/PointcloudComponentController.cpp b/Gems/Pointcloud/Code/Source/Tools/Components/PointcloudComponentController.cpp index 81ebf0e..3fe621a 100644 --- a/Gems/Pointcloud/Code/Source/Tools/Components/PointcloudComponentController.cpp +++ b/Gems/Pointcloud/Code/Source/Tools/Components/PointcloudComponentController.cpp @@ -1,4 +1,5 @@ #include "PointcloudComponentController.h" + #include "Clients/PointcloudComponent.h" #include #include @@ -8,6 +9,7 @@ #include #include #include +#include #include namespace Pointcloud @@ -25,6 +27,12 @@ namespace Pointcloud void PointcloudComponentController::Init() { + m_changeEventHandler = AZ::EventHandler( + [&](PointcloudFeatureProcessorInterface::PointcloudHandle handle) + { + this->HandleChange(handle); + }); + AZ::SystemTickBus::QueueFunction( [this]() { @@ -130,6 +138,7 @@ namespace Pointcloud AZ_Assert(m_featureProcessor, "Failed to enable PointcloudFeatureProcessorInterface."); } } + m_featureProcessor->ConnectChangeEventHandler(m_config.m_pointcloudHandle, m_changeEventHandler); OnAssetChanged(); }); } @@ -172,6 +181,15 @@ namespace Pointcloud return AZ::Edit::PropertyRefreshLevels::EntireTree; } + void PointcloudComponentController::HandleChange(PointcloudFeatureProcessorInterface::PointcloudHandle handle) + { + if (m_config.m_pointcloudHandle == handle) + { + // Refresh cached local bounds + AZ::Interface::Get()->RefreshEntityLocalBoundsUnion(m_config.m_editorEntityId); + } + } + void PointcloudComponentController::OnEntityInfoUpdatedVisibility(AZ::EntityId entityId, bool visible) { if (entityId == m_config.m_editorEntityId) diff --git a/Gems/Pointcloud/Code/Source/Tools/Components/PointcloudComponentController.h b/Gems/Pointcloud/Code/Source/Tools/Components/PointcloudComponentController.h index 04d7a4e..941767b 100644 --- a/Gems/Pointcloud/Code/Source/Tools/Components/PointcloudComponentController.h +++ b/Gems/Pointcloud/Code/Source/Tools/Components/PointcloudComponentController.h @@ -71,6 +71,9 @@ namespace Pointcloud AZ::Crc32 OnAssetChanged(); private: + PointcloudFeatureProcessorInterface::PointcloudChangedEvent::Handler m_changeEventHandler; + void HandleChange(PointcloudFeatureProcessorInterface::PointcloudHandle handle); + PointcloudFeatureProcessorInterface* m_featureProcessor = nullptr; PointcloudComponentConfig m_config; bool visibility = true;