Remove redundant API calls from EditorViewportWidget and use new WorldToScreen call (#4022)
* remove redundant API calls from EditorViewportWidget and use new WorldToScreen call Signed-off-by: hultonha <hultonha@amazon.co.uk> * remove additional pre/post widget render calls that are no longer required Signed-off-by: hultonha <hultonha@amazon.co.uk>
This commit is contained in:
+3
-4
@@ -11,6 +11,7 @@
|
||||
#include <AzCore/Component/TransformBus.h>
|
||||
#include <AzCore/Math/VertexContainerInterface.h>
|
||||
#include <AzCore/std/sort.h>
|
||||
#include <AzFramework/Viewport/ViewportScreen.h>
|
||||
#include <AzToolsFramework/ComponentMode/EditorComponentModeBus.h>
|
||||
#include <AzToolsFramework/Manipulators/LinearManipulator.h>
|
||||
#include <AzToolsFramework/Manipulators/ManipulatorSnapping.h>
|
||||
@@ -363,9 +364,7 @@ namespace AzToolsFramework
|
||||
boxSelectData.m_activeSelection = boxSelectData.m_startSelection;
|
||||
}
|
||||
|
||||
// set the widget context before calls to ViewportWorldToScreen so we are not
|
||||
// going to constantly be pushing/popping the widget context
|
||||
ViewportInteraction::WidgetContextGuard widgetContextGuard(viewportId);
|
||||
const AzFramework::CameraState cameraState = GetCameraState(viewportId);
|
||||
|
||||
// box select active (clicking and dragging)
|
||||
if (editorBoxSelect.BoxRegion())
|
||||
@@ -385,7 +384,7 @@ namespace AzToolsFramework
|
||||
found, fixedVertices, &AZ::FixedVerticesRequestBus<Vertex>::Handler::GetVertex, vertexIndex, localVertex);
|
||||
|
||||
const AZ::Vector3 worldVertex = worldFromLocal.TransformPoint(AZ::AdaptVertexOut<Vertex>(localVertex));
|
||||
const AzFramework::ScreenPoint screenPosition = GetScreenPosition(viewportId, worldVertex);
|
||||
const AzFramework::ScreenPoint screenPosition = AzFramework::WorldToScreen(worldVertex, cameraState);
|
||||
|
||||
// check if a vertex is inside the box select region
|
||||
if (editorBoxSelect.BoxRegion()->contains(ViewportInteraction::QPointFromScreenPoint(screenPosition)))
|
||||
|
||||
@@ -254,11 +254,6 @@ namespace AzToolsFramework
|
||||
virtual bool ShowingWorldSpace() = 0;
|
||||
//! Return the widget to use as the parent for the viewport context menu.
|
||||
virtual QWidget* GetWidgetForViewportContextMenu() = 0;
|
||||
//! Set the render context for the viewport.
|
||||
virtual void BeginWidgetContext() = 0;
|
||||
//! End the render context for the viewport.
|
||||
//! Return to previous context before Begin was called.
|
||||
virtual void EndWidgetContext() = 0;
|
||||
|
||||
protected:
|
||||
~MainEditorViewportInteractionRequests() = default;
|
||||
@@ -297,28 +292,6 @@ namespace AzToolsFramework
|
||||
|
||||
//! Type to inherit to implement MainEditorViewportInteractionRequests.
|
||||
using ViewportMouseCursorRequestBus = AZ::EBus<ViewportMouseCursorRequests, ViewportEBusTraits>;
|
||||
|
||||
//! A helper to wrap Begin/EndWidgetContext.
|
||||
class WidgetContextGuard
|
||||
{
|
||||
public:
|
||||
explicit WidgetContextGuard(const int viewportId)
|
||||
: m_viewportId(viewportId)
|
||||
{
|
||||
MainEditorViewportInteractionRequestBus::Event(
|
||||
viewportId, &MainEditorViewportInteractionRequestBus::Events::BeginWidgetContext);
|
||||
}
|
||||
|
||||
~WidgetContextGuard()
|
||||
{
|
||||
MainEditorViewportInteractionRequestBus::Event(
|
||||
m_viewportId, &MainEditorViewportInteractionRequestBus::Events::EndWidgetContext);
|
||||
}
|
||||
|
||||
private:
|
||||
int m_viewportId; //!< The viewport id the widget context is being set on.
|
||||
};
|
||||
|
||||
} // namespace ViewportInteraction
|
||||
|
||||
//! Utility function to return EntityContextId.
|
||||
|
||||
+2
-5
@@ -11,6 +11,7 @@
|
||||
#include <AzCore/Console/Console.h>
|
||||
#include <AzFramework/Entity/EntityDebugDisplayBus.h>
|
||||
#include <AzFramework/Viewport/CameraState.h>
|
||||
#include <AzFramework/Viewport/ViewportScreen.h>
|
||||
#include <AzFramework/Visibility/BoundsBus.h>
|
||||
#include <AzToolsFramework/API/EditorViewportIconDisplayInterface.h>
|
||||
#include <AzToolsFramework/ToolsComponents/EditorEntityIconComponentBus.h>
|
||||
@@ -118,10 +119,6 @@ namespace AzToolsFramework
|
||||
|
||||
const int viewportId = mouseInteraction.m_mouseInteraction.m_interactionId.m_viewportId;
|
||||
|
||||
// set the widget context before calls to ViewportWorldToScreen so we are not
|
||||
// going to constantly be pushing/popping the widget context
|
||||
ViewportInteraction::WidgetContextGuard widgetContextGuard(viewportId);
|
||||
|
||||
const bool helpersVisible = HelpersVisible();
|
||||
|
||||
// selecting new entities
|
||||
@@ -145,7 +142,7 @@ namespace AzToolsFramework
|
||||
const AZ::Vector3& entityPosition = m_entityDataCache->GetVisibleEntityPosition(entityCacheIndex);
|
||||
|
||||
// selecting based on 2d icon - should only do it when visible and not selected
|
||||
const AzFramework::ScreenPoint screenPosition = GetScreenPosition(viewportId, entityPosition);
|
||||
const AzFramework::ScreenPoint screenPosition = AzFramework::WorldToScreen(entityPosition, cameraState);
|
||||
|
||||
const float distSqFromCamera = cameraState.m_position.GetDistanceSq(entityPosition);
|
||||
const auto iconRange = static_cast<float>(GetIconScale(distSqFromCamera) * s_iconSize * 0.5f);
|
||||
|
||||
-12
@@ -48,18 +48,6 @@ namespace AzToolsFramework
|
||||
return AZ::GetMax(projectedCameraDistance, cameraState.m_nearClip) / apparentDistance;
|
||||
}
|
||||
|
||||
AzFramework::ScreenPoint GetScreenPosition(const int viewportId, const AZ::Vector3& worldTranslation)
|
||||
{
|
||||
AZ_PROFILE_FUNCTION(AzToolsFramework);
|
||||
|
||||
auto screenPosition = AzFramework::ScreenPoint(0, 0);
|
||||
ViewportInteraction::ViewportInteractionRequestBus::EventResult(
|
||||
screenPosition, viewportId, &ViewportInteraction::ViewportInteractionRequestBus::Events::ViewportWorldToScreen,
|
||||
worldTranslation);
|
||||
|
||||
return screenPosition;
|
||||
}
|
||||
|
||||
bool AabbIntersectRay(const AZ::Vector3& origin, const AZ::Vector3& direction, const AZ::Aabb& aabb, float& distance)
|
||||
{
|
||||
AZ_PROFILE_FUNCTION(AzToolsFramework);
|
||||
|
||||
-3
@@ -39,9 +39,6 @@ namespace AzToolsFramework
|
||||
//! Calculate scale factor based on distance from camera
|
||||
float CalculateScreenToWorldMultiplier(const AZ::Vector3& worldPosition, const AzFramework::CameraState& cameraState);
|
||||
|
||||
//! Map from world space to screen space.
|
||||
AzFramework::ScreenPoint GetScreenPosition(int viewportId, const AZ::Vector3& worldTranslation);
|
||||
|
||||
//! Given a mouse interaction, determine if the pick ray from its position
|
||||
//! in screen space intersected an aabb in world space.
|
||||
bool AabbIntersectMouseRay(const ViewportInteraction::MouseInteraction& mouseInteraction, const AZ::Aabb& aabb);
|
||||
|
||||
+3
-12
@@ -412,10 +412,7 @@ namespace AzToolsFramework
|
||||
potentialSelectedEntityIds.clear();
|
||||
}
|
||||
|
||||
// set the widget context before calls to ViewportWorldToScreen so we are not
|
||||
// going to constantly be pushing/popping the widget context
|
||||
ViewportInteraction::WidgetContextGuard widgetContextGuard(viewportId);
|
||||
|
||||
const AzFramework::CameraState cameraState = GetCameraState(viewportId);
|
||||
for (size_t entityCacheIndex = 0; entityCacheIndex < entityDataCache.VisibleEntityDataCount(); ++entityCacheIndex)
|
||||
{
|
||||
if (entityDataCache.IsVisibleEntityLocked(entityCacheIndex) || !entityDataCache.IsVisibleEntityVisible(entityCacheIndex))
|
||||
@@ -426,7 +423,7 @@ namespace AzToolsFramework
|
||||
const AZ::EntityId entityId = entityDataCache.GetVisibleEntityId(entityCacheIndex);
|
||||
const AZ::Vector3& entityPosition = entityDataCache.GetVisibleEntityPosition(entityCacheIndex);
|
||||
|
||||
const AzFramework::ScreenPoint screenPosition = GetScreenPosition(viewportId, entityPosition);
|
||||
const AzFramework::ScreenPoint screenPosition = AzFramework::WorldToScreen(entityPosition, cameraState);
|
||||
|
||||
if (currentKeyboardModifiers.Ctrl())
|
||||
{
|
||||
@@ -1779,13 +1776,7 @@ namespace AzToolsFramework
|
||||
|
||||
CheckDirtyEntityIds();
|
||||
|
||||
const int viewportId = mouseInteraction.m_mouseInteraction.m_interactionId.m_viewportId;
|
||||
|
||||
const AzFramework::CameraState cameraState = GetCameraState(viewportId);
|
||||
|
||||
// set the widget context before calls to ViewportWorldToScreen so we are not
|
||||
// going to constantly be pushing/popping the widget context
|
||||
ViewportInteraction::WidgetContextGuard widgetContextGuard(viewportId);
|
||||
const AzFramework::CameraState cameraState = GetCameraState(mouseInteraction.m_mouseInteraction.m_interactionId.m_viewportId);
|
||||
|
||||
m_cachedEntityIdUnderCursor = m_editorHelpers->HandleMouseInteraction(cameraState, mouseInteraction);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user