AnimNode.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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. // Description : Base of all Animation Nodes
  9. #ifndef CRYINCLUDE_CRYMOVIE_ANIMNODE_H
  10. #define CRYINCLUDE_CRYMOVIE_ANIMNODE_H
  11. #pragma once
  12. #include "IMovieSystem.h"
  13. #include "Movie.h"
  14. // forward declaration
  15. struct SSoundInfo;
  16. /*!
  17. Base class for all Animation nodes,
  18. can host multiple animation tracks, and execute them other time.
  19. Animation node is reference counted.
  20. */
  21. class CAnimNode
  22. : public IAnimNode
  23. {
  24. public:
  25. AZ_CLASS_ALLOCATOR(CAnimNode, AZ::SystemAllocator);
  26. AZ_RTTI(CAnimNode, "{57736B48-5EE7-4530-8051-657ACC9BA1EE}", IAnimNode);
  27. typedef AZStd::vector<AZStd::intrusive_ptr<IAnimTrack>> AnimTracks;
  28. CAnimNode();
  29. CAnimNode(const CAnimNode& other);
  30. CAnimNode(const int id, AnimNodeType nodeType);
  31. ~CAnimNode();
  32. AnimNodeType GetType() const override { return m_nodeType; }
  33. //////////////////////////////////////////////////////////////////////////
  34. void add_ref() override;
  35. void release() override;
  36. //////////////////////////////////////////////////////////////////////////
  37. void SetName(const char* name) override { m_name = name; };
  38. const char* GetName() const override { return m_name.c_str(); };
  39. void SetSequence(IAnimSequence* sequence) override { m_pSequence = sequence; }
  40. // Return Animation Sequence that owns this node.
  41. IAnimSequence* GetSequence() const override { return m_pSequence; };
  42. // CAnimNode's aren't bound to AZ::Entities, CAnimAzEntityNodes are. return InvalidEntityId by default
  43. void SetAzEntityId([[maybe_unused]] const AZ::EntityId& id) override {}
  44. AZ::EntityId GetAzEntityId() const override { return AZ::EntityId(); }
  45. void SetFlags(int flags) override;
  46. int GetFlags() const override;
  47. bool AreFlagsSetOnNodeOrAnyParent(EAnimNodeFlags flagsToCheck) const override;
  48. IMovieSystem* GetMovieSystem() const override { return gEnv->pMovieSystem; };
  49. virtual void OnStart() {}
  50. void OnReset() override {}
  51. virtual void OnResetHard() { OnReset(); }
  52. virtual void OnPause() {}
  53. virtual void OnResume() {}
  54. virtual void OnStop() {}
  55. virtual void OnLoop() {}
  56. //////////////////////////////////////////////////////////////////////////
  57. // Space position/orientation scale.
  58. //////////////////////////////////////////////////////////////////////////
  59. void SetPos([[maybe_unused]] float time, [[maybe_unused]] const AZ::Vector3& pos) override {};
  60. void SetRotate([[maybe_unused]] float time, [[maybe_unused]] const AZ::Quaternion& quat) override {};
  61. void SetScale([[maybe_unused]] float time, [[maybe_unused]] const AZ::Vector3& scale) override {};
  62. Vec3 GetPos() override { return Vec3(0, 0, 0); };
  63. Quat GetRotate() override { return Quat(0, 0, 0, 0); };
  64. Quat GetRotate(float /*time*/) override { return Quat(0, 0, 0, 0); };
  65. Vec3 GetScale() override { return Vec3(0, 0, 0); };
  66. virtual Matrix34 GetReferenceMatrix() const;
  67. //////////////////////////////////////////////////////////////////////////
  68. bool IsParamValid(const CAnimParamType& paramType) const override;
  69. AZStd::string GetParamName(const CAnimParamType& param) const override;
  70. AnimValueType GetParamValueType(const CAnimParamType& paramType) const override;
  71. IAnimNode::ESupportedParamFlags GetParamFlags(const CAnimParamType& paramType) const override;
  72. unsigned int GetParamCount() const override { return 0; };
  73. bool SetParamValue(float time, CAnimParamType param, float val) override;
  74. bool SetParamValue(float time, CAnimParamType param, const Vec3& val) override;
  75. bool SetParamValue(float time, CAnimParamType param, const Vec4& val) override;
  76. bool GetParamValue(float time, CAnimParamType param, float& val) override;
  77. bool GetParamValue(float time, CAnimParamType param, Vec3& val) override;
  78. bool GetParamValue(float time, CAnimParamType param, Vec4& val) override;
  79. void SetTarget([[maybe_unused]] IAnimNode* node) {};
  80. IAnimNode* GetTarget() const { return 0; };
  81. void StillUpdate() override {}
  82. void Animate(SAnimContext& ec) override;
  83. virtual void PrecacheStatic([[maybe_unused]] float startTime) {}
  84. virtual void PrecacheDynamic([[maybe_unused]] float time) {}
  85. void Serialize(XmlNodeRef& xmlNode, bool bLoading, bool bLoadEmptyTracks) override;
  86. void InitPostLoad(IAnimSequence* sequence) override;
  87. void SetNodeOwner(IAnimNodeOwner* pOwner) override;
  88. IAnimNodeOwner* GetNodeOwner() override { return m_pOwner; };
  89. // Called by sequence when needs to activate a node.
  90. void Activate(bool bActivate) override;
  91. //////////////////////////////////////////////////////////////////////////
  92. void SetParent(IAnimNode* parent) override;
  93. IAnimNode* GetParent() const override { return m_pParentNode; };
  94. IAnimNode* HasDirectorAsParent() const override;
  95. //////////////////////////////////////////////////////////////////////////
  96. //////////////////////////////////////////////////////////////////////////
  97. // Track functions.
  98. //////////////////////////////////////////////////////////////////////////
  99. int GetTrackCount() const override;
  100. IAnimTrack* GetTrackByIndex(int nIndex) const override;
  101. IAnimTrack* GetTrackForParameter(const CAnimParamType& paramType) const override;
  102. IAnimTrack* GetTrackForParameter(const CAnimParamType& paramType, uint32 index) const override;
  103. uint32 GetTrackParamIndex(const IAnimTrack* pTrack) const override;
  104. void SetTrack(const CAnimParamType& paramType, IAnimTrack* track) override;
  105. IAnimTrack* CreateTrack(const CAnimParamType& paramType) override;
  106. void InitializeTrackDefaultValue([[maybe_unused]] IAnimTrack* pTrack, [[maybe_unused]] const CAnimParamType& paramType) override {}
  107. void SetTimeRange(Range timeRange) override;
  108. void AddTrack(IAnimTrack* pTrack) override;
  109. bool RemoveTrack(IAnimTrack* pTrack) override;
  110. void CreateDefaultTracks() override {};
  111. void SerializeAnims(XmlNodeRef& xmlNode, bool bLoading, bool bLoadEmptyTracks) override;
  112. //////////////////////////////////////////////////////////////////////////
  113. virtual void PostLoad();
  114. int GetId() const override { return m_id; }
  115. void SetId(int id) { m_id = id; }
  116. void Render() override{}
  117. void UpdateDynamicParams() final;
  118. void TimeChanged(float newTime) override;
  119. void SetExpanded(bool expanded) override;
  120. bool GetExpanded() const override;
  121. static void Reflect(AZ::ReflectContext* context);
  122. protected:
  123. virtual void UpdateDynamicParamsInternal() {};
  124. virtual bool GetParamInfoFromType([[maybe_unused]] const CAnimParamType& paramType, [[maybe_unused]] SParamInfo& info) const { return false; };
  125. int NumTracks() const { return (int)m_tracks.size(); }
  126. IAnimTrack* CreateTrackInternal(const CAnimParamType& paramType, EAnimCurveType trackType, AnimValueType valueType);
  127. IAnimTrack* CreateTrackInternalVector4(const CAnimParamType& paramType) const;
  128. IAnimTrack* CreateTrackInternalQuat(EAnimCurveType trackType, const CAnimParamType& paramType) const;
  129. IAnimTrack* CreateTrackInternalVector(EAnimCurveType trackType, const CAnimParamType& paramType, const AnimValueType animValue) const;
  130. IAnimTrack* CreateTrackInternalFloat(int trackType) const;
  131. // sets track animNode pointer to this node and sorts tracks
  132. void RegisterTrack(IAnimTrack* pTrack);
  133. CMovieSystem* GetCMovieSystem() const { return (CMovieSystem*)gEnv->pMovieSystem; }
  134. bool NeedToRender() const override { return false; }
  135. // nodes which support sounds should override this to reset their start/stop sound states
  136. virtual void ResetSounds() {}
  137. //////////////////////////////////////////////////////////////////////////
  138. // AnimateSound() calls ApplyAudioKey() to trigger audio on sound key frames. Nodes which support audio must override
  139. // this to trigger audio
  140. virtual void ApplyAudioKey([[maybe_unused]] char const* const sTriggerName, [[maybe_unused]] bool const bPlay = true) {};
  141. void AnimateSound(std::vector<SSoundInfo>& nodeSoundInfo, SAnimContext& ec, IAnimTrack* pTrack, size_t numAudioTracks);
  142. //////////////////////////////////////////////////////////////////////////
  143. AnimTracks m_tracks;
  144. AnimNodeType m_nodeType;
  145. AZStd::string m_name;
  146. IAnimSequence* m_pSequence;
  147. IAnimNodeOwner* m_pOwner;
  148. IAnimNode* m_pParentNode;
  149. int m_refCount;
  150. int m_id;
  151. int m_nLoadedParentNodeId; // only used in legacy Serialize()
  152. int m_parentNodeId;
  153. int m_flags;
  154. unsigned int m_bIgnoreSetParam : 1; // Internal flags.
  155. bool m_expanded;
  156. private:
  157. void SortTracks();
  158. bool IsTimeOnSoundKey(float queryTime) const;
  159. static bool TrackOrder(const AZStd::intrusive_ptr<IAnimTrack>& left, const AZStd::intrusive_ptr<IAnimTrack>& right);
  160. AZStd::mutex m_updateDynamicParamsLock;
  161. };
  162. #endif // CRYINCLUDE_CRYMOVIE_ANIMNODE_H