Merge branch 'development' into Prefab/SaveAllPrefabs

Signed-off-by: srikappa-amzn <srikappa@amazon.com>
This commit is contained in:
srikappa-amzn
2021-09-09 09:08:22 -07:00
49 changed files with 5126 additions and 6360 deletions
@@ -44,7 +44,7 @@ namespace AzToolsFramework
const char AssetBundleSettingsFileExtension[] = "bundlesettings";
const char BundleFileExtension[] = "pak";
const char ComparisonRulesFileExtension[] = "rules";
const char ErrorWindowName[] = "AssetBundler";
[[maybe_unused]] const char ErrorWindowName[] = "AssetBundler";
const char* AssetFileInfoListComparison::ComparisonTypeNames[] = { "delta", "union", "intersection", "complement", "filepattern", "intersectioncount" };
const char* AssetFileInfoListComparison::FilePatternTypeNames[] = { "wildcard", "regex" };
const char DefaultTypeName[] = "default";
@@ -9,8 +9,8 @@
#include "EditorBoxSelect.h"
#include <AzFramework/Entity/EntityDebugDisplayBus.h>
#include <AzToolsFramework/ViewportSelection/EditorSelectionUtil.h>
#include <AzToolsFramework/Viewport/ViewportMessages.h>
#include <AzToolsFramework/ViewportSelection/EditorSelectionUtil.h>
#include <QApplication>
@@ -19,11 +19,15 @@ namespace AzToolsFramework
static const AZ::Color s_boxSelectColor = AZ::Color(1.0f, 1.0f, 1.0f, 0.4f);
static const float s_boxSelectLineWidth = 2.0f;
void EditorBoxSelect::HandleMouseInteraction(
const ViewportInteraction::MouseInteractionEvent& mouseInteraction)
void EditorBoxSelect::HandleMouseInteraction(const ViewportInteraction::MouseInteractionEvent& mouseInteraction)
{
AZ_PROFILE_FUNCTION(AzToolsFramework);
if (mouseInteraction.m_mouseEvent == ViewportInteraction::MouseEvent::Down)
{
m_cursorPositionAtDownEvent = mouseInteraction.m_mouseInteraction.m_mousePick.m_screenCoordinates;
}
m_cursorState.SetCurrentPosition(mouseInteraction.m_mouseInteraction.m_mousePick.m_screenCoordinates);
const auto selectClickEvent = ClickDetectorEventFromViewportInteraction(mouseInteraction);
@@ -35,12 +39,7 @@ namespace AzToolsFramework
m_leftMouseDown(mouseInteraction);
}
m_boxSelectRegion = QRect
{
ViewportInteraction::QPointFromScreenPoint(
mouseInteraction.m_mouseInteraction.m_mousePick.m_screenCoordinates),
QSize { 0, 0 }
};
m_boxSelectRegion = QRect{ ViewportInteraction::QPointFromScreenPoint(m_cursorPositionAtDownEvent), QSize{ 0, 0 } };
}
if (m_boxSelectRegion)
@@ -87,11 +86,11 @@ namespace AzToolsFramework
AZ::Vector2 viewportSize = AzToolsFramework::GetCameraState(viewportInfo.m_viewportId).m_viewportSize;
debugDisplay.DrawWireQuad2d(
AZ::Vector2(
aznumeric_cast<float>(m_boxSelectRegion->x()), aznumeric_cast<float>(m_boxSelectRegion->y())) / viewportSize,
AZ::Vector2(aznumeric_cast<float>(m_boxSelectRegion->x()), aznumeric_cast<float>(m_boxSelectRegion->y())) / viewportSize,
AZ::Vector2(
aznumeric_cast<float>(m_boxSelectRegion->x()) + aznumeric_cast<float>(m_boxSelectRegion->width()),
aznumeric_cast<float>(m_boxSelectRegion->y()) + aznumeric_cast<float>(m_boxSelectRegion->height())) / viewportSize,
aznumeric_cast<float>(m_boxSelectRegion->y()) + aznumeric_cast<float>(m_boxSelectRegion->height())) /
viewportSize,
0.f);
debugDisplay.DepthTestOn();
@@ -101,8 +100,7 @@ namespace AzToolsFramework
}
}
void EditorBoxSelect::DisplayScene(
const AzFramework::ViewportInfo& viewportInfo, AzFramework::DebugDisplayRequests& debugDisplay)
void EditorBoxSelect::DisplayScene(const AzFramework::ViewportInfo& viewportInfo, AzFramework::DebugDisplayRequests& debugDisplay)
{
if (m_displayScene)
{
@@ -122,15 +120,14 @@ namespace AzToolsFramework
m_mouseMove = mouseMove;
}
void EditorBoxSelect::InstallLeftMouseUp(
const AZStd::function<void()>& leftMouseUp)
void EditorBoxSelect::InstallLeftMouseUp(const AZStd::function<void()>& leftMouseUp)
{
m_leftMouseUp = leftMouseUp;
}
void EditorBoxSelect::InstallDisplayScene(
const AZStd::function<void(const AzFramework::ViewportInfo& viewportInfo,
AzFramework::DebugDisplayRequests& debugDisplay)>& displayScene)
const AZStd::function<void(const AzFramework::ViewportInfo& viewportInfo, AzFramework::DebugDisplayRequests& debugDisplay)>&
displayScene)
{
m_displayScene = displayScene;
}
@@ -81,5 +81,6 @@ namespace AzToolsFramework
ViewportInteraction::KeyboardModifiers m_previousModifiers; //!< Modifier keys active on the previous frame.
AzFramework::ClickDetector m_clickDetector; //!< Utility type to detect if a mouse click or move has occurred.
AzFramework::CursorState m_cursorState; //!< Utility type to track the current cursor position (and movement/delta).
AzFramework::ScreenPoint m_cursorPositionAtDownEvent; //!< The position of the cursor when first potentially starting a box select.
};
} // namespace AzToolsFramework
@@ -44,39 +44,46 @@ namespace AzToolsFramework
AZ_CVAR(
float,
cl_viewportGizmoAxisLineWidth,
ed_viewportGizmoAxisLineWidth,
4.0f,
nullptr,
AZ::ConsoleFunctorFlags::Null,
"The width of the line for the viewport axis gizmo");
AZ_CVAR(
float,
cl_viewportGizmoAxisLineLength,
ed_viewportGizmoAxisLineLength,
0.7f,
nullptr,
AZ::ConsoleFunctorFlags::Null,
"The length of the line for the viewport axis gizmo");
AZ_CVAR(
float,
cl_viewportGizmoAxisLabelOffset,
ed_viewportGizmoAxisLabelOffset,
1.15f,
nullptr,
AZ::ConsoleFunctorFlags::Null,
"The offset of the label for the viewport axis gizmo");
AZ_CVAR(
float,
cl_viewportGizmoAxisLabelSize,
ed_viewportGizmoAxisLabelSize,
1.0f,
nullptr,
AZ::ConsoleFunctorFlags::Null,
"The size of each label for the viewport axis gizmo");
AZ_CVAR(
AZ::Vector2,
cl_viewportGizmoAxisScreenPosition,
ed_viewportGizmoAxisScreenPosition,
AZ::Vector2(0.045f, 0.9f),
nullptr,
AZ::ConsoleFunctorFlags::Null,
"The screen position of the gizmo in normalized (0-1) ndc space");
AZ_CVAR(
bool,
ed_viewportStickySelect,
true,
nullptr,
AZ::ConsoleFunctorFlags::Null,
"Sticky select implies a single click will not change selection with an entity already selected");
// strings related to new viewport interaction model (EditorTransformComponentSelection)
static const char* const s_togglePivotTitleRightClick = "Toggle pivot";
@@ -991,14 +998,19 @@ namespace AzToolsFramework
// ask the visible entity data cache if the entity is selectable in the viewport
// (useful in the context of drawing when we only care about entities we can see)
static bool SelectableInVisibleViewportCache(const EditorVisibleEntityDataCache& entityDataCache, const AZ::EntityId entityId)
// note: return the index if it is selectable, nullopt otherwise
static AZStd::optional<size_t> SelectableInVisibleViewportCache(
const EditorVisibleEntityDataCache& entityDataCache, const AZ::EntityId entityId)
{
if (auto entityIndex = entityDataCache.GetVisibleEntityIndexFromId(entityId))
{
return entityDataCache.IsVisibleEntitySelectableInViewport(*entityIndex);
if (entityDataCache.IsVisibleEntitySelectableInViewport(*entityIndex))
{
return *entityIndex;
}
}
return false;
return AZStd::nullopt;
}
static AZ::ComponentId GetTransformComponentId(const AZ::EntityId entityId)
@@ -1709,17 +1721,17 @@ namespace AzToolsFramework
m_pivotOverrideFrame.Reset();
}
bool EditorTransformComponentSelection::SelectDeselect(const AZ::EntityId entityIdUnderCursor)
bool EditorTransformComponentSelection::SelectDeselect(const AZ::EntityId entityId)
{
AZ_PROFILE_FUNCTION(AzToolsFramework);
if (entityIdUnderCursor.IsValid())
if (entityId.IsValid())
{
if (IsEntitySelectedInternal(entityIdUnderCursor, m_selectedEntityIds))
if (IsEntitySelectedInternal(entityId, m_selectedEntityIds))
{
if (!UndoRedoOperationInProgress())
{
RemoveEntityFromSelection(entityIdUnderCursor);
RemoveEntityFromSelection(entityId);
const auto nextEntityIds = EntityIdVectorFromContainer(m_selectedEntityIds);
@@ -1742,7 +1754,7 @@ namespace AzToolsFramework
{
if (!UndoRedoOperationInProgress())
{
AddEntityToSelection(entityIdUnderCursor);
AddEntityToSelection(entityId);
const auto nextEntityIds = EntityIdVectorFromContainer(m_selectedEntityIds);
@@ -1783,25 +1795,21 @@ namespace AzToolsFramework
// for entities selected with no bounds of their own (just TransformComponent)
// check selection against the selection indicator aabb
for (AZ::EntityId entityId : m_selectedEntityIds)
for (const AZ::EntityId& entityId : m_selectedEntityIds)
{
if (!SelectableInVisibleViewportCache(*m_entityDataCache, entityId))
if (const auto entityIndex = SelectableInVisibleViewportCache(*m_entityDataCache, entityId); entityIndex.has_value())
{
continue;
}
const AZ::Transform& worldFromLocal = m_entityDataCache->GetVisibleEntityTransform(*entityIndex);
const AZ::Vector3 boxPosition = worldFromLocal.TransformPoint(CalculateCenterOffset(entityId, m_pivotMode));
const AZ::Vector3 scaledSize =
AZ::Vector3(s_pivotSize) * CalculateScreenToWorldMultiplier(worldFromLocal.GetTranslation(), cameraState);
AZ::Transform worldFromLocal;
AZ::TransformBus::EventResult(worldFromLocal, entityId, &AZ::TransformBus::Events::GetWorldTM);
const AZ::Vector3 boxPosition = worldFromLocal.TransformPoint(CalculateCenterOffset(entityId, m_pivotMode));
const AZ::Vector3 scaledSize =
AZ::Vector3(s_pivotSize) * CalculateScreenToWorldMultiplier(worldFromLocal.GetTranslation(), cameraState);
if (AabbIntersectMouseRay(
mouseInteraction.m_mouseInteraction, AZ::Aabb::CreateFromMinMax(boxPosition - scaledSize, boxPosition + scaledSize)))
{
m_cachedEntityIdUnderCursor = entityId;
if (AabbIntersectMouseRay(
mouseInteraction.m_mouseInteraction,
AZ::Aabb::CreateFromMinMax(boxPosition - scaledSize, boxPosition + scaledSize)))
{
m_cachedEntityIdUnderCursor = entityId;
}
}
}
@@ -3490,7 +3498,7 @@ namespace AzToolsFramework
const auto cameraProjection = AzFramework::CameraProjection(gizmoCameraState);
// screen space offset to move the 2d gizmo around
const AZ::Vector2 screenOffset = AZ::Vector2(cl_viewportGizmoAxisScreenPosition) - AZ::Vector2(0.5f, 0.5f);
const AZ::Vector2 screenOffset = AZ::Vector2(ed_viewportGizmoAxisScreenPosition) - AZ::Vector2(0.5f, 0.5f);
// map from a position in world space (relative to the the gizmo camera near the origin) to a position in
// screen space
@@ -3502,7 +3510,7 @@ namespace AzToolsFramework
};
// get all important axis positions in screen space
const float lineLength = cl_viewportGizmoAxisLineLength;
const float lineLength = ed_viewportGizmoAxisLineLength;
const auto gizmoStart = calculateGizmoAxis(AZ::Vector3::CreateZero());
const auto gizmoEndAxisX = calculateGizmoAxis(-AZ::Vector3::CreateAxisX() * lineLength);
const auto gizmoEndAxisY = calculateGizmoAxis(-AZ::Vector3::CreateAxisY() * lineLength);
@@ -3513,7 +3521,7 @@ namespace AzToolsFramework
const AZ::Vector2 gizmoAxisZ = gizmoEndAxisZ - gizmoStart;
// draw the axes of the gizmo
debugDisplay.SetLineWidth(cl_viewportGizmoAxisLineWidth);
debugDisplay.SetLineWidth(ed_viewportGizmoAxisLineWidth);
debugDisplay.SetColor(AZ::Colors::Red);
debugDisplay.DrawLine2d(gizmoStart, gizmoEndAxisX, 1.0f);
debugDisplay.SetColor(AZ::Colors::Lime);
@@ -3522,14 +3530,14 @@ namespace AzToolsFramework
debugDisplay.DrawLine2d(gizmoStart, gizmoEndAxisZ, 1.0f);
debugDisplay.SetLineWidth(1.0f);
const float labelOffset = cl_viewportGizmoAxisLabelOffset;
const float labelOffset = ed_viewportGizmoAxisLabelOffset;
const float screenScale = GetScreenDisplayScaling(viewportId);
const auto labelXScreenPosition = (gizmoStart + (gizmoAxisX * labelOffset)) * editorCameraState.m_viewportSize * screenScale;
const auto labelYScreenPosition = (gizmoStart + (gizmoAxisY * labelOffset)) * editorCameraState.m_viewportSize * screenScale;
const auto labelZScreenPosition = (gizmoStart + (gizmoAxisZ * labelOffset)) * editorCameraState.m_viewportSize * screenScale;
// draw the label of of each axis for the gizmo
const float labelSize = cl_viewportGizmoAxisLabelSize;
const float labelSize = ed_viewportGizmoAxisLabelSize;
debugDisplay.SetColor(AZ::Colors::White);
debugDisplay.Draw2dTextLabel(labelXScreenPosition.GetX(), labelXScreenPosition.GetY(), labelSize, "X", true);
debugDisplay.Draw2dTextLabel(labelYScreenPosition.GetX(), labelYScreenPosition.GetY(), labelSize, "Y", true);
@@ -9,6 +9,7 @@
#pragma once
#include <AzCore/Component/TransformBus.h>
#include <AzCore/Console/IConsole.h>
#include <AzCore/std/containers/vector.h>
#include <AzCore/std/optional.h>
#include <AzCore/std/smart_ptr/unique_ptr.h>
@@ -32,6 +33,8 @@
namespace AzToolsFramework
{
AZ_CVAR_EXTERNED(bool, ed_viewportStickySelect);
class EditorVisibleEntityDataCache;
using EntityIdSet = AZStd::unordered_set<AZ::EntityId>; //!< Alias for unordered_set of EntityIds.
@@ -170,14 +173,11 @@ namespace AzToolsFramework
//! ViewportInteraction::ViewportSelectionRequests
//! Intercept all viewport mouse events and respond to inputs.
bool HandleMouseInteraction(
const ViewportInteraction::MouseInteractionEvent& mouseInteraction) override;
bool HandleMouseInteraction(const ViewportInteraction::MouseInteractionEvent& mouseInteraction) override;
void DisplayViewportSelection(
const AzFramework::ViewportInfo& viewportInfo,
AzFramework::DebugDisplayRequests& debugDisplay) override;
const AzFramework::ViewportInfo& viewportInfo, AzFramework::DebugDisplayRequests& debugDisplay) override;
void DisplayViewportSelection2d(
const AzFramework::ViewportInfo& viewportInfo,
AzFramework::DebugDisplayRequests& debugDisplay) override;
const AzFramework::ViewportInfo& viewportInfo, AzFramework::DebugDisplayRequests& debugDisplay) override;
//! Add an entity to the current selection
void AddEntityToSelection(AZ::EntityId entityId);
@@ -206,7 +206,7 @@ namespace AzToolsFramework
bool IsEntitySelected(AZ::EntityId entityId) const;
void SetSelectedEntities(const EntityIdList& entityIds);
void DeselectEntities();
bool SelectDeselect(AZ::EntityId entityIdUnderCursor);
bool SelectDeselect(AZ::EntityId entityId);
void RefreshSelectedEntityIds();
void RefreshSelectedEntityIds(const EntityIdList& selectedEntityIds);
@@ -253,11 +253,10 @@ namespace AzToolsFramework
void SnapSelectedEntitiesToWorldGrid(float gridSize) override;
// EditorManipulatorCommandUndoRedoRequestBus ...
void UndoRedoEntityManipulatorCommand(
AZ::u8 pivotOverride, const AZ::Transform& transform, AZ::EntityId entityId) override;
void UndoRedoEntityManipulatorCommand(AZ::u8 pivotOverride, const AZ::Transform& transform, AZ::EntityId entityId) override;
// EditorContextMenuBus...
void PopulateEditorGlobalContextMenu(QMenu* menu, const AZ::Vector2 & point, int flags) override;
void PopulateEditorGlobalContextMenu(QMenu* menu, const AZ::Vector2& point, int flags) override;
int GetMenuPosition() const override;
AZStd::string GetMenuIdentifier() const override;
@@ -266,8 +265,7 @@ namespace AzToolsFramework
// ToolsApplicationNotificationBus ...
void BeforeEntitySelectionChanged() override;
void AfterEntitySelectionChanged(
const EntityIdList& newlySelectedEntities, const EntityIdList& newlyDeselectedEntities) override;
void AfterEntitySelectionChanged(const EntityIdList& newlySelectedEntities, const EntityIdList& newlyDeselectedEntities) override;
// TransformNotificationBus ...
void OnTransformChanged(const AZ::Transform& localTM, const AZ::Transform& worldTM) override;
@@ -318,7 +316,8 @@ namespace AzToolsFramework
EntityIdManipulators m_entityIdManipulators; //!< Mapping from a Manipulator to potentially many EntityIds.
EditorBoxSelect m_boxSelect; //!< Type responsible for handling box select.
AZStd::unique_ptr<EntityManipulatorCommand> m_manipulatorMoveCommand; //!< Track adjustments to manipulator translation and orientation (during mouse press/move).
//! Track adjustments to manipulator translation and orientation (during mouse press/move).
AZStd::unique_ptr<EntityManipulatorCommand> m_manipulatorMoveCommand;
AZStd::vector<AZStd::unique_ptr<QAction>> m_actions; //!< What actions are tied to this handler.
ViewportInteraction::KeyboardModifiers m_previousModifiers; //!< What modifiers were held last frame.
EditorContextMenu m_contextMenu; //!< Viewport right click context menu.
@@ -328,8 +327,10 @@ namespace AzToolsFramework
ReferenceFrame m_referenceFrame = ReferenceFrame::Parent; //!< What reference frame is the Manipulator currently operating in.
Frame m_axisPreview; //!< Axes of entity at the time of mouse down to indicate delta of translation.
bool m_triedToRefresh = false; //!< Did a refresh event occur to recalculate the current Manipulator transform.
bool m_didSetSelectedEntities = false; //!< Was EditorTransformComponentSelection responsible for the most recent entity selection change.
bool m_selectedEntityIdsAndManipulatorsDirty = false; //!< Do the active manipulators need to recalculated after a modification (lock/visibility etc).
//! Was EditorTransformComponentSelection responsible for the most recent entity selection change.
bool m_didSetSelectedEntities = false;
//! Do the active manipulators need to recalculated after a modification (lock/visibility etc).
bool m_selectedEntityIdsAndManipulatorsDirty = false;
bool m_transformChangedInternally = false; //!< Was an OnTransformChanged event triggered internally or not.
ViewportUi::ClusterId m_transformModeClusterId; //!< Id of the Viewport UI cluster for changing transform mode.
ViewportUi::ButtonId m_translateButtonId; //!< Id of the Viewport UI button for translate mode.
@@ -363,15 +364,13 @@ namespace AzToolsFramework
//! Calculate the orientation for a group of entities based on the incoming reference frame.
template<typename EntityIdMap>
PivotOrientationResult CalculatePivotOrientationForEntityIds(
const EntityIdMap& entityIdMap, const ReferenceFrame referenceFrame);
PivotOrientationResult CalculatePivotOrientationForEntityIds(const EntityIdMap& entityIdMap, const ReferenceFrame referenceFrame);
//! Calculate the orientation for a group of entities based on the incoming
//! reference frame with possible pivot override.
template<typename EntityIdMap>
PivotOrientationResult CalculateSelectionPivotOrientation(
const EntityIdMap& entityIdMap, const OptionalFrame& pivotOverrideFrame,
const ReferenceFrame referenceFrame);
const EntityIdMap& entityIdMap, const OptionalFrame& pivotOverrideFrame, const ReferenceFrame referenceFrame);
void SetEntityWorldTranslation(AZ::EntityId entityId, const AZ::Vector3& worldTranslation, bool& internal);
void SetEntityLocalTranslation(AZ::EntityId entityId, const AZ::Vector3& localTranslation, bool& internal);