adding support for non-uniform scale for decals

main
greerdv 5 years ago
parent 409489e938
commit d35adce246

@ -88,7 +88,8 @@ namespace AZ
//! Sets the transform of the decal
//! Equivalent to calling SetDecalPosition() + SetDecalOrientation() + SetDecalHalfSize()
virtual void SetDecalTransform(DecalHandle handle, const AZ::Transform& world) = 0;
virtual void SetDecalTransform(DecalHandle handle, const AZ::Transform& world,
const AZ::Vector3& nonUniformScale = AZ::Vector3::CreateOne()) = 0;
//! Sets the material information for this decal
virtual void SetDecalMaterial(DecalHandle handle, const AZ::Data::AssetId) = 0;

@ -262,7 +262,7 @@ namespace AZ
}
}
void DecalFeatureProcessor::SetDecalTransform(DecalHandle handle, const AZ::Transform& world)
void DecalFeatureProcessor::SetDecalTransform(DecalHandle handle, const AZ::Transform& world, const AZ::Vector3& nonUniformScale)
{
// https://jira.agscollab.com/browse/ATOM-4330
// Original Open 3D Engine uploads a 4x4 matrix rather than quaternion, rotation, scale.
@ -274,7 +274,7 @@ namespace AZ
if (handle.IsValid())
{
Quaternion orientation = world.GetRotation();
Vector3 scale = world.GetScale();
Vector3 scale = world.GetScale() * nonUniformScale;
SetDecalHalfSize(handle, scale);
SetDecalPosition(handle, world.GetTranslation());

@ -73,7 +73,8 @@ namespace AZ
//! Sets the transform of the decal
//! Equivalent to calling SetDecalPosition() + SetDecalOrientation() + SetDecalHalfSize()
void SetDecalTransform(DecalHandle handle, const AZ::Transform& world) override;
void SetDecalTransform(DecalHandle handle, const AZ::Transform& world,
const AZ::Vector3& nonUniformScale = AZ::Vector3::CreateOne()) override;
//! Sets the material information for this decal
void SetDecalMaterial(DecalHandle handle, const AZ::Data::AssetId) override;

@ -269,11 +269,12 @@ namespace AZ
}
}
void DecalTextureArrayFeatureProcessor::SetDecalTransform(DecalHandle handle, const AZ::Transform& world)
void DecalTextureArrayFeatureProcessor::SetDecalTransform(DecalHandle handle, const AZ::Transform& world,
const AZ::Vector3& nonUniformScale)
{
if (handle.IsValid())
{
SetDecalHalfSize(handle, world.GetScale());
SetDecalHalfSize(handle, nonUniformScale * world.GetScale());
SetDecalPosition(handle, world.GetTranslation());
SetDecalOrientation(handle, world.GetRotation());

@ -82,7 +82,8 @@ namespace AZ
//! Sets the transform of the decal
//! Equivalent to calling SetDecalPosition() + SetDecalOrientation() + SetDecalHalfSize()
void SetDecalTransform(const DecalHandle handle, const AZ::Transform& world) override;
void SetDecalTransform(const DecalHandle handle, const AZ::Transform& world,
const AZ::Vector3& nonUniformScale = AZ::Vector3::CreateOne()) override;
//! Sets the material information for this decal
void SetDecalMaterial(const DecalHandle handle, const AZ::Data::AssetId id) override;

@ -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

Loading…
Cancel
Save