Preparatory work to allow for more viewport integration tests (#3961)
* preparatory work to allow for more viewport integration tests Signed-off-by: hultonha <hultonha@amazon.co.uk> * minor grammatical fix Signed-off-by: hultonha <hultonha@amazon.co.uk> * fix for missed bus call update Signed-off-by: hultonha <hultonha@amazon.co.uk>
This commit is contained in:
@@ -96,7 +96,7 @@ namespace AzToolsFramework
|
||||
{
|
||||
AZ::EBusReduceResult<AZ::Aabb, AzFramework::AabbUnionAggregator> aabbResult(AZ::Aabb::CreateNull());
|
||||
EditorComponentSelectionRequestsBus::EventResult(
|
||||
aabbResult, entityId, &EditorComponentSelectionRequests::GetEditorSelectionBoundsViewport, viewportInfo);
|
||||
aabbResult, entityId, &EditorComponentSelectionRequestsBus::Events::GetEditorSelectionBoundsViewport, viewportInfo);
|
||||
|
||||
return aabbResult.value;
|
||||
}
|
||||
|
||||
@@ -10,6 +10,25 @@
|
||||
|
||||
namespace AzToolsFramework
|
||||
{
|
||||
AzFramework::ClickDetector::ClickEvent ClickDetectorEventFromViewportInteraction(
|
||||
const ViewportInteraction::MouseInteractionEvent& mouseInteraction)
|
||||
{
|
||||
if (mouseInteraction.m_mouseInteraction.m_mouseButtons.Left())
|
||||
{
|
||||
if (mouseInteraction.m_mouseEvent == ViewportInteraction::MouseEvent::Down)
|
||||
{
|
||||
return AzFramework::ClickDetector::ClickEvent::Down;
|
||||
}
|
||||
|
||||
if (mouseInteraction.m_mouseEvent == ViewportInteraction::MouseEvent::Up)
|
||||
{
|
||||
return AzFramework::ClickDetector::ClickEvent::Up;
|
||||
}
|
||||
}
|
||||
|
||||
return AzFramework::ClickDetector::ClickEvent::Nil;
|
||||
}
|
||||
|
||||
float ManipulatorLineBoundWidth(const AzFramework::ViewportId viewportId /*= AzFramework::InvalidViewportId*/)
|
||||
{
|
||||
float lineBoundWidth = 0.0f;
|
||||
|
||||
@@ -250,8 +250,6 @@ namespace AzToolsFramework
|
||||
virtual AZ::Vector3 PickTerrain(const AzFramework::ScreenPoint& point) = 0;
|
||||
//! Return the terrain height given a world position in 2d (xy plane).
|
||||
virtual float TerrainHeight(const AZ::Vector2& position) = 0;
|
||||
//! Given the current view frustum (viewport) return all visible entities.
|
||||
virtual void FindVisibleEntities(AZStd::vector<AZ::EntityId>& visibleEntities) = 0;
|
||||
//! Is the user holding a modifier key to move the manipulator space from local to world.
|
||||
virtual bool ShowingWorldSpace() = 0;
|
||||
//! Return the widget to use as the parent for the viewport context menu.
|
||||
@@ -269,7 +267,20 @@ namespace AzToolsFramework
|
||||
//! Type to inherit to implement MainEditorViewportInteractionRequests.
|
||||
using MainEditorViewportInteractionRequestBus = AZ::EBus<MainEditorViewportInteractionRequests, ViewportEBusTraits>;
|
||||
|
||||
//! Viewport requests for managing the viewport's cursor state.
|
||||
//! Editor entity requests to be made about the viewport.
|
||||
class EditorEntityViewportInteractionRequests
|
||||
{
|
||||
public:
|
||||
//! Given the current view frustum (viewport) return all visible entities.
|
||||
virtual void FindVisibleEntities(AZStd::vector<AZ::EntityId>& visibleEntities) = 0;
|
||||
|
||||
protected:
|
||||
~EditorEntityViewportInteractionRequests() = default;
|
||||
};
|
||||
|
||||
using EditorEntityViewportInteractionRequestBus = AZ::EBus<EditorEntityViewportInteractionRequests, ViewportEBusTraits>;
|
||||
|
||||
//! Viewport requests for managing the viewport cursor state.
|
||||
class ViewportMouseCursorRequests
|
||||
{
|
||||
public:
|
||||
@@ -321,23 +332,8 @@ namespace AzToolsFramework
|
||||
|
||||
//! Maps a mouse interaction event to a ClickDetector event.
|
||||
//! @note Function only cares about up or down events, all other events are mapped to Nil (ignored).
|
||||
inline AzFramework::ClickDetector::ClickEvent ClickDetectorEventFromViewportInteraction(
|
||||
const ViewportInteraction::MouseInteractionEvent& mouseInteraction)
|
||||
{
|
||||
if (mouseInteraction.m_mouseInteraction.m_mouseButtons.Left())
|
||||
{
|
||||
if (mouseInteraction.m_mouseEvent == ViewportInteraction::MouseEvent::Down)
|
||||
{
|
||||
return AzFramework::ClickDetector::ClickEvent::Down;
|
||||
}
|
||||
|
||||
if (mouseInteraction.m_mouseEvent == ViewportInteraction::MouseEvent::Up)
|
||||
{
|
||||
return AzFramework::ClickDetector::ClickEvent::Up;
|
||||
}
|
||||
}
|
||||
return AzFramework::ClickDetector::ClickEvent::Nil;
|
||||
}
|
||||
AzFramework::ClickDetector::ClickEvent ClickDetectorEventFromViewportInteraction(
|
||||
const ViewportInteraction::MouseInteractionEvent& mouseInteraction);
|
||||
|
||||
//! Wrap EBus call to retrieve manipulator line bound width.
|
||||
//! @note It is possible to pass AzFramework::InvalidViewportId (the default) to perform a Broadcast as opposed to a targeted Event.
|
||||
|
||||
+18
-8
@@ -19,7 +19,7 @@
|
||||
namespace AzToolsFramework
|
||||
{
|
||||
// default ray length for picking in the viewport
|
||||
static const float s_pickRayLength = 1000.0f;
|
||||
static const float EditorPickRayLength = 1000.0f;
|
||||
|
||||
AZ::Vector3 CalculateCenterOffset(const AZ::EntityId entityId, const EditorTransformComponentSelectionRequests::Pivot pivot)
|
||||
{
|
||||
@@ -60,16 +60,27 @@ namespace AzToolsFramework
|
||||
return screenPosition;
|
||||
}
|
||||
|
||||
bool AabbIntersectMouseRay(const ViewportInteraction::MouseInteraction& mouseInteraction, const AZ::Aabb& aabb)
|
||||
bool AabbIntersectRay(const AZ::Vector3& origin, const AZ::Vector3& direction, const AZ::Aabb& aabb, float& distance)
|
||||
{
|
||||
AZ_PROFILE_FUNCTION(AzToolsFramework);
|
||||
|
||||
const AZ::Vector3 rayScaledDir = mouseInteraction.m_mousePick.m_rayDirection * s_pickRayLength;
|
||||
const AZ::Vector3 rayScaledDir = direction * EditorPickRayLength;
|
||||
|
||||
AZ::Vector3 startNormal;
|
||||
float t, end;
|
||||
return AZ::Intersect::IntersectRayAABB(
|
||||
mouseInteraction.m_mousePick.m_rayOrigin, rayScaledDir, rayScaledDir.GetReciprocal(), aabb, t, end, startNormal) > 0;
|
||||
AZ::Vector3 startNormal;
|
||||
if (AZ::Intersect::IntersectRayAABB(origin, rayScaledDir, rayScaledDir.GetReciprocal(), aabb, t, end, startNormal) > 0)
|
||||
{
|
||||
distance = t * EditorPickRayLength;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool AabbIntersectMouseRay(const ViewportInteraction::MouseInteraction& mouseInteraction, const AZ::Aabb& aabb)
|
||||
{
|
||||
float unused;
|
||||
return AabbIntersectRay(mouseInteraction.m_mousePick.m_rayOrigin, mouseInteraction.m_mousePick.m_rayDirection, aabb, unused);
|
||||
}
|
||||
|
||||
bool PickEntity(
|
||||
@@ -117,8 +128,7 @@ namespace AzToolsFramework
|
||||
{
|
||||
float scaling = 1.0f;
|
||||
ViewportInteraction::ViewportInteractionRequestBus::EventResult(
|
||||
scaling, viewportId,
|
||||
&ViewportInteraction::ViewportInteractionRequestBus::Events::DeviceScalingFactor);
|
||||
scaling, viewportId, &ViewportInteraction::ViewportInteractionRequestBus::Events::DeviceScalingFactor);
|
||||
|
||||
return scaling;
|
||||
}
|
||||
|
||||
+4
@@ -46,6 +46,10 @@ namespace AzToolsFramework
|
||||
//! in screen space intersected an aabb in world space.
|
||||
bool AabbIntersectMouseRay(const ViewportInteraction::MouseInteraction& mouseInteraction, const AZ::Aabb& aabb);
|
||||
|
||||
//! Wrapper to perform an intersection between a ray and an aabb.
|
||||
//! Note: direction should be normalized (it is scaled internally by the editor pick distance).
|
||||
bool AabbIntersectRay(const AZ::Vector3& origin, const AZ::Vector3& direction, const AZ::Aabb& aabb, float& distance);
|
||||
|
||||
//! Return if a mouse interaction (pick ray) did intersect the tested EntityId.
|
||||
bool PickEntity(
|
||||
AZ::EntityId entityId, const ViewportInteraction::MouseInteraction& mouseInteraction, float& closestDistance, int viewportId);
|
||||
|
||||
+2
-2
@@ -161,8 +161,8 @@ namespace AzToolsFramework
|
||||
|
||||
// request list of visible entities from authoritative system
|
||||
EntityIdList nextVisibleEntityIds;
|
||||
ViewportInteraction::MainEditorViewportInteractionRequestBus::Event(
|
||||
viewportInfo.m_viewportId, &ViewportInteraction::MainEditorViewportInteractionRequestBus::Events::FindVisibleEntities,
|
||||
ViewportInteraction::EditorEntityViewportInteractionRequestBus::Event(
|
||||
viewportInfo.m_viewportId, &ViewportInteraction::EditorEntityViewportInteractionRequestBus::Events::FindVisibleEntities,
|
||||
nextVisibleEntityIds);
|
||||
|
||||
// only bother resorting if we know the lists have changed
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "ComponentModeTestDoubles.h"
|
||||
#include "ComponentModeTestFixture.h"
|
||||
#include "ComponentModeTestDoubles.h"
|
||||
|
||||
#include <AzCore/UserSettings/UserSettingsComponent.h>
|
||||
|
||||
@@ -15,17 +15,15 @@ namespace UnitTest
|
||||
{
|
||||
void ComponentModeTestFixture::SetUpEditorFixtureImpl()
|
||||
{
|
||||
using namespace AzToolsFramework;
|
||||
using namespace AzToolsFramework::ComponentModeFramework;
|
||||
namespace AztfCmf = AzToolsFramework::ComponentModeFramework;
|
||||
|
||||
auto* app = GetApplication();
|
||||
ASSERT_TRUE(app);
|
||||
|
||||
app->RegisterComponentDescriptor(PlaceholderEditorComponent::CreateDescriptor());
|
||||
app->RegisterComponentDescriptor(AnotherPlaceholderEditorComponent::CreateDescriptor());
|
||||
app->RegisterComponentDescriptor(DependentPlaceholderEditorComponent::CreateDescriptor());
|
||||
app->RegisterComponentDescriptor(AztfCmf::PlaceholderEditorComponent::CreateDescriptor());
|
||||
app->RegisterComponentDescriptor(AztfCmf::AnotherPlaceholderEditorComponent::CreateDescriptor());
|
||||
app->RegisterComponentDescriptor(AztfCmf::DependentPlaceholderEditorComponent::CreateDescriptor());
|
||||
app->RegisterComponentDescriptor(
|
||||
TestComponentModeComponent<OverrideMouseInteractionComponentMode>::CreateDescriptor());
|
||||
app->RegisterComponentDescriptor(IncompatiblePlaceholderEditorComponent::CreateDescriptor());
|
||||
AztfCmf::TestComponentModeComponent<AztfCmf::OverrideMouseInteractionComponentMode>::CreateDescriptor());
|
||||
app->RegisterComponentDescriptor(AztfCmf::IncompatiblePlaceholderEditorComponent::CreateDescriptor());
|
||||
}
|
||||
} // namespace UnitTest
|
||||
|
||||
Reference in New Issue
Block a user