Merge pull request #370 from aws-lumberyard-dev/cgalvan/CherryPickDragAndDropHitTest

[LYN-3122] Cherry-pick: 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.
main
cgalvan 5 years ago committed by GitHub
commit 65565daf5a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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()
{

@ -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()
{

@ -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,51 @@ bool QtViewport::HitTest(const QPoint& point, HitContext& hitInfo)
hitInfo.bUseSelectionHelpers = true;
}
return GetIEditor()->GetObjectManager()->HitTest(hitInfo);
const int viewportId = GetViewportId();
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
using namespace AzToolsFramework::ViewportInteraction;
AZ::EntityId entityIdUnderCursor;
float closestDistance = std::numeric_limits<float>::max();
MouseInteraction mouseInteraction = BuildMouseInteraction(QGuiApplication::mouseButtons(),
QGuiApplication::queryKeyboardModifiers(),
point);
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())
{
// 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;
}
//////////////////////////////////////////////////////////////////////////

@ -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.
//////////////////////////////////////////////////////////////////////////

Loading…
Cancel
Save