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..6835aad 100644 --- a/Gems/Pointcloud/Code/Source/Tools/Components/PointcloudComponentController.h +++ b/Gems/Pointcloud/Code/Source/Tools/Components/PointcloudComponentController.h @@ -70,7 +70,11 @@ namespace Pointcloud AZ::Crc32 OnSetPointSize(); AZ::Crc32 OnAssetChanged(); + private: + PointcloudFeatureProcessorInterface::PointcloudChangedEvent::Handler m_changeEventHandler; + void HandleChange(PointcloudFeatureProcessorInterface::PointcloudHandle handle); + PointcloudFeatureProcessorInterface* m_featureProcessor = nullptr; PointcloudComponentConfig m_config; bool visibility = true;