Fix a problem about rotation and scale manipulator (#7451)

* Load workspace should activate the graph by default.

Signed-off-by: rhhong <rhhong@amazon.com>

* Fixed the bug with rotation and scale manipulator

Signed-off-by: rhhong <rhhong@amazon.com>
This commit is contained in:
Roman
2022-02-07 09:50:31 -08:00
committed by GitHub
parent 2d8b4d8285
commit be242f9c71
2 changed files with 23 additions and 31 deletions
@@ -177,10 +177,19 @@ namespace EMStudio
m_rotateManipulators.ConfigureView(
AzToolsFramework::RotationManipulatorRadius(), AzFramework::ViewportColors::XAxisColor, AzFramework::ViewportColors::YAxisColor,
AzFramework::ViewportColors::ZAxisColor);
m_rotateManipulators.InstallLeftMouseDownCallback(
[this]([[maybe_unused]]const AzToolsFramework::AngularManipulator::Action& action)
{
const AZ::EntityId entityId = m_animViewportWidget->GetAnimViewportRenderer()->GetEntityId();
AZ::TransformBus::EventResult(m_mouseDownStartTransform, entityId, &AZ::TransformBus::Events::GetLocalTM);
});
m_rotateManipulators.InstallMouseMoveCallback(
[this](const AzToolsFramework::AngularManipulator::Action& action)
{
OnManipulatorRotated(action.LocalOrientation());
const AZ::EntityId entityId = m_animViewportWidget->GetAnimViewportRenderer()->GetEntityId();
AZ::TransformBus::Event(entityId, &AZ::TransformBus::Events::SetLocalRotationQuaternion,
m_mouseDownStartTransform.GetRotation() * action.m_current.m_delta);
});
// Setup the scale manipulator
@@ -189,10 +198,21 @@ namespace EMStudio
m_scaleManipulators.ConfigureView(
AzToolsFramework::LinearManipulatorAxisLength(), AzFramework::ViewportColors::XAxisColor,
AzFramework::ViewportColors::YAxisColor, AzFramework::ViewportColors::ZAxisColor);
m_scaleManipulators.InstallAxisLeftMouseDownCallback(
[this]([[maybe_unused]] const AzToolsFramework::LinearManipulator::Action& action)
{
const AZ::EntityId entityId = m_animViewportWidget->GetAnimViewportRenderer()->GetEntityId();
AZ::TransformBus::EventResult(m_mouseDownStartTransform, entityId, &AZ::TransformBus::Events::GetLocalTM);
});
m_scaleManipulators.InstallAxisMouseMoveCallback(
[this](const AzToolsFramework::LinearManipulator::Action& action)
{
OnManipulatorScaled(action.LocalScale(), action.LocalScaleOffset());
// Since we are compulting a uniform scale, the delta scale should be the none-zero value from one of the three axis.
const float deltaScale = action.m_current.m_localPositionOffset.GetMaxElement()
+ action.m_current.m_localPositionOffset.GetMinElement();
const AZ::EntityId entityId = m_animViewportWidget->GetAnimViewportRenderer()->GetEntityId();
AZ::TransformBus::Event(entityId, &AZ::TransformBus::Events::SetLocalUniformScale,
m_mouseDownStartTransform.GetUniformScale() + deltaScale);
});
}
@@ -259,33 +279,6 @@ namespace EMStudio
AZ::TransformBus::Event(entityId, &AZ::TransformBus::Events::SetLocalTranslation, position);
}
void AtomRenderPlugin::OnManipulatorRotated(const AZ::Quaternion& rotation)
{
const AZ::EntityId entityId = m_animViewportWidget->GetAnimViewportRenderer()->GetEntityId();
AZ::TransformBus::Event(entityId, &AZ::TransformBus::Events::SetLocalRotationQuaternion, rotation);
}
void AtomRenderPlugin::OnManipulatorScaled(
const AZ::Vector3& scale, const AZ::Vector3& scaleOffset)
{
// Use the scaleOffset to determine which axis to use on the uniform scale.
float localScale = 1.0f;
if (scaleOffset.GetX() != 0.0f)
{
localScale = scale.GetX();
}
else if (scaleOffset.GetY() != 0.0f)
{
localScale = scale.GetY();
}
else if (scaleOffset.GetZ() != 0.0f)
{
localScale = scale.GetZ();
}
const AZ::EntityId entityId = m_animViewportWidget->GetAnimViewportRenderer()->GetEntityId();
AZ::TransformBus::Event(entityId, &AZ::TransformBus::Events::SetLocalUniformScale, localScale);
}
void AtomRenderPlugin::LoadRenderOptions()
{
AZStd::string renderOptionsFilename(GetManager()->GetAppDataFolder());
@@ -70,8 +70,6 @@ namespace EMStudio
void SetupManipulators();
void OnManipulatorMoved(const AZ::Vector3& position);
void OnManipulatorRotated(const AZ::Quaternion& rotation);
void OnManipulatorScaled(const AZ::Vector3& scale, const AZ::Vector3& scaleOffset);
QWidget* m_innerWidget = nullptr;
AnimViewportWidget* m_animViewportWidget = nullptr;
@@ -82,6 +80,7 @@ namespace EMStudio
AzToolsFramework::RotationManipulators m_rotateManipulators;
AzToolsFramework::ScaleManipulators m_scaleManipulators;
AZStd::shared_ptr<AzToolsFramework::ManipulatorManager> m_manipulatorManager;
AZ::Transform m_mouseDownStartTransform;
MCORE_DEFINECOMMANDCALLBACK(ImportActorCallback);
MCORE_DEFINECOMMANDCALLBACK(RemoveActorCallback);