update editor transform component to uniform scale

This commit is contained in:
greerdv
2021-05-28 16:25:58 +01:00
parent 4442ca5485
commit 8d0051bae9
2 changed files with 20 additions and 20 deletions
@@ -49,10 +49,10 @@ namespace AzToolsFramework
{ {
const AZ::u32 ParentEntityCRC = AZ_CRC("Parent Entity", 0x5b1b276c); const AZ::u32 ParentEntityCRC = AZ_CRC("Parent Entity", 0x5b1b276c);
// Decompose a transform into euler angles in degrees, scale (along basis, any shear will be dropped), and translation. // Decompose a transform into euler angles in degrees, uniform scale, and translation.
void DecomposeTransform(const AZ::Transform& transform, AZ::Vector3& translation, AZ::Vector3& rotation, AZ::Vector3& scale) void DecomposeTransform(const AZ::Transform& transform, AZ::Vector3& translation, AZ::Vector3& rotation, float& scale)
{ {
scale = transform.GetScale(); scale = transform.GetUniformScale();
translation = transform.GetTranslation(); translation = transform.GetTranslation();
rotation = transform.GetRotation().GetEulerDegrees(); rotation = transform.GetRotation().GetEulerDegrees();
} }
@@ -119,7 +119,7 @@ namespace AzToolsFramework
// Decompose the old slice-relative transform and set it as a our editor transform, // Decompose the old slice-relative transform and set it as a our editor transform,
// since the entity is now our parent. // since the entity is now our parent.
EditorTransform editorTransform; EditorTransform editorTransform;
DecomposeTransform(sliceRelTransform, editorTransform.m_translate, editorTransform.m_rotate, editorTransform.m_scale); DecomposeTransform(sliceRelTransform, editorTransform.m_translate, editorTransform.m_rotate, editorTransform.m_uniformScale);
editorTransformElement.Convert<EditorTransform>(context); editorTransformElement.Convert<EditorTransform>(context);
editorTransformElement.SetData(context, editorTransform); editorTransformElement.SetData(context, editorTransform);
} }
@@ -373,7 +373,7 @@ namespace AzToolsFramework
AZ::Transform TransformComponent::GetLocalScaleTM() const AZ::Transform TransformComponent::GetLocalScaleTM() const
{ {
return AZ::Transform::CreateUniformScale(m_editorTransform.m_scale.GetMaxElement()); return AZ::Transform::CreateUniformScale(m_editorTransform.m_uniformScale);
} }
const AZ::Transform& TransformComponent::GetLocalTM() const AZ::Transform& TransformComponent::GetLocalTM()
@@ -390,12 +390,13 @@ namespace AzToolsFramework
// given a local transform, update local transform. // given a local transform, update local transform.
void TransformComponent::SetLocalTM(const AZ::Transform& finalTx) void TransformComponent::SetLocalTM(const AZ::Transform& finalTx)
{ {
AZ::Vector3 tx, rot, scale; AZ::Vector3 tx, rot;
Internal::DecomposeTransform(finalTx, tx, rot, scale); float uniformScale;
Internal::DecomposeTransform(finalTx, tx, rot, uniformScale);
m_editorTransform.m_translate = tx; m_editorTransform.m_translate = tx;
m_editorTransform.m_rotate = rot; m_editorTransform.m_rotate = rot;
m_editorTransform.m_scale = scale; m_editorTransform.m_uniformScale = uniformScale;
TransformChanged(); TransformChanged();
} }
@@ -618,18 +619,18 @@ namespace AzToolsFramework
AZ::Vector3 TransformComponent::GetLocalScale() AZ::Vector3 TransformComponent::GetLocalScale()
{ {
AZ_WarningOnce("TransformComponent", false, "GetLocalScale is deprecated, please use GetLocalUniformScale instead"); AZ_WarningOnce("TransformComponent", false, "GetLocalScale is deprecated, please use GetLocalUniformScale instead");
return m_editorTransform.m_scale; return m_editorTransform.m_legacyScale;
} }
void TransformComponent::SetLocalUniformScale(float scale) void TransformComponent::SetLocalUniformScale(float scale)
{ {
m_editorTransform.m_scale = AZ::Vector3(scale); m_editorTransform.m_uniformScale = scale;
TransformChanged(); TransformChanged();
} }
float TransformComponent::GetLocalUniformScale() float TransformComponent::GetLocalUniformScale()
{ {
return m_editorTransform.m_scale.GetMaxElement(); return m_editorTransform.m_uniformScale;
} }
float TransformComponent::GetWorldUniformScale() float TransformComponent::GetWorldUniformScale()
@@ -1139,8 +1140,6 @@ namespace AzToolsFramework
return AZ::Edit::PropertyRefreshLevels::EntireTree; return AZ::Edit::PropertyRefreshLevels::EntireTree;
} }
void TransformComponent::Reflect(AZ::ReflectContext* context) void TransformComponent::Reflect(AZ::ReflectContext* context)
{ {
// reflect data for script, serialization, editing.. // reflect data for script, serialization, editing..
@@ -1149,7 +1148,7 @@ namespace AzToolsFramework
serializeContext->Class<EditorTransform>()-> serializeContext->Class<EditorTransform>()->
Field("Translate", &EditorTransform::m_translate)-> Field("Translate", &EditorTransform::m_translate)->
Field("Rotate", &EditorTransform::m_rotate)-> Field("Rotate", &EditorTransform::m_rotate)->
Field("Scale", &EditorTransform::m_scale)-> Field("Scale", &EditorTransform::m_legacyScale)->
Field("Locked", &EditorTransform::m_locked)-> Field("Locked", &EditorTransform::m_locked)->
Field("UniformScale", &EditorTransform::m_uniformScale)-> Field("UniformScale", &EditorTransform::m_uniformScale)->
Version(3, &Internal::EditorTransformDataConverter); Version(3, &Internal::EditorTransformDataConverter);
@@ -1239,7 +1238,8 @@ namespace AzToolsFramework
{ {
AzToolsFramework::ScopedUndoBatch undo("Reset transform values"); AzToolsFramework::ScopedUndoBatch undo("Reset transform values");
m_editorTransform.m_translate = AZ::Vector3::CreateZero(); m_editorTransform.m_translate = AZ::Vector3::CreateZero();
m_editorTransform.m_scale = AZ::Vector3::CreateOne(); m_editorTransform.m_legacyScale = AZ::Vector3::CreateOne();
m_editorTransform.m_uniformScale = 1.0f;
m_editorTransform.m_rotate = AZ::Vector3::CreateZero(); m_editorTransform.m_rotate = AZ::Vector3::CreateZero();
OnTransformChanged(); OnTransformChanged();
SetDirty(); SetDirty();
@@ -30,7 +30,7 @@ namespace AzToolsFramework
EditorTransform() EditorTransform()
{ {
m_translate = AZ::Vector3::CreateZero(); m_translate = AZ::Vector3::CreateZero();
m_scale = AZ::Vector3::CreateOne(); m_legacyScale = AZ::Vector3::CreateOne();
m_rotate = AZ::Vector3::CreateZero(); m_rotate = AZ::Vector3::CreateZero();
m_locked = false; m_locked = false;
} }
@@ -40,10 +40,10 @@ namespace AzToolsFramework
return EditorTransform(); return EditorTransform();
} }
AZ::Vector3 m_translate; //! Translation in engine units (meters) AZ::Vector3 m_translate; //!< Translation in engine units (meters)
AZ::Vector3 m_scale; AZ::Vector3 m_legacyScale; //!< Legacy vector scale value, retained only for migration.
float m_uniformScale; float m_uniformScale; //!< Single scale value applied uniformly.
AZ::Vector3 m_rotate; //! Rotation in degrees AZ::Vector3 m_rotate; //!< Rotation in degrees
bool m_locked; bool m_locked;
}; };