fix various issues with collider manipulators and non-uniform scale
Signed-off-by: greerdv <greerdv@amazon.com>
This commit is contained in:
+25
-18
@@ -40,25 +40,26 @@ namespace AzToolsFramework
|
||||
BoxManipulatorRequestBus::EventResult(
|
||||
boxWorldFromLocal, m_entityComponentIdPair, &BoxManipulatorRequests::GetCurrentTransform);
|
||||
|
||||
AZ::Vector3 boxScale = AZ::Vector3::CreateOne();
|
||||
AZ::Vector3 nonUniformScale = AZ::Vector3::CreateOne();
|
||||
BoxManipulatorRequestBus::EventResult(
|
||||
boxScale, m_entityComponentIdPair, &BoxManipulatorRequests::GetBoxScale);
|
||||
nonUniformScale, m_entityComponentIdPair, &BoxManipulatorRequests::GetCurrentNonUniformScale);
|
||||
|
||||
AZ::Vector3 boxDimensions = AZ::Vector3::CreateZero();
|
||||
BoxManipulatorRequestBus::EventResult(
|
||||
boxDimensions, m_entityComponentIdPair, &BoxManipulatorRequests::GetDimensions);
|
||||
|
||||
// ensure we apply the entity scale to the box dimensions so
|
||||
// the manipulators appear in the correct location
|
||||
boxDimensions *= boxScale;
|
||||
AZ::Transform boxLocalTransform = AZ::Transform::CreateIdentity();
|
||||
BoxManipulatorRequestBus::EventResult(
|
||||
boxLocalTransform, m_entityComponentIdPair, &BoxManipulatorRequests::GetCurrentLocalTransform);
|
||||
|
||||
for (size_t manipulatorIndex = 0; manipulatorIndex < m_linearManipulators.size(); ++manipulatorIndex)
|
||||
{
|
||||
if (auto& linearManipulator = m_linearManipulators[manipulatorIndex])
|
||||
{
|
||||
linearManipulator->SetSpace(boxWorldFromLocal);
|
||||
linearManipulator->SetLocalTransform(
|
||||
AZ::Transform::CreateTranslation(s_boxAxes[manipulatorIndex] * 0.5f * boxDimensions));
|
||||
linearManipulator->SetLocalTransform(boxLocalTransform * AZ::Transform::CreateTranslation(
|
||||
s_boxAxes[manipulatorIndex] * 0.5f * boxDimensions));
|
||||
linearManipulator->SetNonUniformScale(nonUniformScale);
|
||||
linearManipulator->SetBoundsDirty();
|
||||
}
|
||||
}
|
||||
@@ -92,29 +93,35 @@ namespace AzToolsFramework
|
||||
[this, entityComponentIdPair](
|
||||
const LinearManipulator::Action& action)
|
||||
{
|
||||
AZ::Transform boxLocalTransform = AZ::Transform::CreateIdentity();
|
||||
BoxManipulatorRequestBus::EventResult(
|
||||
boxLocalTransform, entityComponentIdPair, &BoxManipulatorRequests::GetCurrentLocalTransform);
|
||||
|
||||
AZ::Transform boxWorldTransform = AZ::Transform::CreateIdentity();
|
||||
BoxManipulatorRequestBus::EventResult(
|
||||
boxWorldTransform, entityComponentIdPair, &BoxManipulatorRequests::GetCurrentTransform);
|
||||
float boxScale = AZ::GetMax(AZ::MinTransformScale, boxWorldTransform.GetUniformScale());
|
||||
|
||||
// calculate the position of the manipulator in the reference frame of the box
|
||||
// the local position offset of the manipulator does not take the transform scale into account, so need to apply it here
|
||||
const AZ::Vector3 localPosition = boxLocalTransform.GetInverse().TransformPoint(
|
||||
action.m_start.m_localPosition + action.m_current.m_localPositionOffset / boxScale);
|
||||
|
||||
// calculate the amount of displacement along an axis this manipulator has moved
|
||||
// clamp movement so it cannot go negative based on axis direction
|
||||
const AZ::Vector3 axisDisplacement =
|
||||
action.LocalPosition().GetAbs() * 2.0f
|
||||
* AZ::GetMax<float>(0.0f, action.LocalPosition().GetNormalized().Dot(action.m_fixed.m_axis));
|
||||
|
||||
AZ::Vector3 boxScale = AZ::Vector3::CreateOne();
|
||||
BoxManipulatorRequestBus::EventResult(
|
||||
boxScale, entityComponentIdPair, &BoxManipulatorRequests::GetBoxScale);
|
||||
localPosition.GetAbs() * 2.0f
|
||||
* AZ::GetMax<float>(0.0f, localPosition.GetNormalized().Dot(action.m_fixed.m_axis));
|
||||
|
||||
AZ::Vector3 boxDimensions = AZ::Vector3::CreateZero();
|
||||
BoxManipulatorRequestBus::EventResult(
|
||||
boxDimensions, entityComponentIdPair, &BoxManipulatorRequests::GetDimensions);
|
||||
|
||||
// ensure we take into account the entity scale using the axis displacement
|
||||
const AZ::Vector3 scaledAxisDisplacement =
|
||||
axisDisplacement / boxScale;
|
||||
|
||||
// update dimensions - preserve dimensions not effected by this
|
||||
// axis, and update current axis displacement
|
||||
BoxManipulatorRequestBus::Event(
|
||||
entityComponentIdPair, &BoxManipulatorRequests::SetDimensions,
|
||||
(NotAxis(action.m_fixed.m_axis) * boxDimensions).GetMax(scaledAxisDisplacement));
|
||||
(NotAxis(action.m_fixed.m_axis) * boxDimensions).GetMax(axisDisplacement));
|
||||
|
||||
UpdateManipulators();
|
||||
});
|
||||
|
||||
+5
@@ -31,12 +31,17 @@ namespace AzToolsFramework
|
||||
//! because a collider may have an additional translation/orientation offset from
|
||||
//! the Entity transform.
|
||||
virtual AZ::Transform GetCurrentTransform() = 0;
|
||||
//!
|
||||
//!
|
||||
virtual AZ::Transform GetCurrentLocalTransform() = 0;
|
||||
//! Get the scale currently applied to the box.
|
||||
//! With the Box Shape, the largest x/y/z component is taken
|
||||
//! so scale is always uniform, with colliders the scale may
|
||||
//! be different per component.
|
||||
virtual AZ::Vector3 GetBoxScale() = 0;
|
||||
|
||||
virtual AZ::Vector3 GetCurrentNonUniformScale() { return AZ::Vector3::CreateOne(); }
|
||||
|
||||
protected:
|
||||
~BoxManipulatorRequests() = default;
|
||||
};
|
||||
|
||||
@@ -161,6 +161,11 @@ namespace LmbrCentral
|
||||
return AzToolsFramework::TransformNormalizedScale(m_aaboxShape.GetCurrentTransform());
|
||||
}
|
||||
|
||||
AZ::Transform EditorAxisAlignedBoxShapeComponent::GetCurrentLocalTransform()
|
||||
{
|
||||
return AZ::Transform::CreateIdentity();
|
||||
}
|
||||
|
||||
AZ::Vector3 EditorAxisAlignedBoxShapeComponent::GetBoxScale()
|
||||
{
|
||||
return AZ::Vector3(m_aaboxShape.GetCurrentTransform().GetUniformScale() * m_aaboxShape.GetCurrentNonUniformScale());
|
||||
|
||||
@@ -58,6 +58,7 @@ namespace LmbrCentral
|
||||
AZ::Vector3 GetDimensions() override;
|
||||
void SetDimensions(const AZ::Vector3& dimensions) override;
|
||||
AZ::Transform GetCurrentTransform() override;
|
||||
AZ::Transform GetCurrentLocalTransform() override;
|
||||
AZ::Vector3 GetBoxScale() override;
|
||||
|
||||
void ConfigurationChanged();
|
||||
|
||||
@@ -167,6 +167,11 @@ namespace LmbrCentral
|
||||
return AzToolsFramework::TransformNormalizedScale(m_boxShape.GetCurrentTransform());
|
||||
}
|
||||
|
||||
AZ::Transform EditorBoxShapeComponent::GetCurrentLocalTransform()
|
||||
{
|
||||
return AZ::Transform::CreateIdentity();
|
||||
}
|
||||
|
||||
AZ::Vector3 EditorBoxShapeComponent::GetBoxScale()
|
||||
{
|
||||
return AZ::Vector3(m_boxShape.GetCurrentTransform().GetUniformScale() * m_boxShape.GetCurrentNonUniformScale());
|
||||
|
||||
@@ -57,6 +57,7 @@ namespace LmbrCentral
|
||||
AZ::Vector3 GetDimensions() override;
|
||||
void SetDimensions(const AZ::Vector3& dimensions) override;
|
||||
AZ::Transform GetCurrentTransform() override;
|
||||
AZ::Transform GetCurrentLocalTransform() override;
|
||||
AZ::Vector3 GetBoxScale() override;
|
||||
|
||||
void ConfigurationChanged();
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <PhysX/EditorColliderComponentRequestBus.h>
|
||||
|
||||
#include <AzToolsFramework/Manipulators/ManipulatorManager.h>
|
||||
#include <AzCore/Component/NonUniformScaleBus.h>
|
||||
#include <AzCore/Component/TransformBus.h>
|
||||
#include <AzCore/Component/ComponentBus.h>
|
||||
|
||||
@@ -28,10 +29,14 @@ namespace PhysX
|
||||
AZ::Transform worldTransform;
|
||||
AZ::TransformBus::EventResult(worldTransform, idPair.GetEntityId(), &AZ::TransformInterface::GetWorldTM);
|
||||
|
||||
AZ::Vector3 nonUniformScale = AZ::Vector3::CreateOne();
|
||||
AZ::NonUniformScaleRequestBus::EventResult(nonUniformScale, idPair.GetEntityId(), &AZ::NonUniformScaleRequests::GetScale);
|
||||
|
||||
AZ::Vector3 colliderOffset;
|
||||
PhysX::EditorColliderComponentRequestBus::EventResult(colliderOffset, idPair, &PhysX::EditorColliderComponentRequests::GetColliderOffset);
|
||||
|
||||
m_translationManipulators.SetSpace(worldTransform);
|
||||
m_translationManipulators.SetNonUniformScale(nonUniformScale);
|
||||
m_translationManipulators.SetLocalPosition(colliderOffset);
|
||||
m_translationManipulators.AddEntityComponentIdPair(idPair);
|
||||
m_translationManipulators.Register(AzToolsFramework::g_mainManipulatorManagerId);
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <PhysX/EditorColliderComponentRequestBus.h>
|
||||
#include <AzToolsFramework/Manipulators/ManipulatorManager.h>
|
||||
#include <AzCore/Component/TransformBus.h>
|
||||
#include <AzCore/Component/NonUniformScaleBus.h>
|
||||
#include <AzFramework/Viewport/ViewportColors.h>
|
||||
#include <AzToolsFramework/Manipulators/AngularManipulator.h>
|
||||
#include <AzToolsFramework/ViewportSelection/EditorSelectionUtil.h>
|
||||
@@ -29,6 +30,9 @@ namespace PhysX
|
||||
AZ::Transform worldTransform;
|
||||
AZ::TransformBus::EventResult(worldTransform, idPair.GetEntityId(), &AZ::TransformInterface::GetWorldTM);
|
||||
|
||||
AZ::Vector3 nonUniformScale = AZ::Vector3::CreateOne();
|
||||
AZ::NonUniformScaleRequestBus::EventResult(nonUniformScale, idPair.GetEntityId(), &AZ::NonUniformScaleRequests::GetScale);
|
||||
|
||||
AZ::Quaternion colliderRotation;
|
||||
PhysX::EditorColliderComponentRequestBus::EventResult(colliderRotation, idPair, &PhysX::EditorColliderComponentRequests::GetColliderRotation);
|
||||
|
||||
@@ -36,7 +40,8 @@ namespace PhysX
|
||||
PhysX::EditorColliderComponentRequestBus::EventResult(colliderOffset, idPair, &PhysX::EditorColliderComponentRequests::GetColliderOffset);
|
||||
|
||||
m_rotationManipulators.SetSpace(worldTransform);
|
||||
m_rotationManipulators.SetLocalPosition(colliderOffset);
|
||||
m_rotationManipulators.SetNonUniformScale(nonUniformScale);
|
||||
m_rotationManipulators.SetLocalPosition(nonUniformScale * colliderOffset);
|
||||
m_rotationManipulators.SetLocalOrientation(colliderRotation);
|
||||
m_rotationManipulators.AddEntityComponentIdPair(idPair);
|
||||
m_rotationManipulators.Register(AzToolsFramework::g_mainManipulatorManagerId);
|
||||
@@ -70,7 +75,11 @@ namespace PhysX
|
||||
|
||||
AZ::Vector3 colliderOffset = AZ::Vector3::CreateZero();
|
||||
PhysX::EditorColliderComponentRequestBus::EventResult(colliderOffset, idPair, &PhysX::EditorColliderComponentRequests::GetColliderOffset);
|
||||
m_rotationManipulators.SetLocalPosition(colliderOffset);
|
||||
|
||||
AZ::Vector3 nonUniformScale = AZ::Vector3::CreateOne();
|
||||
AZ::NonUniformScaleRequestBus::EventResult(nonUniformScale, idPair.GetEntityId(), &AZ::NonUniformScaleRequests::GetScale);
|
||||
|
||||
m_rotationManipulators.SetLocalPosition(nonUniformScale * colliderOffset);
|
||||
}
|
||||
|
||||
void ColliderRotationMode::Teardown(const AZ::EntityComponentIdPair& idPair)
|
||||
|
||||
@@ -581,9 +581,8 @@ namespace PhysX
|
||||
|
||||
AZ::Transform EditorColliderComponent::GetColliderLocalTransform() const
|
||||
{
|
||||
const AZ::Vector3 nonUniformScale = Utils::GetTransformScale(GetEntityId());
|
||||
return AZ::Transform::CreateFromQuaternionAndTranslation(
|
||||
m_configuration.m_rotation, m_configuration.m_position * nonUniformScale);
|
||||
m_configuration.m_rotation, m_configuration.m_position);
|
||||
}
|
||||
|
||||
void EditorColliderComponent::UpdateMeshAsset()
|
||||
@@ -1053,12 +1052,22 @@ namespace PhysX
|
||||
|
||||
AZ::Transform EditorColliderComponent::GetCurrentTransform()
|
||||
{
|
||||
return GetColliderWorldTransform();
|
||||
return GetWorldTM();
|
||||
}
|
||||
|
||||
AZ::Transform EditorColliderComponent::GetCurrentLocalTransform()
|
||||
{
|
||||
return GetColliderLocalTransform();
|
||||
}
|
||||
|
||||
AZ::Vector3 EditorColliderComponent::GetBoxScale()
|
||||
{
|
||||
return AZ::Vector3(GetWorldTM().GetUniformScale());
|
||||
return AZ::Vector3::CreateOne();
|
||||
}
|
||||
|
||||
AZ::Vector3 EditorColliderComponent::GetCurrentNonUniformScale()
|
||||
{
|
||||
return m_cachedNonUniformScale;
|
||||
}
|
||||
|
||||
void EditorColliderComponent::OnTransformChanged(const AZ::Transform& /*local*/, const AZ::Transform& world)
|
||||
@@ -1202,7 +1211,7 @@ namespace PhysX
|
||||
|
||||
AZ::Transform EditorColliderComponent::GetColliderWorldTransform()
|
||||
{
|
||||
return AzToolsFramework::TransformNormalizedScale(GetWorldTM()) * GetColliderLocalTransform();
|
||||
return GetWorldTM() * GetColliderLocalTransform();
|
||||
}
|
||||
|
||||
bool EditorColliderComponent::ShouldUpdateCollisionMeshFromRender() const
|
||||
|
||||
@@ -171,7 +171,9 @@ namespace PhysX
|
||||
AZ::Vector3 GetDimensions() override;
|
||||
void SetDimensions(const AZ::Vector3& dimensions) override;
|
||||
AZ::Transform GetCurrentTransform() override;
|
||||
AZ::Transform GetCurrentLocalTransform() override;
|
||||
AZ::Vector3 GetBoxScale() override;
|
||||
AZ::Vector3 GetCurrentNonUniformScale() override;
|
||||
|
||||
// AZ::Render::MeshComponentNotificationBus
|
||||
void OnModelReady(const AZ::Data::Asset<AZ::RPI::ModelAsset>& modelAsset,
|
||||
|
||||
Reference in New Issue
Block a user