3
0

AnimComponentNode.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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_ANIMCOMPONENTNODE_H
  9. #define CRYINCLUDE_CRYMOVIE_ANIMCOMPONENTNODE_H
  10. #pragma once
  11. #include "AnimNode.h"
  12. #include "CharacterTrackAnimator.h"
  13. #include <Maestro/Bus/EditorSequenceAgentComponentBus.h>
  14. /**
  15. * CAnimComponentNode
  16. *
  17. * All animation on AZ::Entity nodes are keyed to tracks on CAnimComponentNodes.
  18. *
  19. */
  20. class CAnimComponentNode
  21. : public CAnimNode
  22. , public Maestro::EditorSequenceAgentComponentNotificationBus::Handler
  23. {
  24. public:
  25. AZ_CLASS_ALLOCATOR(CAnimComponentNode, AZ::SystemAllocator);
  26. AZ_RTTI(CAnimComponentNode, "{722F3D0D-7AEB-46B7-BF13-D5C7A828E9BD}", CAnimNode);
  27. CAnimComponentNode(const int id);
  28. CAnimComponentNode();
  29. ~CAnimComponentNode();
  30. AZ::EntityId GetParentAzEntityId() const { return m_pParentNode ? m_pParentNode->GetAzEntityId() : AZ::EntityId(); }
  31. //////////////////////////////////////////////////////////////////////////
  32. // Overrides from CAnimNode
  33. void Animate(SAnimContext& ac) override;
  34. void OnStart() override;
  35. void OnResume() override;
  36. void OnReset() override;
  37. void OnResetHard() override;
  38. //////////////////////////////////////////////////////////////////////////
  39. //////////////////////////////////////////////////////////////////////////
  40. // Overrides from IAnimNode
  41. // ComponentNodes use reflection for typing - return invalid for this pure virtual for the legacy system
  42. CAnimParamType GetParamType(unsigned int nIndex) const override;
  43. void SetComponent(AZ::ComponentId componentId, const AZ::Uuid& typeId) override;
  44. // returns the componentId of the component the node is associate with, if applicable, or a AZ::InvalidComponentId otherwise
  45. AZ::ComponentId GetComponentId() const override { return m_componentId; }
  46. int SetKeysForChangedTrackValues(float time) override;
  47. void OnStartPlayInEditor() override;
  48. void OnStopPlayInEditor() override;
  49. void SetNodeOwner(IAnimNodeOwner* pOwner) override;
  50. void SetPos(float time, const Vec3& pos) override;
  51. void SetRotate(float time, const Quat& quat) override;
  52. void SetScale(float time, const Vec3& scale) override;
  53. Vec3 GetPos() override;
  54. Quat GetRotate() override;
  55. Quat GetRotate(float time) override;
  56. Vec3 GetScale() override;
  57. void Activate(bool bActivate) override;
  58. //////////////////////////////////////////////////////////////////////////
  59. //////////////////////////////////////////////////////////////////////////
  60. // Override CreateTrack to handle trackMultipliers for Component Tracks
  61. IAnimTrack* CreateTrack(const CAnimParamType& paramType) override;
  62. bool RemoveTrack(IAnimTrack* pTrack) override;
  63. //////////////////////////////////////////////////////////////////////////
  64. // EditorSequenceAgentComponentNotificationBus::Handler Interface
  65. void OnSequenceAgentConnected() override;
  66. void Serialize(XmlNodeRef& xmlNode, bool bLoading, bool bLoadEmptyTracks) override;
  67. const AZ::Uuid& GetComponentTypeId() const { return m_componentTypeId; }
  68. // Skips Event Bus update of Components during animation - used for when another system is overriding a component's properties,
  69. // such as during camera interpolation between two Transforms. This will silently make the Animate() method do nothing - use only if you
  70. // know what you're doing!
  71. void SetSkipComponentAnimationUpdates(bool skipAnimationUpdates)
  72. {
  73. m_skipComponentAnimationUpdates = skipAnimationUpdates;
  74. }
  75. static void Reflect(AZ::ReflectContext* context);
  76. protected:
  77. // functions involved in the process to parse and store component behavior context animated properties
  78. void UpdateDynamicParamsInternal() override;
  79. void UpdateDynamicParams_Editor();
  80. void UpdateDynamicParams_Game();
  81. void InitializeTrackDefaultValue(IAnimTrack* pTrack, const CAnimParamType& paramType) override;
  82. bool GetParamInfoFromType(const CAnimParamType& paramId, SParamInfo& info) const override;
  83. private:
  84. enum ETransformSpaceConversionDirection
  85. {
  86. eTransformConverstionDirection_toWorldSpace = 0,
  87. eTransformConverstionDirection_toLocalSpace
  88. };
  89. // methods to convert world transforms to local transforms to account for Transform Delegate bug working solely
  90. // in world space
  91. void GetParentWorldTransform(AZ::Transform& retTransform) const;
  92. void ConvertBetweenWorldAndLocalPosition(Vec3& position, ETransformSpaceConversionDirection conversionDirection) const;
  93. void ConvertBetweenWorldAndLocalRotation(Quat& rotation, ETransformSpaceConversionDirection conversionDirection) const;
  94. void ConvertBetweenWorldAndLocalScale(Vec3& scale, ETransformSpaceConversionDirection conversionDirection) const;
  95. // Utility function to query the units for a track and set the track multiplier if needed. Returns true if track multiplier was set.
  96. bool SetTrackMultiplier(IAnimTrack* track) const;
  97. void ForceAnimKeyChangeInCharacterTrackAnimator();
  98. // typed support functions for SetKeysForChangedTrackValues()
  99. int SetKeysForChangedBoolTrackValue(IAnimTrack* track, int keyIdx, float time);
  100. int SetKeysForChangedFloatTrackValue(IAnimTrack* track, int keyIdx, float time);
  101. int SetKeysForChangedVector3TrackValue(IAnimTrack* track, int keyIdx, float time, bool applyTrackMultiplier = true, float isChangedTolerance = AZ::Constants::Tolerance);
  102. int SetKeysForChangedQuaternionTrackValue(IAnimTrack* track, int keyIdx, float time);
  103. // Helper function to set individual properties on Simple Motion Component from an AssetBlend Track.
  104. void AnimateAssetBlendSubProperties(const Maestro::AssetBlends<AZ::Data::AssetData>& assetBlendValue);
  105. class BehaviorPropertyInfo
  106. {
  107. public:
  108. BehaviorPropertyInfo() {}
  109. BehaviorPropertyInfo(const AZStd::string& name)
  110. {
  111. *this = name;
  112. }
  113. BehaviorPropertyInfo(const BehaviorPropertyInfo& other)
  114. {
  115. m_displayName = other.m_displayName;
  116. m_animNodeParamInfo.paramType = other.m_displayName;
  117. m_animNodeParamInfo.name = m_displayName;
  118. }
  119. BehaviorPropertyInfo& operator=(const AZStd::string& str)
  120. {
  121. // TODO: clean this up - this weird memory sharing was copied from legacy Cry - could be better.
  122. m_displayName = str;
  123. m_animNodeParamInfo.paramType = str; // set type to AnimParamType::ByString by assigning a string
  124. m_animNodeParamInfo.name = m_displayName;
  125. return *this;
  126. }
  127. AZStd::string m_displayName;
  128. SParamInfo m_animNodeParamInfo;
  129. };
  130. void AddPropertyToParamInfoMap(const CAnimParamType& paramType);
  131. AZ::Uuid m_componentTypeId;
  132. AZ::ComponentId m_componentId;
  133. // a mapping of CAnimParmTypes to SBehaviorPropertyInfo structs for each virtual property
  134. AZStd::unordered_map<CAnimParamType, BehaviorPropertyInfo> m_paramTypeToBehaviorPropertyInfoMap;
  135. // helper class responsible for animating Character Tracks (aka 'Animation' tracks in the TrackView UI)
  136. CCharacterTrackAnimator* m_characterTrackAnimator = nullptr;
  137. bool m_skipComponentAnimationUpdates;
  138. };
  139. #endif // CRYINCLUDE_CRYMOVIE_ANIMCOMPONENTNODE_H