Merge remote-tracking branch 'upstream/stabilization/2106' into nvsickle/MergeStabilizationJun18

This commit is contained in:
nvsickle
2021-06-18 13:25:53 -07:00
578 changed files with 19526 additions and 20039 deletions
@@ -1,47 +1,36 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#include <AzCore/EBus/EBus.h>
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#include <AzCore/EBus/EBus.h>
namespace AzToolsFramework
{
using EntityIdList = AZStd::vector<AZ::EntityId>;
/*!
* Bus for notifications about entity transform changes from the editor viewport
*/
class EditorTransformChangeNotifications
: public AZ::EBusTraits
//! Notifications about entity transform changes from the editor.
class EditorTransformChangeNotifications : public AZ::EBusTraits
{
public:
virtual ~EditorTransformChangeNotifications() = default;
//! A notification that these entities had their transforms changed due to a user interaction in the editor.
//! @param entityIds Entities that had their transform changed.
virtual void OnEntityTransformChanged([[maybe_unused]] const AzToolsFramework::EntityIdList& entityIds)
{
}
/*!
* Notification that the specified entities are about to have their transforms changed due to user interaction in the editor viewport
*
* \param entityIds Entities about to be changed
*/
virtual void OnEntityTransformChanging(const AzToolsFramework::EntityIdList& /*entityIds*/) {};
/*!
* Notification that the specified entities had their transforms changed due to user interaction in the editor viewport
*
* \param entityIds Entities changed
*/
virtual void OnEntityTransformChanged(const AzToolsFramework::EntityIdList& /*entityIds*/) {};
protected:
~EditorTransformChangeNotifications() = default;
};
using EditorTransformChangeNotificationBus = AZ::EBus<EditorTransformChangeNotifications>;
} // namespace AzToolsFramework
@@ -27,6 +27,7 @@
#include <AzFramework/Components/TransformComponent.h>
#include <AzFramework/Visibility/EntityBoundsUnionBus.h>
#include <AzToolsFramework/API/EntityCompositionRequestBus.h>
#include <AzToolsFramework/Entity/EditorEntityTransformBus.h>
#include <AzToolsFramework/API/EntityPropertyEditorRequestsBus.h>
#include <AzToolsFramework/API/ToolsApplicationAPI.h>
#include <AzToolsFramework/Entity/EditorEntityContextBus.h>
@@ -944,7 +945,7 @@ namespace AzToolsFramework
return AZ::Success();
}
AZ::u32 TransformComponent::ParentChanged()
AZ::u32 TransformComponent::ParentChangedInspector()
{
AZ::u32 refreshLevel = AZ::Edit::PropertyRefreshLevels::None;
@@ -974,12 +975,23 @@ namespace AzToolsFramework
return refreshLevel;
}
AZ::u32 TransformComponent::TransformChanged()
AZ::u32 TransformComponent::TransformChangedInspector()
{
if (TransformChanged())
{
AzToolsFramework::EditorTransformChangeNotificationBus::Broadcast(
&AzToolsFramework::EditorTransformChangeNotificationBus::Events::OnEntityTransformChanged,
EntityIdList{ GetEntityId() });
}
return AZ::Edit::PropertyRefreshLevels::None;
}
bool TransformComponent::TransformChanged()
{
if (!m_suppressTransformChangedEvent)
{
auto parent = GetParentTransformComponent();
if (parent)
if (auto parent = GetParentTransformComponent())
{
OnTransformChanged(parent->GetLocalTM(), parent->GetWorldTM());
}
@@ -987,13 +999,15 @@ namespace AzToolsFramework
{
OnTransformChanged(AZ::Transform::Identity(), AZ::Transform::Identity());
}
return true;
}
return AZ::Edit::PropertyRefreshLevels::None;
return false;
}
// This is called when our transform changes static state.
AZ::u32 TransformComponent::StaticChanged()
AZ::u32 TransformComponent::StaticChangedInspector()
{
AzToolsFramework::ToolsApplicationEvents::Bus::Broadcast(
&AzToolsFramework::ToolsApplicationEvents::Bus::Events::InvalidatePropertyDisplay,
@@ -1175,10 +1189,10 @@ namespace AzToolsFramework
Attribute(AZ::Edit::Attributes::AutoExpand, true)->
DataElement(AZ::Edit::UIHandlers::Default, &TransformComponent::m_parentEntityId, "Parent entity", "")->
Attribute(AZ::Edit::Attributes::ChangeValidate, &TransformComponent::ValidatePotentialParent)->
Attribute(AZ::Edit::Attributes::ChangeNotify, &TransformComponent::ParentChanged)->
Attribute(AZ::Edit::Attributes::ChangeNotify, &TransformComponent::ParentChangedInspector)->
Attribute(AZ::Edit::Attributes::SliceFlags, AZ::Edit::SliceFlags::DontGatherReference | AZ::Edit::SliceFlags::NotPushableOnSliceRoot)->
DataElement(AZ::Edit::UIHandlers::Default, &TransformComponent::m_editorTransform, "Values", "")->
Attribute(AZ::Edit::Attributes::ChangeNotify, &TransformComponent::TransformChanged)->
Attribute(AZ::Edit::Attributes::ChangeNotify, &TransformComponent::TransformChangedInspector)->
Attribute(AZ::Edit::Attributes::AutoExpand, true)->
DataElement(AZ::Edit::UIHandlers::Button, &TransformComponent::m_addNonUniformScaleButton, "", "")->
Attribute(AZ::Edit::Attributes::ButtonText, "Add non-uniform scale")->
@@ -1189,7 +1203,7 @@ namespace AzToolsFramework
EnumAttribute(AZ::TransformConfig::ParentActivationTransformMode::MaintainOriginalRelativeTransform, "Original relative transform")->
EnumAttribute(AZ::TransformConfig::ParentActivationTransformMode::MaintainCurrentWorldTransform, "Current world transform")->
DataElement(AZ::Edit::UIHandlers::Default, &TransformComponent::m_isStatic ,"Static", "Static entities are highly optimized and cannot be moved during runtime.")->
Attribute(AZ::Edit::Attributes::ChangeNotify, &TransformComponent::StaticChanged)->
Attribute(AZ::Edit::Attributes::ChangeNotify, &TransformComponent::StaticChangedInspector)->
DataElement(AZ::Edit::UIHandlers::Default, &TransformComponent::m_cachedWorldTransformParent, "Cached Parent Entity", "")->
Attribute(AZ::Edit::Attributes::SliceFlags, AZ::Edit::SliceFlags::DontGatherReference | AZ::Edit::SliceFlags::NotPushable)->
Attribute(AZ::Edit::Attributes::Visibility, AZ::Edit::PropertyVisibility::Hide)->
@@ -182,9 +182,12 @@ namespace AzToolsFramework
static void Reflect(AZ::ReflectContext* context);
AZ::Outcome<void, AZStd::string> ValidatePotentialParent(void* newValue, const AZ::Uuid& valueType);
AZ::u32 ParentChanged();
AZ::u32 TransformChanged();
AZ::u32 StaticChanged();
AZ::u32 TransformChangedInspector();
AZ::u32 ParentChangedInspector();
AZ::u32 StaticChangedInspector();
bool TransformChanged();
AZ::Transform GetLocalTranslationTM() const;
AZ::Transform GetLocalRotationTM() const;
@@ -165,11 +165,13 @@ namespace UnitTest
void EditorEntityComponentChangeDetector::OnEntityTransformChanged(
const AzToolsFramework::EntityIdList& entityIds)
{
m_entityIds = entityIds;
for (const AZ::EntityId& entityId : entityIds)
{
if (const auto* entity = GetEntityById(entityId))
{
if (AZ::Component * transformComponent = entity->FindComponent<Components::TransformComponent>())
if (AZ::Component* transformComponent = entity->FindComponent<Components::TransformComponent>())
{
OnEntityComponentPropertyChanged(transformComponent->GetId());
}
@@ -239,6 +239,7 @@ namespace UnitTest
bool PropertyDisplayInvalidated() const { return m_propertyDisplayInvalidated; }
AZStd::vector<AZ::ComponentId> m_componentIds;
AzToolsFramework::EntityIdList m_entityIds;
private:
// PropertyEditorEntityChangeNotificationBus ...
@@ -1024,7 +1024,6 @@ namespace AzToolsFramework
static void RefreshUiAfterChange(const EntityIdList& entitiyIds)
{
EditorTransformChangeNotificationBus::Broadcast(&EditorTransformChangeNotifications::OnEntityTransformChanged, entitiyIds);
ToolsApplicationNotificationBus::Broadcast(&ToolsApplicationNotificationBus::Events::InvalidatePropertyDisplay, Refresh_Values);
}
@@ -1097,7 +1096,7 @@ namespace AzToolsFramework
auto entityBoxSelectData = AZStd::make_shared<EntityBoxSelectData>();
m_boxSelect.InstallLeftMouseDown(
[this, entityBoxSelectData](const ViewportInteraction::MouseInteractionEvent& /*mouseInteraction*/)
[this, entityBoxSelectData]([[maybe_unused]] const ViewportInteraction::MouseInteractionEvent& mouseInteraction)
{
// begin selection undo/redo command
entityBoxSelectData->m_boxSelectSelectionCommand =
@@ -1295,8 +1294,12 @@ namespace AzToolsFramework
});
translationManipulators->InstallLinearManipulatorMouseUpCallback(
[this]([[maybe_unused]] const LinearManipulator::Action& action) mutable
[this, manipulatorEntityIds]([[maybe_unused]] const LinearManipulator::Action& action) mutable
{
AzToolsFramework::EditorTransformChangeNotificationBus::Broadcast(
&AzToolsFramework::EditorTransformChangeNotificationBus::Events::OnEntityTransformChanged,
manipulatorEntityIds->m_entityIds);
EndRecordManipulatorCommand();
});
@@ -1325,8 +1328,12 @@ namespace AzToolsFramework
});
translationManipulators->InstallPlanarManipulatorMouseUpCallback(
[this, manipulatorEntityIds](const PlanarManipulator::Action& /*action*/)
[this, manipulatorEntityIds]([[maybe_unused]] const PlanarManipulator::Action& action)
{
AzToolsFramework::EditorTransformChangeNotificationBus::Broadcast(
&AzToolsFramework::EditorTransformChangeNotificationBus::Events::OnEntityTransformChanged,
manipulatorEntityIds->m_entityIds);
EndRecordManipulatorCommand();
});
@@ -1354,8 +1361,12 @@ namespace AzToolsFramework
});
translationManipulators->InstallSurfaceManipulatorMouseUpCallback(
[this, manipulatorEntityIds](const SurfaceManipulator::Action& /*action*/)
[this, manipulatorEntityIds]([[maybe_unused]] const SurfaceManipulator::Action& action)
{
AzToolsFramework::EditorTransformChangeNotificationBus::Broadcast(
&AzToolsFramework::EditorTransformChangeNotificationBus::Events::OnEntityTransformChanged,
manipulatorEntityIds->m_entityIds);
EndRecordManipulatorCommand();
});
@@ -1392,7 +1403,7 @@ namespace AzToolsFramework
AZStd::shared_ptr<SharedRotationState> sharedRotationState = AZStd::make_shared<SharedRotationState>();
rotationManipulators->InstallLeftMouseDownCallback(
[this, sharedRotationState](const AngularManipulator::Action& /*action*/) mutable -> void
[this, sharedRotationState]([[maybe_unused]] const AngularManipulator::Action& action) mutable -> void
{
sharedRotationState->m_savedOrientation = AZ::Quaternion::CreateIdentity();
sharedRotationState->m_referenceFrameAtMouseDown = m_referenceFrame;
@@ -1518,8 +1529,12 @@ namespace AzToolsFramework
});
rotationManipulators->InstallLeftMouseUpCallback(
[this](const AngularManipulator::Action& /*action*/)
[this, sharedRotationState]([[maybe_unused]] const AngularManipulator::Action& action)
{
AzToolsFramework::EditorTransformChangeNotificationBus::Broadcast(
&AzToolsFramework::EditorTransformChangeNotificationBus::Events::OnEntityTransformChanged,
sharedRotationState->m_entityIds);
EndRecordManipulatorCommand();
});
@@ -1565,6 +1580,10 @@ namespace AzToolsFramework
auto uniformLeftMouseUpCallback = [this, manipulatorEntityIds]([[maybe_unused]] const LinearManipulator::Action& action)
{
AzToolsFramework::EditorTransformChangeNotificationBus::Broadcast(
&AzToolsFramework::EditorTransformChangeNotificationBus::Events::OnEntityTransformChanged,
manipulatorEntityIds->m_entityIds);
m_entityIdManipulators.m_manipulators->SetLocalTransform(RecalculateAverageManipulatorTransform(
m_entityIdManipulators.m_lookups, m_pivotOverrideFrame, m_pivotMode, m_referenceFrame));
};
@@ -2402,7 +2421,7 @@ namespace AzToolsFramework
AddAction(
m_actions, { QKeySequence(Qt::Key_U) },
/*ID_VIEWPORTUI_VISIBLE=*/50040, "Toggle ViewportUI", "Hide/Unhide Viewport UI",
/*ID_VIEWPORTUI_VISIBLE=*/50040, "Toggle Viewport UI", "Hide/Show Viewport UI",
[this]()
{
SetAllViewportUiVisible(!m_viewportUiVisible);
@@ -3642,17 +3661,17 @@ namespace AzToolsFramework
RegenerateManipulators();
}
void EditorTransformComponentSelection::OnEntityVisibilityChanged(const bool /*visibility*/)
void EditorTransformComponentSelection::OnEntityVisibilityChanged([[maybe_unused]] const bool visibility)
{
m_selectedEntityIdsAndManipulatorsDirty = true;
}
void EditorTransformComponentSelection::OnEntityLockChanged(const bool /*locked*/)
void EditorTransformComponentSelection::OnEntityLockChanged([[maybe_unused]] const bool locked)
{
m_selectedEntityIdsAndManipulatorsDirty = true;
}
void EditorTransformComponentSelection::EnteredComponentMode(const AZStd::vector<AZ::Uuid>& /*componentModeTypes*/)
void EditorTransformComponentSelection::EnteredComponentMode([[maybe_unused]] const AZStd::vector<AZ::Uuid>& componentModeTypes)
{
SetAllViewportUiVisible(false);
@@ -3661,7 +3680,7 @@ namespace AzToolsFramework
ToolsApplicationNotificationBus::Handler::BusDisconnect();
}
void EditorTransformComponentSelection::LeftComponentMode(const AZStd::vector<AZ::Uuid>& /*componentModeTypes*/)
void EditorTransformComponentSelection::LeftComponentMode([[maybe_unused]] const AZStd::vector<AZ::Uuid>& componentModeTypes)
{
SetAllViewportUiVisible(true);
@@ -85,6 +85,8 @@ if(PAL_TRAIT_BUILD_TESTS_SUPPORTED)
AZ::AzManipulatorTestFramework.Static
AZ::AzTest
AZ::AzQtComponents
RUNTIME_DEPENDENCIES
3rdParty::Qt::Test
)
ly_add_googletest(
NAME AZ::AzToolsFramework.Tests
@@ -425,6 +425,43 @@ namespace UnitTest
EXPECT_TRUE(finalEntityTransform.IsClose(finalTransformWorld, 0.01f));
}
TEST_F(EditorTransformComponentSelectionManipulatorTestFixture, TranslatingEntityWithLinearManipulatorNotifiesOnEntityTransformChanged)
{
EditorEntityComponentChangeDetector editorEntityChangeDetector(m_entity1);
// the initial starting position of the entity (in front and to the left of the camera)
const auto initialTransformWorld = AZ::Transform::CreateTranslation(AZ::Vector3(-10.0f, 10.0f, 0.0f));
// where the entity should end up (in front and to the right of the camera)
const auto finalTransformWorld = AZ::Transform::CreateTranslation(AZ::Vector3(10.0f, 10.0f, 0.0f));
// calculate the position in screen space of the initial position of the entity
const auto initialPositionScreen = AzFramework::WorldToScreen(initialTransformWorld.GetTranslation(), m_cameraState);
// calculate the position in screen space of the final position of the entity
const auto finalPositionScreen = AzFramework::WorldToScreen(finalTransformWorld.GetTranslation(), m_cameraState);
// move the entity to its starting position
AzToolsFramework::SetWorldTransform(m_entity1, initialTransformWorld);
// select the entity (this will cause the manipulators to appear in EditorTransformComponentSelection)
AzToolsFramework::SelectEntity(m_entity1);
// create an offset along the linear manipulator pointing along the x-axis (perpendicular to the camera view)
const auto mouseOffsetOnManipulator = AzFramework::ScreenVector(10, 0);
// store the mouse down position on the manipulator
const auto mouseDownPosition = initialPositionScreen + mouseOffsetOnManipulator;
// final position in screen space of the mouse
const auto mouseMovePosition = finalPositionScreen + mouseOffsetOnManipulator;
m_actionDispatcher->CameraState(m_cameraState)
->MousePosition(mouseDownPosition)
->MouseLButtonDown()
->MousePosition(mouseMovePosition)
->MouseLButtonUp();
// verify a EditorTransformChangeNotificationBus::OnEntityTransformChanged occurred
using ::testing::UnorderedElementsAreArray;
EXPECT_THAT(editorEntityChangeDetector.m_entityIds, UnorderedElementsAreArray(m_entityIds));
}
// simple widget to listen for a mouse wheel event and then forward it on to the ViewportSelectionRequestBus
class WheelEventWidget : public QWidget
{
@@ -29,15 +29,20 @@ namespace Benchmark
{},
m_pathString));
auto& prefabDom = m_prefabSystemComponent->FindTemplateDom(instance->GetTemplateId());
for (auto _ : state)
{
state.PauseTiming();
AzFramework::Spawnable spawnable;
AzToolsFramework::Prefab::SpawnableUtils::CreateSpawnable(spawnable, prefabDom);
state.ResumeTiming();
// Create a vector to store spawnables so that they don't get destroyed immediately after construction.
AZStd::vector<AZStd::unique_ptr<AzFramework::Spawnable>> spawnables;
spawnables.reserve(numSpawnables);
for (int spwanableCounter = 0; spwanableCounter < numSpawnables; ++spwanableCounter)
{
AZStd::unique_ptr<AzFramework::Spawnable> spawnable = AZStd::make_unique<AzFramework::Spawnable>();
AzToolsFramework::Prefab::SpawnableUtils::CreateSpawnable(*spawnable, prefabDom);
spawnables.push_back(AZStd::move(spawnable));
}
}
state.SetComplexityN(numSpawnables);
@@ -50,3 +55,4 @@ namespace Benchmark
}
#endif