Hasareej lyn 2301 cluster space 2 (#843)

Initial Implementation of the ViewportUi Space Cluster
This commit is contained in:
Hasareej
2021-05-26 17:12:30 +01:00
committed by GitHub
parent c716d812bc
commit ca5e629dac
6 changed files with 141 additions and 12 deletions
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="24px" height="24px" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<title>Icon / Local</title>
<g id="Icon-/-Local" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<rect id="Rectangle" x="0" y="0" width="24" height="24"></rect>
<polygon id="L" fill="#FFFFFF" fill-rule="nonzero" points="16.9658203 19 16.9658203 16.5 11.1748047 16.5 11.1748047 4.72265625 8.14746094 4.72265625 8.14746094 19"></polygon>
</g>
</svg>

After

Width:  |  Height:  |  Size: 575 B

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="24px" height="24px" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<title>Icon / Parent</title>
<g id="Icon-/-Parent" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<rect id="Rectangle" x="0" y="0" width="24" height="24"></rect>
<path d="M10.5449219,19 L10.5449219,13.921875 L11.84375,13.921875 C13.6145833,13.921875 14.9801432,13.514974 15.9404297,12.7011719 C16.9007161,11.8873698 17.3808594,10.7122396 17.3808594,9.17578125 C17.3808594,7.69791667 16.930013,6.58626302 16.0283203,5.84082031 C15.1266276,5.0953776 13.8098958,4.72265625 12.078125,4.72265625 L12.078125,4.72265625 L7.51757812,4.72265625 L7.51757812,19 L10.5449219,19 Z M11.5410156,11.4414062 L10.5449219,11.4414062 L10.5449219,7.203125 L11.921875,7.203125 C12.7486979,7.203125 13.3557943,7.37239583 13.7431641,7.7109375 C14.1305339,8.04947917 14.3242188,8.57356771 14.3242188,9.28320312 C14.3242188,9.98632812 14.093099,10.5218099 13.6308594,10.8896484 C13.1686198,11.257487 12.4720052,11.4414062 11.5410156,11.4414062 L11.5410156,11.4414062 Z" id="P" fill="#FFFFFF" fill-rule="nonzero"></path>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.2 KiB

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="24px" height="24px" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<title>Icon / World</title>
<g id="Icon-/-World" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<rect id="Rectangle" x="0" y="0" width="24" height="24"></rect>
<path d="M9.41210938,19 L11.3359375,11.5195312 C11.4205729,11.1875 11.5410156,10.632487 11.6972656,9.85449219 C11.8535156,9.0764974 11.9511719,8.51171875 11.9902344,8.16015625 C12.016276,8.44661458 12.1155599,9.00813802 12.2880859,9.84472656 C12.460612,10.6813151 12.5826823,11.2330729 12.6542969,11.5 L12.6542969,11.5 L14.5878906,19 L18.0351562,19 L21.6679688,4.72265625 L18.6894531,4.72265625 L16.8730469,12.515625 C16.7558594,12.984375 16.625651,13.5979818 16.4824219,14.3564453 C16.3391927,15.1149089 16.235026,15.7480469 16.1699219,16.2558594 C16.0983073,15.7285156 15.9941406,15.0970052 15.8574219,14.3613281 C15.7207031,13.625651 15.6067708,13.078776 15.515625,12.7207031 L15.515625,12.7207031 L13.4355469,4.72265625 L10.5742188,4.72265625 L8.49414062,12.7207031 C8.37044271,13.1503906 8.23860677,13.7542318 8.09863281,14.5322266 C7.95865885,15.3102214 7.86914062,15.8847656 7.83007812,16.2558594 C7.68684896,15.2011719 7.45572917,13.9544271 7.13671875,12.515625 L7.13671875,12.515625 L5.31054688,4.72265625 L2.33203125,4.72265625 L5.97460938,19 L9.41210938,19 Z" id="W" fill="#FFFFFF" fill-rule="nonzero"></path>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.5 KiB

@@ -354,6 +354,7 @@
<file>img/UI20/toolbar/Grid.svg</file>
<file>img/UI20/toolbar/Lighting.svg</file>
<file>img/UI20/toolbar/Load.svg</file>
<file>img/UI20/toolbar/Local.svg</file>
<file>img/UI20/toolbar/Locked.svg</file>
<file>img/UI20/toolbar/LUA.svg</file>
<file>img/UI20/toolbar/Material.svg</file>
@@ -362,6 +363,7 @@
<file>img/UI20/toolbar/Object_follow_terrain.svg</file>
<file>img/UI20/toolbar/Object_height.svg</file>
<file>img/UI20/toolbar/Object_list.svg</file>
<file>img/UI20/toolbar/Parent.svg</file>
<file>img/UI20/toolbar/particle.svg</file>
<file>img/UI20/toolbar/Play.svg</file>
<file>img/UI20/toolbar/Redo.svg</file>
@@ -380,6 +382,7 @@
<file>img/UI20/toolbar/undo.svg</file>
<file>img/UI20/toolbar/Unlocked.svg</file>
<file>img/UI20/toolbar/Vertex_snapping.svg</file>
<file>img/UI20/toolbar/World.svg</file>
<file>img/UI20/toolbar/X_axis.svg</file>
<file>img/UI20/toolbar/Y_axis.svg</file>
<file>img/UI20/toolbar/Z_axis.svg</file>
@@ -435,7 +435,7 @@ namespace AzToolsFramework
}
}
static void DestroyTransformModeSelectionCluster(const ViewportUi::ClusterId clusterId)
static void DestroyCluster(const ViewportUi::ClusterId clusterId)
{
ViewportUi::ViewportUiRequestBus::Event(
ViewportUi::DefaultViewportId,
@@ -483,6 +483,26 @@ namespace AzToolsFramework
return worldFromLocal.TransformPoint(CalculateCenterOffset(entityId, pivot));
}
void EditorTransformComponentSelection::UpdateSpaceCluster(const ReferenceFrame referenceFrame)
{
auto buttonIdFromFrameFn = [this](const ReferenceFrame referenceFrame) {
switch (referenceFrame)
{
case ReferenceFrame::Local:
return m_spaceCluster.m_localButtonId;
case ReferenceFrame::Parent:
return m_spaceCluster.m_parentButtonId;
case ReferenceFrame::World:
return m_spaceCluster.m_worldButtonId;
}
return m_spaceCluster.m_parentButtonId;
};
ViewportUi::ViewportUiRequestBus::Event(
ViewportUi::DefaultViewportId, &ViewportUi::ViewportUiRequestBus::Events::SetClusterActiveButton, m_spaceCluster.m_spaceClusterId,
buttonIdFromFrameFn(referenceFrame));
}
namespace ETCS
{
PivotOrientationResult CalculatePivotOrientation(
@@ -789,13 +809,13 @@ namespace AzToolsFramework
EntityIdManipulators& entityIdManipulators,
OptionalFrame& pivotOverrideFrame,
ViewportInteraction::KeyboardModifiers& prevModifiers,
bool& transformChangedInternally)
bool& transformChangedInternally, SpaceCluster spaceCluster)
{
AZ_PROFILE_FUNCTION(AZ::Debug::ProfileCategory::AzToolsFramework);
entityIdManipulators.m_manipulators->SetLocalPosition(action.LocalPosition());
const ReferenceFrame referenceFrame = ReferenceFrameFromModifiers(action.m_modifiers);
const ReferenceFrame referenceFrame = spaceCluster.m_spaceLock ? spaceCluster.m_currentSpace : ReferenceFrameFromModifiers(action.m_modifiers);
if (action.m_modifiers.Ctrl())
{
@@ -1027,6 +1047,7 @@ namespace AzToolsFramework
EditorManipulatorCommandUndoRedoRequestBus::Handler::BusConnect(entityContextId);
CreateTransformModeSelectionCluster();
CreateSpaceSelectionCluster();
RegisterActions();
SetupBoxSelect();
RefreshSelectedEntityIdsAndRegenerateManipulators();
@@ -1037,7 +1058,9 @@ namespace AzToolsFramework
m_selectedEntityIds.clear();
DestroyManipulators(m_entityIdManipulators);
DestroyTransformModeSelectionCluster(m_transformModeClusterId);
DestroyCluster(m_transformModeClusterId);
DestroyCluster(m_spaceCluster.m_spaceClusterId);
UnregisterActions();
m_pivotOverrideFrame.Reset();
@@ -1274,8 +1297,8 @@ namespace AzToolsFramework
[this, prevModifiers, manipulatorEntityIds](const LinearManipulator::Action& action) mutable -> void
{
UpdateTranslationManipulator(
action, manipulatorEntityIds->m_entityIds, m_entityIdManipulators,
m_pivotOverrideFrame, prevModifiers, m_transformChangedInternally);
action, manipulatorEntityIds->m_entityIds, m_entityIdManipulators, m_pivotOverrideFrame, prevModifiers,
m_transformChangedInternally, m_spaceCluster);
});
translationManipulators->InstallLinearManipulatorMouseUpCallback(
@@ -1305,8 +1328,8 @@ namespace AzToolsFramework
[this, prevModifiers, manipulatorEntityIds](const PlanarManipulator::Action& action) mutable -> void
{
UpdateTranslationManipulator(
action, manipulatorEntityIds->m_entityIds, m_entityIdManipulators,
m_pivotOverrideFrame, prevModifiers, m_transformChangedInternally);
action, manipulatorEntityIds->m_entityIds, m_entityIdManipulators, m_pivotOverrideFrame, prevModifiers,
m_transformChangedInternally, m_spaceCluster);
});
translationManipulators->InstallPlanarManipulatorMouseUpCallback(
@@ -1335,8 +1358,8 @@ namespace AzToolsFramework
[this, prevModifiers, manipulatorEntityIds](const SurfaceManipulator::Action& action) mutable -> void
{
UpdateTranslationManipulator(
action, manipulatorEntityIds->m_entityIds, m_entityIdManipulators,
m_pivotOverrideFrame, prevModifiers, m_transformChangedInternally);
action, manipulatorEntityIds->m_entityIds, m_entityIdManipulators, m_pivotOverrideFrame, prevModifiers,
m_transformChangedInternally, m_spaceCluster);
});
translationManipulators->InstallSurfaceManipulatorMouseUpCallback(
@@ -1414,7 +1437,7 @@ namespace AzToolsFramework
[this, prevModifiers, sharedRotationState]
(const AngularManipulator::Action& action) mutable -> void
{
const ReferenceFrame referenceFrame = ReferenceFrameFromModifiers(action.m_modifiers);
const ReferenceFrame referenceFrame = m_spaceCluster.m_spaceLock ? m_spaceCluster.m_currentSpace : ReferenceFrameFromModifiers(action.m_modifiers);
const AZ::Quaternion manipulatorOrientation = action.m_start.m_rotation * action.m_current.m_delta;
// store the pivot override frame when positioning the manipulator manually (ctrl)
@@ -2566,6 +2589,67 @@ namespace AzToolsFramework
m_transformModeSelectionHandler);
}
void EditorTransformComponentSelection::CreateSpaceSelectionCluster()
{
// create the cluster for switching spaces/reference frames
ViewportUi::ViewportUiRequestBus::EventResult(
m_spaceCluster.m_spaceClusterId, ViewportUi::DefaultViewportId, &ViewportUi::ViewportUiRequestBus::Events::CreateCluster,
ViewportUi::Alignment::TopRight);
// create and register the buttons (strings correspond to icons even if the values appear different)
m_spaceCluster.m_worldButtonId = RegisterClusterButton(m_spaceCluster.m_spaceClusterId, "World");
m_spaceCluster.m_parentButtonId = RegisterClusterButton(m_spaceCluster.m_spaceClusterId, "Parent");
m_spaceCluster.m_localButtonId = RegisterClusterButton(m_spaceCluster.m_spaceClusterId, "Local");
auto onButtonClicked = [this](ViewportUi::ButtonId buttonId) {
if (buttonId == m_spaceCluster.m_localButtonId)
{
// Unlock
if (m_spaceCluster.m_spaceLock && m_spaceCluster.m_currentSpace == ReferenceFrame::Local)
{
m_spaceCluster.m_spaceLock = false;
}
else
{
m_spaceCluster.m_spaceLock = true;
m_spaceCluster.m_currentSpace = ReferenceFrame::Local;
}
}
else if (buttonId == m_spaceCluster.m_parentButtonId)
{
// Unlock
if (m_spaceCluster.m_spaceLock && m_spaceCluster.m_currentSpace == ReferenceFrame::Parent)
{
m_spaceCluster.m_spaceLock = false;
}
else
{
m_spaceCluster.m_spaceLock = true;
m_spaceCluster.m_currentSpace = ReferenceFrame::Parent;
}
}
else if (buttonId == m_spaceCluster.m_worldButtonId)
{
// Unlock
if (m_spaceCluster.m_spaceLock && m_spaceCluster.m_currentSpace == ReferenceFrame::World)
{
m_spaceCluster.m_spaceLock = false;
}
else
{
m_spaceCluster.m_spaceLock = true;
m_spaceCluster.m_currentSpace = ReferenceFrame::World;
}
}
};
m_spaceCluster.m_spaceSelectionHandler = AZ::Event<ViewportUi::ButtonId>::Handler(onButtonClicked);
ViewportUi::ViewportUiRequestBus::Event(
ViewportUi::DefaultViewportId, &ViewportUi::ViewportUiRequestBus::Events::RegisterClusterEventHandler,
m_spaceCluster.m_spaceClusterId, m_spaceCluster.m_spaceSelectionHandler);
}
EditorTransformComponentSelectionRequests::Mode EditorTransformComponentSelection::GetTransformMode()
{
return m_mode;
@@ -3277,7 +3361,10 @@ namespace AzToolsFramework
ViewportInteraction::BuildMouseButtons(
QGuiApplication::mouseButtons()), m_boxSelect.Active());
const ReferenceFrame referenceFrame = ReferenceFrameFromModifiers(modifiers);
const ReferenceFrame referenceFrame =
m_spaceCluster.m_spaceLock ? m_spaceCluster.m_currentSpace : ReferenceFrameFromModifiers(modifiers);
UpdateSpaceCluster(referenceFrame);
bool refresh = false;
if (referenceFrame != m_referenceFrame)
@@ -106,6 +106,17 @@ namespace AzToolsFramework
World, //!< World space (space aligned to world axes - identity).
};
struct SpaceCluster
{
ViewportUi::ClusterId m_spaceClusterId;
ViewportUi::ButtonId m_localButtonId;
ViewportUi::ButtonId m_parentButtonId;
ViewportUi::ButtonId m_worldButtonId;
AZ::Event<ViewportUi::ButtonId>::Handler m_spaceSelectionHandler;
ReferenceFrame m_currentSpace = ReferenceFrame::Parent;
bool m_spaceLock = false;
};
//! Entity selection/interaction handling.
//! Provide a suite of functionality for manipulating entities, primarily through their TransformComponent.
class EditorTransformComponentSelection
@@ -160,6 +171,7 @@ namespace AzToolsFramework
void RegenerateManipulators();
void CreateTransformModeSelectionCluster();
void CreateSpaceSelectionCluster();
void ClearManipulatorTranslationOverride();
void ClearManipulatorOrientationOverride();
@@ -285,6 +297,9 @@ namespace AzToolsFramework
AZ::Event<ViewportUi::ButtonId>::Handler m_transformModeSelectionHandler; //!< Event handler for the Viewport UI cluster.
AzFramework::ClickDetector m_clickDetector; //!< Detect different types of mouse click.
AzFramework::CursorState m_cursorState; //!< Track the mouse position and delta movement each frame.
SpaceCluster m_spaceCluster;
void UpdateSpaceCluster(ReferenceFrame referenceFrame);
};
//! The ETCS (EntityTransformComponentSelection) namespace contains functions and data used exclusively by