adding support for non-uniform scale for decals
This commit is contained in:
+24
-1
@@ -75,6 +75,12 @@ namespace AZ
|
||||
incompatible.push_back(AZ_CRC_CE("DecalService"));
|
||||
}
|
||||
|
||||
void DecalComponentController::GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent)
|
||||
{
|
||||
dependent.push_back(AZ_CRC_CE("TransformService"));
|
||||
dependent.push_back(AZ_CRC_CE("NonUniformScaleService"));
|
||||
}
|
||||
|
||||
DecalComponentController::DecalComponentController(const DecalComponentConfig& config)
|
||||
: m_configuration(config)
|
||||
{
|
||||
@@ -90,6 +96,11 @@ namespace AZ
|
||||
m_handle = m_featureProcessor->AcquireDecal();
|
||||
}
|
||||
|
||||
m_cachedNonUniformScale = AZ::Vector3::CreateOne();
|
||||
AZ::NonUniformScaleRequestBus::EventResult(m_cachedNonUniformScale, m_entityId, &AZ::NonUniformScaleRequests::GetScale);
|
||||
AZ::NonUniformScaleRequestBus::Event(m_entityId, &AZ::NonUniformScaleRequests::RegisterScaleChangedEvent,
|
||||
m_nonUniformScaleChangedHandler);
|
||||
|
||||
AZ::Transform local, world;
|
||||
AZ::TransformBus::Event(entityId, &AZ::TransformBus::Events::GetLocalAndWorld, local, world);
|
||||
OnTransformChanged(local, world);
|
||||
@@ -103,6 +114,7 @@ namespace AZ
|
||||
{
|
||||
DecalRequestBus::Handler::BusDisconnect(m_entityId);
|
||||
TransformNotificationBus::Handler::BusDisconnect(m_entityId);
|
||||
m_nonUniformScaleChangedHandler.Disconnect();
|
||||
if (m_featureProcessor)
|
||||
{
|
||||
m_featureProcessor->ReleaseDecal(m_handle);
|
||||
@@ -125,7 +137,18 @@ namespace AZ
|
||||
{
|
||||
if (m_featureProcessor)
|
||||
{
|
||||
m_featureProcessor->SetDecalTransform(m_handle, world);
|
||||
m_featureProcessor->SetDecalTransform(m_handle, world, m_cachedNonUniformScale);
|
||||
}
|
||||
}
|
||||
|
||||
void DecalComponentController::HandleNonUniformScaleChange(const AZ::Vector3& nonUniformScale)
|
||||
{
|
||||
m_cachedNonUniformScale = nonUniformScale;
|
||||
if (m_featureProcessor)
|
||||
{
|
||||
AZ::Transform world = AZ::Transform::CreateIdentity();
|
||||
AZ::TransformBus::EventResult(world, m_entityId, &AZ::TransformBus::Events::GetWorldTM);
|
||||
m_featureProcessor->SetDecalTransform(m_handle, world, nonUniformScale);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
#include <AzCore/Component/Component.h>
|
||||
#include <AzCore/Component/TransformBus.h>
|
||||
#include <AzCore/Component/NonUniformScaleBus.h>
|
||||
#include <AtomLyIntegration/CommonFeatures/Decals/DecalBus.h>
|
||||
#include <AtomLyIntegration/CommonFeatures/Decals/DecalComponentConfig.h>
|
||||
#include <Atom/Feature/Decals/DecalFeatureProcessorInterface.h>
|
||||
@@ -33,6 +34,7 @@ namespace AZ
|
||||
static void Reflect(AZ::ReflectContext* context);
|
||||
static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided);
|
||||
static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible);
|
||||
static void GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent);
|
||||
|
||||
DecalComponentController() = default;
|
||||
DecalComponentController(const DecalComponentConfig& config);
|
||||
@@ -64,11 +66,18 @@ namespace AZ
|
||||
void OpacityChanged();
|
||||
void SortKeyChanged();
|
||||
void MaterialChanged();
|
||||
void HandleNonUniformScaleChange(const AZ::Vector3& nonUniformScale);
|
||||
|
||||
DecalComponentConfig m_configuration;
|
||||
DecalFeatureProcessorInterface* m_featureProcessor = nullptr;
|
||||
DecalFeatureProcessorInterface::DecalHandle m_handle;
|
||||
EntityId m_entityId;
|
||||
AZ::Vector3 m_cachedNonUniformScale = AZ::Vector3::CreateOne();
|
||||
|
||||
AZ::NonUniformScaleChangedEvent::Handler m_nonUniformScaleChangedHandler
|
||||
{
|
||||
[&](const AZ::Vector3& nonUniformScale) { HandleNonUniformScaleChange(nonUniformScale); }
|
||||
};
|
||||
};
|
||||
} // namespace Render
|
||||
} // AZ namespace
|
||||
|
||||
Reference in New Issue
Block a user