IMovieSystem.h 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360
  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 <AzCore/Component/ComponentBus.h>
  10. #include <AzCore/Component/EntityId.h>
  11. #include <AzCore/Math/Crc.h>
  12. #include <AzCore/Math/Quaternion.h>
  13. #include <AzCore/Math/Vector2.h>
  14. #include <AzCore/Math/Vector3.h>
  15. #include <AzCore/Math/Vector4.h>
  16. #include <Range.h>
  17. #include <AnimKey.h>
  18. #include <ISplines.h>
  19. #define DEFAULT_NEAR 0.2f
  20. #define DEFAULT_FOV (75.0f * gf_PI / 180.0f)
  21. // forward declaration.
  22. struct IAnimTrack;
  23. struct IAnimNode;
  24. struct IAnimSequence;
  25. struct IMovieSystem;
  26. struct IKey;
  27. class XmlNodeRef;
  28. struct ISplineInterpolator;
  29. namespace AZ
  30. {
  31. class SerializeContext;
  32. namespace Data
  33. {
  34. class AssetData;
  35. }
  36. }
  37. namespace Maestro
  38. {
  39. template<typename AssetType>
  40. struct AssetBlends;
  41. }
  42. typedef IMovieSystem* (* PFNCREATEMOVIESYSTEM)(struct ISystem*);
  43. #define LIGHT_ANIMATION_SET_NAME "_LightAnimationSet"
  44. #define MAX_ANIM_NAME_LENGTH 64
  45. //! Very high priority for cut scene sounds.
  46. #define MOVIE_SOUND_PRIORITY 230
  47. #if !defined(CONSOLE)
  48. #define MOVIESYSTEM_SUPPORT_EDITING
  49. #endif
  50. typedef std::vector<IAnimSequence*> AnimSequences;
  51. typedef AZStd::vector<AZStd::string> TrackEvents;
  52. // Forward declare
  53. enum class SequenceType;
  54. enum class AnimNodeType;
  55. enum class AnimValueType;
  56. enum class AnimParamType;
  57. // TODO: Refactor headers that are using these values so they are not need in header files
  58. // AnimValueType::Float is the default value
  59. #define kAnimValueDefault static_cast<AnimValueType>(0)
  60. // AnimValueType::Unknown
  61. #define kAnimValueUnknown static_cast<AnimValueType>(0xFFFFFFFF)
  62. // SequenceType::SequenceComponent is the default value
  63. #define kSequenceTypeDefault static_cast<SequenceType>(1)
  64. // AnimParamType::Invalid
  65. #define kAnimParamTypeInvalid static_cast<AnimParamType>(0xFFFFFFFF)
  66. // AnimParamType::ByString
  67. #define kAnimParamTypeByString static_cast<AnimParamType>(8)
  68. //! Flags that can be set on animation node.
  69. enum EAnimNodeFlags
  70. {
  71. eAnimNodeFlags_Expanded = BIT(0), //!< Deprecated, handled by sandbox now
  72. eAnimNodeFlags_EntitySelected = BIT(1), //!< Set if the referenced entity is selected in the editor
  73. eAnimNodeFlags_CanChangeName = BIT(2), //!< Set if this node allow changing of its name.
  74. eAnimNodeFlags_Disabled = BIT(3), //!< Disable this node.
  75. eAnimNodeFlags_DisabledForComponent = BIT(4), //!< Disable this node for a disabled or pending entity component.
  76. };
  77. enum ENodeExportType
  78. {
  79. eNodeExportType_Global = 0,
  80. eNodeExportType_Local = 1,
  81. };
  82. // Common parameters of animation node.
  83. class CAnimParamType
  84. {
  85. friend class CMovieSystem;
  86. friend class AnimSerializer;
  87. public:
  88. AZ_TYPE_INFO_WITH_NAME_DECL(CAnimParamType);
  89. static const uint kParamTypeVersion = 9;
  90. CAnimParamType();
  91. CAnimParamType(const AZStd::string& name);
  92. CAnimParamType(AnimParamType type);
  93. // Convert from old enum or int
  94. void operator =(AnimParamType type);
  95. void operator =(const AZStd::string& name);
  96. // Convert to enum. This needs to be explicit,
  97. // otherwise operator== will be ambiguous
  98. constexpr AnimParamType GetType() const { return m_type; }
  99. // Get name
  100. const char* GetName() const { return m_name.c_str(); }
  101. bool operator ==(const CAnimParamType& animParamType) const;
  102. bool operator !=(const CAnimParamType& animParamType) const;
  103. bool operator <(const CAnimParamType& animParamType) const;
  104. operator size_t() const
  105. {
  106. AZStd::hash<AnimParamType> paramTypeHasher;
  107. size_t retVal = paramTypeHasher(GetType());
  108. AZStd::hash_combine(retVal, AZ::Crc32(GetName()));
  109. return retVal;
  110. }
  111. void SaveToXml(XmlNodeRef& xmlNode) const;
  112. void LoadFromXml(const XmlNodeRef& xmlNode, const uint version = kParamTypeVersion);
  113. // Serialization
  114. void Serialize(XmlNodeRef& xmlNode, bool bLoading, const uint version = kParamTypeVersion);
  115. private:
  116. AnimParamType m_type;
  117. AZStd::string m_name;
  118. };
  119. //! Types of animation track.
  120. // Do not change values! they are serialized
  121. //
  122. // Attention: This should only be expanded if you add a completely new way how tracks store data!
  123. // If you just want to control a new parameter of an entity etc. extend EParamType
  124. //
  125. // Note: TCB splines are only for backward compatibility, Bezier is the default
  126. //
  127. enum EAnimCurveType : unsigned int
  128. {
  129. eAnimCurveType_TCBFloat = 1,
  130. eAnimCurveType_TCBVector = 2,
  131. eAnimCurveType_TCBQuat = 3,
  132. eAnimCurveType_BezierFloat = 4,
  133. eAnimCurveType_Unknown = 0xFFFFFFFF
  134. };
  135. enum ETrackMask
  136. {
  137. eTrackMask_MaskSound = 1 << 11, // Old: 1 << ATRACK_SOUND
  138. };
  139. //! Structure passed to Animate function.
  140. struct SAnimContext
  141. {
  142. SAnimContext();
  143. float time; //!< Current time in seconds.
  144. float dt; //!< Delta of time from previous animation frame in seconds.
  145. float fps; //!< Last calculated frames per second value.
  146. bool singleFrame; //!< This is not a playing animation, more a single-frame update.
  147. bool forcePlay; //!< Set when force playing animation.
  148. bool resetting; //!< Set when animation sequence is resetting.
  149. IAnimSequence* sequence; //!< Sequence in which animation performed.
  150. // TODO: Replace trackMask with something more type safe
  151. // TODO: Mask should be stored with dynamic length
  152. uint32 trackMask; //!< To update certain types of tracks only
  153. float startTime; //!< The start time of this playing sequence
  154. };
  155. /** Parameters for cut-scene cameras
  156. */
  157. struct SCameraParams
  158. {
  159. SCameraParams();
  160. AZ::EntityId cameraEntityId;
  161. float fov;
  162. float nearZ;
  163. bool justActivated;
  164. };
  165. //! Interface for movie-system implemented by user for advanced function-support
  166. struct IMovieUser
  167. {
  168. // <interfuscator:shuffle>
  169. virtual ~IMovieUser(){}
  170. //! Called when movie system requests a camera-change.
  171. virtual void SetActiveCamera(const SCameraParams& Params) = 0;
  172. //! Called when movie system enters into cut-scene mode.
  173. virtual void BeginCutScene(IAnimSequence* pSeq, unsigned long dwFlags, bool bResetFX) = 0;
  174. //! Called when movie system exits from cut-scene mode.
  175. virtual void EndCutScene(IAnimSequence* pSeq, unsigned long dwFlags) = 0;
  176. //! Called when movie system wants to send a global event.
  177. virtual void SendGlobalEvent(const char* pszEvent) = 0;
  178. // </interfuscator:shuffle>
  179. };
  180. //! Callback-class
  181. struct IMovieCallback
  182. {
  183. //! Callback-reasons
  184. enum ECallbackReason
  185. {
  186. CBR_CHANGENODE, // Node is changing.
  187. CBR_CHANGETRACK // Track of the node is changing.
  188. };
  189. // <interfuscator:shuffle>
  190. virtual ~IMovieCallback(){}
  191. // Called by movie system.
  192. virtual void OnMovieCallback(ECallbackReason reason, IAnimNode* pNode) = 0;
  193. virtual void OnSetCamera(const SCameraParams& Params) = 0;
  194. virtual bool IsSequenceCamUsed() const = 0;
  195. // </interfuscator:shuffle>
  196. };
  197. /** Interface of Animation Track.
  198. */
  199. struct IAnimTrack
  200. {
  201. AZ_TYPE_INFO_WITH_NAME_DECL(IAnimTrack);
  202. AZ_RTTI_NO_TYPE_INFO_DECL();
  203. AZ_CLASS_ALLOCATOR_DECL
  204. static void Reflect(AZ::ReflectContext* context);
  205. //! Flags that can be set on animation track.
  206. enum EAnimTrackFlags
  207. {
  208. eAnimTrackFlags_Linear = BIT(1), //!< Use only linear interpolation between keys.
  209. eAnimTrackFlags_Loop = BIT(2), //!< Play this track in a loop.
  210. eAnimTrackFlags_Cycle = BIT(3), //!< Cycle track.
  211. eAnimTrackFlags_Disabled = BIT(4), //!< Disable this track.
  212. //////////////////////////////////////////////////////////////////////////
  213. // Used by editor.
  214. //////////////////////////////////////////////////////////////////////////
  215. eAnimTrackFlags_Hidden = BIT(5), //!< Set when track is hidden in track view.
  216. eAnimTrackFlags_Muted = BIT(8), //!< Mute this sound track or music track. This only affects the playback in editor on these types of tracks.
  217. };
  218. // <interfuscator:shuffle>
  219. virtual ~IAnimTrack() {};
  220. // for intrusive_ptr support
  221. virtual void add_ref() = 0;
  222. virtual void release() = 0;
  223. //////////////////////////////////////////////////////////////////////////
  224. virtual EAnimCurveType GetCurveType() = 0;
  225. virtual AnimValueType GetValueType() = 0;
  226. #ifdef MOVIESYSTEM_SUPPORT_EDITING
  227. // This color is used for the editor.
  228. virtual ColorB GetCustomColor() const = 0;
  229. virtual void SetCustomColor(ColorB color) = 0;
  230. virtual bool HasCustomColor() const = 0;
  231. virtual void ClearCustomColor() = 0;
  232. #endif
  233. // Return what parameter of the node, this track is attached to.
  234. virtual const CAnimParamType& GetParameterType() const = 0;
  235. // Assign node parameter ID for this track.
  236. virtual void SetParameterType(CAnimParamType type) = 0;
  237. virtual void SetNode(IAnimNode* node) = 0;
  238. // Return Animation Sequence that owns this node.
  239. virtual IAnimNode* GetNode() = 0;
  240. //////////////////////////////////////////////////////////////////////////
  241. // Animation track can contain sub-tracks (Position XYZ anim track have sub-tracks for x,y,z)
  242. // Get count of sub tracks.
  243. virtual int GetSubTrackCount() const = 0;
  244. // Retrieve pointer the specfied sub track.
  245. virtual IAnimTrack* GetSubTrack(int nIndex) const = 0;
  246. virtual AZStd::string GetSubTrackName(int nIndex) const = 0;
  247. virtual void SetSubTrackName(int nIndex, const char* name) = 0;
  248. //////////////////////////////////////////////////////////////////////////
  249. virtual void GetKeyValueRange(float& fMin, float& fMax) const = 0;
  250. virtual void SetKeyValueRange(float fMin, float fMax) = 0;
  251. //! Return number of keys in track.
  252. virtual int GetNumKeys() const = 0;
  253. //! Return true if keys exists in this track
  254. virtual bool HasKeys() const = 0;
  255. //! Set number of keys in track.
  256. //! If needed adds empty keys at end or remove keys from end.
  257. virtual void SetNumKeys(int numKeys) = 0;
  258. //! Remove specified key.
  259. virtual void RemoveKey(int num) = 0;
  260. //! Get key at specified location.
  261. //! @param key Must be valid pointer to compatible key structure, to be filled with specified key location.
  262. virtual void GetKey(int index, IKey* key) const = 0;
  263. //! Get time of specified key.
  264. //! @return key time.
  265. virtual float GetKeyTime(int index) const = 0;
  266. //! Find key at given time.
  267. //! @return Index of found key, or -1 if key with this time not found.
  268. virtual int FindKey(float time) = 0;
  269. //! Get flags of specified key.
  270. //! @return key time.
  271. virtual int GetKeyFlags(int index) = 0;
  272. //! Set key at specified location.
  273. //! @param key Must be valid pointer to compatible key structure.
  274. virtual void SetKey(int index, IKey* key) = 0;
  275. //! Set time of specified key.
  276. virtual void SetKeyTime(int index, float time) = 0;
  277. //! Set flags of specified key.
  278. virtual void SetKeyFlags(int index, int flags) = 0;
  279. //! Sort keys in track (after time of keys was modified).
  280. virtual void SortKeys() = 0;
  281. //! Get track flags.
  282. virtual int GetFlags() = 0;
  283. //! Check if track is masked by mask
  284. // TODO: Mask should be stored with dynamic length
  285. virtual bool IsMasked(const uint32 mask) const = 0;
  286. //! Set track flags.
  287. virtual void SetFlags(int flags) = 0;
  288. //! Create key at given time, and return its index.
  289. //! @return Index of new key.
  290. virtual int CreateKey(float time) = 0;
  291. //! Clone key at specified index.
  292. //! @retun Index of new key.
  293. virtual int CloneKey(int key) = 0;
  294. //! Clone key at specified index from another track of SAME TYPE.
  295. //! @retun Index of new key.
  296. virtual int CopyKey(IAnimTrack* pFromTrack, int nFromKey) = 0;
  297. //! Get info about specified key.
  298. //! @param Short human readable text description of this key.
  299. //! @param duration of this key in seconds.
  300. virtual void GetKeyInfo(int key, const char*& description, float& duration) = 0;
  301. //////////////////////////////////////////////////////////////////////////
  302. // Get track value at specified time.
  303. // Interpolates keys if needed.
  304. // Applies a scale multiplier set in SetMultiplier(), if requested
  305. //////////////////////////////////////////////////////////////////////////
  306. virtual void GetValue(float time, float& value, bool applyMultiplier=false) = 0;
  307. /**
  308. * O3DE_DEPRECATION_NOTICE(GHI-9133)
  309. * use equivalent GetValue that accepts AZ::Vector3
  310. **/
  311. virtual void GetValue(float time, Vec3& value, bool applyMultiplier = false) = 0;
  312. /**
  313. * O3DE_DEPRECATION_NOTICE(GHI-9133)
  314. * use equivalent GetValue that accepts AZ::Vector4
  315. **/
  316. virtual void GetValue(float time, Vec4& value, bool applyMultiplier = false) = 0;
  317. /**
  318. * O3DE_DEPRECATION_NOTICE(GHI-9133)
  319. * use equivalent GetValue that accepts AZ::Quaternion
  320. **/
  321. virtual void GetValue(float time, Quat& value) = 0;
  322. virtual void GetValue(float time, bool& value) = 0;
  323. virtual void GetValue(float time, Maestro::AssetBlends<AZ::Data::AssetData>& value) = 0;
  324. // support for AZ:: vector types - re-route to legacy types
  325. void GetValue(float time, AZ::Vector3& value, bool applyMultiplier = false);
  326. void GetValue(float time, AZ::Vector4& value, bool applyMultiplier = false);
  327. void GetValue(float time, AZ::Quaternion& value);
  328. //////////////////////////////////////////////////////////////////////////
  329. // Set track value at specified time.
  330. // Adds new keys if required.
  331. //////////////////////////////////////////////////////////////////////////
  332. virtual void SetValue(float time, const float& value, bool bDefault = false, bool applyMultiplier = false) = 0;
  333. /**
  334. * O3DE_DEPRECATION_NOTICE(GHI-9133)
  335. * use equivalent SetValue that accepts AZ::Vector3
  336. **/
  337. virtual void SetValue(float time, const Vec3& value, bool bDefault = false, bool applyMultiplier = false) = 0;
  338. /**
  339. * O3DE_DEPRECATION_NOTICE(GHI-9133)
  340. * use equivalent SetValue that accepts AZ::Vector4
  341. **/
  342. virtual void SetValue(float time, const Vec4& value, bool bDefault = false, bool applyMultiplier = false) = 0;
  343. /**
  344. * O3DE_DEPRECATION_NOTICE(GHI-9133)
  345. * use equivalent SetValue that accepts AZ::Quaternion
  346. **/
  347. virtual void SetValue(float time, const Quat& value, bool bDefault = false) = 0;
  348. virtual void SetValue(float time, const bool& value, bool bDefault = false) = 0;
  349. virtual void SetValue(float time, const Maestro::AssetBlends<AZ::Data::AssetData>& value, bool bDefault = false) = 0;
  350. // support for AZ:: vector types - re-route to legacy types
  351. void SetValue(float time, AZ::Vector4& value, bool bDefault = false, bool applyMultiplier = false);
  352. void SetValue(float time, AZ::Vector3& value, bool bDefault = false, bool applyMultiplier = false);
  353. void SetValue(float time, AZ::Quaternion& value, bool bDefault = false);
  354. // Only for position tracks, offset all track keys by this amount.
  355. virtual void OffsetKeyPosition(const Vec3& value) = 0;
  356. // Used to update the data in tracks after the parent entity has been changed.
  357. virtual void UpdateKeyDataAfterParentChanged(const AZ::Transform& oldParentWorldTM, const AZ::Transform& newParentWorldTM) = 0;
  358. // Assign active time range for this track.
  359. virtual void SetTimeRange(const Range& timeRange) = 0;
  360. //! @deprecated - IAnimTracks use AZ::Serialization now. Legacy - Serialize this animation track to XML.
  361. virtual bool Serialize(XmlNodeRef& xmlNode, bool bLoading, bool bLoadEmptyTracks = true) = 0;
  362. virtual bool SerializeSelection(XmlNodeRef& xmlNode, bool bLoading, bool bCopySelected = false, float fTimeOffset = 0) = 0;
  363. virtual void InitPostLoad(IAnimSequence* /*sequence*/) {};
  364. //! For custom track animate parameters.
  365. virtual void Animate([[maybe_unused]] SAnimContext& ec) {};
  366. // Get access to the internal spline of the track.
  367. virtual ISplineInterpolator* GetSpline() const { return 0; };
  368. virtual bool IsKeySelected([[maybe_unused]] int key) const { return false; }
  369. virtual void SelectKey([[maybe_unused]] int key, [[maybe_unused]] bool select) {}
  370. virtual void SetSortMarkerKey([[maybe_unused]] unsigned int keyIndex, [[maybe_unused]] bool enabled) {}
  371. virtual bool IsSortMarkerKey([[maybe_unused]] unsigned int keyIndex) const { return false; }
  372. //! Return the index of the key which lies right after the given key in time.
  373. //! @param key Index of of key.
  374. //! @return Index of the next key in time. If the last key given, this returns -1.
  375. // In case of keys sorted, it's just 'key+1', but if not sorted, it can be another value.
  376. virtual int NextKeyByTime(int key) const;
  377. //! Get the animation layer index assigned. (only for character/look-at tracks ATM)
  378. virtual int GetAnimationLayerIndex() const { return -1; }
  379. //! Set the animation layer index. (only for character/look-at tracks ATM)
  380. virtual void SetAnimationLayerIndex([[maybe_unused]] int index) { }
  381. //! Returns whether the track responds to muting (false by default), which only affects the Edtior.
  382. //! Tracks that use mute should override this, such as CSoundTrack
  383. //! @return Boolean of whether the track respnnds to muting or not
  384. virtual bool UsesMute() const { return false; }
  385. //! Set a multiplier which will be multiplied to track values in SetValue and divided out in GetValue if requested
  386. virtual void SetMultiplier(float trackValueMultiplier) = 0;
  387. // Expanded state interface
  388. virtual void SetExpanded(bool expanded) = 0;
  389. virtual bool GetExpanded() const = 0;
  390. virtual unsigned int GetId() const = 0;
  391. virtual void SetId(unsigned int id) = 0;
  392. // </interfuscator:shuffle>
  393. };
  394. /** Callback called by animation node when its animated.
  395. */
  396. struct IAnimNodeOwner
  397. {
  398. // <interfuscator:shuffle>
  399. virtual ~IAnimNodeOwner(){}
  400. virtual void OnNodeAnimated([[maybe_unused]] IAnimNode* pNode) {}
  401. virtual void OnNodeVisibilityChanged(IAnimNode* pNode, const bool bHidden) = 0;
  402. virtual void OnNodeReset([[maybe_unused]] IAnimNode* pNode) {}
  403. // mark the node's sequence object layer as modified
  404. virtual void MarkAsModified() = 0;
  405. // </interfuscator:shuffle>
  406. };
  407. /** Base class for all Animation nodes,
  408. can host multiple animation tracks, and execute them other time.
  409. Animation node is reference counted.
  410. */
  411. struct IAnimNode
  412. {
  413. public:
  414. AZ_TYPE_INFO_WITH_NAME_DECL(IAnimNode);
  415. AZ_RTTI_NO_TYPE_INFO_DECL()
  416. AZ_CLASS_ALLOCATOR_DECL;
  417. static void Reflect(AZ::ReflectContext* context);
  418. //////////////////////////////////////////////////////////////////////////
  419. // Supported params.
  420. //////////////////////////////////////////////////////////////////////////
  421. enum ESupportedParamFlags
  422. {
  423. eSupportedParamFlags_MultipleTracks = 0x01, // Set if parameter can be assigned multiple tracks.
  424. eSupportedParamFlags_Hidden = 0x02, // Hidden from the Track View UI.
  425. };
  426. struct SParamInfo
  427. {
  428. SParamInfo();
  429. SParamInfo(const char* _name, CAnimParamType _paramType, AnimValueType _valueType, ESupportedParamFlags _flags);
  430. AZStd::string name; // parameter name.
  431. CAnimParamType paramType; // parameter id.
  432. AnimValueType valueType; // value type, defines type of track to use for animating this parameter.
  433. ESupportedParamFlags flags; // combination of flags from ESupportedParamFlags.
  434. };
  435. using AnimParamInfos = AZStd::vector<SParamInfo>;
  436. // <interfuscator:shuffle>
  437. virtual ~IAnimNode() {};
  438. // for intrusive_ptr support
  439. virtual void add_ref() = 0;
  440. virtual void release() = 0;
  441. //! Set node name.
  442. virtual void SetName(const char* name) = 0;
  443. //! Get node name.
  444. virtual const char* GetName() const = 0;
  445. // Get Type of this node.
  446. virtual AnimNodeType GetType() const = 0;
  447. // Return Animation Sequence that owns this node.
  448. virtual IAnimSequence* GetSequence() const = 0;
  449. // Set the Animation Sequence that owns this node.
  450. virtual void SetSequence(IAnimSequence* sequence) = 0;
  451. // Called when sequence is activated / deactivated
  452. virtual void Activate(bool bActivate) = 0;
  453. // Set AnimNode flags.
  454. // @param flags One or more flags from EAnimNodeFlags.
  455. // @see EAnimNodeFlags
  456. virtual void SetFlags(int flags) = 0;
  457. // Get AnimNode flags.
  458. // @return flags set on node.
  459. // @see EAnimNodeFlags
  460. virtual int GetFlags() const = 0;
  461. // return true if flagsToCheck is set on the node or any of the node's parents
  462. virtual bool AreFlagsSetOnNodeOrAnyParent(EAnimNodeFlags flagsToCheck) const = 0;
  463. // AZ::Entity is bound/handled via their Id over EBuses, as opposed to directly with pointers.
  464. virtual void SetAzEntityId(const AZ::EntityId& id) = 0;
  465. virtual AZ::EntityId GetAzEntityId() const = 0;
  466. // Return movie system that created this node.
  467. virtual IMovieSystem* GetMovieSystem() const = 0;
  468. //////////////////////////////////////////////////////////////////////////
  469. // Space position/orientation scale.
  470. //////////////////////////////////////////////////////////////////////////
  471. //! Translate entity node.
  472. virtual void SetPos(float time, const Vec3& pos) = 0;
  473. //! Rotate entity node.
  474. virtual void SetRotate(float time, const Quat& quat) = 0;
  475. //! Scale entity node.
  476. virtual void SetScale(float time, const Vec3& scale) = 0;
  477. /**
  478. * O3DE_DEPRECATION_NOTICE(GHI-9326)
  479. * use equivalent SetPos that accepts AZ::Vector3
  480. **/
  481. void SetPos(float time, const AZ::Vector3& pos);
  482. /**
  483. * O3DE_DEPRECATION_NOTICE(GHI-9326)
  484. * use equivalent SetRotate that accepts AZ::Quaternion
  485. **/
  486. void SetRotate(float time, const AZ::Quaternion& rot);
  487. /**
  488. * O3DE_DEPRECATION_NOTICE(GHI-9326)
  489. * use equivalent SetScale that accepts AZ::Vector3
  490. **/
  491. void SetScale(float time, const AZ::Vector3& scale);
  492. //! Compute and return the offset which brings the current position to the given position
  493. virtual Vec3 GetOffsetPosition(const Vec3& position);
  494. //! Get current entity position.
  495. virtual Vec3 GetPos() = 0;
  496. //! Get current entity rotation.
  497. virtual Quat GetRotate() = 0;
  498. //! Get entity rotation at specified time.
  499. virtual Quat GetRotate(float time) = 0;
  500. //! Get current entity scale.
  501. virtual Vec3 GetScale() = 0;
  502. // General Set param.
  503. // Set float/vec3/vec4 parameter at given time.
  504. // @return true if parameter set, false if this parameter not exist in node.
  505. virtual bool SetParamValue(float time, CAnimParamType param, float value) = 0;
  506. virtual bool SetParamValue(float time, CAnimParamType param, const Vec3& value) = 0;
  507. virtual bool SetParamValue(float time, CAnimParamType param, const Vec4& value) = 0;
  508. /**
  509. * O3DE_DEPRECATION_NOTICE(GHI-9326)
  510. * use equivalent SetParamValue that accepts AZ::Vector3
  511. **/
  512. bool SetParamValue(float time, CAnimParamType param, const AZ::Vector3& value);
  513. /**
  514. * O3DE_DEPRECATION_NOTICE(GHI-9326)
  515. * use equivalent SetParamValue that accepts AZ::Vector4
  516. **/
  517. bool SetParamValue(float time, CAnimParamType param, const AZ::Vector4& value);
  518. // Get float/vec3/vec4 parameter at given time.
  519. // @return true if parameter exist, false if this parameter not exist in node.
  520. virtual bool GetParamValue(float time, CAnimParamType param, float& value) = 0;
  521. virtual bool GetParamValue(float time, CAnimParamType param, Vec3& value) = 0;
  522. virtual bool GetParamValue(float time, CAnimParamType param, Vec4& value) = 0;
  523. /**
  524. * O3DE_DEPRECATION_NOTICE(GHI-9326)
  525. * use equivalent GetParamValue that accepts AZ::Vector4
  526. **/
  527. bool GetParamValue(float time, CAnimParamType param, AZ::Vector3& value);
  528. /**
  529. * O3DE_DEPRECATION_NOTICE(GHI-9326)
  530. * use equivalent GetParamValue that accepts AZ::Vector4
  531. **/
  532. bool GetParamValue(float time, CAnimParamType param, AZ::Vector4& value);
  533. //! Evaluate animation node while not playing animation.
  534. virtual void StillUpdate() = 0;
  535. //! Evaluate animation to the given time.
  536. virtual void Animate(SAnimContext& ec) = 0;
  537. // Description:
  538. // Returns number of supported parameters by this animation node (position,rotation,scale,etc..).
  539. // Returns:
  540. // Number of supported parameters.
  541. virtual unsigned int GetParamCount() const = 0;
  542. // Description:
  543. // Returns the type of a param by index
  544. // Arguments:
  545. // nIndex - parameter index in range 0 <= nIndex < GetSupportedParamCount()
  546. virtual CAnimParamType GetParamType(unsigned int nIndex) const = 0;
  547. // Description:
  548. // Check if parameter is supported by this node.
  549. virtual bool IsParamValid(const CAnimParamType& paramType) const = 0;
  550. // Description:
  551. // Returns name of supported parameter of this animation node or NULL if not available
  552. // Arguments:
  553. // paramType - parameter id
  554. virtual AZStd::string GetParamName(const CAnimParamType& paramType) const = 0;
  555. // Description:
  556. // Returns the params value type
  557. virtual AnimValueType GetParamValueType(const CAnimParamType& paramType) const = 0;
  558. // Description:
  559. // Returns the params value type
  560. virtual ESupportedParamFlags GetParamFlags(const CAnimParamType& paramType) const = 0;
  561. // Called node data is re-initialized, such as when changing the entity associated with it.
  562. virtual void OnReset() = 0;
  563. //////////////////////////////////////////////////////////////////////////
  564. // Working with Tracks.
  565. //////////////////////////////////////////////////////////////////////////
  566. virtual int GetTrackCount() const = 0;
  567. // Return track assigned to the specified parameter.
  568. virtual IAnimTrack* GetTrackByIndex(int nIndex) const = 0;
  569. // Return first track assigned to the specified parameter.
  570. virtual IAnimTrack* GetTrackForParameter(const CAnimParamType& paramType) const = 0;
  571. // Return the i-th track assigned to the specified parameter in case of multiple tracks.
  572. virtual IAnimTrack* GetTrackForParameter(const CAnimParamType& paramType, uint32 index) const = 0;
  573. // Get the index of a given track among tracks with the same parameter type in this node.
  574. virtual uint32 GetTrackParamIndex(const IAnimTrack* pTrack) const = 0;
  575. // Creates a new track for given parameter.
  576. virtual IAnimTrack* CreateTrack(const CAnimParamType& paramType) = 0;
  577. // Initializes track default values after de-serialization / user creation. Only called in editor.
  578. virtual void InitializeTrackDefaultValue(IAnimTrack* pTrack, const CAnimParamType& paramType) = 0;
  579. // Assign animation track to parameter.
  580. // if track parameter is NULL track with parameter id param will be removed.
  581. virtual void SetTrack(const CAnimParamType& paramType, IAnimTrack* track) = 0;
  582. // Set time range for all tracks in this sequence.
  583. virtual void SetTimeRange(Range timeRange) = 0;
  584. // Remove track from anim node.
  585. virtual void AddTrack(IAnimTrack* pTrack) = 0;
  586. // Remove track from anim node.
  587. virtual bool RemoveTrack(IAnimTrack* pTrack) = 0;
  588. // Description:
  589. // Creates default set of tracks supported by this node.
  590. virtual void CreateDefaultTracks() = 0;
  591. // returns the tangent type to use for created keys. Override this if you have an animNode that you wish
  592. // to have tangents other than UNIFIED created for new keys.
  593. virtual int GetDefaultKeyTangentFlags() const { return SPLINE_KEY_TANGENT_UNIFIED; }
  594. //////////////////////////////////////////////////////////////////////////
  595. //////////////////////////////////////////////////////////////////////////
  596. //////////////////////////////////////////////////////////////////////////
  597. // Callback for animation node used by editor.
  598. // Register notification callback with animation node.
  599. virtual void SetNodeOwner(IAnimNodeOwner* pOwner) = 0;
  600. virtual IAnimNodeOwner* GetNodeOwner() = 0;
  601. /**
  602. * O3DE_DEPRECATION_NOTICE(GHI-9326)
  603. * Serialization for Sequence data in Component Entity Sequences now occurs through AZ::SerializeContext and the Sequence Component
  604. **/
  605. virtual void Serialize(XmlNodeRef& xmlNode, bool bLoading, bool bLoadEmptyTracks) = 0;
  606. /**
  607. * O3DE_DEPRECATION_NOTICE(GHI-9326)
  608. * Serialization for Sequence data in Component Entity Sequences now occurs through AZ::SerializeContext and the Sequence Component
  609. **/
  610. virtual void SerializeAnims(XmlNodeRef& xmlNode, bool bLoading, bool bLoadEmptyTracks) = 0;
  611. // Sets up internal pointers post load from Sequence Component
  612. virtual void InitPostLoad(IAnimSequence* sequence) = 0;
  613. //////////////////////////////////////////////////////////////////////////
  614. //////////////////////////////////////////////////////////////////////////
  615. // Groups interface
  616. //////////////////////////////////////////////////////////////////////////
  617. virtual void SetParent(IAnimNode* pParent) = 0;
  618. virtual IAnimNode* GetParent() const = 0;
  619. virtual IAnimNode* HasDirectorAsParent() const = 0;
  620. //////////////////////////////////////////////////////////////////////////
  621. virtual void Render() = 0;
  622. virtual bool NeedToRender() const = 0;
  623. // Called from editor if dynamic params need updating
  624. virtual void UpdateDynamicParams() = 0;
  625. // </interfuscator:shuffle>
  626. // Used by AnimCameraNode
  627. virtual bool GetShakeRotation([[maybe_unused]] const float& time, [[maybe_unused]] Quat& rot){return false; }
  628. virtual void SetCameraShakeSeed([[maybe_unused]] const uint shakeSeed){};
  629. // override this method to handle explicit setting of time
  630. virtual void TimeChanged([[maybe_unused]] float newTime) {};
  631. // Compares all of the node's track values at the given time with the associated property value and
  632. // sets a key at that time if they are different to match the latter
  633. // Returns the number of keys set
  634. virtual int SetKeysForChangedTrackValues([[maybe_unused]] float time) { return 0; };
  635. // Callbacks used when Game/Simulation mode is started and stopped in the Editor. Override if you want to handle these events
  636. virtual void OnStartPlayInEditor() {};
  637. virtual void OnStopPlayInEditor() {};
  638. ////////////////////////////////////////////////////////////////////////////////
  639. // interface for Components - implemented by CAnimComponentNode
  640. // Override if the derived node has an associated component type (e.g. CAnimComponentNode)
  641. virtual void SetComponent([[maybe_unused]] AZ::ComponentId comopnentId, [[maybe_unused]] const AZ::Uuid& componentTypeId) {}
  642. // returns the componentId of the component the node is associate with, if applicable, or a AZ::InvalidComponentId otherwise
  643. virtual AZ::ComponentId GetComponentId() const { return AZ::InvalidComponentId; }
  644. // ~interface for Components
  645. ////////////////////////////////////////////////////////////////////////////////
  646. // Used to disable any animation that is overridden by a SceneNode during camera interpolation, such as
  647. // FoV, transform, nearZ
  648. virtual void SetSkipInterpolatedCameraNode([[maybe_unused]] const bool skipNodeCameraAnimation) {};
  649. // Expanded state interface
  650. virtual void SetExpanded(bool expanded) = 0;
  651. virtual bool GetExpanded() const = 0;
  652. // Return the node id. This id is unique within a given sequence.
  653. virtual int GetId() const = 0;
  654. };
  655. //! Track event listener
  656. struct ITrackEventListener
  657. {
  658. //! Reasons
  659. enum ETrackEventReason
  660. {
  661. eTrackEventReason_Added,
  662. eTrackEventReason_Removed,
  663. eTrackEventReason_Renamed,
  664. eTrackEventReason_Triggered,
  665. eTrackEventReason_MovedUp,
  666. eTrackEventReason_MovedDown,
  667. };
  668. // <interfuscator:shuffle>
  669. virtual ~ITrackEventListener(){}
  670. // Description:
  671. // Called when track event is updated
  672. // Arguments:
  673. // pSeq - Animation sequence
  674. // reason - Reason for update (see EReason)
  675. // event - Track event added
  676. // pUserData - Data to accompany reason
  677. virtual void OnTrackEvent(IAnimSequence* sequence, int reason, const char* event, void* pUserData) = 0;
  678. // </interfuscator:shuffle>
  679. };
  680. struct IAnimLegacySequenceObject
  681. {
  682. // <interfuscator:shuffle>
  683. virtual ~IAnimLegacySequenceObject() {}
  684. virtual void OnNameChanged() = 0;
  685. virtual void OnModified() = 0;
  686. // </interfuscator:shuffle>
  687. };
  688. struct IAnimStringTable
  689. {
  690. AZ_TYPE_INFO_WITH_NAME_DECL(IAnimStringTable);
  691. AZ_RTTI_NO_TYPE_INFO_DECL();
  692. virtual ~IAnimStringTable() {}
  693. // for intrusive_ptr support
  694. virtual void add_ref() = 0;
  695. virtual void release() = 0;
  696. virtual const char* Add(const char* p) = 0;
  697. };
  698. /** Animation sequence, operates on animation nodes contained in it.
  699. */
  700. struct IAnimSequence
  701. {
  702. AZ_TYPE_INFO_WITH_NAME_DECL(IAnimSequence);
  703. AZ_RTTI_NO_TYPE_INFO_DECL();
  704. AZ_CLASS_ALLOCATOR_DECL;
  705. static const int kSequenceVersion = 5;
  706. static void Reflect(AZ::ReflectContext* context);
  707. //! Flags used for SetFlags(),GetFlags(),SetParentFlags(),GetParentFlags() methods.
  708. enum EAnimSequenceFlags
  709. {
  710. eSeqFlags_PlayOnReset = BIT(0), //!< Start playing this sequence immediately after reset of movie system(Level load).
  711. eSeqFlags_OutOfRangeConstant = BIT(1), //!< Constant Out-Of-Range,time continues normally past sequence time range.
  712. eSeqFlags_OutOfRangeLoop = BIT(2), //!< Loop Out-Of-Range,time wraps back to the start of range when reaching end of range.
  713. eSeqFlags_CutScene = BIT(3), //!< Cut scene sequence.
  714. eSeqFlags_NoHUD = BIT(4), //!< @deprecated - Don`t display HUD
  715. eSeqFlags_NoPlayer = BIT(5), //!< Disable input and drawing of player
  716. eSeqFlags_NoGameSounds = BIT(9), //!< Suppress all game sounds.
  717. eSeqFlags_NoSeek = BIT(10), //!< Cannot seek in sequence.
  718. eSeqFlags_NoAbort = BIT(11), //!< Cutscene can not be aborted
  719. eSeqFlags_NoSpeed = BIT(13), //!< Cannot modify sequence speed - TODO: add interface control if required
  720. // eSeqFlags_CanWarpInFixedTime = BIT(14), //!< @deprecated - Timewarp by scaling a fixed time step - removed July 2017, unused
  721. eSeqFlags_EarlyMovieUpdate = BIT(15), //!< Turn the 'sys_earlyMovieUpdate' on during the sequence.
  722. eSeqFlags_LightAnimationSet = BIT(16), //!< A special unique sequence for light animations
  723. eSeqFlags_NoMPSyncingNeeded = BIT(17), //!< this sequence doesn't require MP net syncing
  724. eSeqFlags_DisplayAsFramesOrSeconds = BIT(18), //!< Display Start/End time as frames or seconds
  725. };
  726. virtual ~IAnimSequence() {};
  727. // for intrusive_ptr support
  728. virtual void add_ref() = 0;
  729. virtual void release() = 0;
  730. //! Set the name of this sequence. (ex. "Intro" in the same case as above)
  731. virtual void SetName(const char* name) = 0;
  732. //! Get the name of this sequence. (ex. "Intro" in the same case as above)
  733. virtual const char* GetName() const = 0;
  734. //! Get the ID (unique in a level and consistent across renaming) of this sequence.
  735. virtual uint32 GetId () const = 0;
  736. //! Resets the ID to the next available ID - used on sequence loads into levels to resolve ID collisions
  737. virtual void ResetId() = 0;
  738. // Legacy sequence objects are connected by pointers. SequenceComponents are connected by AZ::EntityId
  739. virtual void SetLegacySequenceObject(IAnimLegacySequenceObject* legacySequenceObject) = 0;
  740. virtual IAnimLegacySequenceObject* GetLegacySequenceObject() const = 0;
  741. virtual void SetSequenceEntityId(const AZ::EntityId& entityOwnerId) = 0;
  742. virtual const AZ::EntityId& GetSequenceEntityId() const = 0;
  743. //! Set the currently active director node.
  744. virtual void SetActiveDirector(IAnimNode* pDirectorNode) = 0;
  745. //! Get the currently active director node, if any.
  746. virtual IAnimNode* GetActiveDirector() const = 0;
  747. //! Set animation sequence flags
  748. virtual void SetFlags(int flags) = 0;
  749. //! Get animation sequence flags
  750. virtual int GetFlags() const = 0;
  751. //! Get cutscene related animation sequence flags
  752. virtual int GetCutSceneFlags(const bool localFlags = false) const = 0;
  753. //! Set parent animation sequence
  754. virtual void SetParentSequence(IAnimSequence* pParentSequence) = 0;
  755. //! Get parent animation sequence
  756. virtual const IAnimSequence* GetParentSequence() const = 0;
  757. //! Check whether this sequence has the given sequence as a descendant through one of its sequence tracks.
  758. virtual bool IsAncestorOf(const IAnimSequence* sequence) const = 0;
  759. //! Return number of animation nodes in sequence.
  760. virtual int GetNodeCount() const = 0;
  761. //! Get animation node at specified index.
  762. virtual IAnimNode* GetNode(int index) const = 0;
  763. //! Add animation node to sequence.
  764. //! @return True if node added, same node will not be added 2 times.
  765. virtual bool AddNode(IAnimNode* node) = 0;
  766. // Reorders the array of nodes, so the specified node is placed after or before the given pivot node depending on the parameter 'next'.
  767. virtual void ReorderNode(IAnimNode* node, IAnimNode* pPivotNode, bool next) = 0;
  768. // Description:
  769. // Creates a new animation node with specified type.
  770. // Arguments:
  771. // nodeType - Type of node, one of AnimNodeType enums.
  772. virtual IAnimNode* CreateNode(AnimNodeType nodeType) = 0;
  773. // Description:
  774. // Creates a new animation node from serialized node XML.
  775. // Arguments:
  776. // node - Serialized form of node
  777. virtual IAnimNode* CreateNode(XmlNodeRef node) = 0;
  778. //! Remove animation node from sequence.
  779. virtual void RemoveNode(IAnimNode* node, bool removeChildRelationships /*=true*/) = 0;
  780. // Finds node by name, can be slow.
  781. // If the node belongs to a director, the director node also should be given
  782. // since there can be multiple instances of the same node(i.e. the same name)
  783. // across multiple director nodes.
  784. virtual IAnimNode* FindNodeByName(const char* sNodeName, const IAnimNode* pParentDirector) = 0;
  785. //! Remove all nodes from sequence.
  786. virtual void RemoveAll() = 0;
  787. // Activate sequence by binding sequence animations to nodes.
  788. // must be called prior animating sequence.
  789. virtual void Activate() = 0;
  790. /** Check if sequence is activated
  791. */
  792. virtual bool IsActivated() const = 0;
  793. // Deactivates sequence by unbinding sequence animations from nodes.
  794. virtual void Deactivate() = 0;
  795. // Pre-caches data associated with this anim sequence.
  796. virtual void PrecacheData(float startTime = 0.0f) = 0;
  797. // Update sequence while not playing animation.
  798. virtual void StillUpdate() = 0;
  799. // Render function call for some special node.
  800. virtual void Render() = 0;
  801. // Evaluate animations of all nodes in sequence.
  802. // Sequence must be activated before animating.
  803. virtual void Animate(const SAnimContext& ec) = 0;
  804. //! Set time range of this sequence.
  805. virtual void SetTimeRange(Range timeRange) = 0;
  806. //! Get time range of this sequence.
  807. virtual Range GetTimeRange() = 0;
  808. //! Resets the sequence
  809. virtual void Reset(bool bSeekToStart) = 0;
  810. //! This can have more time-consuming tasks performed additional to tasks of the usual 'Reset()' method.
  811. virtual void ResetHard() = 0;
  812. // Called to pause sequence.
  813. virtual void Pause() = 0;
  814. // Called to resume sequence.
  815. virtual void Resume() = 0;
  816. /** Called to check if sequence is paused.
  817. */
  818. virtual bool IsPaused() const = 0;
  819. /** Called when a sequence is looped.
  820. */
  821. virtual void OnLoop() = 0;
  822. /** Move/Scale all keys in tracks from previous time range to new time range.
  823. */
  824. virtual void AdjustKeysToTimeRange(const Range& timeRange) = 0;
  825. /** Called when time was explicitly jumped to/set.
  826. */
  827. virtual void TimeChanged(float newTime) = 0;
  828. // fix up internal pointers after load from Sequence Component
  829. virtual void InitPostLoad() = 0;
  830. // Copy some nodes of this sequence to XML.
  831. virtual void CopyNodes(XmlNodeRef& xmlNode, IAnimNode** pSelectedNodes, uint32 count) = 0;
  832. // Paste nodes given by the XML to this sequence.
  833. virtual void PasteNodes(const XmlNodeRef& xmlNode, IAnimNode* pParent) = 0;
  834. // Summary:
  835. // Adds/removes track events in sequence.
  836. virtual bool AddTrackEvent(const char* szEvent) = 0;
  837. virtual bool RemoveTrackEvent(const char* szEvent) = 0;
  838. virtual bool RenameTrackEvent(const char* szEvent, const char* szNewEvent) = 0;
  839. virtual bool MoveUpTrackEvent(const char* szEvent) = 0;
  840. virtual bool MoveDownTrackEvent(const char* szEvent) = 0;
  841. virtual void ClearTrackEvents() = 0;
  842. // Summary:
  843. // Gets the track events in the sequence.
  844. virtual int GetTrackEventsCount() const = 0;
  845. // Summary:
  846. // Gets the specified track event in the sequence.
  847. virtual char const* GetTrackEvent(int iIndex) const = 0;
  848. virtual IAnimStringTable* GetTrackEventStringTable() = 0;
  849. // Summary:
  850. // Called to trigger a track event.
  851. virtual void TriggerTrackEvent(const char* event, const char* param = NULL) = 0;
  852. //! Track event listener
  853. virtual void AddTrackEventListener(ITrackEventListener* pListener) = 0;
  854. virtual void RemoveTrackEventListener(ITrackEventListener* pListener) = 0;
  855. // return the sequence type - legacy or new component entity
  856. virtual SequenceType GetSequenceType() const = 0;
  857. // Expanded state interface
  858. virtual void SetExpanded(bool expanded) = 0;
  859. virtual bool GetExpanded() const = 0;
  860. virtual unsigned int GetUniqueTrackIdAndGenerateNext() = 0;
  861. // </interfuscator:shuffle>
  862. };
  863. /** Movie Listener interface.
  864. Register at movie system to get notified about movie events
  865. */
  866. struct IMovieListener
  867. {
  868. enum EMovieEvent
  869. {
  870. eMovieEvent_Started = 0, // fired when sequence is started
  871. eMovieEvent_Stopped, // fired when sequence ended normally
  872. eMovieEvent_Aborted, // fired when sequence was aborted before normal end (STOP and ABORTED event are mutually exclusive!)
  873. eMovieEvent_Updated, // fired after sequence time or playback speed was updated
  874. eMovieEvent_RecordModeStarted, // fired when Record Mode is started
  875. eMovieEvent_RecordModeStopped, // fired when Record Mode is stopped
  876. };
  877. // <interfuscator:shuffle>
  878. virtual ~IMovieListener(){}
  879. //! callback on movie events
  880. virtual void OnMovieEvent(EMovieEvent movieEvent, IAnimSequence* pAnimSequence) = 0;
  881. // </interfuscator:shuffle>
  882. };
  883. /** Movie System interface.
  884. Main entrance point to engine movie capability.
  885. Enumerate available movies, update all movies, create animation nodes and tracks.
  886. */
  887. struct IMovieSystem
  888. {
  889. AZ_TYPE_INFO_WITH_NAME_DECL(IMovieSystem);
  890. AZ_RTTI_NO_TYPE_INFO_DECL();
  891. enum ESequenceStopBehavior
  892. {
  893. eSSB_LeaveTime = 0, // When sequence is stopped it remains in last played time.
  894. eSSB_GotoEndTime = 1, // Default behavior in game, sequence is animated at end time before stop.
  895. eSSB_GotoStartTime = 2, // Default behavior in editor, sequence is animated at start time before stop.
  896. };
  897. // <interfuscator:shuffle>
  898. virtual ~IMovieSystem(){}
  899. //! Release movie system.
  900. virtual void Release() = 0;
  901. //! Set the user.
  902. virtual void SetUser(IMovieUser* pUser) = 0;
  903. //! Get the user.
  904. virtual IMovieUser* GetUser() = 0;
  905. virtual IAnimSequence* CreateSequence(const char* sequence, bool bLoad = false, uint32 id = 0, SequenceType = kSequenceTypeDefault, AZ::EntityId entityId = AZ::EntityId()) = 0;
  906. virtual void AddSequence(IAnimSequence* sequence) = 0;
  907. virtual void RemoveSequence(IAnimSequence* sequence) = 0;
  908. virtual IAnimSequence* FindLegacySequenceByName(const char* sequence) const = 0;
  909. virtual IAnimSequence* FindSequence(const AZ::EntityId& componentEntitySequenceId) const = 0;
  910. virtual IAnimSequence* FindSequenceById(uint32 id) const = 0;
  911. virtual IAnimSequence* GetSequence(int i) const = 0;
  912. virtual int GetNumSequences() const = 0;
  913. virtual IAnimSequence* GetPlayingSequence(int i) const = 0;
  914. virtual int GetNumPlayingSequences() const = 0;
  915. virtual bool IsCutScenePlaying() const = 0;
  916. virtual uint32 GrabNextSequenceId() = 0;
  917. // called whenever a new sequence Id is set - to update nextSequenceId
  918. virtual void OnSetSequenceId(uint32 sequenceId) = 0;
  919. //////////////////////////////////////////////////////////////////////////
  920. //
  921. // If the name of a sequence changes, the keys that refer it in the
  922. // sequence track of the director node should be properly updated also.
  923. //
  924. // @param before The old name of the sequence.
  925. // @param after The new name of the sequence.
  926. // @return Number of modified sequence keys.
  927. //
  928. //////////////////////////////////////////////////////////////////////////
  929. virtual int OnSequenceRenamed(const char* before, const char* after) = 0;
  930. //////////////////////////////////////////////////////////////////////////
  931. //
  932. // If the name of a camera changes, the keys that refer it in the
  933. // camera track of the director node should be properly updated also.
  934. // This updates the name of the corresponding camera node also, if any.
  935. //
  936. // @param before The old name of the camera.
  937. // @param after The new name of the camera.
  938. // @return Number of modified camera keys.
  939. //
  940. //////////////////////////////////////////////////////////////////////////
  941. virtual int OnCameraRenamed(const char* before, const char* after) = 0;
  942. // Adds a listener to a sequence
  943. // @param sequence Pointer to sequence
  944. // @param pListener Pointer to an IMovieListener
  945. // @return true on successful add, false otherwise
  946. virtual bool AddMovieListener(IAnimSequence* sequence, IMovieListener* pListener) = 0;
  947. // Removes a listener from a sequence
  948. // @param sequence Pointer to sequence
  949. // @param pListener Pointer to an IMovieListener
  950. // @return true on successful removal, false otherwise
  951. virtual bool RemoveMovieListener(IAnimSequence* sequence, IMovieListener* pListener) = 0;
  952. virtual ISystem* GetSystem() = 0;
  953. // Remove all sequences from movie system.
  954. virtual void RemoveAllSequences() = 0;
  955. //////////////////////////////////////////////////////////////////////////
  956. // Sequence playback.
  957. //////////////////////////////////////////////////////////////////////////
  958. // Start playing sequence.
  959. // Call ignored if sequence is already playing.
  960. // @param sequence Name of sequence to play.
  961. virtual void PlaySequence(const char* pSequenceName, IAnimSequence* pParentSeq, bool bResetFX, bool bTrackedSequence, float startTime = -FLT_MAX, float endTime = -FLT_MAX) = 0;
  962. // Start playing sequence.
  963. // Call ignored if sequence is already playing.
  964. // @param sequence Pointer to Valid sequence to play.
  965. virtual void PlaySequence(IAnimSequence* sequence, IAnimSequence* pParentSeq, bool bResetFX, bool bTrackedSequence, float startTime = -FLT_MAX, float endTime = -FLT_MAX) = 0;
  966. // Stops currently playing sequence.
  967. // Ignored if sequence is not playing.
  968. // Returns true if sequence has been stopped. false otherwise
  969. // @param sequence Name of playing sequence to stop.
  970. virtual bool StopSequence(const char* pSequenceName) = 0;
  971. // Stop's currently playing sequence.
  972. // Ignored if sequence is not playing.
  973. // Returns true if sequence has been stopped. false otherwise
  974. // @param sequence Pointer to Valid sequence to stop.
  975. virtual bool StopSequence(IAnimSequence* sequence) = 0;
  976. /** Aborts a currently playing sequence.
  977. Ignored if sequence is not playing.
  978. Calls IMovieListener with MOVIE_EVENT_ABORTED event (MOVIE_EVENT_DONE is NOT called)
  979. Returns true if sequence has been aborted. false otherwise
  980. @param sequence Pointer to Valid sequence to stop.
  981. @param bLeaveTime If false, uses default stop behavior, otherwise leaves the sequence at time
  982. */
  983. virtual bool AbortSequence(IAnimSequence* sequence, bool bLeaveTime = false) = 0;
  984. // Stops all currently playing sequences.
  985. virtual void StopAllSequences() = 0;
  986. // Stops all playing cut-scene sequences.
  987. // This will not stop all sequences, but only those with CUT_SCENE flag set.
  988. virtual void StopAllCutScenes() = 0;
  989. // Checks if specified sequence is playing.
  990. virtual bool IsPlaying(IAnimSequence* seq) const = 0;
  991. /** Resets playback state of movie system,
  992. usually called after loading of level,
  993. */
  994. virtual void Reset(bool bPlayOnReset, bool bSeekToStart) = 0;
  995. // Sequences with PLAY_ONRESET flag will start playing after this call.
  996. virtual void PlayOnLoadSequences() = 0;
  997. // Update movie system while not playing animation.
  998. virtual void StillUpdate() = 0;
  999. // Updates movie system every frame before the entity system to animate all playing sequences.
  1000. virtual void PreUpdate(const float dt) = 0;
  1001. // Updates movie system every frame after the entity system to animate all playing sequences.
  1002. virtual void PostUpdate(const float dt) = 0;
  1003. // Render function call of some special node.
  1004. virtual void Render() = 0;
  1005. // Set and enable Fixed Step cvars
  1006. virtual void EnableFixedStepForCapture(float step) = 0;
  1007. // Disable Fixed Step cvars and return to previous settings
  1008. virtual void DisableFixedStepForCapture() = 0;
  1009. // Signal the capturing start.
  1010. virtual void StartCapture(const ICaptureKey& key, int frame) = 0;
  1011. // Signal the capturing end.
  1012. virtual void EndCapture() = 0;
  1013. // Actually turn on/off the capturing.
  1014. // This is needed for the timing issue of turning on/off the capturing.
  1015. virtual void ControlCapture() = 0;
  1016. // Returns true if a Render Output capture is currently active.
  1017. virtual bool IsCapturing() const = 0;
  1018. // Set movie system into recording mode,
  1019. // While in recording mode any changes made to node will be added as keys to tracks.
  1020. virtual void SetRecording(bool recording) = 0;
  1021. virtual bool IsRecording() const = 0;
  1022. virtual void EnableCameraShake(bool bEnabled) = 0;
  1023. // Pause any playing sequences.
  1024. virtual void Pause() = 0;
  1025. // Resume playing sequences.
  1026. virtual void Resume() = 0;
  1027. // Pause cut scenes in editor.
  1028. virtual void PauseCutScenes() = 0;
  1029. // Resume cut scenes in editor.
  1030. virtual void ResumeCutScenes() = 0;
  1031. // Callback when animation-data changes
  1032. virtual void SetCallback(IMovieCallback* pCallback) = 0;
  1033. virtual IMovieCallback* GetCallback() = 0;
  1034. virtual const SCameraParams& GetCameraParams() const = 0;
  1035. virtual void SetCameraParams(const SCameraParams& Params) = 0;
  1036. virtual void SendGlobalEvent(const char* pszEvent) = 0;
  1037. // Gets the float time value for a sequence that is already playing
  1038. virtual float GetPlayingTime(IAnimSequence* pSeq) = 0;
  1039. virtual float GetPlayingSpeed(IAnimSequence* pSeq) = 0;
  1040. // Sets the time progression of an already playing cutscene.
  1041. // If IAnimSequence:NO_SEEK flag is set on pSeq, this call is ignored.
  1042. virtual bool SetPlayingTime(IAnimSequence* pSeq, float fTime) = 0;
  1043. virtual bool SetPlayingSpeed(IAnimSequence* pSeq, float fSpeed) = 0;
  1044. // Set behavior pattern for stopping sequences.
  1045. virtual void SetSequenceStopBehavior(ESequenceStopBehavior behavior) = 0;
  1046. // Set the start and end time of an already playing cutscene.
  1047. virtual bool GetStartEndTime(IAnimSequence* pSeq, float& fStartTime, float& fEndTime) = 0;
  1048. virtual bool SetStartEndTime(IAnimSequence* pSeq, const float fStartTime, const float fEndTime) = 0;
  1049. // Make the specified sequence go to a given frame time.
  1050. // @param seqName A sequence name.
  1051. // @param targetFrame A target frame to go to in time.
  1052. virtual void GoToFrame(const char* seqName, float targetFrame) = 0;
  1053. // Get the name of camera used for sequences instead of cameras specified in the director node.
  1054. virtual const char* GetOverrideCamName() const = 0;
  1055. // Get behavior pattern for stopping sequences.
  1056. virtual IMovieSystem::ESequenceStopBehavior GetSequenceStopBehavior() = 0;
  1057. // These are used to disable 'Ragdollize' events in the editor when the 'AI/Physics' is off.
  1058. virtual bool IsPhysicsEventsEnabled() const = 0;
  1059. virtual void EnablePhysicsEvents(bool enable) = 0;
  1060. virtual void EnableBatchRenderMode(bool bOn) = 0;
  1061. virtual bool IsInBatchRenderMode() const = 0;
  1062. virtual void LoadParamTypeFromXml(CAnimParamType& animParamType, const XmlNodeRef& xmlNode, const uint version) = 0;
  1063. virtual void SaveParamTypeToXml(const CAnimParamType& animParamType, XmlNodeRef& xmlNode) = 0;
  1064. // Should only be called from CAnimParamType
  1065. virtual void SerializeParamType(CAnimParamType& animParamType, XmlNodeRef& xmlNode, bool bLoading, const uint version) = 0;
  1066. // For buffering and presenting user notification messages in the Editor. Will also print as an AZ_Warning()
  1067. virtual void LogUserNotificationMsg(const AZStd::string& msg) = 0;
  1068. virtual void ClearUserNotificationMsgs() = 0;
  1069. virtual const AZStd::string& GetUserNotificationMsgs() const = 0;
  1070. // Call this from OnActivate() when a new sequence component entity is activated.
  1071. virtual void OnSequenceActivated(IAnimSequence* sequence) = 0;
  1072. #ifdef MOVIESYSTEM_SUPPORT_EDITING
  1073. virtual AnimNodeType GetNodeTypeFromString(const char* pString) const = 0;
  1074. virtual CAnimParamType GetParamTypeFromString(const char* pString) const = 0;
  1075. #endif
  1076. // fill in the animNodeType from the xmlNode description (or vice versa)
  1077. virtual void SerializeNodeType(AnimNodeType& animNodeType, XmlNodeRef& xmlNode, bool bLoading, const uint version, int flags) = 0;
  1078. // </interfuscator:shuffle>
  1079. };