Ensure render geometry is refreshed when the mesh component controller is moved (#6452)
* ensure render geometry is refreshed when the mesh component controller is moved Signed-off-by: Tom Hulton-Harrop <82228511+hultonha@users.noreply.github.com> * cache bus pointer and send update notification when mesh changes Signed-off-by: Tom Hulton-Harrop <82228511+hultonha@users.noreply.github.com> * add integration test to detect MeshComponentController notification to IntersectionNotificationBus Signed-off-by: Tom Hulton-Harrop <82228511+hultonha@users.noreply.github.com> * remove optimize off Signed-off-by: Tom Hulton-Harrop <82228511+hultonha@users.noreply.github.com> * update build visibility for AtomLyIntegration editor static lib Signed-off-by: Tom Hulton-Harrop <82228511+hultonha@users.noreply.github.com> * move runtime dependencies to gem module Signed-off-by: Tom Hulton-Harrop <82228511+hultonha@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
a623e52331
commit
5940982244
+26
-10
@@ -82,7 +82,6 @@ namespace AZ
|
||||
->Field("MinimumScreenCoverage", &MeshComponentConfig::m_minimumScreenCoverage)
|
||||
->Field("QualityDecayRate", &MeshComponentConfig::m_qualityDecayRate);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool MeshComponentConfig::IsAssetSet()
|
||||
@@ -225,33 +224,42 @@ namespace AZ
|
||||
{
|
||||
}
|
||||
|
||||
static AzFramework::EntityContextId FindOwningContextId(const AZ::EntityId entityId)
|
||||
{
|
||||
AzFramework::EntityContextId contextId = AzFramework::EntityContextId::CreateNull();
|
||||
AzFramework::EntityIdContextQueryBus::EventResult(
|
||||
contextId, entityId, &AzFramework::EntityIdContextQueries::GetOwningContextId);
|
||||
return contextId;
|
||||
}
|
||||
|
||||
void MeshComponentController::Activate(const AZ::EntityComponentIdPair& entityComponentIdPair)
|
||||
{
|
||||
const AZ::EntityId entityId = entityComponentIdPair.GetEntityId();
|
||||
m_entityComponentIdPair = entityComponentIdPair;
|
||||
|
||||
m_transformInterface = TransformBus::FindFirstHandler(entityId);
|
||||
AZ_Warning("MeshComponentController", m_transformInterface, "Unable to attach to a TransformBus handler. This mesh will always be rendered at the origin.");
|
||||
AZ_Warning(
|
||||
"MeshComponentController", m_transformInterface,
|
||||
"Unable to attach to a TransformBus handler. This mesh will always be rendered at the origin.");
|
||||
|
||||
m_meshFeatureProcessor = RPI::Scene::GetFeatureProcessorForEntity<MeshFeatureProcessorInterface>(entityId);
|
||||
AZ_Error("MeshComponentController", m_meshFeatureProcessor, "Unable to find a MeshFeatureProcessorInterface on the entityId.");
|
||||
|
||||
m_cachedNonUniformScale = AZ::Vector3::CreateOne();
|
||||
AZ::NonUniformScaleRequestBus::EventResult(m_cachedNonUniformScale, entityId, &AZ::NonUniformScaleRequests::GetScale);
|
||||
AZ::NonUniformScaleRequestBus::Event(entityId, &AZ::NonUniformScaleRequests::RegisterScaleChangedEvent,
|
||||
m_nonUniformScaleChangedHandler);
|
||||
AZ::NonUniformScaleRequestBus::Event(
|
||||
entityId, &AZ::NonUniformScaleRequests::RegisterScaleChangedEvent, m_nonUniformScaleChangedHandler);
|
||||
|
||||
const auto entityContextId = FindOwningContextId(entityId);
|
||||
MeshComponentRequestBus::Handler::BusConnect(entityId);
|
||||
TransformNotificationBus::Handler::BusConnect(entityId);
|
||||
MaterialReceiverRequestBus::Handler::BusConnect(entityId);
|
||||
MaterialComponentNotificationBus::Handler::BusConnect(entityId);
|
||||
AzFramework::BoundsRequestBus::Handler::BusConnect(entityId);
|
||||
AzFramework::EntityContextId contextId;
|
||||
AzFramework::EntityIdContextQueryBus::EventResult(
|
||||
contextId, entityId, &AzFramework::EntityIdContextQueries::GetOwningContextId);
|
||||
AzFramework::RenderGeometry::IntersectionRequestBus::Handler::BusConnect({entityId, contextId});
|
||||
AzFramework::RenderGeometry::IntersectionRequestBus::Handler::BusConnect({ entityId, entityContextId });
|
||||
AzFramework::RenderGeometry::IntersectionNotificationBus::Bind(m_intersectionNotificationBus, entityContextId);
|
||||
|
||||
//Buses must be connected before RegisterModel in case requests are made as a result of HandleModelChange
|
||||
// Buses must be connected before RegisterModel in case requests are made as a result of HandleModelChange
|
||||
RegisterModel();
|
||||
}
|
||||
|
||||
@@ -291,6 +299,11 @@ namespace AZ
|
||||
{
|
||||
m_meshFeatureProcessor->SetTransform(m_meshHandle, world, m_cachedNonUniformScale);
|
||||
}
|
||||
|
||||
// ensure the render geometry is kept in sync with any changes to the entity the mesh is on
|
||||
AzFramework::RenderGeometry::IntersectionNotificationBus::Event(
|
||||
m_intersectionNotificationBus, &AzFramework::RenderGeometry::IntersectionNotificationBus::Events::OnGeometryChanged,
|
||||
m_entityComponentIdPair.GetEntityId());
|
||||
}
|
||||
|
||||
void MeshComponentController::HandleNonUniformScaleChange(const AZ::Vector3& nonUniformScale)
|
||||
@@ -301,7 +314,7 @@ namespace AZ
|
||||
m_meshFeatureProcessor->SetTransform(m_meshHandle, m_transformInterface->GetWorldTM(), m_cachedNonUniformScale);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
RPI::ModelMaterialSlotMap MeshComponentController::GetModelMaterialSlots() const
|
||||
{
|
||||
Data::Asset<const RPI::ModelAsset> modelAsset = GetModelAsset();
|
||||
@@ -369,6 +382,9 @@ namespace AZ
|
||||
MeshComponentNotificationBus::Event(entityId, &MeshComponentNotificationBus::Events::OnModelReady, m_configuration.m_modelAsset, model);
|
||||
MaterialReceiverNotificationBus::Event(entityId, &MaterialReceiverNotificationBus::Events::OnMaterialAssignmentsChanged);
|
||||
AZ::Interface<AzFramework::IEntityBoundsUnion>::Get()->RefreshEntityLocalBoundsUnion(entityId);
|
||||
AzFramework::RenderGeometry::IntersectionNotificationBus::Event(
|
||||
m_intersectionNotificationBus, &AzFramework::RenderGeometry::IntersectionNotificationBus::Events::OnGeometryChanged,
|
||||
m_entityComponentIdPair.GetEntityId());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user