3
0

IMovieSystem.h 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338
  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 AZ::Vector3& 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. virtual void SetPos(float time, const AZ::Vector3& pos) = 0;
  469. virtual void SetRotate(float time, const AZ::Quaternion& rot) = 0;
  470. virtual void SetScale(float time, const AZ::Vector3& scale) = 0;
  471. //! Compute and return the offset which brings the current position to the given position
  472. virtual Vec3 GetOffsetPosition(const Vec3& position);
  473. //! Get current entity position.
  474. virtual Vec3 GetPos() = 0;
  475. //! Get current entity rotation.
  476. virtual Quat GetRotate() = 0;
  477. //! Get entity rotation at specified time.
  478. virtual Quat GetRotate(float time) = 0;
  479. //! Get current entity scale.
  480. virtual Vec3 GetScale() = 0;
  481. // General Set param.
  482. // Set float/vec3/vec4 parameter at given time.
  483. // @return true if parameter set, false if this parameter not exist in node.
  484. virtual bool SetParamValue(float time, CAnimParamType param, float value) = 0;
  485. virtual bool SetParamValue(float time, CAnimParamType param, const Vec3& value) = 0;
  486. virtual bool SetParamValue(float time, CAnimParamType param, const Vec4& value) = 0;
  487. /**
  488. * O3DE_DEPRECATION_NOTICE(GHI-9326)
  489. * use equivalent SetParamValue that accepts AZ::Vector3
  490. **/
  491. bool SetParamValue(float time, CAnimParamType param, const AZ::Vector3& value);
  492. /**
  493. * O3DE_DEPRECATION_NOTICE(GHI-9326)
  494. * use equivalent SetParamValue that accepts AZ::Vector4
  495. **/
  496. bool SetParamValue(float time, CAnimParamType param, const AZ::Vector4& value);
  497. // Get float/vec3/vec4 parameter at given time.
  498. // @return true if parameter exist, false if this parameter not exist in node.
  499. virtual bool GetParamValue(float time, CAnimParamType param, float& value) = 0;
  500. virtual bool GetParamValue(float time, CAnimParamType param, Vec3& value) = 0;
  501. virtual bool GetParamValue(float time, CAnimParamType param, Vec4& value) = 0;
  502. /**
  503. * O3DE_DEPRECATION_NOTICE(GHI-9326)
  504. * use equivalent GetParamValue that accepts AZ::Vector4
  505. **/
  506. bool GetParamValue(float time, CAnimParamType param, AZ::Vector3& value);
  507. /**
  508. * O3DE_DEPRECATION_NOTICE(GHI-9326)
  509. * use equivalent GetParamValue that accepts AZ::Vector4
  510. **/
  511. bool GetParamValue(float time, CAnimParamType param, AZ::Vector4& value);
  512. //! Evaluate animation node while not playing animation.
  513. virtual void StillUpdate() = 0;
  514. //! Evaluate animation to the given time.
  515. virtual void Animate(SAnimContext& ec) = 0;
  516. // Description:
  517. // Returns number of supported parameters by this animation node (position,rotation,scale,etc..).
  518. // Returns:
  519. // Number of supported parameters.
  520. virtual unsigned int GetParamCount() const = 0;
  521. // Description:
  522. // Returns the type of a param by index
  523. // Arguments:
  524. // nIndex - parameter index in range 0 <= nIndex < GetSupportedParamCount()
  525. virtual CAnimParamType GetParamType(unsigned int nIndex) const = 0;
  526. // Description:
  527. // Check if parameter is supported by this node.
  528. virtual bool IsParamValid(const CAnimParamType& paramType) const = 0;
  529. // Description:
  530. // Returns name of supported parameter of this animation node or NULL if not available
  531. // Arguments:
  532. // paramType - parameter id
  533. virtual AZStd::string GetParamName(const CAnimParamType& paramType) const = 0;
  534. // Description:
  535. // Returns the params value type
  536. virtual AnimValueType GetParamValueType(const CAnimParamType& paramType) const = 0;
  537. // Description:
  538. // Returns the params value type
  539. virtual ESupportedParamFlags GetParamFlags(const CAnimParamType& paramType) const = 0;
  540. // Called node data is re-initialized, such as when changing the entity associated with it.
  541. virtual void OnReset() = 0;
  542. //////////////////////////////////////////////////////////////////////////
  543. // Working with Tracks.
  544. //////////////////////////////////////////////////////////////////////////
  545. virtual int GetTrackCount() const = 0;
  546. // Return track assigned to the specified parameter.
  547. virtual IAnimTrack* GetTrackByIndex(int nIndex) const = 0;
  548. // Return first track assigned to the specified parameter.
  549. virtual IAnimTrack* GetTrackForParameter(const CAnimParamType& paramType) const = 0;
  550. // Return the i-th track assigned to the specified parameter in case of multiple tracks.
  551. virtual IAnimTrack* GetTrackForParameter(const CAnimParamType& paramType, uint32 index) const = 0;
  552. // Get the index of a given track among tracks with the same parameter type in this node.
  553. virtual uint32 GetTrackParamIndex(const IAnimTrack* pTrack) const = 0;
  554. // Creates a new track for given parameter.
  555. virtual IAnimTrack* CreateTrack(const CAnimParamType& paramType) = 0;
  556. // Initializes track default values after de-serialization / user creation. Only called in editor.
  557. virtual void InitializeTrackDefaultValue(IAnimTrack* pTrack, const CAnimParamType& paramType) = 0;
  558. // Assign animation track to parameter.
  559. // if track parameter is NULL track with parameter id param will be removed.
  560. virtual void SetTrack(const CAnimParamType& paramType, IAnimTrack* track) = 0;
  561. // Set time range for all tracks in this sequence.
  562. virtual void SetTimeRange(Range timeRange) = 0;
  563. // Remove track from anim node.
  564. virtual void AddTrack(IAnimTrack* pTrack) = 0;
  565. // Remove track from anim node.
  566. virtual bool RemoveTrack(IAnimTrack* pTrack) = 0;
  567. // Description:
  568. // Creates default set of tracks supported by this node.
  569. virtual void CreateDefaultTracks() = 0;
  570. // returns the tangent type to use for created keys. Override this if you have an animNode that you wish
  571. // to have tangents other than UNIFIED created for new keys.
  572. virtual int GetDefaultKeyTangentFlags() const { return SPLINE_KEY_TANGENT_UNIFIED; }
  573. //////////////////////////////////////////////////////////////////////////
  574. //////////////////////////////////////////////////////////////////////////
  575. //////////////////////////////////////////////////////////////////////////
  576. // Callback for animation node used by editor.
  577. // Register notification callback with animation node.
  578. virtual void SetNodeOwner(IAnimNodeOwner* pOwner) = 0;
  579. virtual IAnimNodeOwner* GetNodeOwner() = 0;
  580. /**
  581. * O3DE_DEPRECATION_NOTICE(GHI-9326)
  582. * Serialization for Sequence data in Component Entity Sequences now occurs through AZ::SerializeContext and the Sequence Component
  583. **/
  584. virtual void Serialize(XmlNodeRef& xmlNode, bool bLoading, bool bLoadEmptyTracks) = 0;
  585. /**
  586. * O3DE_DEPRECATION_NOTICE(GHI-9326)
  587. * Serialization for Sequence data in Component Entity Sequences now occurs through AZ::SerializeContext and the Sequence Component
  588. **/
  589. virtual void SerializeAnims(XmlNodeRef& xmlNode, bool bLoading, bool bLoadEmptyTracks) = 0;
  590. // Sets up internal pointers post load from Sequence Component
  591. virtual void InitPostLoad(IAnimSequence* sequence) = 0;
  592. //////////////////////////////////////////////////////////////////////////
  593. //////////////////////////////////////////////////////////////////////////
  594. // Groups interface
  595. //////////////////////////////////////////////////////////////////////////
  596. virtual void SetParent(IAnimNode* pParent) = 0;
  597. virtual IAnimNode* GetParent() const = 0;
  598. virtual IAnimNode* HasDirectorAsParent() const = 0;
  599. //////////////////////////////////////////////////////////////////////////
  600. virtual void Render() = 0;
  601. virtual bool NeedToRender() const = 0;
  602. // Called from editor if dynamic params need updating
  603. virtual void UpdateDynamicParams() = 0;
  604. // </interfuscator:shuffle>
  605. // Used by AnimCameraNode
  606. virtual bool GetShakeRotation([[maybe_unused]] const float& time, [[maybe_unused]] Quat& rot){return false; }
  607. virtual void SetCameraShakeSeed([[maybe_unused]] const uint shakeSeed){};
  608. // override this method to handle explicit setting of time
  609. virtual void TimeChanged([[maybe_unused]] float newTime) {};
  610. // Compares all of the node's track values at the given time with the associated property value and
  611. // sets a key at that time if they are different to match the latter
  612. // Returns the number of keys set
  613. virtual int SetKeysForChangedTrackValues([[maybe_unused]] float time) { return 0; };
  614. // Callbacks used when Game/Simulation mode is started and stopped in the Editor. Override if you want to handle these events
  615. virtual void OnStartPlayInEditor() {};
  616. virtual void OnStopPlayInEditor() {};
  617. ////////////////////////////////////////////////////////////////////////////////
  618. // interface for Components - implemented by CAnimComponentNode
  619. // Override if the derived node has an associated component type (e.g. CAnimComponentNode)
  620. virtual void SetComponent([[maybe_unused]] AZ::ComponentId comopnentId, [[maybe_unused]] const AZ::Uuid& componentTypeId) {}
  621. // returns the componentId of the component the node is associate with, if applicable, or a AZ::InvalidComponentId otherwise
  622. virtual AZ::ComponentId GetComponentId() const { return AZ::InvalidComponentId; }
  623. // ~interface for Components
  624. ////////////////////////////////////////////////////////////////////////////////
  625. // Used to disable any animation that is overridden by a SceneNode during camera interpolation, such as
  626. // FoV, transform, nearZ
  627. virtual void SetSkipInterpolatedCameraNode([[maybe_unused]] const bool skipNodeCameraAnimation) {};
  628. // Expanded state interface
  629. virtual void SetExpanded(bool expanded) = 0;
  630. virtual bool GetExpanded() const = 0;
  631. // Return the node id. This id is unique within a given sequence.
  632. virtual int GetId() const = 0;
  633. };
  634. //! Track event listener
  635. struct ITrackEventListener
  636. {
  637. //! Reasons
  638. enum ETrackEventReason
  639. {
  640. eTrackEventReason_Added,
  641. eTrackEventReason_Removed,
  642. eTrackEventReason_Renamed,
  643. eTrackEventReason_Triggered,
  644. eTrackEventReason_MovedUp,
  645. eTrackEventReason_MovedDown,
  646. };
  647. // <interfuscator:shuffle>
  648. virtual ~ITrackEventListener(){}
  649. // Description:
  650. // Called when track event is updated
  651. // Arguments:
  652. // pSeq - Animation sequence
  653. // reason - Reason for update (see EReason)
  654. // event - Track event added
  655. // pUserData - Data to accompany reason
  656. virtual void OnTrackEvent(IAnimSequence* sequence, int reason, const char* event, void* pUserData) = 0;
  657. // </interfuscator:shuffle>
  658. };
  659. struct IAnimLegacySequenceObject
  660. {
  661. // <interfuscator:shuffle>
  662. virtual ~IAnimLegacySequenceObject() {}
  663. virtual void OnNameChanged() = 0;
  664. virtual void OnModified() = 0;
  665. // </interfuscator:shuffle>
  666. };
  667. struct IAnimStringTable
  668. {
  669. AZ_TYPE_INFO_WITH_NAME_DECL(IAnimStringTable);
  670. AZ_RTTI_NO_TYPE_INFO_DECL();
  671. virtual ~IAnimStringTable() {}
  672. // for intrusive_ptr support
  673. virtual void add_ref() = 0;
  674. virtual void release() = 0;
  675. virtual const char* Add(const char* p) = 0;
  676. };
  677. /** Animation sequence, operates on animation nodes contained in it.
  678. */
  679. struct IAnimSequence
  680. {
  681. AZ_TYPE_INFO_WITH_NAME_DECL(IAnimSequence);
  682. AZ_RTTI_NO_TYPE_INFO_DECL();
  683. AZ_CLASS_ALLOCATOR_DECL;
  684. static const int kSequenceVersion = 5;
  685. static void Reflect(AZ::ReflectContext* context);
  686. //! Flags used for SetFlags(),GetFlags(),SetParentFlags(),GetParentFlags() methods.
  687. enum EAnimSequenceFlags
  688. {
  689. eSeqFlags_PlayOnReset = BIT(0), //!< Start playing this sequence immediately after reset of movie system(Level load).
  690. eSeqFlags_OutOfRangeConstant = BIT(1), //!< Constant Out-Of-Range,time continues normally past sequence time range.
  691. eSeqFlags_OutOfRangeLoop = BIT(2), //!< Loop Out-Of-Range,time wraps back to the start of range when reaching end of range.
  692. eSeqFlags_CutScene = BIT(3), //!< Cut scene sequence.
  693. eSeqFlags_NoHUD = BIT(4), //!< @deprecated - Don`t display HUD
  694. eSeqFlags_NoPlayer = BIT(5), //!< Disable input and drawing of player
  695. eSeqFlags_NoGameSounds = BIT(9), //!< Suppress all game sounds.
  696. eSeqFlags_NoSeek = BIT(10), //!< Cannot seek in sequence.
  697. eSeqFlags_NoAbort = BIT(11), //!< Cutscene can not be aborted
  698. eSeqFlags_NoSpeed = BIT(13), //!< Cannot modify sequence speed - TODO: add interface control if required
  699. // eSeqFlags_CanWarpInFixedTime = BIT(14), //!< @deprecated - Timewarp by scaling a fixed time step - removed July 2017, unused
  700. eSeqFlags_EarlyMovieUpdate = BIT(15), //!< Turn the 'sys_earlyMovieUpdate' on during the sequence.
  701. eSeqFlags_LightAnimationSet = BIT(16), //!< A special unique sequence for light animations
  702. eSeqFlags_NoMPSyncingNeeded = BIT(17), //!< this sequence doesn't require MP net syncing
  703. eSeqFlags_DisplayAsFramesOrSeconds = BIT(18), //!< Display Start/End time as frames or seconds
  704. };
  705. virtual ~IAnimSequence() {};
  706. // for intrusive_ptr support
  707. virtual void add_ref() = 0;
  708. virtual void release() = 0;
  709. //! Set the name of this sequence. (ex. "Intro" in the same case as above)
  710. virtual void SetName(const char* name) = 0;
  711. //! Get the name of this sequence. (ex. "Intro" in the same case as above)
  712. virtual const char* GetName() const = 0;
  713. //! Get the ID (unique in a level and consistent across renaming) of this sequence.
  714. virtual uint32 GetId () const = 0;
  715. //! Resets the ID to the next available ID - used on sequence loads into levels to resolve ID collisions
  716. virtual void ResetId() = 0;
  717. // Legacy sequence objects are connected by pointers. SequenceComponents are connected by AZ::EntityId
  718. virtual void SetLegacySequenceObject(IAnimLegacySequenceObject* legacySequenceObject) = 0;
  719. virtual IAnimLegacySequenceObject* GetLegacySequenceObject() const = 0;
  720. virtual void SetSequenceEntityId(const AZ::EntityId& entityOwnerId) = 0;
  721. virtual const AZ::EntityId& GetSequenceEntityId() const = 0;
  722. //! Set the currently active director node.
  723. virtual void SetActiveDirector(IAnimNode* pDirectorNode) = 0;
  724. //! Get the currently active director node, if any.
  725. virtual IAnimNode* GetActiveDirector() const = 0;
  726. //! Set animation sequence flags
  727. virtual void SetFlags(int flags) = 0;
  728. //! Get animation sequence flags
  729. virtual int GetFlags() const = 0;
  730. //! Get cutscene related animation sequence flags
  731. virtual int GetCutSceneFlags(const bool localFlags = false) const = 0;
  732. //! Set parent animation sequence
  733. virtual void SetParentSequence(IAnimSequence* pParentSequence) = 0;
  734. //! Get parent animation sequence
  735. virtual const IAnimSequence* GetParentSequence() const = 0;
  736. //! Check whether this sequence has the given sequence as a descendant through one of its sequence tracks.
  737. virtual bool IsAncestorOf(const IAnimSequence* sequence) const = 0;
  738. //! Return number of animation nodes in sequence.
  739. virtual int GetNodeCount() const = 0;
  740. //! Get animation node at specified index.
  741. virtual IAnimNode* GetNode(int index) const = 0;
  742. //! Add animation node to sequence.
  743. //! @return True if node added, same node will not be added 2 times.
  744. virtual bool AddNode(IAnimNode* node) = 0;
  745. // Reorders the array of nodes, so the specified node is placed after or before the given pivot node depending on the parameter 'next'.
  746. virtual void ReorderNode(IAnimNode* node, IAnimNode* pPivotNode, bool next) = 0;
  747. // Description:
  748. // Creates a new animation node with specified type.
  749. // Arguments:
  750. // nodeType - Type of node, one of AnimNodeType enums.
  751. virtual IAnimNode* CreateNode(AnimNodeType nodeType) = 0;
  752. // Description:
  753. // Creates a new animation node from serialized node XML.
  754. // Arguments:
  755. // node - Serialized form of node
  756. virtual IAnimNode* CreateNode(XmlNodeRef node) = 0;
  757. //! Remove animation node from sequence.
  758. virtual void RemoveNode(IAnimNode* node, bool removeChildRelationships /*=true*/) = 0;
  759. // Finds node by name, can be slow.
  760. // If the node belongs to a director, the director node also should be given
  761. // since there can be multiple instances of the same node(i.e. the same name)
  762. // across multiple director nodes.
  763. virtual IAnimNode* FindNodeByName(const char* sNodeName, const IAnimNode* pParentDirector) = 0;
  764. //! Remove all nodes from sequence.
  765. virtual void RemoveAll() = 0;
  766. // Activate sequence by binding sequence animations to nodes.
  767. // must be called prior animating sequence.
  768. virtual void Activate() = 0;
  769. /** Check if sequence is activated
  770. */
  771. virtual bool IsActivated() const = 0;
  772. // Deactivates sequence by unbinding sequence animations from nodes.
  773. virtual void Deactivate() = 0;
  774. // Pre-caches data associated with this anim sequence.
  775. virtual void PrecacheData(float startTime = 0.0f) = 0;
  776. // Update sequence while not playing animation.
  777. virtual void StillUpdate() = 0;
  778. // Render function call for some special node.
  779. virtual void Render() = 0;
  780. // Evaluate animations of all nodes in sequence.
  781. // Sequence must be activated before animating.
  782. virtual void Animate(const SAnimContext& ec) = 0;
  783. //! Set time range of this sequence.
  784. virtual void SetTimeRange(Range timeRange) = 0;
  785. //! Get time range of this sequence.
  786. virtual Range GetTimeRange() = 0;
  787. //! Resets the sequence
  788. virtual void Reset(bool bSeekToStart) = 0;
  789. //! This can have more time-consuming tasks performed additional to tasks of the usual 'Reset()' method.
  790. virtual void ResetHard() = 0;
  791. // Called to pause sequence.
  792. virtual void Pause() = 0;
  793. // Called to resume sequence.
  794. virtual void Resume() = 0;
  795. /** Called to check if sequence is paused.
  796. */
  797. virtual bool IsPaused() const = 0;
  798. /** Called when a sequence is looped.
  799. */
  800. virtual void OnLoop() = 0;
  801. /** Move/Scale all keys in tracks from previous time range to new time range.
  802. */
  803. virtual void AdjustKeysToTimeRange(const Range& timeRange) = 0;
  804. /** Called when time was explicitly jumped to/set.
  805. */
  806. virtual void TimeChanged(float newTime) = 0;
  807. // fix up internal pointers after load from Sequence Component
  808. virtual void InitPostLoad() = 0;
  809. // Copy some nodes of this sequence to XML.
  810. virtual void CopyNodes(XmlNodeRef& xmlNode, IAnimNode** pSelectedNodes, uint32 count) = 0;
  811. // Paste nodes given by the XML to this sequence.
  812. virtual void PasteNodes(const XmlNodeRef& xmlNode, IAnimNode* pParent) = 0;
  813. // Summary:
  814. // Adds/removes track events in sequence.
  815. virtual bool AddTrackEvent(const char* szEvent) = 0;
  816. virtual bool RemoveTrackEvent(const char* szEvent) = 0;
  817. virtual bool RenameTrackEvent(const char* szEvent, const char* szNewEvent) = 0;
  818. virtual bool MoveUpTrackEvent(const char* szEvent) = 0;
  819. virtual bool MoveDownTrackEvent(const char* szEvent) = 0;
  820. virtual void ClearTrackEvents() = 0;
  821. // Summary:
  822. // Gets the track events in the sequence.
  823. virtual int GetTrackEventsCount() const = 0;
  824. // Summary:
  825. // Gets the specified track event in the sequence.
  826. virtual char const* GetTrackEvent(int iIndex) const = 0;
  827. virtual IAnimStringTable* GetTrackEventStringTable() = 0;
  828. // Summary:
  829. // Called to trigger a track event.
  830. virtual void TriggerTrackEvent(const char* event, const char* param = NULL) = 0;
  831. //! Track event listener
  832. virtual void AddTrackEventListener(ITrackEventListener* pListener) = 0;
  833. virtual void RemoveTrackEventListener(ITrackEventListener* pListener) = 0;
  834. // return the sequence type - legacy or new component entity
  835. virtual SequenceType GetSequenceType() const = 0;
  836. // Expanded state interface
  837. virtual void SetExpanded(bool expanded) = 0;
  838. virtual bool GetExpanded() const = 0;
  839. virtual unsigned int GetUniqueTrackIdAndGenerateNext() = 0;
  840. // </interfuscator:shuffle>
  841. };
  842. /** Movie Listener interface.
  843. Register at movie system to get notified about movie events
  844. */
  845. struct IMovieListener
  846. {
  847. enum EMovieEvent
  848. {
  849. eMovieEvent_Started = 0, // fired when sequence is started
  850. eMovieEvent_Stopped, // fired when sequence ended normally
  851. eMovieEvent_Aborted, // fired when sequence was aborted before normal end (STOP and ABORTED event are mutually exclusive!)
  852. eMovieEvent_Updated, // fired after sequence time or playback speed was updated
  853. eMovieEvent_RecordModeStarted, // fired when Record Mode is started
  854. eMovieEvent_RecordModeStopped, // fired when Record Mode is stopped
  855. };
  856. // <interfuscator:shuffle>
  857. virtual ~IMovieListener(){}
  858. //! callback on movie events
  859. virtual void OnMovieEvent(EMovieEvent movieEvent, IAnimSequence* pAnimSequence) = 0;
  860. // </interfuscator:shuffle>
  861. };
  862. /** Movie System interface.
  863. Main entrance point to engine movie capability.
  864. Enumerate available movies, update all movies, create animation nodes and tracks.
  865. */
  866. struct IMovieSystem
  867. {
  868. AZ_TYPE_INFO_WITH_NAME_DECL(IMovieSystem);
  869. AZ_RTTI_NO_TYPE_INFO_DECL();
  870. enum ESequenceStopBehavior
  871. {
  872. eSSB_LeaveTime = 0, // When sequence is stopped it remains in last played time.
  873. eSSB_GotoEndTime = 1, // Default behavior in game, sequence is animated at end time before stop.
  874. eSSB_GotoStartTime = 2, // Default behavior in editor, sequence is animated at start time before stop.
  875. };
  876. // <interfuscator:shuffle>
  877. virtual ~IMovieSystem(){}
  878. //! Release movie system.
  879. virtual void Release() = 0;
  880. //! Set the user.
  881. virtual void SetUser(IMovieUser* pUser) = 0;
  882. //! Get the user.
  883. virtual IMovieUser* GetUser() = 0;
  884. virtual IAnimSequence* CreateSequence(const char* sequence, bool bLoad = false, uint32 id = 0, SequenceType = kSequenceTypeDefault, AZ::EntityId entityId = AZ::EntityId()) = 0;
  885. virtual void AddSequence(IAnimSequence* sequence) = 0;
  886. virtual void RemoveSequence(IAnimSequence* sequence) = 0;
  887. virtual IAnimSequence* FindLegacySequenceByName(const char* sequence) const = 0;
  888. virtual IAnimSequence* FindSequence(const AZ::EntityId& componentEntitySequenceId) const = 0;
  889. virtual IAnimSequence* FindSequenceById(uint32 id) const = 0;
  890. virtual IAnimSequence* GetSequence(int i) const = 0;
  891. virtual int GetNumSequences() const = 0;
  892. virtual IAnimSequence* GetPlayingSequence(int i) const = 0;
  893. virtual int GetNumPlayingSequences() const = 0;
  894. virtual bool IsCutScenePlaying() const = 0;
  895. virtual uint32 GrabNextSequenceId() = 0;
  896. // called whenever a new sequence Id is set - to update nextSequenceId
  897. virtual void OnSetSequenceId(uint32 sequenceId) = 0;
  898. //////////////////////////////////////////////////////////////////////////
  899. //
  900. // If the name of a sequence changes, the keys that refer it in the
  901. // sequence track of the director node should be properly updated also.
  902. //
  903. // @param before The old name of the sequence.
  904. // @param after The new name of the sequence.
  905. // @return Number of modified sequence keys.
  906. //
  907. //////////////////////////////////////////////////////////////////////////
  908. virtual int OnSequenceRenamed(const char* before, const char* after) = 0;
  909. //////////////////////////////////////////////////////////////////////////
  910. //
  911. // If the name of a camera changes, the keys that refer it in the
  912. // camera track of the director node should be properly updated also.
  913. // This updates the name of the corresponding camera node also, if any.
  914. //
  915. // @param before The old name of the camera.
  916. // @param after The new name of the camera.
  917. // @return Number of modified camera keys.
  918. //
  919. //////////////////////////////////////////////////////////////////////////
  920. virtual int OnCameraRenamed(const char* before, const char* after) = 0;
  921. // Adds a listener to a sequence
  922. // @param sequence Pointer to sequence
  923. // @param pListener Pointer to an IMovieListener
  924. // @return true on successful add, false otherwise
  925. virtual bool AddMovieListener(IAnimSequence* sequence, IMovieListener* pListener) = 0;
  926. // Removes a listener from a sequence
  927. // @param sequence Pointer to sequence
  928. // @param pListener Pointer to an IMovieListener
  929. // @return true on successful removal, false otherwise
  930. virtual bool RemoveMovieListener(IAnimSequence* sequence, IMovieListener* pListener) = 0;
  931. virtual ISystem* GetSystem() = 0;
  932. // Remove all sequences from movie system.
  933. virtual void RemoveAllSequences() = 0;
  934. //////////////////////////////////////////////////////////////////////////
  935. // Sequence playback.
  936. //////////////////////////////////////////////////////////////////////////
  937. // Start playing sequence.
  938. // Call ignored if sequence is already playing.
  939. // @param sequence Name of sequence to play.
  940. virtual void PlaySequence(const char* pSequenceName, IAnimSequence* pParentSeq, bool bResetFX, bool bTrackedSequence, float startTime = -FLT_MAX, float endTime = -FLT_MAX) = 0;
  941. // Start playing sequence.
  942. // Call ignored if sequence is already playing.
  943. // @param sequence Pointer to Valid sequence to play.
  944. virtual void PlaySequence(IAnimSequence* sequence, IAnimSequence* pParentSeq, bool bResetFX, bool bTrackedSequence, float startTime = -FLT_MAX, float endTime = -FLT_MAX) = 0;
  945. // Stops currently playing sequence.
  946. // Ignored if sequence is not playing.
  947. // Returns true if sequence has been stopped. false otherwise
  948. // @param sequence Name of playing sequence to stop.
  949. virtual bool StopSequence(const char* pSequenceName) = 0;
  950. // Stop's currently playing sequence.
  951. // Ignored if sequence is not playing.
  952. // Returns true if sequence has been stopped. false otherwise
  953. // @param sequence Pointer to Valid sequence to stop.
  954. virtual bool StopSequence(IAnimSequence* sequence) = 0;
  955. /** Aborts a currently playing sequence.
  956. Ignored if sequence is not playing.
  957. Calls IMovieListener with MOVIE_EVENT_ABORTED event (MOVIE_EVENT_DONE is NOT called)
  958. Returns true if sequence has been aborted. false otherwise
  959. @param sequence Pointer to Valid sequence to stop.
  960. @param bLeaveTime If false, uses default stop behavior, otherwise leaves the sequence at time
  961. */
  962. virtual bool AbortSequence(IAnimSequence* sequence, bool bLeaveTime = false) = 0;
  963. // Stops all currently playing sequences.
  964. virtual void StopAllSequences() = 0;
  965. // Stops all playing cut-scene sequences.
  966. // This will not stop all sequences, but only those with CUT_SCENE flag set.
  967. virtual void StopAllCutScenes() = 0;
  968. // Checks if specified sequence is playing.
  969. virtual bool IsPlaying(IAnimSequence* seq) const = 0;
  970. /** Resets playback state of movie system,
  971. usually called after loading of level,
  972. */
  973. virtual void Reset(bool bPlayOnReset, bool bSeekToStart) = 0;
  974. // Sequences with PLAY_ONRESET flag will start playing after this call.
  975. virtual void PlayOnLoadSequences() = 0;
  976. // Update movie system while not playing animation.
  977. virtual void StillUpdate() = 0;
  978. // Updates movie system every frame before the entity system to animate all playing sequences.
  979. virtual void PreUpdate(const float dt) = 0;
  980. // Updates movie system every frame after the entity system to animate all playing sequences.
  981. virtual void PostUpdate(const float dt) = 0;
  982. // Render function call of some special node.
  983. virtual void Render() = 0;
  984. // Set and enable Fixed Step cvars
  985. virtual void EnableFixedStepForCapture(float step) = 0;
  986. // Disable Fixed Step cvars and return to previous settings
  987. virtual void DisableFixedStepForCapture() = 0;
  988. // Signal the capturing start.
  989. virtual void StartCapture(const ICaptureKey& key, int frame) = 0;
  990. // Signal the capturing end.
  991. virtual void EndCapture() = 0;
  992. // Actually turn on/off the capturing.
  993. // This is needed for the timing issue of turning on/off the capturing.
  994. virtual void ControlCapture() = 0;
  995. // Returns true if a Render Output capture is currently active.
  996. virtual bool IsCapturing() const = 0;
  997. // Set movie system into recording mode,
  998. // While in recording mode any changes made to node will be added as keys to tracks.
  999. virtual void SetRecording(bool recording) = 0;
  1000. virtual bool IsRecording() const = 0;
  1001. virtual void EnableCameraShake(bool bEnabled) = 0;
  1002. // Pause any playing sequences.
  1003. virtual void Pause() = 0;
  1004. // Resume playing sequences.
  1005. virtual void Resume() = 0;
  1006. // Pause cut scenes in editor.
  1007. virtual void PauseCutScenes() = 0;
  1008. // Resume cut scenes in editor.
  1009. virtual void ResumeCutScenes() = 0;
  1010. // Callback when animation-data changes
  1011. virtual void SetCallback(IMovieCallback* pCallback) = 0;
  1012. virtual IMovieCallback* GetCallback() = 0;
  1013. virtual const SCameraParams& GetCameraParams() const = 0;
  1014. virtual void SetCameraParams(const SCameraParams& Params) = 0;
  1015. virtual void SendGlobalEvent(const char* pszEvent) = 0;
  1016. // Gets the float time value for a sequence that is already playing
  1017. virtual float GetPlayingTime(IAnimSequence* pSeq) = 0;
  1018. virtual float GetPlayingSpeed(IAnimSequence* pSeq) = 0;
  1019. // Sets the time progression of an already playing cutscene.
  1020. // If IAnimSequence:NO_SEEK flag is set on pSeq, this call is ignored.
  1021. virtual bool SetPlayingTime(IAnimSequence* pSeq, float fTime) = 0;
  1022. virtual bool SetPlayingSpeed(IAnimSequence* pSeq, float fSpeed) = 0;
  1023. // Set behavior pattern for stopping sequences.
  1024. virtual void SetSequenceStopBehavior(ESequenceStopBehavior behavior) = 0;
  1025. // Set the start and end time of an already playing cutscene.
  1026. virtual bool GetStartEndTime(IAnimSequence* pSeq, float& fStartTime, float& fEndTime) = 0;
  1027. virtual bool SetStartEndTime(IAnimSequence* pSeq, const float fStartTime, const float fEndTime) = 0;
  1028. // Make the specified sequence go to a given frame time.
  1029. // @param seqName A sequence name.
  1030. // @param targetFrame A target frame to go to in time.
  1031. virtual void GoToFrame(const char* seqName, float targetFrame) = 0;
  1032. // Get the name of camera used for sequences instead of cameras specified in the director node.
  1033. virtual const char* GetOverrideCamName() const = 0;
  1034. // Get behavior pattern for stopping sequences.
  1035. virtual IMovieSystem::ESequenceStopBehavior GetSequenceStopBehavior() = 0;
  1036. // These are used to disable 'Ragdollize' events in the editor when the 'AI/Physics' is off.
  1037. virtual bool IsPhysicsEventsEnabled() const = 0;
  1038. virtual void EnablePhysicsEvents(bool enable) = 0;
  1039. virtual void EnableBatchRenderMode(bool bOn) = 0;
  1040. virtual bool IsInBatchRenderMode() const = 0;
  1041. virtual void LoadParamTypeFromXml(CAnimParamType& animParamType, const XmlNodeRef& xmlNode, const uint version) = 0;
  1042. virtual void SaveParamTypeToXml(const CAnimParamType& animParamType, XmlNodeRef& xmlNode) = 0;
  1043. // Should only be called from CAnimParamType
  1044. virtual void SerializeParamType(CAnimParamType& animParamType, XmlNodeRef& xmlNode, bool bLoading, const uint version) = 0;
  1045. // For buffering and presenting user notification messages in the Editor. Will also print as an AZ_Warning()
  1046. virtual void LogUserNotificationMsg(const AZStd::string& msg) = 0;
  1047. virtual void ClearUserNotificationMsgs() = 0;
  1048. virtual const AZStd::string& GetUserNotificationMsgs() const = 0;
  1049. // Call this from OnActivate() when a new sequence component entity is activated.
  1050. virtual void OnSequenceActivated(IAnimSequence* sequence) = 0;
  1051. #ifdef MOVIESYSTEM_SUPPORT_EDITING
  1052. virtual AnimNodeType GetNodeTypeFromString(const char* pString) const = 0;
  1053. virtual CAnimParamType GetParamTypeFromString(const char* pString) const = 0;
  1054. #endif
  1055. // fill in the animNodeType from the xmlNode description (or vice versa)
  1056. virtual void SerializeNodeType(AnimNodeType& animNodeType, XmlNodeRef& xmlNode, bool bLoading, const uint version, int flags) = 0;
  1057. // </interfuscator:shuffle>
  1058. };