CompoundSplineTrack.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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_CRYMOVIE_COMPOUNDSPLINETRACK_H
  9. #define CRYINCLUDE_CRYMOVIE_COMPOUNDSPLINETRACK_H
  10. #pragma once
  11. #include "IMovieSystem.h"
  12. #define MAX_SUBTRACKS 4
  13. //////////////////////////////////////////////////////////////////////////
  14. class CCompoundSplineTrack
  15. : public IAnimTrack
  16. {
  17. public:
  18. AZ_CLASS_ALLOCATOR(CCompoundSplineTrack, AZ::SystemAllocator);
  19. AZ_RTTI(CCompoundSplineTrack, "{E6B88EF4-6DB7-48E7-9758-DF6C9E40D4D2}", IAnimTrack);
  20. CCompoundSplineTrack(int nDims, AnimValueType inValueType, CAnimParamType subTrackParamTypes[MAX_SUBTRACKS], bool expanded);
  21. CCompoundSplineTrack();
  22. //////////////////////////////////////////////////////////////////////////
  23. // for intrusive_ptr support
  24. void add_ref() override;
  25. void release() override;
  26. //////////////////////////////////////////////////////////////////////////
  27. void SetNode(IAnimNode* node) override;
  28. // Return Animation Node that owns this Track.
  29. IAnimNode* GetNode() override { return m_node; }
  30. int GetSubTrackCount() const override { return m_nDimensions; };
  31. IAnimTrack* GetSubTrack(int nIndex) const override;
  32. AZStd::string GetSubTrackName(int nIndex) const override;
  33. void SetSubTrackName(int nIndex, const char* name) override;
  34. EAnimCurveType GetCurveType() override { return eAnimCurveType_BezierFloat; };
  35. AnimValueType GetValueType() override { return m_valueType; };
  36. const CAnimParamType& GetParameterType() const override { return m_nParamType; };
  37. void SetParameterType(CAnimParamType type) override { m_nParamType = type; }
  38. int GetNumKeys() const override;
  39. void SetNumKeys([[maybe_unused]] int numKeys) override { assert(0); };
  40. bool HasKeys() const override;
  41. void RemoveKey(int num) override;
  42. void GetKeyInfo(int key, const char*& description, float& duration) override;
  43. int CreateKey([[maybe_unused]] float time) override { assert(0); return 0; };
  44. int CloneKey([[maybe_unused]] int fromKey) override { assert(0); return 0; };
  45. int CopyKey([[maybe_unused]] IAnimTrack* pFromTrack, [[maybe_unused]] int nFromKey) override { assert(0); return 0; };
  46. void GetKey([[maybe_unused]] int index, [[maybe_unused]] IKey* key) const override { assert(0); };
  47. float GetKeyTime(int index) const override;
  48. int FindKey([[maybe_unused]] float time) override { assert(0); return 0; };
  49. int GetKeyFlags([[maybe_unused]] int index) override { assert(0); return 0; };
  50. void SetKey([[maybe_unused]] int index, [[maybe_unused]] IKey* key) override { assert(0); };
  51. void SetKeyTime(int index, float time) override;
  52. void SetKeyFlags([[maybe_unused]] int index, [[maybe_unused]] int flags) override { assert(0); };
  53. void SortKeys() override { assert(0); };
  54. bool IsKeySelected(int key) const override;
  55. void SelectKey(int key, bool select) override;
  56. int GetFlags() override { return m_flags; };
  57. bool IsMasked([[maybe_unused]] const uint32 mask) const override { return false; }
  58. void SetFlags(int flags) override
  59. {
  60. m_flags = flags;
  61. }
  62. //////////////////////////////////////////////////////////////////////////
  63. // Get track value at specified time.
  64. // Interpolates keys if needed.
  65. //////////////////////////////////////////////////////////////////////////
  66. void GetValue(float time, float& value, bool applyMultiplier = false) override;
  67. void GetValue(float time, Vec3& value, bool applyMultiplier = false) override;
  68. void GetValue(float time, Vec4& value, bool applyMultiplier = false) override;
  69. void GetValue(float time, Quat& value) override;
  70. void GetValue([[maybe_unused]] float time, [[maybe_unused]] bool& value) override { assert(0); };
  71. void GetValue([[maybe_unused]] float time, [[maybe_unused]] Maestro::AssetBlends<AZ::Data::AssetData>& value) override { assert(0); }
  72. //////////////////////////////////////////////////////////////////////////
  73. // Set track value at specified time.
  74. // Adds new keys if required.
  75. //////////////////////////////////////////////////////////////////////////
  76. void SetValue(float time, const float& value, bool bDefault = false, bool applyMultiplier = false) override;
  77. void SetValue(float time, const Vec3& value, bool bDefault = false, bool applyMultiplier = false) override;
  78. void SetValue(float time, const Vec4& value, bool bDefault = false, bool applyMultiplier = false) override;
  79. void SetValue(float time, const Quat& value, bool bDefault = false) override;
  80. void SetValue([[maybe_unused]] float time, [[maybe_unused]] const bool& value, [[maybe_unused]] bool bDefault = false) override { assert(0); };
  81. void SetValue([[maybe_unused]] float time, [[maybe_unused]] const Maestro::AssetBlends<AZ::Data::AssetData>& value, [[maybe_unused]] bool bDefault = false) override { assert(0); }
  82. void OffsetKeyPosition(const AZ::Vector3& value) override;
  83. void UpdateKeyDataAfterParentChanged(const AZ::Transform& oldParentWorldTM, const AZ::Transform& newParentWorldTM) override;
  84. void SetTimeRange(const Range& timeRange) override;
  85. bool Serialize(XmlNodeRef& xmlNode, bool bLoading, bool bLoadEmptyTracks = true) override;
  86. bool SerializeSelection(XmlNodeRef& xmlNode, bool bLoading, bool bCopySelected = false, float fTimeOffset = 0) override;
  87. int NextKeyByTime(int key) const override;
  88. void SetSubTrackName(const int i, const AZStd::string& name) { assert (i < MAX_SUBTRACKS); m_subTrackNames[i] = name; }
  89. #ifdef MOVIESYSTEM_SUPPORT_EDITING
  90. ColorB GetCustomColor() const override
  91. { return m_customColor; }
  92. void SetCustomColor(ColorB color) override
  93. {
  94. m_customColor = color;
  95. m_bCustomColorSet = true;
  96. }
  97. bool HasCustomColor() const override
  98. { return m_bCustomColorSet; }
  99. void ClearCustomColor() override
  100. { m_bCustomColorSet = false; }
  101. #endif
  102. void GetKeyValueRange(float& fMin, float& fMax) const override
  103. {
  104. if (GetSubTrackCount() > 0)
  105. {
  106. m_subTracks[0]->GetKeyValueRange(fMin, fMax);
  107. }
  108. };
  109. void SetKeyValueRange(float fMin, float fMax) override
  110. {
  111. for (int i = 0; i < m_nDimensions; ++i)
  112. {
  113. m_subTracks[i]->SetKeyValueRange(fMin, fMax);
  114. }
  115. };
  116. void SetMultiplier(float trackMultiplier) override
  117. {
  118. for (int i = 0; i < m_nDimensions; ++i)
  119. {
  120. m_subTracks[i]->SetMultiplier(trackMultiplier);
  121. }
  122. }
  123. void SetExpanded(bool expanded) override;
  124. bool GetExpanded() const override;
  125. unsigned int GetId() const override;
  126. void SetId(unsigned int id) override;
  127. static void Reflect(AZ::ReflectContext* context);
  128. protected:
  129. int m_refCount;
  130. AnimValueType m_valueType;
  131. int m_nDimensions;
  132. AZStd::vector<AZStd::intrusive_ptr<IAnimTrack>> m_subTracks;
  133. int m_flags;
  134. CAnimParamType m_nParamType;
  135. AZStd::vector<AZStd::string> m_subTrackNames;
  136. #ifdef MOVIESYSTEM_SUPPORT_EDITING
  137. ColorB m_customColor;
  138. bool m_bCustomColorSet;
  139. #endif
  140. float PreferShortestRotPath(float degree, float degree0) const;
  141. int GetSubTrackIndex(int& key) const;
  142. IAnimNode* m_node;
  143. bool m_expanded;
  144. unsigned int m_id = 0;
  145. };
  146. //////////////////////////////////////////////////////////////////////////
  147. inline void CCompoundSplineTrack::add_ref()
  148. {
  149. ++m_refCount;
  150. }
  151. //////////////////////////////////////////////////////////////////////////
  152. inline void CCompoundSplineTrack::release()
  153. {
  154. if (--m_refCount <= 0)
  155. {
  156. delete this;
  157. }
  158. }
  159. #endif // CRYINCLUDE_CRYMOVIE_COMPOUNDSPLINETRACK_H