WhiteBoxMeshAssetUndoCommand.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include "Asset/WhiteBoxMeshAssetBus.h"
  9. #include "WhiteBoxMeshAssetUndoCommand.h"
  10. namespace WhiteBox
  11. {
  12. AZ_CLASS_ALLOCATOR_IMPL(WhiteBoxMeshAssetUndoCommand, AZ::SystemAllocator);
  13. WhiteBoxMeshAssetUndoCommand::WhiteBoxMeshAssetUndoCommand()
  14. : AzToolsFramework::UndoSystem::URSequencePoint("WhiteBoxMeshAssetUndoCommand")
  15. {
  16. }
  17. void WhiteBoxMeshAssetUndoCommand::SetAsset(AZ::Data::Asset<Pipeline::WhiteBoxMeshAsset> asset)
  18. {
  19. m_asset = asset;
  20. }
  21. void WhiteBoxMeshAssetUndoCommand::SetUndoState(const Api::WhiteBoxMeshStream& undoState)
  22. {
  23. m_undoState = undoState;
  24. }
  25. void WhiteBoxMeshAssetUndoCommand::SetRedoState(const Api::WhiteBoxMeshStream& redoState)
  26. {
  27. m_redoState = redoState;
  28. }
  29. void WhiteBoxMeshAssetUndoCommand::Undo()
  30. {
  31. Api::ReadMesh(*m_asset->GetMesh(), m_undoState);
  32. m_asset->SetWhiteBoxData(m_undoState);
  33. WhiteBoxMeshAssetNotificationBus::Event(
  34. m_asset.GetId(), &WhiteBoxMeshAssetNotificationBus::Events::OnWhiteBoxMeshAssetModified, m_asset);
  35. }
  36. void WhiteBoxMeshAssetUndoCommand::Redo()
  37. {
  38. Api::ReadMesh(*m_asset->GetMesh(), m_redoState);
  39. m_asset->SetWhiteBoxData(m_redoState);
  40. WhiteBoxMeshAssetNotificationBus::Event(
  41. m_asset.GetId(), &WhiteBoxMeshAssetNotificationBus::Events::OnWhiteBoxMeshAssetModified, m_asset);
  42. }
  43. bool WhiteBoxMeshAssetUndoCommand::Changed() const
  44. {
  45. return m_undoState != m_redoState;
  46. }
  47. } // namespace WhiteBox