hook up non-uniform scale manipulator callbacks

This commit is contained in:
greerdv
2021-05-14 11:52:29 +01:00
parent 41ea7a1b81
commit d365d00abd
4 changed files with 73 additions and 15 deletions
@@ -42,6 +42,7 @@ namespace AzToolsFramework
~LinearManipulator() = default;
/// A Manipulator must only be created and managed through a shared_ptr.
/// @note worldFromLocal should not contain scale.
static AZStd::shared_ptr<LinearManipulator> MakeShared(const AZ::Transform& worldFromLocal);
/// Unchanging data set once for the linear manipulator.
@@ -82,14 +82,16 @@ namespace AzToolsFramework
AZ::NonUniformScaleRequestBus::Handler::BusConnect(GetEntityId());
// ComponentMode
AZ::EntityComponentIdPair entityComponentIdPair(GetEntityId(), GetId());
NonUniformScaleManipulatorRequestBus::Handler::BusConnect(entityComponentIdPair);
m_componentModeDelegate.ConnectWithSingleComponentMode<
EditorNonUniformScaleComponent, NonUniformScaleComponentMode>(
AZ::EntityComponentIdPair(GetEntityId(), GetId()), this);
EditorNonUniformScaleComponent, NonUniformScaleComponentMode>(entityComponentIdPair, this);
}
void EditorNonUniformScaleComponent::Deactivate()
{
m_componentModeDelegate.Disconnect();
NonUniformScaleManipulatorRequestBus::Handler::BusDisconnect();
AZ::NonUniformScaleRequestBus::Handler::BusDisconnect();
}
@@ -1,29 +1,73 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#include <AzCore/Component/TransformBus.h>
#include <AzFramework/Viewport/ViewportColors.h>
#include <AzToolsFramework/Manipulators/ManipulatorManager.h>
#include <AzToolsFramework/ToolsComponents/EditorNonUniformScaleComponentMode.h>
namespace AzToolsFramework
{
namespace Components
{
NonUniformScaleComponentMode::NonUniformScaleComponentMode(const AZ::EntityComponentIdPair& entityComponentIdPair,
AZ::Uuid componentType)
NonUniformScaleComponentMode::NonUniformScaleComponentMode(
const AZ::EntityComponentIdPair& entityComponentIdPair, AZ::Uuid componentType)
: EditorBaseComponentMode(entityComponentIdPair, componentType)
{
m_entityComponentIdPair = entityComponentIdPair;
AZ::Transform worldFromLocal = AZ::Transform::CreateIdentity();
AZ::TransformBus::EventResult(worldFromLocal, m_entityComponentIdPair.GetEntityId(), &AZ::TransformBus::Events::GetWorldTM);
worldFromLocal.ExtractScale();
m_manipulators = AZStd::make_unique<ScaleManipulators>(worldFromLocal);
m_manipulators->Register(g_mainManipulatorManagerId);
m_manipulators->SetAxes(AZ::Vector3::CreateAxisX(), AZ::Vector3::CreateAxisY(), AZ::Vector3::CreateAxisZ());
m_manipulators->ConfigureView(
2.0f, AzFramework::ViewportColors::XAxisColor, AzFramework::ViewportColors::YAxisColor,
AzFramework::ViewportColors::ZAxisColor);
m_manipulators->InstallAxisLeftMouseDownCallback([this](const LinearManipulator::Action& action) {
AZ::Vector3 nonUniformScale = AZ::Vector3::CreateOne();
NonUniformScaleManipulatorRequestBus::EventResult(
nonUniformScale, m_entityComponentIdPair, &NonUniformScaleManipulatorRequests::GetScale);
m_initialScale = nonUniformScale + action.m_start.m_scaleSnapOffset;
NonUniformScaleManipulatorRequestBus::Event(
m_entityComponentIdPair, &NonUniformScaleManipulatorRequests::SetScale, m_initialScale);
});
m_manipulators->InstallAxisMouseMoveCallback([this](const LinearManipulator::Action& action) {
const AZ::Vector3 scale =
(AZ::Vector3::CreateOne() + ((action.LocalScaleOffset() * action.m_start.m_sign) / m_initialScale))
.GetMax(AZ::Vector3(AZ::MinTransformScale));
NonUniformScaleManipulatorRequestBus::Event(
m_entityComponentIdPair, &NonUniformScaleManipulatorRequests::SetScale, scale * m_initialScale);
});
}
NonUniformScaleComponentMode::~NonUniformScaleComponentMode()
{
if (m_manipulators)
{
m_manipulators->Unregister();
}
m_manipulators.reset();
}
void NonUniformScaleComponentMode::Refresh()
@@ -13,6 +13,7 @@
#pragma once
#include <AzToolsFramework/ComponentMode/EditorBaseComponentMode.h>
#include <AzToolsFramework/Manipulators/ScaleManipulators.h>
namespace AzToolsFramework
{
@@ -24,12 +25,17 @@ namespace AzToolsFramework
: public AZ::EntityComponentBus
{
public:
//! Gets the non-uniform scale.
virtual AZ::Vector3 GetScale() const = 0;
//! Sets the non-uniform scale.
virtual void SetScale(const AZ::Vector3& scale) = 0;
protected:
~NonUniformScaleManipulatorRequests() = default;
};
//! Type to inherit to implement NonUniformScaleManipulatorRequests
//! Type to inherit to implement NonUniformScaleManipulatorRequests.
using NonUniformScaleManipulatorRequestBus = AZ::EBus<NonUniformScaleManipulatorRequests>;
class NonUniformScaleComponentMode
@@ -47,6 +53,11 @@ namespace AzToolsFramework
// EditorBaseComponentMode
void Refresh() override;
private:
AZ::EntityComponentIdPair m_entityComponentIdPair;
AZStd::unique_ptr<ScaleManipulators> m_manipulators;
AZ::Vector3 m_initialScale;
};
} // namespace Components
} // namespace AzToolsFramework