SequenceComponentBus.h 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843
  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/Asset/AssetCommon.h>
  10. #include <AzCore/Math/Quaternion.h>
  11. #include <AzCore/Math/Vector3.h>
  12. #include <AzCore/Component/ComponentApplicationBus.h>
  13. #include <AzCore/Component/Entity.h>
  14. #include <AzCore/Component/ComponentBus.h>
  15. #include <AzCore/std/string/string.h>
  16. namespace Maestro
  17. {
  18. /*!
  19. * SequenceComponentRequests EBus Interface
  20. * Messages serviced by SequenceComponents.
  21. */
  22. class SequenceComponentRequests
  23. : public AZ::ComponentBus
  24. {
  25. public:
  26. /**
  27. * helper class to define an animatable property address
  28. */
  29. class AnimatablePropertyAddress
  30. {
  31. public:
  32. AZ_TYPE_INFO(AnimatablePropertyAddress, "{CEE14802-F1E8-4C0A-9750-64C59C39ECE9}");
  33. AnimatablePropertyAddress(AZ::ComponentId componentId, const AZStd::string& virtualPropertyName)
  34. : m_componentId(componentId)
  35. , m_virtualPropertyName(virtualPropertyName) {}
  36. AnimatablePropertyAddress()
  37. : m_componentId(AZ::InvalidComponentId) {}
  38. const AZStd::string& GetVirtualPropertyName() const { return m_virtualPropertyName; }
  39. AZ::ComponentId GetComponentId() const { return m_componentId; }
  40. bool operator== (const AnimatablePropertyAddress& rhs) const
  41. {
  42. return (m_componentId == rhs.m_componentId && m_virtualPropertyName == rhs.m_virtualPropertyName);
  43. }
  44. private:
  45. AZ::ComponentId m_componentId; // componentId of the component being animated on the sequenceAgent's entity
  46. AZStd::string m_virtualPropertyName; // EBus virtual property name being animated on the component
  47. };
  48. /**
  49. * Interface for an animated value to abstract the type (i.e. float/Vector3/Bool) of the value.
  50. *
  51. * Inherited concrete subclasses determines the actual type of the animatedValue and fills in get/set methods
  52. * for casting to other types
  53. */
  54. // forward declarations
  55. class AnimatedFloatValue;
  56. class AnimatedVector3Value;
  57. class AnimatedBoolValue;
  58. class AnimatedQuaternionValue;
  59. class AnimatedAssetIdValue;
  60. class AnimatedValue
  61. {
  62. public:
  63. AZ_TYPE_INFO(AnimatedValue, "{5C4BBDD6-8F80-4510-B5B8-8FA0FBD101A6}");
  64. virtual ~AnimatedValue() {};
  65. // Query the type of the value
  66. virtual AZ::TypeId GetTypeId() const = 0;
  67. void GetValue(AZ::Vector3& vector3Value) const
  68. {
  69. vector3Value = GetVector3Value();
  70. }
  71. void GetValue(AZ::Quaternion& quaternionValue) const
  72. {
  73. quaternionValue = GetQuaternionValue();
  74. }
  75. void GetValue(float& floatValue) const
  76. {
  77. floatValue = GetFloatValue();
  78. }
  79. void GetValue(bool& boolValue) const
  80. {
  81. boolValue = GetBoolValue();
  82. }
  83. void GetValue(AZ::s32& s32Value) const
  84. {
  85. s32Value = GetS32Value();
  86. }
  87. void GetValue(AZ::u32& u32Value) const
  88. {
  89. u32Value = GetU32Value();
  90. }
  91. void GetValue(AZ::Data::AssetId& assetIdValue) const
  92. {
  93. assetIdValue = GetAssetIdValue();
  94. }
  95. // same as above but returning the value
  96. virtual AZ::Quaternion GetQuaternionValue() const = 0;
  97. virtual AZ::Vector3 GetVector3Value() const = 0;
  98. virtual float GetFloatValue() const = 0;
  99. virtual bool GetBoolValue() const = 0;
  100. virtual AZ::s32 GetS32Value() const = 0;
  101. virtual AZ::u32 GetU32Value() const = 0;
  102. virtual const AZ::Data::AssetId& GetAssetIdValue() const = 0;
  103. // Set the value to the given arg. Returns true if the arg is the 'native' type of the concrete animated value
  104. virtual bool SetValue(const AZ::Vector3& vector3Value) = 0;
  105. virtual bool SetValue(const AZ::Quaternion& quaternionValue) = 0;
  106. virtual bool SetValue(float floatValue) = 0;
  107. virtual bool SetValue(bool boolValue) = 0;
  108. virtual bool SetValue(AZ::s32 s32Value) = 0;
  109. virtual bool SetValue(AZ::u32 u32Value) = 0;
  110. virtual bool SetValue(const AZ::Data::AssetId& assetIdValue) = 0;
  111. virtual bool IsClose(const AnimatedFloatValue& rhs, float tolerance = AZ::Constants::Tolerance) const = 0;
  112. virtual bool IsClose(const AnimatedVector3Value& rhs, float tolerance = AZ::Constants::Tolerance) const = 0;
  113. virtual bool IsClose(const AnimatedQuaternionValue& rhs, float tolerance = AZ::Constants::Tolerance) const = 0;
  114. virtual bool IsClose(const AnimatedBoolValue& rhs, float tolerance = AZ::Constants::Tolerance) const = 0;
  115. virtual bool IsClose(const AnimatedAssetIdValue& rhs, float tolerance = AZ::Constants::Tolerance) const = 0;
  116. protected:
  117. AnimatedValue() {} // protected constructor as the interface should never be constructed directly - it's an abstract class
  118. };
  119. class AnimatedFloatValue
  120. : public AnimatedValue
  121. {
  122. public:
  123. AZ_TYPE_INFO(AnimatedFloatValue, "{2C90BCBB-1DF2-47C8-8193-18EFE1C70E20}");
  124. AnimatedFloatValue(float value = .0f) { m_value = value; }
  125. ~AnimatedFloatValue() {}
  126. AZ::TypeId GetTypeId() const override
  127. {
  128. return AZ::AzTypeInfo<float>::Uuid();
  129. }
  130. AZ::Vector3 GetVector3Value() const override
  131. {
  132. return AZ::Vector3(m_value);
  133. }
  134. AZ::Quaternion GetQuaternionValue() const override
  135. {
  136. return AZ::Quaternion(m_value);
  137. }
  138. float GetFloatValue() const override
  139. {
  140. return m_value;
  141. }
  142. bool GetBoolValue() const override
  143. {
  144. return (!AZ::IsClose(m_value, .0f, FLT_EPSILON));
  145. }
  146. AZ::s32 GetS32Value() const override
  147. {
  148. return static_cast<AZ::s32>(m_value);
  149. }
  150. AZ::u32 GetU32Value() const override
  151. {
  152. return static_cast<AZ::u32>(m_value);
  153. }
  154. const AZ::Data::AssetId& GetAssetIdValue() const override
  155. {
  156. AZ_Assert(0, "Not expected to be used.");
  157. static AZ::Data::AssetId assetId;
  158. return assetId;
  159. }
  160. bool SetValue(const AZ::Vector3& vector3Value) override
  161. {
  162. m_value = vector3Value.GetX();
  163. return false;
  164. }
  165. bool SetValue(const AZ::Quaternion& quaternionValue) override
  166. {
  167. m_value = quaternionValue.GetLength();
  168. return false;
  169. }
  170. bool SetValue(float floatValue) override
  171. {
  172. m_value = floatValue;
  173. return true;
  174. }
  175. bool SetValue(bool boolValue) override
  176. {
  177. m_value = boolValue ? 1.0f : .0f;
  178. return false;
  179. }
  180. bool SetValue(AZ::s32 s32Value) override
  181. {
  182. m_value = static_cast<float>(s32Value);
  183. return false;
  184. }
  185. bool SetValue(AZ::u32 u32Value) override
  186. {
  187. m_value = static_cast<float>(u32Value);
  188. return false;
  189. }
  190. bool SetValue(const AZ::Data::AssetId& assetIdValue) override
  191. {
  192. AZ_UNUSED(assetIdValue);
  193. return true;
  194. }
  195. bool IsClose(const AnimatedFloatValue& rhs, float tolerance = AZ::Constants::FloatEpsilon) const override
  196. {
  197. return AZ::IsClose(m_value, rhs.GetFloatValue(), tolerance);
  198. }
  199. bool IsClose(const AnimatedVector3Value& rhs, float tolerance = AZ::Constants::Tolerance) const override
  200. {
  201. return AZ::IsClose(m_value, rhs.GetFloatValue(), tolerance);
  202. }
  203. bool IsClose(const AnimatedQuaternionValue& rhs, float tolerance = AZ::Constants::Tolerance) const override
  204. {
  205. return AZ::IsClose(m_value, rhs.GetFloatValue(), tolerance);
  206. }
  207. bool IsClose(const AnimatedBoolValue& rhs, float tolerance = AZ::Constants::Tolerance) const override
  208. {
  209. return rhs.GetBoolValue() == (!AZ::IsClose(m_value, .0f, tolerance));
  210. }
  211. bool IsClose(const AnimatedAssetIdValue& rhs, float tolerance = AZ::Constants::Tolerance) const override
  212. {
  213. AZ_Assert(0, "Shouldnt be used.");
  214. AZ_UNUSED(rhs);
  215. AZ_UNUSED(tolerance);
  216. return false;
  217. }
  218. private:
  219. float m_value;
  220. };
  221. class AnimatedVector3Value
  222. : public AnimatedValue
  223. {
  224. public:
  225. AZ_TYPE_INFO(AnimatedVector3Value, "{B8CDD566-9D55-47B2-BF91-162E428B237E}");
  226. AnimatedVector3Value(const AZ::Vector3& value) { m_value = value; }
  227. ~AnimatedVector3Value() {}
  228. AZ::TypeId GetTypeId() const override
  229. {
  230. return AZ::Vector3::TYPEINFO_Uuid();
  231. }
  232. AZ::Vector3 GetVector3Value() const override
  233. {
  234. return m_value;
  235. }
  236. AZ::Quaternion GetQuaternionValue() const override
  237. {
  238. // treat m_value as Euler Angles in degrees
  239. return AZ::ConvertEulerDegreesToQuaternion(m_value);
  240. }
  241. float GetFloatValue() const override
  242. {
  243. return m_value.GetX(); // return the first component
  244. }
  245. bool GetBoolValue() const override
  246. {
  247. return !m_value.IsClose(AZ::Vector3::CreateZero());
  248. }
  249. AZ::s32 GetS32Value() const override
  250. {
  251. return static_cast<AZ::s32>(m_value.GetX());
  252. }
  253. AZ::u32 GetU32Value() const override
  254. {
  255. return static_cast<AZ::u32>(m_value.GetX());
  256. }
  257. const AZ::Data::AssetId& GetAssetIdValue() const override
  258. {
  259. AZ_Assert(0, "Not expected to be used.");
  260. static AZ::Data::AssetId assetId;
  261. return assetId;
  262. }
  263. bool SetValue(const AZ::Vector3& vector3Value) override
  264. {
  265. m_value = vector3Value;
  266. return true;
  267. }
  268. bool SetValue(const AZ::Quaternion& quaternionValue) override
  269. {
  270. m_value = AZ::ConvertQuaternionToEulerDegrees(quaternionValue);
  271. return true;
  272. }
  273. bool SetValue(float floatValue) override
  274. {
  275. m_value.Set(floatValue); // sets vector components to floatValue
  276. return false;
  277. }
  278. bool SetValue(bool boolValue) override
  279. {
  280. m_value = boolValue ? AZ::Vector3::CreateOne() : AZ::Vector3::CreateZero();
  281. return false;
  282. }
  283. bool SetValue(AZ::s32 s32Value) override
  284. {
  285. m_value.Set(static_cast<float>(s32Value));
  286. return false;
  287. }
  288. bool SetValue(AZ::u32 u32Value) override
  289. {
  290. m_value.Set(static_cast<float>(u32Value));
  291. return false;
  292. }
  293. bool SetValue(const AZ::Data::AssetId& assetIdValue) override
  294. {
  295. AZ_UNUSED(assetIdValue);
  296. return true;
  297. }
  298. bool IsClose(const AnimatedFloatValue& rhs, float tolerance = AZ::Constants::FloatEpsilon) const override
  299. {
  300. return m_value.IsClose(rhs.GetVector3Value(), tolerance);
  301. }
  302. bool IsClose(const AnimatedVector3Value& rhs, float tolerance = AZ::Constants::Tolerance) const override
  303. {
  304. return m_value.IsClose(rhs.GetVector3Value(), tolerance);
  305. }
  306. bool IsClose(const AnimatedQuaternionValue& rhs, float tolerance = AZ::Constants::Tolerance) const override
  307. {
  308. return m_value.IsClose(rhs.GetVector3Value(), tolerance);
  309. }
  310. bool IsClose(const AnimatedBoolValue& rhs, float tolerance = AZ::Constants::Tolerance) const override
  311. {
  312. return rhs.GetBoolValue() == (!m_value.IsClose(AZ::Vector3::CreateZero(), tolerance));
  313. }
  314. bool IsClose(const AnimatedAssetIdValue& rhs, float tolerance = AZ::Constants::Tolerance) const override
  315. {
  316. AZ_Assert(0, "Shouldn't be used.");
  317. AZ_UNUSED(rhs);
  318. AZ_UNUSED(tolerance);
  319. return false;
  320. }
  321. private:
  322. AZ::Vector3 m_value;
  323. };
  324. class AnimatedQuaternionValue
  325. : public AnimatedValue
  326. {
  327. public:
  328. AZ_TYPE_INFO(AnimatedQuaternionValue, "{572E640B-9375-4E16-8F3A-5DCA1734B820}");
  329. AnimatedQuaternionValue(const AZ::Quaternion value) { m_value = value; }
  330. ~AnimatedQuaternionValue() {}
  331. AZ::TypeId GetTypeId() const override
  332. {
  333. return AZ::Quaternion::TYPEINFO_Uuid();
  334. }
  335. AZ::Vector3 GetVector3Value() const override
  336. {
  337. // convert Quaternion to Euler angles
  338. return AZ::ConvertQuaternionToEulerDegrees(m_value);
  339. }
  340. AZ::Quaternion GetQuaternionValue() const override
  341. {
  342. return m_value;
  343. }
  344. float GetFloatValue() const override
  345. {
  346. // return the length of the quat
  347. return m_value.GetLength();
  348. }
  349. bool GetBoolValue() const override
  350. {
  351. return !m_value.IsZero();
  352. }
  353. AZ::s32 GetS32Value() const override
  354. {
  355. return static_cast<AZ::s32>(m_value.GetLength());
  356. }
  357. AZ::u32 GetU32Value() const override
  358. {
  359. return static_cast<AZ::u32>(m_value.GetLength());
  360. }
  361. const AZ::Data::AssetId& GetAssetIdValue() const override
  362. {
  363. AZ_Assert(0, "Not expected to be used.");
  364. static AZ::Data::AssetId assetId;
  365. return assetId;
  366. }
  367. bool SetValue(const AZ::Vector3& vector3Value) override
  368. {
  369. // convert from Euler angles
  370. m_value = AZ::ConvertEulerRadiansToQuaternion(vector3Value);
  371. return false;
  372. }
  373. bool SetValue(const AZ::Quaternion& quaternionValue) override
  374. {
  375. m_value = quaternionValue;
  376. return true;
  377. }
  378. bool SetValue(float floatValue) override
  379. {
  380. m_value.Set(floatValue); // sets quat with all components set to floatValue
  381. return false;
  382. }
  383. bool SetValue(bool boolValue) override
  384. {
  385. m_value = boolValue ? AZ::Quaternion::CreateIdentity() : AZ::Quaternion::CreateZero();
  386. return false;
  387. }
  388. bool SetValue(AZ::s32 s32Value) override
  389. {
  390. m_value.Set(static_cast<float>(s32Value));
  391. return false;
  392. }
  393. bool SetValue(AZ::u32 u32Value) override
  394. {
  395. m_value.Set(static_cast<float>(u32Value));
  396. return false;
  397. }
  398. bool SetValue(const AZ::Data::AssetId& assetIdValue) override
  399. {
  400. AZ_UNUSED(assetIdValue);
  401. return true;
  402. }
  403. bool IsClose(const AnimatedFloatValue& rhs, float tolerance = AZ::Constants::FloatEpsilon) const override
  404. {
  405. return m_value.IsClose(rhs.GetQuaternionValue(), tolerance);
  406. }
  407. bool IsClose(const AnimatedVector3Value& rhs, float tolerance = AZ::Constants::Tolerance) const override
  408. {
  409. return m_value.IsClose(rhs.GetQuaternionValue(), tolerance);
  410. }
  411. bool IsClose(const AnimatedQuaternionValue& rhs, float tolerance = AZ::Constants::Tolerance) const override
  412. {
  413. return m_value.IsClose(rhs.m_value, tolerance);
  414. }
  415. bool IsClose(const AnimatedBoolValue& rhs, float tolerance = AZ::Constants::Tolerance) const override
  416. {
  417. return rhs.GetBoolValue() == (!m_value.IsZero(tolerance));
  418. }
  419. bool IsClose(const AnimatedAssetIdValue& rhs, float tolerance = AZ::Constants::Tolerance) const override
  420. {
  421. AZ_Assert(0, "Shouldn't be used.");
  422. AZ_UNUSED(rhs);
  423. AZ_UNUSED(tolerance);
  424. return false;
  425. }
  426. private:
  427. AZ::Quaternion m_value;
  428. };
  429. class AnimatedBoolValue
  430. : public AnimatedValue
  431. {
  432. public:
  433. AZ_TYPE_INFO(AnimatedBoolValue, "{5FF422AD-20E7-4109-A2EA-4AACE8213860}");
  434. AnimatedBoolValue(bool value) { m_value = value; }
  435. ~AnimatedBoolValue() {}
  436. AZ::TypeId GetTypeId() const override
  437. {
  438. return AZ::AzTypeInfo<bool>::Uuid();
  439. }
  440. AZ::Vector3 GetVector3Value() const override
  441. {
  442. return m_value ? AZ::Vector3::CreateOne() : AZ::Vector3::CreateZero();;
  443. }
  444. AZ::Quaternion GetQuaternionValue() const override
  445. {
  446. return m_value ? AZ::Quaternion::CreateIdentity() : AZ::Quaternion::CreateZero();;
  447. }
  448. float GetFloatValue() const override
  449. {
  450. return m_value ? 1.0f : .0f;
  451. }
  452. bool GetBoolValue() const override
  453. {
  454. return m_value;
  455. }
  456. AZ::s32 GetS32Value() const override
  457. {
  458. return m_value ? 1 : 0;
  459. }
  460. AZ::u32 GetU32Value() const override
  461. {
  462. return m_value ? 1 : 0;
  463. }
  464. const AZ::Data::AssetId& GetAssetIdValue() const override
  465. {
  466. AZ_Assert(0, "Not expected to be used.");
  467. static AZ::Data::AssetId assetId;
  468. return assetId;
  469. }
  470. bool SetValue(const AZ::Vector3& vector3Value) override
  471. {
  472. m_value = !vector3Value.IsClose(AZ::Vector3::CreateZero());
  473. return false;
  474. }
  475. bool SetValue(const AZ::Quaternion& quaternionValue) override
  476. {
  477. m_value = !quaternionValue.IsZero();
  478. return false;
  479. }
  480. bool SetValue(float floatValue) override
  481. {
  482. m_value = !AZ::IsClose(floatValue, .0f, FLT_EPSILON);
  483. return false;
  484. }
  485. bool SetValue(bool boolValue) override
  486. {
  487. m_value = boolValue;
  488. return true;
  489. }
  490. bool SetValue(AZ::s32 s32Value) override
  491. {
  492. m_value = s32Value != 0;
  493. return false;
  494. }
  495. bool SetValue(AZ::u32 u32Value) override
  496. {
  497. m_value = u32Value != 0;
  498. return false;
  499. }
  500. bool SetValue(const AZ::Data::AssetId& assetIdValue) override
  501. {
  502. AZ_UNUSED(assetIdValue);
  503. return true;
  504. }
  505. bool IsClose(const AnimatedFloatValue& rhs, float tolerance = AZ::Constants::FloatEpsilon) const override
  506. {
  507. return m_value == (!AZ::IsClose(rhs.GetFloatValue(), .0f, tolerance));
  508. }
  509. bool IsClose(const AnimatedVector3Value& rhs, float tolerance = AZ::Constants::Tolerance) const override
  510. {
  511. return m_value == (!rhs.GetVector3Value().IsClose(AZ::Vector3::CreateZero(), tolerance));
  512. }
  513. bool IsClose(const AnimatedQuaternionValue& rhs, float tolerance = AZ::Constants::Tolerance) const override
  514. {
  515. return m_value == (!rhs.GetQuaternionValue().IsZero(tolerance));
  516. }
  517. bool IsClose(const AnimatedBoolValue& rhs, float tolerance = AZ::Constants::Tolerance) const override
  518. {
  519. (void)tolerance; // avoid compiler warning for unused variable
  520. return m_value == rhs.m_value;
  521. }
  522. bool IsClose(const AnimatedAssetIdValue& rhs, float tolerance = AZ::Constants::Tolerance) const override
  523. {
  524. AZ_Assert(0, "Shouldn't be used.");
  525. AZ_UNUSED(rhs);
  526. AZ_UNUSED(tolerance);
  527. return false;
  528. }
  529. private:
  530. bool m_value;
  531. };
  532. class AnimatedAssetIdValue
  533. : public AnimatedValue
  534. {
  535. public:
  536. AZ_TYPE_INFO(AnimatedAssetIdValue, "{BA8AFA84-44C7-4358-AB35-775AF2B8A109}");
  537. AnimatedAssetIdValue() { m_value.SetInvalid(); }
  538. AnimatedAssetIdValue(const AZ::Data::AssetId& value) { m_value = value; }
  539. AZ::TypeId GetTypeId() const override
  540. {
  541. return AZ::AzTypeInfo<AZ::Data::AssetId>::Uuid();
  542. }
  543. AZ::Vector3 GetVector3Value() const override
  544. {
  545. return AZ::Vector3::CreateZero();;
  546. }
  547. AZ::Quaternion GetQuaternionValue() const override
  548. {
  549. return AZ::Quaternion::CreateZero();;
  550. }
  551. float GetFloatValue() const override
  552. {
  553. return 0.0f;
  554. }
  555. bool GetBoolValue() const override
  556. {
  557. return false;
  558. }
  559. AZ::s32 GetS32Value() const override
  560. {
  561. return 0;
  562. }
  563. AZ::u32 GetU32Value() const override
  564. {
  565. return 0;
  566. }
  567. const AZ::Data::AssetId& GetAssetIdValue() const override
  568. {
  569. return m_value;
  570. }
  571. bool SetValue(const AZ::Vector3& vector3Value) override
  572. {
  573. AZ_UNUSED(vector3Value);
  574. return false;
  575. }
  576. bool SetValue(const AZ::Quaternion& quaternionValue) override
  577. {
  578. AZ_UNUSED(quaternionValue);
  579. return false;
  580. }
  581. bool SetValue(float floatValue) override
  582. {
  583. AZ_UNUSED(floatValue);
  584. return false;
  585. }
  586. bool SetValue(bool boolValue) override
  587. {
  588. AZ_UNUSED(boolValue);
  589. return true;
  590. }
  591. bool SetValue(AZ::s32 s32Value) override
  592. {
  593. AZ_UNUSED(s32Value);
  594. return false;
  595. }
  596. bool SetValue(AZ::u32 u32Value) override
  597. {
  598. AZ_UNUSED(u32Value);
  599. return false;
  600. }
  601. bool SetValue(const AZ::Data::AssetId& assetIdValue) override
  602. {
  603. m_value = assetIdValue;
  604. return true;
  605. }
  606. bool IsClose([[maybe_unused]] const AnimatedFloatValue& rhs, float tolerance = AZ::Constants::FloatEpsilon) const override
  607. {
  608. AZ_UNUSED(tolerance);
  609. return false;
  610. }
  611. bool IsClose([[maybe_unused]] const AnimatedVector3Value& rhs, float tolerance = AZ::Constants::Tolerance) const override
  612. {
  613. AZ_UNUSED(tolerance);
  614. return false;
  615. }
  616. bool IsClose([[maybe_unused]] const AnimatedQuaternionValue& rhs, float tolerance = AZ::Constants::Tolerance) const override
  617. {
  618. AZ_UNUSED(tolerance);
  619. return false;
  620. }
  621. bool IsClose([[maybe_unused]] const AnimatedBoolValue& rhs, float tolerance = AZ::Constants::Tolerance) const override
  622. {
  623. AZ_UNUSED(tolerance);
  624. return false;
  625. }
  626. bool IsClose(const AnimatedAssetIdValue& rhs, [[maybe_unused]] float tolerance = AZ::Constants::Tolerance) const override
  627. {
  628. return m_value == rhs.m_value;
  629. }
  630. private:
  631. AZ::Data::AssetId m_value;
  632. };
  633. //////////////////////////////////////////////////////////////////////////
  634. // EBusTraits overrides - application is a singleton
  635. static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single; // Only one component on a entity can implement the events
  636. //////////////////////////////////////////////////////////////////////////
  637. /**
  638. * Set a value for an animated property at the given address on the given entity.
  639. * @param animatedEntityId the entity Id of the entity containing the animatedAddress
  640. * @param animatedAddress identifies the component and property to be set
  641. * @param value the value to set - this must be instance of one of the concrete subclasses of AnimatedValue, corresponding to the type of the property referenced by the animatedAdresss
  642. * @return true if the value was changed.
  643. */
  644. virtual bool SetAnimatedPropertyValue(const AZ::EntityId& animatedEntityId, const AnimatablePropertyAddress& animatableAddress, const AnimatedValue& value) = 0;
  645. /**
  646. * Get the current value for a property
  647. * @param returnValue holds the value to get - this must be instance of one of the concrete subclasses of AnimatedValue, corresponding to the type of the property referenced by the animatedAdresss
  648. * @param animatedEntityId the entity Id of the entity containing the animatedAddress
  649. * @param animatedAddress identifies the component and property to be set
  650. */
  651. virtual bool GetAnimatedPropertyValue(AnimatedValue& returnValue, const AZ::EntityId& animatedEntityId, const AnimatablePropertyAddress& animatableAddress) = 0;
  652. /** Returns the Uuid of the type for the property at the animatableAddress on the given entityId
  653. */
  654. virtual AZ::Uuid GetAnimatedAddressTypeId(const AZ::EntityId& enityId, const Maestro::SequenceComponentRequests::AnimatablePropertyAddress& animatableAddress) = 0;
  655. /**
  656. * Track View will expect some components to supply a GetAssetDuration event so Track View can query the duration of an asset (like a motion)
  657. * without having any knowledge of that that asset is.
  658. */
  659. virtual void GetAssetDuration(AnimatedValue& returnValue, const AZ::EntityId& animatedEntityId, AZ::ComponentId componentId, const AZ::Data::AssetId& assetId) = 0;
  660. //////////////////////////////////////////////////////////////////////////
  661. // Behaviors
  662. /**
  663. * Play sequence from the start to end times set the sequence
  664. */
  665. virtual void Play() {}
  666. /**
  667. * Play sequence between the start to end times, outside of which the sequence behaves according to its 'Out of Range' time setting
  668. * @param startTime Sequence start time in seconds
  669. * @param endTime Sequence end time in seconds
  670. */
  671. virtual void PlayBetweenTimes(float startTime, float endTime) {(void)startTime; (void)endTime;}
  672. /**
  673. * Stop the sequence. Stopping the sequence jumps the play time to the end of the sequence.
  674. */
  675. virtual void Stop() {}
  676. /**
  677. * Pause the sequence. Sequence must be playing for pause to have an effect. Pausing leaves the play time at its current position.
  678. */
  679. virtual void Pause() {}
  680. /**
  681. * Resume the sequence. Resume essentially 'unpauses' a sequence. It must have been playing before the pause for playback to start again.
  682. */
  683. virtual void Resume() {}
  684. /**
  685. * Set the play speed
  686. * @param newSpeed speed multiplier (1.0 is normal speed, less is slower, more is faster).
  687. */
  688. virtual void SetPlaySpeed(float newSpeed) {(void)newSpeed;}
  689. /**
  690. * Move the Playhead to the given time
  691. * @param time time to move the play head to, in seconds, clamped to be between the start and end times of the sequence
  692. */
  693. virtual void JumpToTime(float newTime) {(void)newTime;}
  694. /**
  695. * Move the Playhead to the end of the sequence
  696. */
  697. virtual void JumpToEnd() {}
  698. /**
  699. * Move the Playhead to the beginning of the sequence
  700. */
  701. virtual void JumpToBeginning() {}
  702. /**
  703. * Returns the current play time in seconds
  704. */
  705. virtual float GetCurrentPlayTime() { return .0f; }
  706. /**
  707. * Returns the current play back speed as a multiplier (1.0 is normal speed, less is slower, more is faster).
  708. */
  709. virtual float GetPlaySpeed() { return 1.0f; }
  710. //////////////////////////////////////////////////////////////////////////
  711. };
  712. using SequenceComponentRequestBus = AZ::EBus<SequenceComponentRequests>;
  713. /**
  714. * Notifications from the Sequence Component
  715. */
  716. class SequenceComponentNotification
  717. : public AZ::ComponentBus
  718. {
  719. public:
  720. ////////////////////////////////////////////////////////////////////////
  721. // EBusTraits
  722. // multiple handlers (addressed by AZ::EntityId inherited from AZ::ComponentBus)
  723. static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Multiple;
  724. ////////////////////////////////////////////////////////////////////////
  725. virtual ~SequenceComponentNotification() {}
  726. /**
  727. * Called when Sequence starts
  728. * @param startTime Time when sequence starts, in seconds
  729. */
  730. virtual void OnStart(float startTime) { (void)startTime; }
  731. /**
  732. * Called when Sequence stops
  733. * @param stopTime Time when the sequence stops, in seconds
  734. */
  735. virtual void OnStop(float stopTime) { (void)stopTime; }
  736. /**
  737. * Called when Sequence pauses
  738. */
  739. virtual void OnPause() {}
  740. /**
  741. * Called when Sequence resumes
  742. */
  743. virtual void OnResume() {}
  744. /**
  745. * Called when Sequence is aborted
  746. * @param abortTime Time when the sequence aborts, in seconds
  747. */
  748. virtual void OnAbort(float abortTime) { (void)abortTime; }
  749. /**
  750. * Called when Sequence is updated. That is, when the current play time changes, or the playback speed changes.
  751. * @param updateTime Time when the sequence updates, in seconds
  752. */
  753. virtual void OnUpdate(float updateTime) { (void)updateTime; }
  754. /**
  755. * Called when a Sequence Event is triggered.
  756. * @param paramValue The Event Key's Value parameter as a string
  757. */
  758. virtual void OnTrackEventTriggered(const char* eventName, const char* eventValue) { (void)eventName; (void)eventValue; }
  759. /**
  760. * Called when a Sequence changes camera during playback in Track View.
  761. * @param cameraEntityId entityId of the new camera.
  762. */
  763. virtual void OnCameraChanged([[maybe_unused]] const AZ::EntityId& oldCameraEntityId, [[maybe_unused]] const AZ::EntityId& newCameraEntityId) {}
  764. };
  765. using SequenceComponentNotificationBus = AZ::EBus<SequenceComponentNotification>;
  766. } // namespace Maestro
  767. namespace AZStd
  768. {
  769. template <>
  770. struct hash < Maestro::SequenceComponentRequests::AnimatablePropertyAddress >
  771. {
  772. inline size_t operator()(const Maestro::SequenceComponentRequests::AnimatablePropertyAddress& animatablePropertyAddress) const
  773. {
  774. AZStd::hash<AZ::ComponentId> componentIdHasher;
  775. size_t retVal = componentIdHasher(animatablePropertyAddress.GetComponentId());
  776. AZStd::hash_combine(retVal, animatablePropertyAddress.GetVirtualPropertyName());
  777. return retVal;
  778. }
  779. };
  780. } // namespace AZStd