Update intersect behavior for positioning entities in the viewport (#5906)

* update intersect behavior for positioning entities in the viewport and restore SurfaceManipulator

Signed-off-by: Tom Hulton-Harrop <82228511+hultonha@users.noreply.github.com>

* tests for surface manipulator from EditorTransformComponentSelection

Signed-off-by: Tom Hulton-Harrop <82228511+hultonha@users.noreply.github.com>

* update comments in tests and remove #pragma optimize('', off)@

Signed-off-by: Tom Hulton-Harrop <82228511+hultonha@users.noreply.github.com>

* add new file for FindClosestPickIntersection tests

Signed-off-by: Tom Hulton-Harrop <82228511+hultonha@users.noreply.github.com>

* add remaining tests for surface manipulator and snap fixes

Signed-off-by: Tom Hulton-Harrop <82228511+hultonha@users.noreply.github.com>

* some small updates and polish before PR

Signed-off-by: Tom Hulton-Harrop <82228511+hultonha@users.noreply.github.com>

* small updates following PR feedback

Signed-off-by: Tom Hulton-Harrop <82228511+hultonha@users.noreply.github.com>
This commit is contained in:
Tom Hulton-Harrop
2021-11-30 15:07:40 +00:00
committed by GitHub
parent 75d6cb2527
commit 6908a3e945
31 changed files with 811 additions and 280 deletions
@@ -39,6 +39,10 @@ namespace AzManipulatorTestFramework
DerivedDispatcherT* MouseLButtonDown();
//! Set the left mouse button up.
DerivedDispatcherT* MouseLButtonUp();
//! Set the middle mouse button down.
DerivedDispatcherT* MouseMButtonDown();
//! Set the middle mouse button up.
DerivedDispatcherT* MouseMButtonUp();
//! Send a double click event.
DerivedDispatcherT* MouseLButtonDoubleClick();
//! Set the keyboard modifier button down.
@@ -73,6 +77,8 @@ namespace AzManipulatorTestFramework
virtual void CameraStateImpl(const AzFramework::CameraState& cameraState) = 0;
virtual void MouseLButtonDownImpl() = 0;
virtual void MouseLButtonUpImpl() = 0;
virtual void MouseMButtonDownImpl() = 0;
virtual void MouseMButtonUpImpl() = 0;
virtual void MouseLButtonDoubleClickImpl() = 0;
virtual void MousePositionImpl(const AzFramework::ScreenPoint& position) = 0;
virtual void KeyboardModifierDownImpl(const AzToolsFramework::ViewportInteraction::KeyboardModifier& keyModifier) = 0;
@@ -183,6 +189,22 @@ namespace AzManipulatorTestFramework
return static_cast<DerivedDispatcherT*>(this);
}
template<typename DerivedDispatcherT>
DerivedDispatcherT* ActionDispatcher<DerivedDispatcherT>::MouseMButtonDown()
{
Log("Mouse middle button down");
MouseMButtonDownImpl();
return static_cast<DerivedDispatcherT*>(this);
}
template<typename DerivedDispatcherT>
DerivedDispatcherT* ActionDispatcher<DerivedDispatcherT>::MouseMButtonUp()
{
Log("Mouse middle button up");
MouseMButtonUpImpl();
return static_cast<DerivedDispatcherT*>(this);
}
template<typename DerivedDispatcherT>
DerivedDispatcherT* ActionDispatcher<DerivedDispatcherT>::MouseLButtonDoubleClick()
{
@@ -8,6 +8,7 @@
#pragma once
#include <AzFramework/Viewport/ViewportId.h>
#include <AzToolsFramework/Manipulators/ManipulatorBus.h>
#include <AzToolsFramework/UnitTest/AzToolsFrameworkTestHelpers.h>
#include <AzToolsFramework/Viewport/ViewportMessages.h>
@@ -40,7 +41,7 @@ namespace AzManipulatorTestFramework
//! Set the angular step.
virtual void SetAngularStep(float step) = 0;
//! Get the viewport id.
virtual int GetViewportId() const = 0;
virtual AzFramework::ViewportId GetViewportId() const = 0;
//! Updates the visibility state.
//! Updates which entities are currently visible given the current camera state.
virtual void UpdateVisibility() = 0;
@@ -30,7 +30,7 @@ namespace AzManipulatorTestFramework
private:
AZStd::shared_ptr<CustomManipulatorManager> m_customManager;
std::unique_ptr<ViewportInteraction> m_viewportInteraction;
std::unique_ptr<DirectCallManipulatorManager> m_manipulatorManager;
AZStd::unique_ptr<ViewportInteraction> m_viewportInteraction;
AZStd::unique_ptr<DirectCallManipulatorManager> m_manipulatorManager;
};
} // namespace AzManipulatorTestFramework
@@ -25,7 +25,7 @@ namespace AzManipulatorTestFramework
using MouseInteractionEvent = AzToolsFramework::ViewportInteraction::MouseInteractionEvent;
public:
explicit ImmediateModeActionDispatcher(ManipulatorViewportInteraction& viewportManipulatorInteraction);
explicit ImmediateModeActionDispatcher(ManipulatorViewportInteraction& manipulatorViewportInteraction);
~ImmediateModeActionDispatcher();
//! Clear the current event state.
@@ -55,13 +55,15 @@ namespace AzManipulatorTestFramework
AZStd::chrono::milliseconds EditorViewportInputTimeNow() override;
protected:
// ActionDispatcher ...
// ActionDispatcher overrides ...
void SetSnapToGridImpl(bool enabled) override;
void SetStickySelectImpl(bool enabled) override;
void GridSizeImpl(float size) override;
void CameraStateImpl(const AzFramework::CameraState& cameraState) override;
void MouseLButtonDownImpl() override;
void MouseLButtonUpImpl() override;
void MouseMButtonDownImpl() override;
void MouseMButtonUpImpl() override;
void MouseLButtonDoubleClickImpl() override;
void MousePositionImpl(const AzFramework::ScreenPoint& position) override;
void KeyboardModifierDownImpl(const KeyboardModifier& keyModifier) override;
@@ -82,7 +84,7 @@ namespace AzManipulatorTestFramework
const MouseInteractionEvent* GetMouseInteractionEvent() const;
mutable AZStd::unique_ptr<MouseInteractionEvent> m_event;
ManipulatorViewportInteraction& m_viewportManipulatorInteraction;
ManipulatorViewportInteraction& m_manipulatorViewportInteraction;
//! Current time that ticks up after each call to EditorViewportInputTimeNow.
AZStd::chrono::milliseconds m_timeNow = AZStd::chrono::milliseconds(0);
@@ -33,7 +33,7 @@ namespace AzManipulatorTestFramework
void SetAngularSnapping(bool enabled) override;
void SetGridSize(float size) override;
void SetAngularStep(float step) override;
int GetViewportId() const override;
AzFramework::ViewportId GetViewportId() const override;
void UpdateVisibility() override;
void SetStickySelect(bool enabled) override;
AZ::Vector3 DefaultEditorCameraPosition() const override;
@@ -60,9 +60,10 @@ namespace AzManipulatorTestFramework
void FindVisibleEntities(AZStd::vector<AZ::EntityId>& visibleEntities) override;
private:
static constexpr AzFramework::ViewportId m_viewportId = 1234; //!< Arbitrary viewport id for manipulator tests.
AzFramework::EntityVisibilityQuery m_entityVisibilityQuery;
AZStd::unique_ptr<NullDebugDisplayRequests> m_nullDebugDisplayRequests;
const int m_viewportId = 1234; // Arbitrary viewport id for manipulator tests
AzFramework::CameraState m_cameraState;
bool m_gridSnapping = false;
bool m_angularSnapping = false;
@@ -29,8 +29,8 @@ namespace AzManipulatorTestFramework
using KeyboardModifier = AzToolsFramework::ViewportInteraction::KeyboardModifier;
using MouseInteractionEvent = AzToolsFramework::ViewportInteraction::MouseInteractionEvent;
ImmediateModeActionDispatcher::ImmediateModeActionDispatcher(ManipulatorViewportInteraction& viewportManipulatorInteraction)
: m_viewportManipulatorInteraction(viewportManipulatorInteraction)
ImmediateModeActionDispatcher::ImmediateModeActionDispatcher(ManipulatorViewportInteraction& manipulatorViewportInteraction)
: m_manipulatorViewportInteraction(manipulatorViewportInteraction)
{
AzToolsFramework::ViewportInteraction::EditorModifierKeyRequestBus::Handler::BusConnect();
AzToolsFramework::ViewportInteraction::EditorViewportInputTimeNowRequestBus::Handler::BusConnect();
@@ -48,34 +48,34 @@ namespace AzManipulatorTestFramework
// mouse down and mouse up event, to match the editor behavior we insert this event
// to ensure the tests are simulating the same environment as the editor
GetMouseInteractionEvent()->m_mouseEvent = AzToolsFramework::ViewportInteraction::MouseEvent::Move;
m_viewportManipulatorInteraction.GetManipulatorManager().ConsumeMouseInteractionEvent(*m_event);
m_manipulatorViewportInteraction.GetManipulatorManager().ConsumeMouseInteractionEvent(*m_event);
}
void ImmediateModeActionDispatcher::SetSnapToGridImpl(const bool enabled)
{
m_viewportManipulatorInteraction.GetViewportInteraction().SetGridSnapping(enabled);
m_manipulatorViewportInteraction.GetViewportInteraction().SetGridSnapping(enabled);
}
void ImmediateModeActionDispatcher::SetStickySelectImpl(const bool enabled)
{
m_viewportManipulatorInteraction.GetViewportInteraction().SetStickySelect(enabled);
m_manipulatorViewportInteraction.GetViewportInteraction().SetStickySelect(enabled);
}
void ImmediateModeActionDispatcher::GridSizeImpl(const float size)
{
m_viewportManipulatorInteraction.GetViewportInteraction().SetGridSize(size);
m_manipulatorViewportInteraction.GetViewportInteraction().SetGridSize(size);
}
void ImmediateModeActionDispatcher::CameraStateImpl(const AzFramework::CameraState& cameraState)
{
m_viewportManipulatorInteraction.GetViewportInteraction().SetCameraState(cameraState);
m_manipulatorViewportInteraction.GetViewportInteraction().SetCameraState(cameraState);
}
void ImmediateModeActionDispatcher::MouseLButtonDownImpl()
{
ToggleOn(GetMouseInteractionEvent()->m_mouseInteraction.m_mouseButtons.m_mouseButtons, MouseButton::Left);
GetMouseInteractionEvent()->m_mouseEvent = AzToolsFramework::ViewportInteraction::MouseEvent::Down;
m_viewportManipulatorInteraction.GetManipulatorManager().ConsumeMouseInteractionEvent(*m_event);
m_manipulatorViewportInteraction.GetManipulatorManager().ConsumeMouseInteractionEvent(*m_event);
// the mouse position will be the same as the previous event, thus the delta will be 0
MouseMoveAfterButton();
}
@@ -83,17 +83,35 @@ namespace AzManipulatorTestFramework
void ImmediateModeActionDispatcher::MouseLButtonUpImpl()
{
GetMouseInteractionEvent()->m_mouseEvent = AzToolsFramework::ViewportInteraction::MouseEvent::Up;
m_viewportManipulatorInteraction.GetManipulatorManager().ConsumeMouseInteractionEvent(*m_event);
m_manipulatorViewportInteraction.GetManipulatorManager().ConsumeMouseInteractionEvent(*m_event);
ToggleOff(GetMouseInteractionEvent()->m_mouseInteraction.m_mouseButtons.m_mouseButtons, MouseButton::Left);
// the mouse position will be the same as the previous event, thus the delta will be 0
MouseMoveAfterButton();
}
void ImmediateModeActionDispatcher::MouseMButtonDownImpl()
{
ToggleOn(GetMouseInteractionEvent()->m_mouseInteraction.m_mouseButtons.m_mouseButtons, MouseButton::Middle);
GetMouseInteractionEvent()->m_mouseEvent = AzToolsFramework::ViewportInteraction::MouseEvent::Down;
m_manipulatorViewportInteraction.GetManipulatorManager().ConsumeMouseInteractionEvent(*m_event);
// the mouse position will be the same as the previous event, thus the delta will be 0
MouseMoveAfterButton();
}
void ImmediateModeActionDispatcher::MouseMButtonUpImpl()
{
GetMouseInteractionEvent()->m_mouseEvent = AzToolsFramework::ViewportInteraction::MouseEvent::Up;
m_manipulatorViewportInteraction.GetManipulatorManager().ConsumeMouseInteractionEvent(*m_event);
ToggleOff(GetMouseInteractionEvent()->m_mouseInteraction.m_mouseButtons.m_mouseButtons, MouseButton::Middle);
// the mouse position will be the same as the previous event, thus the delta will be 0
MouseMoveAfterButton();
}
void ImmediateModeActionDispatcher::MouseLButtonDoubleClickImpl()
{
GetMouseInteractionEvent()->m_mouseEvent = AzToolsFramework::ViewportInteraction::MouseEvent::DoubleClick;
ToggleOn(GetMouseInteractionEvent()->m_mouseInteraction.m_mouseButtons.m_mouseButtons, MouseButton::Left);
m_viewportManipulatorInteraction.GetManipulatorManager().ConsumeMouseInteractionEvent(*m_event);
m_manipulatorViewportInteraction.GetManipulatorManager().ConsumeMouseInteractionEvent(*m_event);
ToggleOff(GetMouseInteractionEvent()->m_mouseInteraction.m_mouseButtons.m_mouseButtons, MouseButton::Left);
// the mouse position will be the same as the previous event, thus the delta will be 0
MouseMoveAfterButton();
@@ -101,10 +119,10 @@ namespace AzManipulatorTestFramework
void ImmediateModeActionDispatcher::MousePositionImpl(const AzFramework::ScreenPoint& position)
{
const auto cameraState = m_viewportManipulatorInteraction.GetViewportInteraction().GetCameraState();
const auto cameraState = m_manipulatorViewportInteraction.GetViewportInteraction().GetCameraState();
GetMouseInteractionEvent()->m_mouseInteraction.m_mousePick = BuildMousePick(position, cameraState);
GetMouseInteractionEvent()->m_mouseEvent = AzToolsFramework::ViewportInteraction::MouseEvent::Move;
m_viewportManipulatorInteraction.GetManipulatorManager().ConsumeMouseInteractionEvent(*m_event);
m_manipulatorViewportInteraction.GetManipulatorManager().ConsumeMouseInteractionEvent(*m_event);
}
void ImmediateModeActionDispatcher::KeyboardModifierDownImpl(const KeyboardModifier& keyModifier)
@@ -144,7 +162,7 @@ namespace AzManipulatorTestFramework
{
m_event = AZStd::unique_ptr<MouseInteractionEvent>(AZStd::make_unique<MouseInteractionEvent>());
m_event->m_mouseInteraction.m_interactionId.m_viewportId =
m_viewportManipulatorInteraction.GetViewportInteraction().GetViewportId();
m_manipulatorViewportInteraction.GetViewportInteraction().GetViewportId();
}
return m_event.get();
@@ -178,12 +196,12 @@ namespace AzManipulatorTestFramework
void ImmediateModeActionDispatcher::ExpectManipulatorBeingInteractedImpl()
{
EXPECT_TRUE(m_viewportManipulatorInteraction.GetManipulatorManager().ManipulatorBeingInteracted());
EXPECT_TRUE(m_manipulatorViewportInteraction.GetManipulatorManager().ManipulatorBeingInteracted());
}
void ImmediateModeActionDispatcher::ExpectManipulatorNotBeingInteractedImpl()
{
EXPECT_FALSE(m_viewportManipulatorInteraction.GetManipulatorManager().ManipulatorBeingInteracted());
EXPECT_FALSE(m_manipulatorViewportInteraction.GetManipulatorManager().ManipulatorBeingInteracted());
}
ImmediateModeActionDispatcher* ImmediateModeActionDispatcher::ResetEvent()
@@ -135,20 +135,20 @@ namespace AzManipulatorTestFramework
m_angularStep = step;
}
int ViewportInteraction::GetViewportId() const
AzFramework::ViewportId ViewportInteraction::GetViewportId() const
{
return m_viewportId;
}
AZ::Vector3 ViewportInteraction::ViewportScreenToWorld([[maybe_unused]] const AzFramework::ScreenPoint& screenPosition)
{
return AZ::Vector3::CreateZero();
return AzFramework::ScreenToWorld(screenPosition, m_cameraState);
}
AzToolsFramework::ViewportInteraction::ProjectedViewportRay ViewportInteraction::ViewportScreenToWorldRay(
[[maybe_unused]] const AzFramework::ScreenPoint& screenPosition)
{
return {};
return AzToolsFramework::ViewportInteraction::ViewportScreenToWorldRay(m_cameraState, screenPosition);
}
float ViewportInteraction::DeviceScalingFactor()