update transform widget to work with uniform scale
This commit is contained in:
@@ -13,6 +13,7 @@
|
|||||||
#include <AzCore/EBus/EBus.h>
|
#include <AzCore/EBus/EBus.h>
|
||||||
#include <AzToolsFramework/Debug/TraceContext.h>
|
#include <AzToolsFramework/Debug/TraceContext.h>
|
||||||
#include <AzToolsFramework/UI/PropertyEditor/PropertyVectorCtrl.hxx>
|
#include <AzToolsFramework/UI/PropertyEditor/PropertyVectorCtrl.hxx>
|
||||||
|
#include <AzToolsFramework/UI/PropertyEditor/PropertyDoubleSpinCtrl.hxx>
|
||||||
#include <SceneAPI/SceneUI/RowWidgets/TransformRowHandler.h>
|
#include <SceneAPI/SceneUI/RowWidgets/TransformRowHandler.h>
|
||||||
|
|
||||||
namespace AZ
|
namespace AZ
|
||||||
@@ -58,10 +59,11 @@ namespace AZ
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
AzToolsFramework::Vector3PropertyHandler handler;
|
AzToolsFramework::Vector3PropertyHandler vector3Handler;
|
||||||
handler.ConsumeAttribute(widget->GetTranslationWidget(), attrib, attrValue, debugName);
|
vector3Handler.ConsumeAttribute(widget->GetTranslationWidget(), attrib, attrValue, debugName);
|
||||||
handler.ConsumeAttribute(widget->GetRotationWidget(), attrib, attrValue, debugName);
|
vector3Handler.ConsumeAttribute(widget->GetRotationWidget(), attrib, attrValue, debugName);
|
||||||
handler.ConsumeAttribute(widget->GetScaleWidget(), attrib, attrValue, debugName);
|
AzToolsFramework::doublePropertySpinboxHandler spinboxHandler;
|
||||||
|
spinboxHandler.ConsumeAttribute(widget->GetScaleWidget(), attrib, attrValue, debugName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
#include <QGridLayout>
|
#include <QGridLayout>
|
||||||
#include <SceneAPI/SceneUI/RowWidgets/TransformRowWidget.h>
|
#include <SceneAPI/SceneUI/RowWidgets/TransformRowWidget.h>
|
||||||
#include <AzQtComponents/Components/Widgets/VectorInput.h>
|
#include <AzQtComponents/Components/Widgets/VectorInput.h>
|
||||||
|
#include <AzToolsFramework/UI/PropertyEditor/PropertyDoubleSpinCtrl.hxx>
|
||||||
#include <AzToolsFramework/UI/PropertyEditor/PropertyEditorAPI.h>
|
#include <AzToolsFramework/UI/PropertyEditor/PropertyEditorAPI.h>
|
||||||
#include <AzToolsFramework/UI/PropertyEditor/PropertyRowWidget.hxx>
|
#include <AzToolsFramework/UI/PropertyEditor/PropertyRowWidget.hxx>
|
||||||
|
|
||||||
@@ -47,7 +48,7 @@ namespace AZ
|
|||||||
ExpandedTransform::ExpandedTransform()
|
ExpandedTransform::ExpandedTransform()
|
||||||
: m_translation(0, 0, 0)
|
: m_translation(0, 0, 0)
|
||||||
, m_rotation(0, 0, 0)
|
, m_rotation(0, 0, 0)
|
||||||
, m_scale(1, 1, 1)
|
, m_scale(1)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,14 +61,14 @@ namespace AZ
|
|||||||
{
|
{
|
||||||
m_translation = transform.GetTranslation();
|
m_translation = transform.GetTranslation();
|
||||||
m_rotation = transform.GetEulerDegrees();
|
m_rotation = transform.GetEulerDegrees();
|
||||||
m_scale = transform.GetScale();
|
m_scale = transform.GetUniformScale();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExpandedTransform::GetTransform(AZ::Transform& transform) const
|
void ExpandedTransform::GetTransform(AZ::Transform& transform) const
|
||||||
{
|
{
|
||||||
transform = Transform::CreateTranslation(m_translation);
|
transform = Transform::CreateTranslation(m_translation);
|
||||||
transform *= AZ::ConvertEulerDegreesToTransform(m_rotation);
|
transform *= AZ::ConvertEulerDegreesToTransform(m_rotation);
|
||||||
transform.MultiplyByScale(m_scale);
|
transform.MultiplyByUniformScale(m_scale);
|
||||||
}
|
}
|
||||||
|
|
||||||
const AZ::Vector3& ExpandedTransform::GetTranslation() const
|
const AZ::Vector3& ExpandedTransform::GetTranslation() const
|
||||||
@@ -90,12 +91,12 @@ namespace AZ
|
|||||||
m_rotation = rotation;
|
m_rotation = rotation;
|
||||||
}
|
}
|
||||||
|
|
||||||
const AZ::Vector3& ExpandedTransform::GetScale() const
|
const float ExpandedTransform::GetScale() const
|
||||||
{
|
{
|
||||||
return m_scale;
|
return m_scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExpandedTransform::SetScale(const AZ::Vector3& scale)
|
void ExpandedTransform::SetScale(const float scale)
|
||||||
{
|
{
|
||||||
m_scale = scale;
|
m_scale = scale;
|
||||||
}
|
}
|
||||||
@@ -131,7 +132,7 @@ namespace AZ
|
|||||||
m_rotationWidget->setMaximum(360);
|
m_rotationWidget->setMaximum(360);
|
||||||
m_rotationWidget->setSuffix(" degrees");
|
m_rotationWidget->setSuffix(" degrees");
|
||||||
|
|
||||||
m_scaleWidget = new AzQtComponents::VectorInput(this, 3);
|
m_scaleWidget = new AzToolsFramework::PropertyDoubleSpinCtrl(this);
|
||||||
m_scaleWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
m_scaleWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
||||||
m_scaleWidget->setMinimum(0);
|
m_scaleWidget->setMinimum(0);
|
||||||
m_scaleWidget->setMaximum(10000);
|
m_scaleWidget->setMaximum(10000);
|
||||||
@@ -191,13 +192,10 @@ namespace AZ
|
|||||||
AzToolsFramework::PropertyEditorGUIMessages::Bus::Broadcast(&AzToolsFramework::PropertyEditorGUIMessages::RequestWrite, this);
|
AzToolsFramework::PropertyEditorGUIMessages::Bus::Broadcast(&AzToolsFramework::PropertyEditorGUIMessages::RequestWrite, this);
|
||||||
});
|
});
|
||||||
|
|
||||||
QObject::connect(m_scaleWidget, &AzQtComponents::VectorInput::valueChanged, this, [this]
|
QObject::connect(m_scaleWidget, &AzToolsFramework::PropertyDoubleSpinCtrl::valueChanged, this, [this]
|
||||||
{
|
{
|
||||||
AzQtComponents::VectorInput* widget = this->GetScaleWidget();
|
AzToolsFramework::PropertyDoubleSpinCtrl* widget = this->GetScaleWidget();
|
||||||
AZ::Vector3 scale;
|
float scale = aznumeric_cast<float>(widget->value());
|
||||||
|
|
||||||
PopulateVector3(widget, scale);
|
|
||||||
|
|
||||||
m_transform.SetScale(scale);
|
m_transform.SetScale(scale);
|
||||||
AzToolsFramework::PropertyEditorGUIMessages::Bus::Broadcast(&AzToolsFramework::PropertyEditorGUIMessages::RequestWrite, this);
|
AzToolsFramework::PropertyEditorGUIMessages::Bus::Broadcast(&AzToolsFramework::PropertyEditorGUIMessages::RequestWrite, this);
|
||||||
});
|
});
|
||||||
@@ -224,9 +222,7 @@ namespace AZ
|
|||||||
m_rotationWidget->setValuebyIndex(m_transform.GetRotation().GetY(), 1);
|
m_rotationWidget->setValuebyIndex(m_transform.GetRotation().GetY(), 1);
|
||||||
m_rotationWidget->setValuebyIndex(m_transform.GetRotation().GetZ(), 2);
|
m_rotationWidget->setValuebyIndex(m_transform.GetRotation().GetZ(), 2);
|
||||||
|
|
||||||
m_scaleWidget->setValuebyIndex(m_transform.GetScale().GetX(), 0);
|
m_scaleWidget->setValue(m_transform.GetScale());
|
||||||
m_scaleWidget->setValuebyIndex(m_transform.GetScale().GetY(), 1);
|
|
||||||
m_scaleWidget->setValuebyIndex(m_transform.GetScale().GetZ(), 2);
|
|
||||||
|
|
||||||
blockSignals(false);
|
blockSignals(false);
|
||||||
}
|
}
|
||||||
@@ -251,7 +247,7 @@ namespace AZ
|
|||||||
return m_rotationWidget;
|
return m_rotationWidget;
|
||||||
}
|
}
|
||||||
|
|
||||||
AzQtComponents::VectorInput* TransformRowWidget::GetScaleWidget()
|
AzToolsFramework::PropertyDoubleSpinCtrl* TransformRowWidget::GetScaleWidget()
|
||||||
{
|
{
|
||||||
return m_scaleWidget;
|
return m_scaleWidget;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
#include <AzCore/Math/Uuid.h>
|
#include <AzCore/Math/Uuid.h>
|
||||||
#include <AzCore/Memory/SystemAllocator.h>
|
#include <AzCore/Memory/SystemAllocator.h>
|
||||||
#include <SceneAPI/SceneUI/SceneUIConfiguration.h>
|
#include <SceneAPI/SceneUI/SceneUIConfiguration.h>
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace AzQtComponents
|
namespace AzQtComponents
|
||||||
@@ -28,6 +29,11 @@ namespace AzQtComponents
|
|||||||
class VectorInput;
|
class VectorInput;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace AzToolsFramework
|
||||||
|
{
|
||||||
|
class PropertyDoubleSpinCtrl;
|
||||||
|
}
|
||||||
|
|
||||||
namespace AZ
|
namespace AZ
|
||||||
{
|
{
|
||||||
namespace SceneAPI
|
namespace SceneAPI
|
||||||
@@ -51,14 +57,14 @@ namespace AZ
|
|||||||
const AZ::Vector3& GetRotation() const;
|
const AZ::Vector3& GetRotation() const;
|
||||||
void SetRotation(const AZ::Vector3& translation);
|
void SetRotation(const AZ::Vector3& translation);
|
||||||
|
|
||||||
const AZ::Vector3& GetScale() const;
|
const float GetScale() const;
|
||||||
void SetScale(const AZ::Vector3& scale);
|
void SetScale(const float scale);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
AZ_PUSH_DISABLE_DLL_EXPORT_MEMBER_WARNING
|
AZ_PUSH_DISABLE_DLL_EXPORT_MEMBER_WARNING
|
||||||
AZ::Vector3 m_translation;
|
AZ::Vector3 m_translation;
|
||||||
AZ::Vector3 m_rotation;
|
AZ::Vector3 m_rotation;
|
||||||
AZ::Vector3 m_scale;
|
float m_scale;
|
||||||
AZ_POP_DISABLE_DLL_EXPORT_MEMBER_WARNING
|
AZ_POP_DISABLE_DLL_EXPORT_MEMBER_WARNING
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -78,7 +84,7 @@ namespace AZ
|
|||||||
|
|
||||||
AzQtComponents::VectorInput* GetTranslationWidget();
|
AzQtComponents::VectorInput* GetTranslationWidget();
|
||||||
AzQtComponents::VectorInput* GetRotationWidget();
|
AzQtComponents::VectorInput* GetRotationWidget();
|
||||||
AzQtComponents::VectorInput* GetScaleWidget();
|
AzToolsFramework::PropertyDoubleSpinCtrl* GetScaleWidget();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
ExpandedTransform m_transform;
|
ExpandedTransform m_transform;
|
||||||
@@ -87,7 +93,7 @@ namespace AZ
|
|||||||
|
|
||||||
AzQtComponents::VectorInput* m_translationWidget;
|
AzQtComponents::VectorInput* m_translationWidget;
|
||||||
AzQtComponents::VectorInput* m_rotationWidget;
|
AzQtComponents::VectorInput* m_rotationWidget;
|
||||||
AzQtComponents::VectorInput* m_scaleWidget;
|
AzToolsFramework::PropertyDoubleSpinCtrl* m_scaleWidget;
|
||||||
};
|
};
|
||||||
} // namespace SceneUI
|
} // namespace SceneUI
|
||||||
} // namespace SceneAPI
|
} // namespace SceneAPI
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ namespace AZ
|
|||||||
|
|
||||||
Vector3 m_translation = Vector3(10.0f, 20.0f, 30.0f);
|
Vector3 m_translation = Vector3(10.0f, 20.0f, 30.0f);
|
||||||
Vector3 m_rotation = Vector3(30.0f, 45.0f, 60.0f);
|
Vector3 m_rotation = Vector3(30.0f, 45.0f, 60.0f);
|
||||||
Vector3 m_scale = Vector3(2.0f, 3.0f, 4.0f);
|
float m_scale = 3.0f;
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_F(TransformRowWidgetTest, GetTranslation_TranslationInMatrix_TranslationCanBeRetrievedDirectly)
|
TEST_F(TransformRowWidgetTest, GetTranslation_TranslationInMatrix_TranslationCanBeRetrievedDirectly)
|
||||||
@@ -83,26 +83,22 @@ namespace AZ
|
|||||||
|
|
||||||
TEST_F(TransformRowWidgetTest, GetScale_ScaleInMatrix_ScaleCanBeRetrievedDirectly)
|
TEST_F(TransformRowWidgetTest, GetScale_ScaleInMatrix_ScaleCanBeRetrievedDirectly)
|
||||||
{
|
{
|
||||||
m_transform = Transform::CreateScale(m_scale);
|
m_transform = Transform::CreateUniformScale(m_scale);
|
||||||
m_expanded.SetTransform(m_transform);
|
m_expanded.SetTransform(m_transform);
|
||||||
|
|
||||||
const Vector3& returned = m_expanded.GetScale();
|
const float returned = m_expanded.GetScale();
|
||||||
EXPECT_NEAR(m_scale.GetX(), returned.GetX(), 0.1f);
|
EXPECT_NEAR(m_scale, returned, 0.1f);
|
||||||
EXPECT_NEAR(m_scale.GetY(), returned.GetY(), 0.1f);
|
|
||||||
EXPECT_NEAR(m_scale.GetZ(), returned.GetZ(), 0.1f);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TransformRowWidgetTest, GetScale_ScaleInMatrix_ScaleCanBeRetrievedFromTransform)
|
TEST_F(TransformRowWidgetTest, GetScale_ScaleInMatrix_ScaleCanBeRetrievedFromTransform)
|
||||||
{
|
{
|
||||||
m_transform = Transform::CreateScale(m_scale);
|
m_transform = Transform::CreateUniformScale(m_scale);
|
||||||
m_expanded.SetTransform(m_transform);
|
m_expanded.SetTransform(m_transform);
|
||||||
|
|
||||||
Transform rebuild;
|
Transform rebuild;
|
||||||
m_expanded.GetTransform(rebuild);
|
m_expanded.GetTransform(rebuild);
|
||||||
Vector3 returned = rebuild.GetScale();
|
float returned = rebuild.GetUniformScale();
|
||||||
EXPECT_NEAR(m_scale.GetX(), returned.GetX(), 0.1f);
|
EXPECT_NEAR(m_scale, returned, 0.1f);
|
||||||
EXPECT_NEAR(m_scale.GetY(), returned.GetY(), 0.1f);
|
|
||||||
EXPECT_NEAR(m_scale.GetZ(), returned.GetZ(), 0.1f);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TransformRowWidgetTest, GetTransform_RotateAndTranslateInMatrix_ReconstructedTransformMatchesOriginal)
|
TEST_F(TransformRowWidgetTest, GetTransform_RotateAndTranslateInMatrix_ReconstructedTransformMatchesOriginal)
|
||||||
@@ -121,7 +117,7 @@ namespace AZ
|
|||||||
{
|
{
|
||||||
Quaternion quaternion = AZ::ConvertEulerDegreesToQuaternion(m_rotation);
|
Quaternion quaternion = AZ::ConvertEulerDegreesToQuaternion(m_rotation);
|
||||||
m_transform = Transform::CreateFromQuaternionAndTranslation(quaternion, m_translation);
|
m_transform = Transform::CreateFromQuaternionAndTranslation(quaternion, m_translation);
|
||||||
m_transform.MultiplyByScale(m_scale);
|
m_transform.MultiplyByUniformScale(m_scale);
|
||||||
m_expanded.SetTransform(m_transform);
|
m_expanded.SetTransform(m_transform);
|
||||||
|
|
||||||
Transform rebuild;
|
Transform rebuild;
|
||||||
|
|||||||
Reference in New Issue
Block a user