TrackViewTrack.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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. #ifndef CRYINCLUDE_EDITOR_TRACKVIEW_TRACKVIEWTRACK_H
  9. #define CRYINCLUDE_EDITOR_TRACKVIEW_TRACKVIEWTRACK_H
  10. #pragma once
  11. #include "IMovieSystem.h"
  12. #include <AzToolsFramework/Entity/EditorEntityContextBus.h>
  13. #include "TrackViewNode.h"
  14. class CTrackViewAnimNode;
  15. enum class AnimValueType;
  16. // Represents a bundle of tracks
  17. class CTrackViewTrackBundle
  18. {
  19. public:
  20. CTrackViewTrackBundle()
  21. : m_bAllOfSameType(true)
  22. , m_bHasRotationTrack(false) {}
  23. unsigned int GetCount() const { return static_cast<unsigned int>(m_tracks.size()); }
  24. CTrackViewTrack* GetTrack(const unsigned int index) { return m_tracks[index]; }
  25. const CTrackViewTrack* GetTrack(const unsigned int index) const { return m_tracks[index]; }
  26. void AppendTrack(CTrackViewTrack* pTrack);
  27. void AppendTrackBundle(const CTrackViewTrackBundle& bundle);
  28. bool RemoveTrack(CTrackViewTrack* pTrackToRemove);
  29. bool IsOneTrack() const;
  30. bool AreAllOfSameType() const { return m_bAllOfSameType; }
  31. bool HasRotationTrack() const { return m_bHasRotationTrack; }
  32. private:
  33. bool m_bAllOfSameType;
  34. bool m_bHasRotationTrack;
  35. std::vector<CTrackViewTrack*> m_tracks;
  36. };
  37. // Track Memento for Undo/Redo
  38. class CTrackViewTrackMemento
  39. {
  40. private:
  41. friend class CTrackViewTrack;
  42. XmlNodeRef m_serializedTrackState;
  43. };
  44. ////////////////////////////////////////////////////////////////////////////
  45. //
  46. // This class represents a IAnimTrack in TrackView and contains
  47. // the editor side code for changing it
  48. //
  49. // It does *not* have ownership of the IAnimTrack, therefore deleting it
  50. // will not destroy the CryMovie track
  51. //
  52. ////////////////////////////////////////////////////////////////////////////
  53. class CTrackViewTrack final
  54. : public CTrackViewNode
  55. , public AzToolsFramework::EditorEntityContextNotificationBus::Handler
  56. {
  57. friend class CTrackViewKeyHandle;
  58. friend class CTrackViewKeyConstHandle;
  59. friend class CTrackViewKeyBundle;
  60. public:
  61. CTrackViewTrack(IAnimTrack* pTrack, CTrackViewAnimNode* pTrackAnimNode, CTrackViewNode* pParentNode,
  62. bool bIsSubTrack = false, unsigned int subTrackIndex = 0);
  63. ~CTrackViewTrack();
  64. CTrackViewAnimNode* GetAnimNode() const;
  65. // Name getter
  66. AZStd::string GetName() const override;
  67. // CTrackViewNode
  68. virtual ETrackViewNodeType GetNodeType() const override { return eTVNT_Track; }
  69. // Check for compound/sub track
  70. bool IsCompoundTrack() const { return m_bIsCompoundTrack; }
  71. // Sub track index
  72. bool IsSubTrack() const { return m_bIsSubTrack; }
  73. unsigned int GetSubTrackIndex() const { return m_subTrackIndex; }
  74. // Snap time value to prev/next key in track
  75. virtual bool SnapTimeToPrevKey(float& time) const override;
  76. virtual bool SnapTimeToNextKey(float& time) const override;
  77. // Expanded state interface
  78. void SetExpanded(bool expanded) override;
  79. bool GetExpanded() const override;
  80. // Key getters
  81. virtual unsigned int GetKeyCount() const { return m_pAnimTrack->GetNumKeys(); }
  82. virtual CTrackViewKeyHandle GetKey(unsigned int index);
  83. virtual CTrackViewKeyConstHandle GetKey(unsigned int index) const;
  84. virtual CTrackViewKeyHandle GetKeyByTime(const float time);
  85. virtual CTrackViewKeyHandle GetNearestKeyByTime(const float time);
  86. CTrackViewKeyBundle GetSelectedKeys() override;
  87. CTrackViewKeyBundle GetAllKeys() override;
  88. CTrackViewKeyBundle GetKeysInTimeRange(const float t0, const float t1) override;
  89. // Key modifications
  90. virtual CTrackViewKeyHandle CreateKey(const float time);
  91. virtual void SlideKeys(const float time0, const float timeOffset);
  92. void UpdateKeyDataAfterParentChanged(const AZ::Transform& oldParentWorldTM, const AZ::Transform& newParentWorldTM);
  93. // Value getters
  94. template <class Type>
  95. void GetValue(const float time, Type& value, bool applyMultiplier) const
  96. {
  97. assert (m_pAnimTrack.get());
  98. return m_pAnimTrack->GetValue(time, value, applyMultiplier);
  99. }
  100. template <class Type>
  101. void GetValue(const float time, Type& value) const
  102. {
  103. assert(m_pAnimTrack.get());
  104. return m_pAnimTrack->GetValue(time, value);
  105. }
  106. void GetKeyValueRange(float& min, float& max) const;
  107. // Type getters
  108. const CAnimParamType& GetParameterType() const { return m_pAnimTrack->GetParameterType(); }
  109. AnimValueType GetValueType() const { return m_pAnimTrack->GetValueType(); }
  110. EAnimCurveType GetCurveType() const { return m_pAnimTrack->GetCurveType(); }
  111. // Mask
  112. bool IsMasked(uint32 mask) const { return m_pAnimTrack->IsMasked(mask); }
  113. // Flag getter
  114. IAnimTrack::EAnimTrackFlags GetFlags() const;
  115. // Spline getter
  116. ISplineInterpolator* GetSpline() const { return m_pAnimTrack->GetSpline(); }
  117. // Color
  118. ColorB GetCustomColor() const;
  119. void SetCustomColor(ColorB color);
  120. bool HasCustomColor() const;
  121. void ClearCustomColor();
  122. // Memento
  123. virtual CTrackViewTrackMemento GetMemento() const;
  124. virtual void RestoreFromMemento(const CTrackViewTrackMemento& memento);
  125. // Disabled state
  126. virtual void SetDisabled(bool bDisabled) override;
  127. virtual bool IsDisabled() const override;
  128. // Muted state
  129. void SetMuted(bool bMuted);
  130. bool IsMuted() const;
  131. // Returns if the contained AnimTrack responds to muting
  132. bool UsesMute() const { return m_pAnimTrack.get() ? m_pAnimTrack->UsesMute() : false; }
  133. // Key selection
  134. void SelectKeys(const bool bSelected);
  135. // Paste from XML representation with time offset
  136. void PasteKeys(XmlNodeRef xmlNode, const float timeOffset);
  137. // Animation layer index
  138. void SetAnimationLayerIndex(const int index);
  139. int GetAnimationLayerIndex() const;
  140. //////////////////////////////////////////////////////////////////////////
  141. // AzToolsFramework::EditorEntityContextNotificationBus implementation
  142. void OnStartPlayInEditor() override;
  143. void OnStopPlayInEditor() override;
  144. //~AzToolsFramework::EditorEntityContextNotificationBus implementation
  145. IAnimTrack* GetAnimTrack() const { return m_pAnimTrack.get(); }
  146. unsigned int GetId() const
  147. {
  148. return m_pAnimTrack->GetId();
  149. }
  150. void SetId(unsigned int id)
  151. {
  152. m_pAnimTrack->SetId(id);
  153. }
  154. private:
  155. CTrackViewKeyHandle GetPrevKey(const float time);
  156. CTrackViewKeyHandle GetNextKey(const float time);
  157. // Those are called from CTrackViewKeyHandle
  158. void SetKey(unsigned int keyIndex, IKey* pKey);
  159. void GetKey(unsigned int keyIndex, IKey* pKey) const;
  160. void SelectKey(unsigned int keyIndex, bool bSelect);
  161. bool IsKeySelected(unsigned int keyIndex) const;
  162. void SetSortMarkerKey(unsigned int keyIndex, bool enabled);
  163. bool IsSortMarkerKey(unsigned int keyIndex) const;
  164. void SetKeyTime(const int index, const float time, bool notifyListeners = true);
  165. float GetKeyTime(const int index) const;
  166. void RemoveKey(const int index);
  167. int CloneKey(const int index);
  168. CTrackViewKeyBundle GetKeys(bool bOnlySelected, float t0, float t1);
  169. CTrackViewKeyHandle GetSubTrackKeyHandle(unsigned int index) const;
  170. // Copy selected keys to XML representation for clipboard
  171. void CopyKeysToClipboard(XmlNodeRef& xmlNode, const bool bOnlySelectedKeys, const bool bOnlyFromSelectedTracks) override;
  172. bool m_bIsCompoundTrack;
  173. bool m_bIsSubTrack;
  174. unsigned int m_subTrackIndex;
  175. AZStd::intrusive_ptr<IAnimTrack> m_pAnimTrack;
  176. CTrackViewAnimNode* m_pTrackAnimNode;
  177. // used to stash AZ Entity ID's stored in track keys when entering/exiting AI/Physic or Ctrl-G game modes
  178. AZStd::unordered_map<CAnimParamType, AZStd::vector<AZ::EntityId>> m_paramTypeToStashedEntityIdMap;
  179. };
  180. #endif // CRYINCLUDE_EDITOR_TRACKVIEW_TRACKVIEWTRACK_H