TrackViewTrack.h 8.1 KB

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