Fixing pivot offset when performing undo on Transform component (#6150)

* Fixing undo offest on transform component

Signed-off-by: Mikhail Naumov <mnaumov@amazon.com>

* Fixining possible issue with firing an unnecessary OnTransformChanged event when entity is manually disabled/enabled

Signed-off-by: Mikhail Naumov <mnaumov@amazon.com>

* Adding better comments

Signed-off-by: Mikhail Naumov <mnaumov@amazon.com>

* Unit tests

Signed-off-by: Mikhail Naumov <mnaumov@amazon.com>

* Cherrupicking changes

Signed-off-by: Mikhail Naumov <mnaumov@amazon.com>
This commit is contained in:
Mikhail Naumov
2021-12-06 08:46:47 -06:00
committed by GitHub
parent dc8f9dc233
commit c5615f812c
6 changed files with 181 additions and 79 deletions
@@ -860,18 +860,20 @@ namespace AzToolsFramework
return;
}
bool isDuringUndoRedo = false;
EBUS_EVENT_RESULT(isDuringUndoRedo, AzToolsFramework::ToolsApplicationRequests::Bus, IsDuringUndoRedo);
if (!isDuringUndoRedo)
bool suppressTransformChangedEvent = m_suppressTransformChangedEvent;
// temporarily disable calling OnTransformChanged, because CheckApplyCachedWorldTransform is not guaranteed
// to call it when m_cachedWorldTransform is identity. We send it manually later.
m_suppressTransformChangedEvent = false;
// When parent comes online, compute local TM from world TM.
CheckApplyCachedWorldTransform(parentTransform->GetWorldTM());
if (!m_initialized)
{
// When parent comes online, compute local TM from world TM.
CheckApplyCachedWorldTransform(parentTransform->GetWorldTM());
}
else
{
// During undo operations, just apply our local TM.
m_initialized = true;
// If this is the first time this entity is being activated, manually compute OnTransformChanged
// this can occur when either the entity first created or undo/redo command is performed
OnTransformChanged(AZ::Transform::Identity(), parentTransform->GetWorldTM());
}
m_suppressTransformChangedEvent = suppressTransformChangedEvent;
auto& parentChildIds = GetParentTransformComponent()->m_childrenEntityIds;
if (parentChildIds.end() == AZStd::find(parentChildIds.begin(), parentChildIds.end(), GetEntityId()))
@@ -242,6 +242,9 @@ namespace AzToolsFramework
// element is used rather than a data element.
bool m_addNonUniformScaleButton = false;
// Used to check whether entity was just created vs manually reactivated. Set true after OnEntityActivated is called the first time.
bool m_initialized = false;
// Deprecated
AZ::InterpolationMode m_interpolatePosition;
AZ::InterpolationMode m_interpolateRotation;