Skip to content

Commit 6d6a10b

Browse files
authored
[Pointcloud] Fixes in Pointcloud Gem (#62)
* Enable pointcloud bus for editor component * Query for FeatureProcessor before enabling (to avoid log flooding) * Empty Pointcloud asset breaks viewport selection - fix by not applying transforms on invalid bounds * Add ChangeEvent to PointcloudFeatureProcessor to update cached local bounds * Code cleanup Signed-off-by: Mateusz Żak <[email protected]>
1 parent 288a29c commit 6d6a10b

9 files changed

+73
-46
lines changed
File renamed without changes.

Gems/Pointcloud/Code/Include/Pointcloud/PointcloudFeatureProcessorInterface.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ namespace Pointcloud
2424
{
2525
public:
2626
using PointcloudHandle = int;
27+
using PointcloudChangedEvent = AZ::Event<PointcloudHandle>;
2728
constexpr static PointcloudHandle InvalidPointcloudHandle = -1;
2829
AZ_RTTI(PointcloudFeatureProcessorInterface, "{8597AF27-EB4E-4363-8889-3BFC2AF5D2EC}", AZ::RPI::FeatureProcessor);
2930

@@ -67,5 +68,8 @@ namespace Pointcloud
6768
//! Get the bounds of a pointcloud
6869
//! @param handle The handle of the pointcloud obtained from AcquirePointcloud
6970
virtual AZStd::optional<AZ::Aabb> GetBounds(const PointcloudHandle& handle) const = 0;
71+
72+
//! Connects a handler to any changes to a Pointcloud. Changes include loading and reloading
73+
virtual void ConnectChangeEventHandler(const PointcloudHandle& meshHandle, PointcloudChangedEvent::Handler& handler) = 0;
7074
};
7175
} // namespace Pointcloud

Gems/Pointcloud/Code/Source/Clients/PointcloudComponent.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@
88

99
#include "PointcloudComponent.h"
1010
#include <Atom/RPI.Public/Scene.h>
11-
#include <AzCore/Serialization/EditContext.h>
1211
#include <AzCore/Serialization/SerializeContext.h>
13-
#include <Pointcloud/PointcloudComponentControllerConfigurationBus.h>
14-
#include <Pointcloud/PointcloudTypeIds.h>
15-
#include <Render/PointcloudFeatureProcessor.h>
1612

1713
namespace Pointcloud
1814
{

Gems/Pointcloud/Code/Source/Render/PointcloudFeatureProcessor.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ namespace Pointcloud
128128
pcData.m_bounds = aabb;
129129

130130
UpdateDrawPacket();
131+
m_pointcloudChangedEvent.Signal(PointcloudDataIndex);
131132
}
132133

133134
PointcloudFeatureProcessorInterface::PointcloudHandle PointcloudFeatureProcessor::AcquirePointcloudFromAsset(
@@ -366,4 +367,12 @@ namespace Pointcloud
366367
}
367368
return AZStd::nullopt;
368369
}
370+
void PointcloudFeatureProcessor::ConnectChangeEventHandler(
371+
const PointcloudHandle& pointcloudHandle, PointcloudChangedEvent::Handler& handler)
372+
{
373+
if (pointcloudHandle != InvalidPointcloudHandle)
374+
{
375+
handler.Connect(m_pointcloudChangedEvent);
376+
}
377+
}
369378
} // namespace Pointcloud

Gems/Pointcloud/Code/Source/Render/PointcloudFeatureProcessor.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ namespace Pointcloud
4545
uint32_t GetPointCount(const PointcloudHandle& handle) const override;
4646
AZStd::optional<AZ::Aabb> GetBounds(const PointcloudHandle& handle) const override;
4747

48+
void ConnectChangeEventHandler(const PointcloudHandle& meshHandle, PointcloudChangedEvent::Handler& handler) override;
49+
4850
protected:
4951
// RPI::SceneNotificationBus overrides
5052
void OnRenderPipelineChanged(
@@ -101,5 +103,6 @@ namespace Pointcloud
101103
AZStd::unordered_map<PointcloudHandle, PointcloudData> m_pointcloudData; //!< Map of pointcloud data
102104
PointcloudHandle m_currentPointcloudDataIndex = 0; //!< Index to the next pointcloud data to be created
103105
AZStd::unordered_map<AZ::Data::AssetId, PointcloudHandle> m_pointcloudAssets;
106+
PointcloudChangedEvent m_pointcloudChangedEvent;
104107
};
105108
} // namespace Pointcloud

Gems/Pointcloud/Code/Source/Tools/Components/PointcloudComponentController.cpp

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "PointcloudComponentController.h"
2+
23
#include "Clients/PointcloudComponent.h"
34
#include <Atom/RPI.Public/Scene.h>
45
#include <AzCore/Component/ComponentBus.h>
@@ -8,6 +9,7 @@
89
#include <AzCore/Serialization/EditContextConstants.inl>
910
#include <AzCore/Serialization/SerializeContext.h>
1011
#include <AzFramework/Entity/EntityContext.h>
12+
#include <AzFramework/Visibility/EntityBoundsUnionBus.h>
1113
#include <Render/PointcloudFeatureProcessor.h>
1214

1315
namespace Pointcloud
@@ -25,17 +27,25 @@ namespace Pointcloud
2527

2628
void PointcloudComponentController::Init()
2729
{
30+
m_changeEventHandler = AZ::EventHandler<PointcloudFeatureProcessorInterface::PointcloudHandle>(
31+
[&](PointcloudFeatureProcessorInterface::PointcloudHandle handle)
32+
{
33+
this->HandleChange(handle);
34+
});
35+
2836
AZ::SystemTickBus::QueueFunction(
2937
[this]()
3038
{
31-
m_scene = AZ::RPI::Scene::GetSceneForEntityId(m_config.m_editorEntityId);
32-
if (m_scene)
39+
m_featureProcessor = AZ::RPI::Scene::GetFeatureProcessorForEntity<PointcloudFeatureProcessor>(m_config.m_editorEntityId);
40+
if (!m_featureProcessor)
3341
{
34-
m_featureProcessor = m_scene->EnableFeatureProcessor<PointcloudFeatureProcessor>();
35-
36-
AZ_Assert(m_featureProcessor, "Failed to enable PointcloudFeatureProcessorInterface.");
37-
OnAssetChanged();
42+
if (auto* scene = AZ::RPI::Scene::GetSceneForEntityId(m_config.m_editorEntityId))
43+
{
44+
m_featureProcessor = scene->EnableFeatureProcessor<PointcloudFeatureProcessor>();
45+
AZ_Assert(m_featureProcessor, "Failed to enable PointcloudFeatureProcessorInterface.");
46+
}
3847
}
48+
OnAssetChanged();
3949
});
4050
}
4151

@@ -119,14 +129,17 @@ namespace Pointcloud
119129
AZ::SystemTickBus::QueueFunction(
120130
[this]()
121131
{
122-
m_scene = AZ::RPI::Scene::GetSceneForEntityId(m_config.m_editorEntityId);
123-
if (m_scene)
132+
m_featureProcessor = AZ::RPI::Scene::GetFeatureProcessorForEntity<PointcloudFeatureProcessor>(m_config.m_editorEntityId);
133+
if (!m_featureProcessor)
124134
{
125-
m_featureProcessor = m_scene->EnableFeatureProcessor<PointcloudFeatureProcessor>();
126-
127-
AZ_Assert(m_featureProcessor, "Failed to enable PointcloudFeatureProcessorInterface.");
128-
OnAssetChanged();
135+
if (auto* scene = AZ::RPI::Scene::GetSceneForEntityId(m_config.m_editorEntityId))
136+
{
137+
m_featureProcessor = scene->EnableFeatureProcessor<PointcloudFeatureProcessor>();
138+
AZ_Assert(m_featureProcessor, "Failed to enable PointcloudFeatureProcessorInterface.");
139+
}
129140
}
141+
m_featureProcessor->ConnectChangeEventHandler(m_config.m_pointcloudHandle, m_changeEventHandler);
142+
OnAssetChanged();
130143
});
131144
}
132145

@@ -153,7 +166,6 @@ namespace Pointcloud
153166
{
154167
if (m_featureProcessor)
155168
{
156-
printf("Feature processor exists\n");
157169
m_featureProcessor->ReleasePointcloud(m_config.m_pointcloudHandle);
158170
if (m_config.m_pointcloudAsset.GetId().IsValid())
159171
{
@@ -169,6 +181,15 @@ namespace Pointcloud
169181
return AZ::Edit::PropertyRefreshLevels::EntireTree;
170182
}
171183

184+
void PointcloudComponentController::HandleChange(PointcloudFeatureProcessorInterface::PointcloudHandle handle)
185+
{
186+
if (m_config.m_pointcloudHandle == handle)
187+
{
188+
// Refresh cached local bounds
189+
AZ::Interface<AzFramework::IEntityBoundsUnion>::Get()->RefreshEntityLocalBoundsUnion(m_config.m_editorEntityId);
190+
}
191+
}
192+
172193
void PointcloudComponentController::OnEntityInfoUpdatedVisibility(AZ::EntityId entityId, bool visible)
173194
{
174195
if (entityId == m_config.m_editorEntityId)
@@ -189,6 +210,7 @@ namespace Pointcloud
189210
{
190211
m_config.m_pointcloudAsset = asset;
191212
}
213+
192214
void PointcloudComponentController::SetPointSize(float pointSize)
193215
{
194216
m_config.m_pointSize = pointSize;

Gems/Pointcloud/Code/Source/Tools/Components/PointcloudComponentController.h

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,12 @@
88

99
#pragma once
1010

11-
#include "AzCore/Math/Aabb.h"
12-
1311
#include <AzCore/Component/ComponentBus.h>
1412
#include <AzCore/Component/EntityId.h>
1513
#include <AzCore/Component/TransformBus.h>
16-
#include <AzCore/Memory/Memory_fwd.h>
17-
#include <AzCore/Memory/SystemAllocator.h>
18-
#include <AzCore/base.h>
19-
#include <AzFramework/Spawnable/Spawnable.h>
20-
#include <Pointcloud/PointcloudComponentControllerConfigurationBus.h>
14+
#include <AzCore/Math/Aabb.h>
15+
#include <Pointcloud/PointcloudConfigurationBus.h>
2116
#include <Pointcloud/PointcloudFeatureProcessorInterface.h>
22-
#include <Pointcloud/PointcloudTypeIds.h>
2317

2418
namespace Pointcloud
2519
{
@@ -37,7 +31,7 @@ namespace Pointcloud
3731
float m_pointSize = 1.0f;
3832
PointcloudFeatureProcessorInterface::PointcloudHandle m_pointcloudHandle =
3933
PointcloudFeatureProcessorInterface::InvalidPointcloudHandle;
40-
AZ::Data::Asset<PointcloudAsset> m_pointcloudAsset;
34+
AZ::Data::Asset<PointcloudAsset> m_pointcloudAsset = {};
4135
};
4236

4337
class PointcloudComponentController
@@ -61,7 +55,8 @@ namespace Pointcloud
6155
//////////////////////////////////////////////////////////////////////////
6256

6357
//////////////////////////////////////////////////////////////////////////
64-
void OnTransformChanged(const AZ::Transform& local, const AZ::Transform& world);
58+
// AZ::TransformNotificationBus::Handler overrides ...
59+
void OnTransformChanged(const AZ::Transform& local, const AZ::Transform& world) override;
6560

6661
// AzToolsFramework::EditorEntityInfoNotificationBus overrides ...
6762
void OnEntityInfoUpdatedVisibility(AZ::EntityId entityId, bool visible);
@@ -76,8 +71,10 @@ namespace Pointcloud
7671
AZ::Crc32 OnAssetChanged();
7772

7873
private:
74+
PointcloudFeatureProcessorInterface::PointcloudChangedEvent::Handler m_changeEventHandler;
75+
void HandleChange(PointcloudFeatureProcessorInterface::PointcloudHandle handle);
76+
7977
PointcloudFeatureProcessorInterface* m_featureProcessor = nullptr;
80-
AZ::RPI::Scene* m_scene = nullptr;
8178
PointcloudComponentConfig m_config;
8279
bool visibility = true;
8380
};

Gems/Pointcloud/Code/Source/Tools/Components/PointcloudEditorComponent.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#include "PointcloudEditorComponent.h"
22
#include "Clients/PointcloudComponent.h"
33

4-
#include <Atom/RPI.Public/Scene.h>
54
#include <AzToolsFramework/Entity/EditorEntityInfoBus.h>
65
#include <AzToolsFramework/ToolsComponents/EditorComponentBase.h>
76
#include <Render/PointcloudFeatureProcessor.h>
@@ -61,17 +60,16 @@ namespace Pointcloud
6160
AzToolsFramework::EditorComponentSelectionRequestsBus::Handler::BusDisconnect();
6261
AzFramework::BoundsRequestBus::Handler::BusDisconnect();
6362
}
64-
bool PointcloudEditorComponent::ShouldActivateController() const
65-
{
66-
return false;
67-
}
6863

6964
AZ::Aabb PointcloudEditorComponent::GetWorldBounds()
7065
{
7166
AZ::Transform transform = AZ::Transform::CreateIdentity();
7267
AZ::TransformBus::EventResult(transform, GetEntityId(), &AZ::TransformBus::Events::GetWorldTM);
7368
AZ::Aabb bounds = m_controller.GetBounds();
74-
bounds.ApplyTransform(transform);
69+
if (bounds.IsValid())
70+
{
71+
bounds.ApplyTransform(transform);
72+
}
7573
return bounds;
7674
}
7775

@@ -80,7 +78,10 @@ namespace Pointcloud
8078
AZ::Transform transform = AZ::Transform::CreateIdentity();
8179
AZ::TransformBus::EventResult(transform, GetEntityId(), &AZ::TransformBus::Events::GetLocalTM);
8280
AZ::Aabb bounds = m_controller.GetBounds();
83-
bounds.ApplyTransform(transform);
81+
if (bounds.IsValid())
82+
{
83+
bounds.ApplyTransform(transform);
84+
}
8485
return bounds;
8586
}
8687

Gems/Pointcloud/Code/Source/Tools/Components/PointcloudEditorComponent.h

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,15 @@
22

33
#include "PointcloudComponentController.h"
44

5-
#include "../../Clients/PointcloudComponent.h"
6-
#include <AzToolsFramework/API/ComponentEntitySelectionBus.h>
7-
8-
#include <AzFramework/Visibility/BoundsBus.h>
5+
#include "Clients/PointcloudComponent.h"
96

10-
#include <AzCore/Asset/AssetCommon.h>
11-
#include <AzCore/Component/TickBus.h>
127
#include <AzCore/Component/TransformBus.h>
13-
#include <AzFramework/Entity/EntityContextBus.h>
148
#include <AzFramework/Entity/EntityDebugDisplayBus.h>
15-
#include <AzFramework/Scene/Scene.h>
16-
#include <AzFramework/Spawnable/SpawnableEntitiesInterface.h>
9+
#include <AzFramework/Visibility/BoundsBus.h>
10+
#include <AzToolsFramework/API/ComponentEntitySelectionBus.h>
1711
#include <AzToolsFramework/Entity/EditorEntityInfoBus.h>
1812
#include <AzToolsFramework/ToolsComponents/EditorComponentAdapter.h>
1913
#include <AzToolsFramework/ToolsComponents/EditorComponentBase.h>
20-
#include <Pointcloud/PointcloudComponentControllerConfigurationBus.h>
2114
#include <Pointcloud/PointcloudFeatureProcessorInterface.h>
2215
#include <Pointcloud/PointcloudTypeIds.h>
2316

@@ -47,18 +40,20 @@ namespace Pointcloud
4740
// EditorComponentBase interface overrides ...
4841
void Activate() override;
4942
void Deactivate() override;
50-
bool ShouldActivateController() const override;
5143

44+
// AzFramework::BoundsRequestBus overrides ...
5245
AZ::Aabb GetWorldBounds() override;
5346
AZ::Aabb GetLocalBounds() override;
5447

48+
// AzToolsFramework::EditorComponentSelectionRequestsBus overrides ...
5549
AZ::Aabb GetEditorSelectionBoundsViewport(const AzFramework::ViewportInfo& viewportInfo) override;
5650
bool EditorSelectionIntersectRayViewport(
5751
const AzFramework::ViewportInfo& viewportInfo, const AZ::Vector3& src, const AZ::Vector3& dir, float& distance) override;
5852

5953
bool SupportsEditorRayIntersect() override;
6054
bool SupportsEditorRayIntersectViewport(const AzFramework::ViewportInfo& viewportInfo) override;
6155

56+
// AzFramework::EntityDebugDisplayEventBus overrides ...
6257
void DisplayEntityViewport(const AzFramework::ViewportInfo& viewportInfo, AzFramework::DebugDisplayRequests& debugDisplay) override;
6358

6459
private:

0 commit comments

Comments
 (0)