Skip to content

Commit

Permalink
Add ChangeEvent to PointcloudFeatureProcessor
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
zakmat committed Sep 17, 2024
1 parent 86b6162 commit cdb44a3
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ namespace Pointcloud
{
public:
using PointcloudHandle = int;
using PointcloudChangedEvent = AZ::Event<PointcloudHandle>;
constexpr static PointcloudHandle InvalidPointcloudHandle = -1;
AZ_RTTI(PointcloudFeatureProcessorInterface, "{8597AF27-EB4E-4363-8889-3BFC2AF5D2EC}", AZ::RPI::FeatureProcessor);

Expand Down Expand Up @@ -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<AZ::Aabb> 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
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ namespace Pointcloud
pcData.m_bounds = aabb;

UpdateDrawPacket();
m_pointcloudChangedEvent.Signal(PointcloudDataIndex);
}

PointcloudFeatureProcessorInterface::PointcloudHandle PointcloudFeatureProcessor::AcquirePointcloudFromAsset(
Expand Down Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ namespace Pointcloud
uint32_t GetPointCount(const PointcloudHandle& handle) const override;
AZStd::optional<AZ::Aabb> GetBounds(const PointcloudHandle& handle) const override;

void ConnectChangeEventHandler(const PointcloudHandle& meshHandle, PointcloudChangedEvent::Handler& handler) override;

protected:
// RPI::SceneNotificationBus overrides
void OnRenderPipelineChanged(
Expand Down Expand Up @@ -101,5 +103,6 @@ namespace Pointcloud
AZStd::unordered_map<PointcloudHandle, PointcloudData> m_pointcloudData; //!< Map of pointcloud data
PointcloudHandle m_currentPointcloudDataIndex = 0; //!< Index to the next pointcloud data to be created
AZStd::unordered_map<AZ::Data::AssetId, PointcloudHandle> m_pointcloudAssets;
PointcloudChangedEvent m_pointcloudChangedEvent;
};
} // namespace Pointcloud
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "PointcloudComponentController.h"

#include "Clients/PointcloudComponent.h"
#include <Atom/RPI.Public/Scene.h>
#include <AzCore/Component/ComponentBus.h>
Expand All @@ -8,6 +9,7 @@
#include <AzCore/Serialization/EditContextConstants.inl>
#include <AzCore/Serialization/SerializeContext.h>
#include <AzFramework/Entity/EntityContext.h>
#include <AzFramework/Visibility/EntityBoundsUnionBus.h>
#include <Render/PointcloudFeatureProcessor.h>

namespace Pointcloud
Expand All @@ -25,6 +27,12 @@ namespace Pointcloud

void PointcloudComponentController::Init()
{
m_changeEventHandler = AZ::EventHandler<PointcloudFeatureProcessorInterface::PointcloudHandle>(
[&](PointcloudFeatureProcessorInterface::PointcloudHandle handle)
{
this->HandleChange(handle);
});

AZ::SystemTickBus::QueueFunction(
[this]()
{
Expand Down Expand Up @@ -130,6 +138,7 @@ namespace Pointcloud
AZ_Assert(m_featureProcessor, "Failed to enable PointcloudFeatureProcessorInterface.");
}
}
m_featureProcessor->ConnectChangeEventHandler(m_config.m_pointcloudHandle, m_changeEventHandler);
OnAssetChanged();
});
}
Expand Down Expand Up @@ -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<AzFramework::IEntityBoundsUnion>::Get()->RefreshEntityLocalBoundsUnion(m_config.m_editorEntityId);
}
}

void PointcloudComponentController::OnEntityInfoUpdatedVisibility(AZ::EntityId entityId, bool visible)
{
if (entityId == m_config.m_editorEntityId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit cdb44a3

Please sign in to comment.