SurfaceData cleanups to prepare for bulk APIs (#7166)
* Initial cleanup of GetSurfacePointsFromRegion in prep for bulk API support. * Removed the generated lookup point from the output structure. Nothing was using it, and by keeping it separate, I can pass it in as a list of points that can be passed throughout the terrain, gradient, and surface data APIs. * Clarified on the SurfaceProvider bus that GetSurfacePoints() only gets valid XY values on the inPosition. * Simplified the TerrainSurfaceDataSystemComponent implementation a bit. The EnumerateHandlers() and the terrain Aabb checks were overkill. Also, the terrain Aabb check assumed that the Z value on the inPosition was valid, which it isn't always. Signed-off-by: Mike Balfour <82224783+mbalfour-amzn@users.noreply.github.com> * Remove CryCommon dependency. Signed-off-by: Mike Balfour <82224783+mbalfour-amzn@users.noreply.github.com>
This commit is contained in:
@@ -195,12 +195,11 @@ namespace SurfaceData
|
||||
{
|
||||
const AZ::u32 entryAddress = entryPair.first;
|
||||
const SurfaceDataRegistryEntry& entry = entryPair.second;
|
||||
AZ::Vector3 point2d(inPosition.GetX(), inPosition.GetY(), entry.m_bounds.GetMax().GetZ());
|
||||
if (!entry.m_bounds.IsValid() || entry.m_bounds.Contains(point2d))
|
||||
if (!entry.m_bounds.IsValid() || AabbContains2D(entry.m_bounds, inPosition))
|
||||
{
|
||||
if (!hasDesiredTags || hasModifierTags || HasMatchingTags(desiredTags, entry.m_tags))
|
||||
{
|
||||
SurfaceDataProviderRequestBus::Event(entryAddress, &SurfaceDataProviderRequestBus::Events::GetSurfacePoints, point2d, surfacePointList);
|
||||
SurfaceDataProviderRequestBus::Event(entryAddress, &SurfaceDataProviderRequestBus::Events::GetSurfacePoints, inPosition, surfacePointList);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -212,8 +211,7 @@ namespace SurfaceData
|
||||
{
|
||||
const AZ::u32 entryAddress = entryPair.first;
|
||||
const SurfaceDataRegistryEntry& entry = entryPair.second;
|
||||
AZ::Vector3 point2d(inPosition.GetX(), inPosition.GetY(), entry.m_bounds.GetMax().GetZ());
|
||||
if (!entry.m_bounds.IsValid() || entry.m_bounds.Contains(point2d))
|
||||
if (!entry.m_bounds.IsValid() || AabbContains2D(entry.m_bounds, inPosition))
|
||||
{
|
||||
SurfaceDataModifierRequestBus::Event(entryAddress, &SurfaceDataModifierRequestBus::Events::ModifySurfacePoints, surfacePointList);
|
||||
}
|
||||
@@ -227,12 +225,19 @@ namespace SurfaceData
|
||||
}
|
||||
}
|
||||
|
||||
void SurfaceDataSystemComponent::GetSurfacePointsFromRegion(const AZ::Aabb& inRegion, const AZ::Vector2 stepSize, const SurfaceTagVector& desiredTags, SurfacePointListPerPosition& surfacePointListPerPosition) const
|
||||
void SurfaceDataSystemComponent::GetSurfacePointsFromRegion(const AZ::Aabb& inRegion, const AZ::Vector2 stepSize,
|
||||
const SurfaceTagVector& desiredTags, SurfacePointLists& surfacePointLists) const
|
||||
{
|
||||
AZStd::lock_guard<decltype(m_registrationMutex)> registrationLock(m_registrationMutex);
|
||||
|
||||
surfacePointListPerPosition.clear();
|
||||
surfacePointListPerPosition.reserve(aznumeric_cast<uint32_t>(ceil(inRegion.GetXExtent() / stepSize.GetX())) * aznumeric_cast<uint32_t>(ceil(inRegion.GetYExtent() / stepSize.GetY())));
|
||||
const size_t totalQueryPositions = aznumeric_cast<size_t>(ceil(inRegion.GetXExtent() / stepSize.GetX())) *
|
||||
aznumeric_cast<size_t>(ceil(inRegion.GetYExtent() / stepSize.GetY()));
|
||||
|
||||
AZStd::vector<AZ::Vector3> inPositions;
|
||||
inPositions.reserve(totalQueryPositions);
|
||||
|
||||
surfacePointLists.clear();
|
||||
surfacePointLists.reserve(totalQueryPositions);
|
||||
|
||||
// Initialize our list-per-position list with every input position to query from the region.
|
||||
// This is inclusive on the min sides of inRegion, and exclusive on the max sides.
|
||||
@@ -240,7 +245,8 @@ namespace SurfaceData
|
||||
{
|
||||
for (float x = inRegion.GetMin().GetX(); x < inRegion.GetMax().GetX(); x += stepSize.GetX())
|
||||
{
|
||||
surfacePointListPerPosition.emplace_back(AZ::Vector3(x, y, AZ::Constants::FloatMax), SurfaceData::SurfacePointList{});
|
||||
inPositions.emplace_back(AZ::Vector3(x, y, AZ::Constants::FloatMax));
|
||||
surfacePointLists.emplace_back(SurfaceData::SurfacePointList{});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -259,14 +265,14 @@ namespace SurfaceData
|
||||
( alwaysApplies || AabbOverlaps2D(entry.m_bounds, inRegion) )
|
||||
)
|
||||
{
|
||||
for (auto& surfacePointListAndPoint : surfacePointListPerPosition)
|
||||
for (size_t index = 0; index < totalQueryPositions; index++)
|
||||
{
|
||||
const auto& point2d = surfacePointListAndPoint.first;
|
||||
SurfacePointList& surfacePointList = surfacePointListAndPoint.second;
|
||||
AZ::Vector3 point3d(point2d.GetX(), point2d.GetY(), entry.m_bounds.GetMax().GetZ());
|
||||
if (alwaysApplies || entry.m_bounds.Contains(point3d))
|
||||
const auto& inPosition = inPositions[index];
|
||||
SurfacePointList& surfacePointList = surfacePointLists[index];
|
||||
if (alwaysApplies || AabbContains2D(entry.m_bounds, inPosition))
|
||||
{
|
||||
SurfaceDataProviderRequestBus::Event(entryPair.first, &SurfaceDataProviderRequestBus::Events::GetSurfacePoints, point3d, surfacePointList);
|
||||
SurfaceDataProviderRequestBus::Event(
|
||||
entryPair.first, &SurfaceDataProviderRequestBus::Events::GetSurfacePoints, inPosition, surfacePointList);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -284,14 +290,13 @@ namespace SurfaceData
|
||||
|
||||
if (alwaysApplies || AabbOverlaps2D(entry.m_bounds, inRegion))
|
||||
{
|
||||
for (auto& surfacePointListAndPoint : surfacePointListPerPosition)
|
||||
for (size_t index = 0; index < totalQueryPositions; index++)
|
||||
{
|
||||
const auto& point2d = surfacePointListAndPoint.first;
|
||||
SurfacePointList& surfacePointList = surfacePointListAndPoint.second;
|
||||
const auto& inPosition = inPositions[index];
|
||||
SurfacePointList& surfacePointList = surfacePointLists[index];
|
||||
if (!surfacePointList.empty())
|
||||
{
|
||||
AZ::Vector3 point3d(point2d.GetX(), point2d.GetY(), entry.m_bounds.GetMax().GetZ());
|
||||
if (alwaysApplies || entry.m_bounds.Contains(point3d))
|
||||
if (alwaysApplies || AabbContains2D(entry.m_bounds, inPosition))
|
||||
{
|
||||
SurfaceDataModifierRequestBus::Event(entryPair.first, &SurfaceDataModifierRequestBus::Events::ModifySurfacePoints, surfacePointList);
|
||||
}
|
||||
@@ -304,9 +309,8 @@ namespace SurfaceData
|
||||
// same XY coordinates and extremely similar Z values. This produces results that are sorted in decreasing Z order.
|
||||
// Also, this filters out any remaining points that don't match the desired tag list. This can happen when a surface provider
|
||||
// doesn't add a desired tag, and a surface modifier has the *potential* to add it, but then doesn't.
|
||||
for (auto& surfacePointListAndPoint : surfacePointListPerPosition)
|
||||
for (auto& surfacePointList : surfacePointLists)
|
||||
{
|
||||
auto& surfacePointList = surfacePointListAndPoint.second;
|
||||
if (!surfacePointList.empty())
|
||||
{
|
||||
CombineSortAndFilterNeighboringPoints(surfacePointList, hasDesiredTags, desiredTags);
|
||||
|
||||
Reference in New Issue
Block a user