[LYN-3122] Fixed the viewport Entity hit test logic. This allows the BuildDragDropContext to detect hit position correctly so that assets dragged into the viewport are placed in the correct position.

This commit is contained in:
Chris Galvan
2021-04-27 11:17:24 -05:00
parent 59a2550595
commit f269d92f90
4 changed files with 67 additions and 9 deletions
+1 -4
View File
@@ -234,11 +234,8 @@ public:
QPoint ViewportToWidget(const QPoint& point) const;
QSize WidgetToViewport(const QSize& size) const;
/// Take raw input and create a final mouse interaction.
/// @attention Do not map **point** from widget to viewport explicitly,
/// this is handled internally by BuildMouseInteraction - just pass directly.
AzToolsFramework::ViewportInteraction::MouseInteraction BuildMouseInteraction(
Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, const QPoint& point);
Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, const QPoint& point) override;
void SetPlayerPos()
{
+1 -4
View File
@@ -238,11 +238,8 @@ public:
QPoint ViewportToWidget(const QPoint& point) const;
QSize WidgetToViewport(const QSize& size) const;
/// Take raw input and create a final mouse interaction.
/// @attention Do not map **point** from widget to viewport explicitly,
/// this is handled internally by BuildMouseInteraction - just pass directly.
AzToolsFramework::ViewportInteraction::MouseInteraction BuildMouseInteraction(
Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, const QPoint& point);
Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, const QPoint& point) override;
void SetPlayerPos()
{
+58 -1
View File
@@ -21,6 +21,9 @@
// AzQtComponents
#include <AzQtComponents/DragAndDrop/ViewportDragAndDrop.h>
#include <AzToolsFramework/API/ComponentEntitySelectionBus.h>
#include <AzToolsFramework/ViewportSelection/EditorSelectionUtil.h>
// Editor
#include "ViewManager.h"
#include "Include/ITransformManipulator.h"
@@ -1091,6 +1094,13 @@ void QtViewport::SetAxisConstrain(int axis)
m_activeAxis = axis;
};
AzToolsFramework::ViewportInteraction::MouseInteraction QtViewport::BuildMouseInteraction(
[[maybe_unused]] Qt::MouseButtons buttons, [[maybe_unused]] Qt::KeyboardModifiers modifiers, [[maybe_unused]] const QPoint& point)
{
// Implemented by sub-class
return AzToolsFramework::ViewportInteraction::MouseInteraction();
}
//////////////////////////////////////////////////////////////////////////
bool QtViewport::HitTest(const QPoint& point, HitContext& hitInfo)
{
@@ -1103,7 +1113,54 @@ bool QtViewport::HitTest(const QPoint& point, HitContext& hitInfo)
hitInfo.bUseSelectionHelpers = true;
}
return GetIEditor()->GetObjectManager()->HitTest(hitInfo);
const int viewportId = GetViewportId();
// TODO: Use the EditorVisibleEntityDataCache instead once we are able to move to EditorViewportWidget
AzToolsFramework::EntityIdList visibleEntityIds;
AzToolsFramework::ViewportInteraction::MainEditorViewportInteractionRequestBus::Event(
viewportId,
&AzToolsFramework::ViewportInteraction::MainEditorViewportInteractionRequests::FindVisibleEntities,
visibleEntityIds);
// Look through all visible entities to find the closest one to the specified mouse point
AZ::EntityId entityIdUnderCursor;
float closestDistance = std::numeric_limits<float>::max();
for (auto entityId : visibleEntityIds)
{
using AzFramework::ViewportInfo;
// Check if components provide an aabb
if (const AZ::Aabb aabb = AzToolsFramework::CalculateEditorEntitySelectionBounds(entityId, ViewportInfo{ viewportId });
aabb.IsValid())
{
using namespace AzToolsFramework::ViewportInteraction;
MouseInteraction mouseInteraction = BuildMouseInteraction(QGuiApplication::mouseButtons(),
QGuiApplication::queryKeyboardModifiers(),
point);
// Coarse grain check
if (AzToolsFramework::AabbIntersectMouseRay(mouseInteraction, aabb))
{
// If success, pick against specific component
if (AzToolsFramework::PickEntity(
entityId, mouseInteraction,
closestDistance, viewportId))
{
entityIdUnderCursor = entityId;
}
}
}
}
// If we hit a valid Entity, then store the distance in the HitContext
// so that the caller can use this for calculations
if (entityIdUnderCursor.IsValid())
{
hitInfo.dist = closestDistance;
return true;
}
return false;
}
//////////////////////////////////////////////////////////////////////////
+7
View File
@@ -17,6 +17,7 @@
#pragma once
#if !defined(Q_MOC_RUN)
#include <AzToolsFramework/Viewport/ViewportTypes.h>
#include <AzToolsFramework/ViewportUi/ViewportUiManager.h>
#include <Cry_Color.h>
#include "IPostRenderer.h"
@@ -405,6 +406,12 @@ public:
void SetAxisConstrain(int axis);
/// Take raw input and create a final mouse interaction.
/// @attention Do not map **point** from widget to viewport explicitly,
/// this is handled internally by BuildMouseInteraction - just pass directly.
virtual AzToolsFramework::ViewportInteraction::MouseInteraction BuildMouseInteraction(
Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, const QPoint& point);
//////////////////////////////////////////////////////////////////////////
// Selection.
//////////////////////////////////////////////////////////////////////////