From 41ea7a1b8112e2138131063b14087f19ba364ecc Mon Sep 17 00:00:00 2001 From: greerdv Date: Thu, 13 May 2021 20:52:29 +0100 Subject: [PATCH 1/8] add stubs for non-uniform scale component mode --- .../EditorNonUniformScaleComponent.cpp | 13 +++++ .../EditorNonUniformScaleComponent.h | 21 ++++++++ .../EditorNonUniformScaleComponentMode.cpp | 33 ++++++++++++ .../EditorNonUniformScaleComponentMode.h | 52 +++++++++++++++++++ .../aztoolsframework_files.cmake | 2 + 5 files changed, 121 insertions(+) create mode 100644 Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/EditorNonUniformScaleComponentMode.cpp create mode 100644 Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/EditorNonUniformScaleComponentMode.h diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/EditorNonUniformScaleComponent.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/EditorNonUniformScaleComponent.cpp index a61f042049..0ff91f24f4 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/EditorNonUniformScaleComponent.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/EditorNonUniformScaleComponent.cpp @@ -16,6 +16,8 @@ #include #include +#include + namespace AzToolsFramework { namespace Components @@ -32,6 +34,7 @@ namespace AzToolsFramework serializeContext->Class() ->Version(1) ->Field("NonUniformScale", &EditorNonUniformScaleComponent::m_scale) + ->Field("ComponentMode", &EditorNonUniformScaleComponent::m_componentModeDelegate) ; if (AZ::EditContext* editContext = serializeContext->GetEditContext()) @@ -50,6 +53,9 @@ namespace AzToolsFramework ->Attribute(AZ::Edit::Attributes::Max, AZ::MaxTransformScale) ->Attribute(AZ::Edit::Attributes::Step, 0.1f) ->Attribute(AZ::Edit::Attributes::ChangeNotify, &EditorNonUniformScaleComponent::OnScaleChanged) + ->DataElement(AZ::Edit::UIHandlers::Default, &EditorNonUniformScaleComponent::m_componentModeDelegate, + "Component Mode", "Non-uniform Scale Component Mode") + ->Attribute(AZ::Edit::Attributes::Visibility, AZ::Edit::PropertyVisibility::ShowChildrenOnly) ; } } @@ -74,10 +80,17 @@ namespace AzToolsFramework void EditorNonUniformScaleComponent::Activate() { AZ::NonUniformScaleRequestBus::Handler::BusConnect(GetEntityId()); + + // ComponentMode + m_componentModeDelegate.ConnectWithSingleComponentMode< + EditorNonUniformScaleComponent, NonUniformScaleComponentMode>( + AZ::EntityComponentIdPair(GetEntityId(), GetId()), this); } void EditorNonUniformScaleComponent::Deactivate() { + m_componentModeDelegate.Disconnect(); + AZ::NonUniformScaleRequestBus::Handler::BusDisconnect(); } diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/EditorNonUniformScaleComponent.h b/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/EditorNonUniformScaleComponent.h index ea67ab3962..d7ce953b22 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/EditorNonUniformScaleComponent.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/EditorNonUniformScaleComponent.h @@ -13,6 +13,9 @@ #pragma once #include +#include +#include +#include #include namespace AzToolsFramework @@ -23,6 +26,9 @@ namespace AzToolsFramework class EditorNonUniformScaleComponent : public AzToolsFramework::Components::EditorComponentBase , public AZ::NonUniformScaleRequestBus::Handler + , public AzToolsFramework::EditorComponentSelectionRequestsBus::Handler + , public AzToolsFramework::EditorComponentSelectionNotificationsBus::Handler + , private NonUniformScaleManipulatorRequestBus::Handler { public: AZ_EDITOR_COMPONENT(EditorNonUniformScaleComponent, "{2933FB4F-B3DA-4CD1-8106-F37300730777}", EditorComponentBase); @@ -40,6 +46,18 @@ namespace AzToolsFramework void SetScale(const AZ::Vector3& scale) override; void RegisterScaleChangedEvent(AZ::NonUniformScaleChangedEvent::Handler& handler); + protected: + // EditorComponentSelectionRequestsBus overrides ... + AZ::Aabb GetEditorSelectionBoundsViewport( + [[maybe_unused]] const AzFramework::ViewportInfo& viewportInfo) override { return AZ::Aabb::CreateNull(); }; + bool EditorSelectionIntersectRayViewport( + [[maybe_unused]] const AzFramework::ViewportInfo& viewportInfo, + [[maybe_unused]] const AZ::Vector3& src, [[maybe_unused]] const AZ::Vector3& dir, [[maybe_unused]] float& distance) override { return false; }; + bool SupportsEditorRayIntersect() override { return true; } + + // EditorComponentSelectionNotificationsBus overrides ... + void OnAccentTypeChanged([[maybe_unused]] AzToolsFramework::EntityAccentType accent) override {}; + private: static void GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent); static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible); @@ -52,6 +70,9 @@ namespace AzToolsFramework AZ::Vector3 m_scale = AZ::Vector3::CreateOne(); AZ::NonUniformScaleChangedEvent m_scaleChangedEvent; + + //! Responsible for detecting ComponentMode activation and creating a concrete ComponentMode. + AzToolsFramework::ComponentModeFramework::ComponentModeDelegate m_componentModeDelegate; }; } // namespace Components } // namespace AzToolsFramework diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/EditorNonUniformScaleComponentMode.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/EditorNonUniformScaleComponentMode.cpp new file mode 100644 index 0000000000..4be0e834dd --- /dev/null +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/EditorNonUniformScaleComponentMode.cpp @@ -0,0 +1,33 @@ +/* +* 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 + +namespace AzToolsFramework +{ + namespace Components + { + NonUniformScaleComponentMode::NonUniformScaleComponentMode(const AZ::EntityComponentIdPair& entityComponentIdPair, + AZ::Uuid componentType) + : EditorBaseComponentMode(entityComponentIdPair, componentType) + { + } + + NonUniformScaleComponentMode::~NonUniformScaleComponentMode() + { + } + + void NonUniformScaleComponentMode::Refresh() + { + } + } // namespace Components +} // namespace AzToolsFramework diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/EditorNonUniformScaleComponentMode.h b/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/EditorNonUniformScaleComponentMode.h new file mode 100644 index 0000000000..d4cd0125db --- /dev/null +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/EditorNonUniformScaleComponentMode.h @@ -0,0 +1,52 @@ +/* +* 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. +* +*/ + +#pragma once + +#include + +namespace AzToolsFramework +{ + namespace Components + { + //! Interface for handling non-uniform scale manipulator requests. + //! Used by NonUniformScaleComponentMode. + class NonUniformScaleManipulatorRequests + : public AZ::EntityComponentBus + { + public: + + protected: + ~NonUniformScaleManipulatorRequests() = default; + }; + + //! Type to inherit to implement NonUniformScaleManipulatorRequests + using NonUniformScaleManipulatorRequestBus = AZ::EBus; + + class NonUniformScaleComponentMode + : public AzToolsFramework::ComponentModeFramework::EditorBaseComponentMode + { + public: + AZ_CLASS_ALLOCATOR(NonUniformScaleComponentMode, AZ::SystemAllocator, 0) + + NonUniformScaleComponentMode(const AZ::EntityComponentIdPair& entityComponentIdPair, AZ::Uuid componentType); + NonUniformScaleComponentMode(const NonUniformScaleComponentMode&) = delete; + NonUniformScaleComponentMode& operator=(const NonUniformScaleComponentMode&) = delete; + NonUniformScaleComponentMode(NonUniformScaleComponentMode&&) = delete; + NonUniformScaleComponentMode& operator=(NonUniformScaleComponentMode&&) = delete; + ~NonUniformScaleComponentMode(); + + // EditorBaseComponentMode + void Refresh() override; + }; + } // namespace Components +} // namespace AzToolsFramework diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/aztoolsframework_files.cmake b/Code/Framework/AzToolsFramework/AzToolsFramework/aztoolsframework_files.cmake index 06f78ecdd3..45f52704bf 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/aztoolsframework_files.cmake +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/aztoolsframework_files.cmake @@ -303,6 +303,8 @@ set(FILES ToolsComponents/AzToolsFrameworkConfigurationSystemComponent.cpp ToolsComponents/EditorNonUniformScaleComponent.h ToolsComponents/EditorNonUniformScaleComponent.cpp + ToolsComponents/EditorNonUniformScaleComponentMode.h + ToolsComponents/EditorNonUniformScaleComponentMode.cpp ToolsMessaging/EntityHighlightBus.h UI/Docking/DockWidgetUtils.cpp UI/Docking/DockWidgetUtils.h From d365d00abd8555490ae6278876b016c439f3c7cf Mon Sep 17 00:00:00 2001 From: greerdv Date: Fri, 14 May 2021 11:52:29 +0100 Subject: [PATCH 2/8] hook up non-uniform scale manipulator callbacks --- .../Manipulators/LinearManipulator.h | 1 + .../EditorNonUniformScaleComponent.cpp | 6 +- .../EditorNonUniformScaleComponentMode.cpp | 68 +++++++++++++++---- .../EditorNonUniformScaleComponentMode.h | 13 +++- 4 files changed, 73 insertions(+), 15 deletions(-) diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Manipulators/LinearManipulator.h b/Code/Framework/AzToolsFramework/AzToolsFramework/Manipulators/LinearManipulator.h index 9de9f0dee3..576c543dce 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Manipulators/LinearManipulator.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Manipulators/LinearManipulator.h @@ -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 MakeShared(const AZ::Transform& worldFromLocal); /// Unchanging data set once for the linear manipulator. diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/EditorNonUniformScaleComponent.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/EditorNonUniformScaleComponent.cpp index 0ff91f24f4..276fe0b3ab 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/EditorNonUniformScaleComponent.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/EditorNonUniformScaleComponent.cpp @@ -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(); } diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/EditorNonUniformScaleComponentMode.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/EditorNonUniformScaleComponentMode.cpp index 4be0e834dd..0521a1f2d6 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/EditorNonUniformScaleComponentMode.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/EditorNonUniformScaleComponentMode.cpp @@ -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 +#include +#include #include 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(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() diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/EditorNonUniformScaleComponentMode.h b/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/EditorNonUniformScaleComponentMode.h index d4cd0125db..8b40438d38 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/EditorNonUniformScaleComponentMode.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/EditorNonUniformScaleComponentMode.h @@ -13,6 +13,7 @@ #pragma once #include +#include 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; class NonUniformScaleComponentMode @@ -47,6 +53,11 @@ namespace AzToolsFramework // EditorBaseComponentMode void Refresh() override; + + private: + AZ::EntityComponentIdPair m_entityComponentIdPair; + AZStd::unique_ptr m_manipulators; + AZ::Vector3 m_initialScale; }; } // namespace Components } // namespace AzToolsFramework From 5508bf7e1d4472efc1af7086f99bf8e2bc4d249d Mon Sep 17 00:00:00 2001 From: greerdv Date: Fri, 14 May 2021 12:06:44 +0100 Subject: [PATCH 3/8] remove unnecessary non-uniform scale manipulator bus --- .../EditorNonUniformScaleComponent.cpp | 52 +++++++++---------- .../EditorNonUniformScaleComponent.h | 1 - .../EditorNonUniformScaleComponentMode.cpp | 14 ++--- .../EditorNonUniformScaleComponentMode.h | 42 ++++----------- 4 files changed, 44 insertions(+), 65 deletions(-) diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/EditorNonUniformScaleComponent.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/EditorNonUniformScaleComponent.cpp index 276fe0b3ab..03ad5cb3c7 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/EditorNonUniformScaleComponent.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/EditorNonUniformScaleComponent.cpp @@ -1,20 +1,20 @@ /* -* 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 +#include +#include #include #include -#include -#include +#include #include @@ -34,13 +34,13 @@ namespace AzToolsFramework serializeContext->Class() ->Version(1) ->Field("NonUniformScale", &EditorNonUniformScaleComponent::m_scale) - ->Field("ComponentMode", &EditorNonUniformScaleComponent::m_componentModeDelegate) - ; + ->Field("ComponentMode", &EditorNonUniformScaleComponent::m_componentModeDelegate); if (AZ::EditContext* editContext = serializeContext->GetEditContext()) { - editContext->Class("Non-uniform Scale", - "Non-uniform scale for this entity only (does not propagate through hierarchy)") + editContext + ->Class( + "Non-uniform Scale", "Non-uniform scale for this entity only (does not propagate through hierarchy)") ->ClassElement(AZ::Edit::ClassElements::EditorData, "") ->Attribute(AZ::Edit::Attributes::FixedComponentListIndex, 1) ->Attribute(AZ::Edit::Attributes::RemoveableByUser, true) @@ -53,10 +53,10 @@ namespace AzToolsFramework ->Attribute(AZ::Edit::Attributes::Max, AZ::MaxTransformScale) ->Attribute(AZ::Edit::Attributes::Step, 0.1f) ->Attribute(AZ::Edit::Attributes::ChangeNotify, &EditorNonUniformScaleComponent::OnScaleChanged) - ->DataElement(AZ::Edit::UIHandlers::Default, &EditorNonUniformScaleComponent::m_componentModeDelegate, - "Component Mode", "Non-uniform Scale Component Mode") - ->Attribute(AZ::Edit::Attributes::Visibility, AZ::Edit::PropertyVisibility::ShowChildrenOnly) - ; + ->DataElement( + AZ::Edit::UIHandlers::Default, &EditorNonUniformScaleComponent::m_componentModeDelegate, "Component Mode", + "Non-uniform Scale Component Mode") + ->Attribute(AZ::Edit::Attributes::Visibility, AZ::Edit::PropertyVisibility::ShowChildrenOnly); } } } @@ -82,16 +82,13 @@ namespace AzToolsFramework AZ::NonUniformScaleRequestBus::Handler::BusConnect(GetEntityId()); // ComponentMode - AZ::EntityComponentIdPair entityComponentIdPair(GetEntityId(), GetId()); - NonUniformScaleManipulatorRequestBus::Handler::BusConnect(entityComponentIdPair); - m_componentModeDelegate.ConnectWithSingleComponentMode< - EditorNonUniformScaleComponent, NonUniformScaleComponentMode>(entityComponentIdPair, this); + m_componentModeDelegate.ConnectWithSingleComponentMode( + AZ::EntityComponentIdPair(GetEntityId(), GetId()), this); } void EditorNonUniformScaleComponent::Deactivate() { m_componentModeDelegate.Disconnect(); - NonUniformScaleManipulatorRequestBus::Handler::BusDisconnect(); AZ::NonUniformScaleRequestBus::Handler::BusDisconnect(); } @@ -111,7 +108,8 @@ namespace AzToolsFramework else { AZ::Vector3 clampedScale = scale.GetClamp(AZ::Vector3(AZ::MinTransformScale), AZ::Vector3(AZ::MaxTransformScale)); - AZ_Warning("Editor Non-uniform Scale Component", false, "SetScale value was clamped from %s to %s for entity %s", + AZ_Warning( + "Editor Non-uniform Scale Component", false, "SetScale value was clamped from %s to %s for entity %s", AZ::ToString(scale).c_str(), AZ::ToString(clampedScale).c_str(), GetEntity()->GetName().c_str()); m_scale = clampedScale; } diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/EditorNonUniformScaleComponent.h b/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/EditorNonUniformScaleComponent.h index d7ce953b22..32f0b2918f 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/EditorNonUniformScaleComponent.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/EditorNonUniformScaleComponent.h @@ -28,7 +28,6 @@ namespace AzToolsFramework , public AZ::NonUniformScaleRequestBus::Handler , public AzToolsFramework::EditorComponentSelectionRequestsBus::Handler , public AzToolsFramework::EditorComponentSelectionNotificationsBus::Handler - , private NonUniformScaleManipulatorRequestBus::Handler { public: AZ_EDITOR_COMPONENT(EditorNonUniformScaleComponent, "{2933FB4F-B3DA-4CD1-8106-F37300730777}", EditorComponentBase); diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/EditorNonUniformScaleComponentMode.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/EditorNonUniformScaleComponentMode.cpp index 0521a1f2d6..87f71f2912 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/EditorNonUniformScaleComponentMode.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/EditorNonUniformScaleComponentMode.cpp @@ -10,6 +10,7 @@ * */ +#include #include #include #include @@ -42,13 +43,14 @@ namespace AzToolsFramework m_manipulators->InstallAxisLeftMouseDownCallback([this](const LinearManipulator::Action& action) { AZ::Vector3 nonUniformScale = AZ::Vector3::CreateOne(); - NonUniformScaleManipulatorRequestBus::EventResult( - nonUniformScale, m_entityComponentIdPair, &NonUniformScaleManipulatorRequests::GetScale); + + AZ::NonUniformScaleRequestBus::EventResult( + nonUniformScale, m_entityComponentIdPair.GetEntityId(), &AZ::NonUniformScaleRequests::GetScale); m_initialScale = nonUniformScale + action.m_start.m_scaleSnapOffset; - NonUniformScaleManipulatorRequestBus::Event( - m_entityComponentIdPair, &NonUniformScaleManipulatorRequests::SetScale, m_initialScale); + AZ::NonUniformScaleRequestBus::Event( + m_entityComponentIdPair.GetEntityId(), &AZ::NonUniformScaleRequests::SetScale, m_initialScale); }); m_manipulators->InstallAxisMouseMoveCallback([this](const LinearManipulator::Action& action) { @@ -56,8 +58,8 @@ namespace AzToolsFramework (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); + AZ::NonUniformScaleRequestBus::Event( + m_entityComponentIdPair.GetEntityId(), &AZ::NonUniformScaleRequests::SetScale, scale * m_initialScale); }); } diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/EditorNonUniformScaleComponentMode.h b/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/EditorNonUniformScaleComponentMode.h index 8b40438d38..9b38067fdf 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/EditorNonUniformScaleComponentMode.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/EditorNonUniformScaleComponentMode.h @@ -1,14 +1,14 @@ /* -* 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. + * + */ #pragma once @@ -19,27 +19,7 @@ namespace AzToolsFramework { namespace Components { - //! Interface for handling non-uniform scale manipulator requests. - //! Used by NonUniformScaleComponentMode. - class NonUniformScaleManipulatorRequests - : 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. - using NonUniformScaleManipulatorRequestBus = AZ::EBus; - - class NonUniformScaleComponentMode - : public AzToolsFramework::ComponentModeFramework::EditorBaseComponentMode + class NonUniformScaleComponentMode : public AzToolsFramework::ComponentModeFramework::EditorBaseComponentMode { public: AZ_CLASS_ALLOCATOR(NonUniformScaleComponentMode, AZ::SystemAllocator, 0) From e9386bcb9b4aa1cfa4b6126fd50d5bab3e154761 Mon Sep 17 00:00:00 2001 From: greerdv Date: Fri, 14 May 2021 13:29:54 +0100 Subject: [PATCH 4/8] remove unecessary overrides --- .../EditorNonUniformScaleComponent.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/EditorNonUniformScaleComponent.h b/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/EditorNonUniformScaleComponent.h index 32f0b2918f..d3bcb86bab 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/EditorNonUniformScaleComponent.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/EditorNonUniformScaleComponent.h @@ -46,16 +46,16 @@ namespace AzToolsFramework void RegisterScaleChangedEvent(AZ::NonUniformScaleChangedEvent::Handler& handler); protected: - // EditorComponentSelectionRequestsBus overrides ... - AZ::Aabb GetEditorSelectionBoundsViewport( - [[maybe_unused]] const AzFramework::ViewportInfo& viewportInfo) override { return AZ::Aabb::CreateNull(); }; - bool EditorSelectionIntersectRayViewport( - [[maybe_unused]] const AzFramework::ViewportInfo& viewportInfo, - [[maybe_unused]] const AZ::Vector3& src, [[maybe_unused]] const AZ::Vector3& dir, [[maybe_unused]] float& distance) override { return false; }; - bool SupportsEditorRayIntersect() override { return true; } + //// EditorComponentSelectionRequestsBus overrides ... + //AZ::Aabb GetEditorSelectionBoundsViewport( + // [[maybe_unused]] const AzFramework::ViewportInfo& viewportInfo) override { return AZ::Aabb::CreateNull(); }; + //bool EditorSelectionIntersectRayViewport( + // [[maybe_unused]] const AzFramework::ViewportInfo& viewportInfo, + // [[maybe_unused]] const AZ::Vector3& src, [[maybe_unused]] const AZ::Vector3& dir, [[maybe_unused]] float& distance) override { return false; }; + //bool SupportsEditorRayIntersect() override { return true; } - // EditorComponentSelectionNotificationsBus overrides ... - void OnAccentTypeChanged([[maybe_unused]] AzToolsFramework::EntityAccentType accent) override {}; + //// EditorComponentSelectionNotificationsBus overrides ... + //void OnAccentTypeChanged([[maybe_unused]] AzToolsFramework::EntityAccentType accent) override {}; private: static void GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent); From 068deea9188fc58134067ee1d99ab95f8c57036c Mon Sep 17 00:00:00 2001 From: greerdv Date: Fri, 14 May 2021 13:31:25 +0100 Subject: [PATCH 5/8] remove unnecessary overrides --- .../ToolsComponents/EditorNonUniformScaleComponent.h | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/EditorNonUniformScaleComponent.h b/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/EditorNonUniformScaleComponent.h index d3bcb86bab..d0fa7db6a3 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/EditorNonUniformScaleComponent.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/EditorNonUniformScaleComponent.h @@ -45,18 +45,6 @@ namespace AzToolsFramework void SetScale(const AZ::Vector3& scale) override; void RegisterScaleChangedEvent(AZ::NonUniformScaleChangedEvent::Handler& handler); - protected: - //// EditorComponentSelectionRequestsBus overrides ... - //AZ::Aabb GetEditorSelectionBoundsViewport( - // [[maybe_unused]] const AzFramework::ViewportInfo& viewportInfo) override { return AZ::Aabb::CreateNull(); }; - //bool EditorSelectionIntersectRayViewport( - // [[maybe_unused]] const AzFramework::ViewportInfo& viewportInfo, - // [[maybe_unused]] const AZ::Vector3& src, [[maybe_unused]] const AZ::Vector3& dir, [[maybe_unused]] float& distance) override { return false; }; - //bool SupportsEditorRayIntersect() override { return true; } - - //// EditorComponentSelectionNotificationsBus overrides ... - //void OnAccentTypeChanged([[maybe_unused]] AzToolsFramework::EntityAccentType accent) override {}; - private: static void GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent); static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible); From c8568a7cf2d7d59c11c7594c39f60fdf4ac86948 Mon Sep 17 00:00:00 2001 From: greerdv Date: Fri, 14 May 2021 13:51:02 +0100 Subject: [PATCH 6/8] add feedback from PR --- .../ToolsComponents/EditorNonUniformScaleComponent.cpp | 2 -- .../ToolsComponents/EditorNonUniformScaleComponentMode.cpp | 5 ----- .../ToolsComponents/EditorNonUniformScaleComponentMode.h | 2 +- 3 files changed, 1 insertion(+), 8 deletions(-) diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/EditorNonUniformScaleComponent.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/EditorNonUniformScaleComponent.cpp index 03ad5cb3c7..62294aaed7 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/EditorNonUniformScaleComponent.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/EditorNonUniformScaleComponent.cpp @@ -16,8 +16,6 @@ #include #include -#include - namespace AzToolsFramework { namespace Components diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/EditorNonUniformScaleComponentMode.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/EditorNonUniformScaleComponentMode.cpp index 87f71f2912..b800247929 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/EditorNonUniformScaleComponentMode.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/EditorNonUniformScaleComponentMode.cpp @@ -28,15 +28,10 @@ namespace AzToolsFramework AZ::Transform worldFromLocal = AZ::Transform::CreateIdentity(); AZ::TransformBus::EventResult(worldFromLocal, m_entityComponentIdPair.GetEntityId(), &AZ::TransformBus::Events::GetWorldTM); - worldFromLocal.ExtractScale(); - m_manipulators = AZStd::make_unique(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); diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/EditorNonUniformScaleComponentMode.h b/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/EditorNonUniformScaleComponentMode.h index 9b38067fdf..1169a4f13e 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/EditorNonUniformScaleComponentMode.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/EditorNonUniformScaleComponentMode.h @@ -31,7 +31,7 @@ namespace AzToolsFramework NonUniformScaleComponentMode& operator=(NonUniformScaleComponentMode&&) = delete; ~NonUniformScaleComponentMode(); - // EditorBaseComponentMode + // EditorBaseComponentMode overrides ... void Refresh() override; private: From f2d415ecb8676639dcb95401ea5cefae4d86bad8 Mon Sep 17 00:00:00 2001 From: greerdv Date: Fri, 14 May 2021 19:38:25 +0100 Subject: [PATCH 7/8] add functionality for central scale manipulator --- .../EditorNonUniformScaleComponentMode.cpp | 29 +++++++++++++++---- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/EditorNonUniformScaleComponentMode.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/EditorNonUniformScaleComponentMode.cpp index b800247929..6c587e1ff4 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/EditorNonUniformScaleComponentMode.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/EditorNonUniformScaleComponentMode.cpp @@ -36,7 +36,7 @@ namespace AzToolsFramework 2.0f, AzFramework::ViewportColors::XAxisColor, AzFramework::ViewportColors::YAxisColor, AzFramework::ViewportColors::ZAxisColor); - m_manipulators->InstallAxisLeftMouseDownCallback([this](const LinearManipulator::Action& action) { + auto mouseDownCallback = [this](const LinearManipulator::Action& action) { AZ::Vector3 nonUniformScale = AZ::Vector3::CreateOne(); AZ::NonUniformScaleRequestBus::EventResult( @@ -46,15 +46,32 @@ namespace AzToolsFramework AZ::NonUniformScaleRequestBus::Event( m_entityComponentIdPair.GetEntityId(), &AZ::NonUniformScaleRequests::SetScale, m_initialScale); - }); + }; + + m_manipulators->InstallAxisLeftMouseDownCallback(mouseDownCallback); 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)); + const AZ::Vector3 scaleMultiplier = + (AZ::Vector3::CreateOne() + ((action.LocalScaleOffset() * action.m_start.m_sign) / m_initialScale)); AZ::NonUniformScaleRequestBus::Event( - m_entityComponentIdPair.GetEntityId(), &AZ::NonUniformScaleRequests::SetScale, scale * m_initialScale); + m_entityComponentIdPair.GetEntityId(), &AZ::NonUniformScaleRequests::SetScale, + (scaleMultiplier * m_initialScale).GetClamp(AZ::Vector3(AZ::MinTransformScale), AZ::Vector3(AZ::MaxTransformScale))); + }); + + m_manipulators->InstallUniformLeftMouseDownCallback(mouseDownCallback); + + m_manipulators->InstallUniformMouseMoveCallback([this](const LinearManipulator::Action& action) { + const auto sumVectorElements = [](const AZ::Vector3& vec) { return vec.GetX() + vec.GetY() + vec.GetZ(); }; + + const float minScaleMultiplier = AZ::MinTransformScale / m_initialScale.GetMinElement(); + const float maxScaleMultiplier = AZ::MaxTransformScale / m_initialScale.GetMaxElement(); + const float scaleMultiplier = AZ::GetClamp( + 1.0f + sumVectorElements(action.m_start.m_sign * action.LocalScaleOffset() / m_initialScale), minScaleMultiplier, + maxScaleMultiplier); + + AZ::NonUniformScaleRequestBus::Event( + m_entityComponentIdPair.GetEntityId(), &AZ::NonUniformScaleRequests::SetScale, scaleMultiplier * m_initialScale); }); } From 7edef63884e56fb04104608a987c3bb5bad84db3 Mon Sep 17 00:00:00 2001 From: greerdv Date: Mon, 17 May 2021 13:20:52 +0100 Subject: [PATCH 8/8] address PR feedback --- .../ToolsComponents/EditorNonUniformScaleComponent.cpp | 2 +- .../ToolsComponents/EditorNonUniformScaleComponent.h | 2 -- .../ToolsComponents/EditorNonUniformScaleComponentMode.cpp | 3 ++- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/EditorNonUniformScaleComponent.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/EditorNonUniformScaleComponent.cpp index 62294aaed7..f72de82f36 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/EditorNonUniformScaleComponent.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/EditorNonUniformScaleComponent.cpp @@ -81,7 +81,7 @@ namespace AzToolsFramework // ComponentMode m_componentModeDelegate.ConnectWithSingleComponentMode( - AZ::EntityComponentIdPair(GetEntityId(), GetId()), this); + AZ::EntityComponentIdPair(GetEntityId(), GetId()), nullptr); } void EditorNonUniformScaleComponent::Deactivate() diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/EditorNonUniformScaleComponent.h b/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/EditorNonUniformScaleComponent.h index d0fa7db6a3..eb51fe3d80 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/EditorNonUniformScaleComponent.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/EditorNonUniformScaleComponent.h @@ -26,8 +26,6 @@ namespace AzToolsFramework class EditorNonUniformScaleComponent : public AzToolsFramework::Components::EditorComponentBase , public AZ::NonUniformScaleRequestBus::Handler - , public AzToolsFramework::EditorComponentSelectionRequestsBus::Handler - , public AzToolsFramework::EditorComponentSelectionNotificationsBus::Handler { public: AZ_EDITOR_COMPONENT(EditorNonUniformScaleComponent, "{2933FB4F-B3DA-4CD1-8106-F37300730777}", EditorComponentBase); diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/EditorNonUniformScaleComponentMode.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/EditorNonUniformScaleComponentMode.cpp index 6c587e1ff4..97e27ac748 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/EditorNonUniformScaleComponentMode.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/EditorNonUniformScaleComponentMode.cpp @@ -32,8 +32,9 @@ namespace AzToolsFramework m_manipulators = AZStd::make_unique(worldFromLocal); m_manipulators->Register(g_mainManipulatorManagerId); m_manipulators->SetAxes(AZ::Vector3::CreateAxisX(), AZ::Vector3::CreateAxisY(), AZ::Vector3::CreateAxisZ()); + const float axisLength = 2.0f; m_manipulators->ConfigureView( - 2.0f, AzFramework::ViewportColors::XAxisColor, AzFramework::ViewportColors::YAxisColor, + axisLength, AzFramework::ViewportColors::XAxisColor, AzFramework::ViewportColors::YAxisColor, AzFramework::ViewportColors::ZAxisColor); auto mouseDownCallback = [this](const LinearManipulator::Action& action) {