[LYN-3099] Fixed some issues with vegetation planting on surfaces (#1554)
* [LYN-3099] Fix vegetation raycasts to use bounded ray queries instead of FLT_MAX. Raycasts with a distance of FLT_MAX sometimes overflowed deep in IntersectSegmentTriangleCCW, so it's better to have strict start/end positional queries. We have specific starts and ends anyways, so it's a safer approach anyways. This also adds support for Non-Uniform Scale for meshes, since it was clearly not working correctly in vegetation when testing various scaled meshes. * Addressed PR feedback
This commit is contained in:
+17
-3
@@ -73,8 +73,14 @@ namespace SurfaceData
|
||||
}
|
||||
}
|
||||
|
||||
SurfaceDataMeshComponent::SurfaceDataMeshComponent()
|
||||
: m_nonUniformScaleChangedHandler([this]([[maybe_unused]] const AZ::Vector3& scale) { this->OnCompositionChanged(); })
|
||||
{
|
||||
}
|
||||
|
||||
SurfaceDataMeshComponent::SurfaceDataMeshComponent(const SurfaceDataMeshConfig& configuration)
|
||||
: m_configuration(configuration)
|
||||
, m_nonUniformScaleChangedHandler([this]([[maybe_unused]] const AZ::Vector3& scale) { this->OnCompositionChanged(); })
|
||||
{
|
||||
}
|
||||
|
||||
@@ -83,6 +89,9 @@ namespace SurfaceData
|
||||
AZ::TransformNotificationBus::Handler::BusConnect(GetEntityId());
|
||||
AZ::Render::MeshComponentNotificationBus::Handler::BusConnect(GetEntityId());
|
||||
|
||||
AZ::NonUniformScaleRequestBus::Event(
|
||||
GetEntityId(), &AZ::NonUniformScaleRequests::RegisterScaleChangedEvent, m_nonUniformScaleChangedHandler);
|
||||
|
||||
m_providerHandle = InvalidSurfaceDataRegistryHandle;
|
||||
m_refresh = false;
|
||||
|
||||
@@ -98,6 +107,7 @@ namespace SurfaceData
|
||||
m_providerHandle = InvalidSurfaceDataRegistryHandle;
|
||||
}
|
||||
|
||||
m_nonUniformScaleChangedHandler.Disconnect();
|
||||
SurfaceDataProviderRequestBus::Handler::BusDisconnect();
|
||||
AZ::TickBus::Handler::BusDisconnect();
|
||||
AZ::TransformNotificationBus::Handler::BusDisconnect();
|
||||
@@ -157,9 +167,10 @@ namespace SurfaceData
|
||||
return false;
|
||||
}
|
||||
|
||||
const AZ::Vector3 rayOrigin = AZ::Vector3(inPosition.GetX(), inPosition.GetY(), m_meshBounds.GetMax().GetZ() + s_rayAABBHeightPadding);
|
||||
const AZ::Vector3 rayDirection = -AZ::Vector3::CreateAxisZ();
|
||||
return GetMeshRayIntersection(*mesh, m_meshWorldTM, m_meshWorldTMInverse, rayOrigin, rayDirection, outPosition, outNormal);
|
||||
const AZ::Vector3 rayStart = AZ::Vector3(inPosition.GetX(), inPosition.GetY(), m_meshBounds.GetMax().GetZ() + s_rayAABBHeightPadding);
|
||||
const AZ::Vector3 rayEnd = AZ::Vector3(inPosition.GetX(), inPosition.GetY(), m_meshBounds.GetMin().GetZ() - s_rayAABBHeightPadding);
|
||||
return GetMeshRayIntersection(
|
||||
*mesh, m_meshWorldTM, m_meshWorldTMInverse, m_meshNonUniformScale, rayStart, rayEnd, outPosition, outNormal);
|
||||
}
|
||||
|
||||
|
||||
@@ -241,6 +252,9 @@ namespace SurfaceData
|
||||
AZ::TransformBus::EventResult(m_meshWorldTM, GetEntityId(), &AZ::TransformBus::Events::GetWorldTM);
|
||||
m_meshWorldTMInverse = m_meshWorldTM.GetInverse();
|
||||
|
||||
m_meshNonUniformScale = AZ::Vector3::CreateOne();
|
||||
AZ::NonUniformScaleRequestBus::EventResult(m_meshNonUniformScale, GetEntityId(), &AZ::NonUniformScaleRequests::GetScale);
|
||||
|
||||
meshValidAfterUpdate = (m_meshAssetData.GetAs<AZ::RPI::ModelAsset>() != nullptr) && (m_meshBounds.IsValid());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user