TrackViewPythonFuncs.cpp 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726
  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. #include "EditorDefs.h"
  9. #include "TrackViewPythonFuncs.h"
  10. // CryCommon
  11. #include <CryCommon/Maestro/Types/AnimNodeType.h>
  12. #include <CryCommon/Maestro/Types/AnimParamType.h>
  13. #include <CryCommon/Maestro/Types/AnimValueType.h>
  14. // Editor
  15. #include "AnimationContext.h"
  16. #include <AzCore/Asset/AssetSerializer.h>
  17. namespace
  18. {
  19. CTrackViewSequence* GetSequenceByEntityIdOrName(const CTrackViewSequenceManager* pSequenceManager, const char* entityIdOrName)
  20. {
  21. // the "name" string will be an AZ::EntityId in string form if this was called from
  22. // TrackView code. But for backward compatibility we also support a sequence name.
  23. bool isNameAValidU64 = false;
  24. QString entityIdString = entityIdOrName;
  25. AZ::u64 nameAsU64 = entityIdString.toULongLong(&isNameAValidU64);
  26. CTrackViewSequence* pSequence = nullptr;
  27. if (isNameAValidU64)
  28. {
  29. // "name" string was a valid u64 represented as a string. Use as an entity Id to search for sequence.
  30. pSequence = pSequenceManager->GetSequenceByEntityId(AZ::EntityId(nameAsU64));
  31. }
  32. if (!pSequence)
  33. {
  34. // name passed in could not find a sequence by using it as an EntityId. Use it as a
  35. // sequence name for backward compatibility
  36. pSequence = pSequenceManager->GetSequenceByName(entityIdOrName);
  37. }
  38. return pSequence;
  39. }
  40. }
  41. namespace
  42. {
  43. //////////////////////////////////////////////////////////////////////////
  44. // Misc
  45. //////////////////////////////////////////////////////////////////////////
  46. void PyTrackViewSetRecording(bool bRecording)
  47. {
  48. CAnimationContext* pAnimationContext = GetIEditor()->GetAnimation();
  49. if (pAnimationContext)
  50. {
  51. pAnimationContext->SetRecording(bRecording);
  52. }
  53. }
  54. //////////////////////////////////////////////////////////////////////////
  55. // Sequences
  56. //////////////////////////////////////////////////////////////////////////
  57. void PyTrackViewNewSequence(const char* name, int sequenceType)
  58. {
  59. CTrackViewSequenceManager* pSequenceManager = GetIEditor()->GetSequenceManager();
  60. CTrackViewSequence* pSequence = pSequenceManager->GetSequenceByName(name);
  61. if (pSequence)
  62. {
  63. throw std::runtime_error("A sequence with this name already exists");
  64. }
  65. CUndo undo("Create TrackView sequence");
  66. pSequenceManager->CreateSequence(name, static_cast<SequenceType>(sequenceType));
  67. }
  68. void PyTrackViewDeleteSequence(const char* name)
  69. {
  70. CTrackViewSequenceManager* pSequenceManager = GetIEditor()->GetSequenceManager();
  71. CTrackViewSequence* pSequence = GetSequenceByEntityIdOrName(pSequenceManager, name);
  72. if (pSequence)
  73. {
  74. pSequenceManager->DeleteSequence(pSequence);
  75. return;
  76. }
  77. throw std::runtime_error("Could not find sequence");
  78. }
  79. void PyTrackViewSetCurrentSequence(const char* name)
  80. {
  81. const CTrackViewSequenceManager* sequenceManager = GetIEditor()->GetSequenceManager();
  82. CTrackViewSequence* sequence = GetSequenceByEntityIdOrName(sequenceManager, name);
  83. CAnimationContext* animationContext = GetIEditor()->GetAnimation();
  84. bool force = false;
  85. bool noNotify = false;
  86. bool user = true;
  87. animationContext->SetSequence(sequence, force, noNotify, user);
  88. }
  89. int PyTrackViewGetNumSequences()
  90. {
  91. const CTrackViewSequenceManager* pSequenceManager = GetIEditor()->GetSequenceManager();
  92. AZ_TracePrintf("", "PyTrackViewGetNumSequences called")
  93. return pSequenceManager->GetCount();
  94. }
  95. AZStd::string PyTrackViewGetSequenceName(unsigned int index)
  96. {
  97. if (static_cast<int>(index) < PyTrackViewGetNumSequences())
  98. {
  99. const CTrackViewSequenceManager* pSequenceManager = GetIEditor()->GetSequenceManager();
  100. return pSequenceManager->GetSequenceByIndex(index)->GetName();
  101. }
  102. throw std::runtime_error("Could not find sequence");
  103. }
  104. Range PyTrackViewGetSequenceTimeRange(const char* name)
  105. {
  106. const CTrackViewSequenceManager* pSequenceManager = GetIEditor()->GetSequenceManager();
  107. CTrackViewSequence* pSequence = GetSequenceByEntityIdOrName(pSequenceManager, name);
  108. if (!pSequence)
  109. {
  110. throw std::runtime_error("A sequence with this name doesn't exists");
  111. }
  112. return pSequence->GetTimeRange();
  113. }
  114. void PyTrackViewSetSequenceTimeRange(const char* name, float start, float end)
  115. {
  116. const CTrackViewSequenceManager* pSequenceManager = GetIEditor()->GetSequenceManager();
  117. CTrackViewSequence* pSequence = GetSequenceByEntityIdOrName(pSequenceManager, name);
  118. if (!pSequence)
  119. {
  120. throw std::runtime_error("A sequence with this name doesn't exists");
  121. }
  122. CUndo undo("Set sequence time range");
  123. pSequence->SetTimeRange(Range(start, end));
  124. pSequence->MarkAsModified();
  125. }
  126. void PyTrackViewPlaySequence()
  127. {
  128. CAnimationContext* pAnimationContext = GetIEditor()->GetAnimation();
  129. if (pAnimationContext->IsPlaying())
  130. {
  131. throw std::runtime_error("A sequence is already playing");
  132. }
  133. pAnimationContext->SetPlaying(true);
  134. }
  135. void PyTrackViewStopSequence()
  136. {
  137. CAnimationContext* pAnimationContext = GetIEditor()->GetAnimation();
  138. if (!pAnimationContext->IsPlaying())
  139. {
  140. throw std::runtime_error("No sequence is playing");
  141. }
  142. pAnimationContext->SetPlaying(false);
  143. }
  144. void PyTrackViewSetSequenceTime(float time)
  145. {
  146. CAnimationContext* pAnimationContext = GetIEditor()->GetAnimation();
  147. pAnimationContext->SetTime(time);
  148. }
  149. //////////////////////////////////////////////////////////////////////////
  150. // Nodes
  151. //////////////////////////////////////////////////////////////////////////
  152. void PyTrackViewAddNode(const char* nodeTypeString, const char* nodeName)
  153. {
  154. CTrackViewSequence* pSequence = GetIEditor()->GetAnimation()->GetSequence();
  155. if (!pSequence)
  156. {
  157. throw std::runtime_error("No sequence is active");
  158. }
  159. IMovieSystem* movieSystem = AZ::Interface<IMovieSystem>::Get();
  160. if (movieSystem)
  161. {
  162. const AnimNodeType nodeType = movieSystem->GetNodeTypeFromString(nodeTypeString);
  163. if (nodeType == AnimNodeType::Invalid)
  164. {
  165. throw std::runtime_error("Invalid node type");
  166. }
  167. CUndo undo("Create anim node");
  168. pSequence->CreateSubNode(nodeName, nodeType);
  169. }
  170. }
  171. void PyTrackViewAddSelectedEntities()
  172. {
  173. CAnimationContext* animationContext = GetIEditor()->GetAnimation();
  174. CTrackViewSequence* sequence = animationContext->GetSequence();
  175. if (!sequence)
  176. {
  177. throw std::runtime_error("No sequence is active");
  178. }
  179. AZStd::vector<AnimParamType> tracks = {
  180. AnimParamType::Position,
  181. AnimParamType::Rotation
  182. };
  183. AzToolsFramework::ScopedUndoBatch undoBatch("Add entities to Track View");
  184. sequence->AddSelectedEntities(tracks);
  185. sequence->BindToEditorObjects();
  186. undoBatch.MarkEntityDirty(sequence->GetSequenceComponentEntityId());
  187. }
  188. void PyTrackViewAddLayerNode()
  189. {
  190. CAnimationContext* pAnimationContext = GetIEditor()->GetAnimation();
  191. CTrackViewSequence* pSequence = pAnimationContext->GetSequence();
  192. if (!pSequence)
  193. {
  194. throw std::runtime_error("No sequence is active");
  195. }
  196. CUndo undo("Add current layer to TrackView");
  197. pSequence->AddCurrentLayer();
  198. }
  199. CTrackViewAnimNode* GetNodeFromName(const char* nodeName, const char* parentDirectorName)
  200. {
  201. CAnimationContext* pAnimationContext = GetIEditor()->GetAnimation();
  202. CTrackViewSequence* pSequence = pAnimationContext->GetSequence();
  203. if (!pSequence)
  204. {
  205. throw std::runtime_error("No sequence is active");
  206. }
  207. CTrackViewAnimNode* pParentDirector = pSequence;
  208. if (strlen(parentDirectorName) > 0)
  209. {
  210. CTrackViewAnimNodeBundle foundNodes = pSequence->GetAnimNodesByName(parentDirectorName);
  211. if (foundNodes.GetCount() == 0 || foundNodes.GetNode(0)->GetType() != AnimNodeType::Director)
  212. {
  213. throw std::runtime_error("Director node not found");
  214. }
  215. pParentDirector = foundNodes.GetNode(0);
  216. }
  217. CTrackViewAnimNodeBundle foundNodes = pParentDirector->GetAnimNodesByName(nodeName);
  218. return (foundNodes.GetCount() > 0) ? foundNodes.GetNode(0) : nullptr;
  219. }
  220. void PyTrackViewDeleteNode(AZStd::string_view nodeName, AZStd::string_view parentDirectorName)
  221. {
  222. CTrackViewAnimNode* pNode = GetNodeFromName(nodeName.data(), parentDirectorName.data());
  223. if (pNode == nullptr)
  224. {
  225. throw std::runtime_error("Couldn't find node");
  226. }
  227. CTrackViewAnimNode* pParentNode = static_cast<CTrackViewAnimNode*>(pNode->GetParentNode());
  228. CUndo undo("Delete TrackView Node");
  229. pParentNode->RemoveSubNode(pNode);
  230. }
  231. void PyTrackViewAddTrack(const char* paramName, const char* nodeName, const char* parentDirectorName)
  232. {
  233. CTrackViewAnimNode* pNode = GetNodeFromName(nodeName, parentDirectorName);
  234. if (!pNode)
  235. {
  236. throw std::runtime_error("Couldn't find node");
  237. }
  238. // Add tracks to menu, that can be added to animation node.
  239. const int paramCount = pNode->GetParamCount();
  240. for (int i = 0; i < paramCount; ++i)
  241. {
  242. CAnimParamType paramType = pNode->GetParamType(i);
  243. if (paramType == AnimParamType::Invalid)
  244. {
  245. continue;
  246. }
  247. IAnimNode::ESupportedParamFlags paramFlags = pNode->GetParamFlags(paramType);
  248. CTrackViewTrack* pTrack = pNode->GetTrackForParameter(paramType);
  249. if (!pTrack || (paramFlags & IAnimNode::eSupportedParamFlags_MultipleTracks))
  250. {
  251. AZStd::string name = pNode->GetParamName(paramType);
  252. if (name == paramName)
  253. {
  254. CUndo undo("Create track");
  255. if (!pNode->CreateTrack(paramType))
  256. {
  257. undo.Cancel();
  258. throw std::runtime_error("Could not create track");
  259. }
  260. pNode->SetSelected(true);
  261. return;
  262. }
  263. }
  264. }
  265. throw std::runtime_error("Could not create track");
  266. }
  267. void PyTrackViewDeleteTrack(const char* paramName, uint32 index, const char* nodeName, const char* parentDirectorName)
  268. {
  269. CTrackViewAnimNode* pNode = GetNodeFromName(nodeName, parentDirectorName);
  270. if (!pNode)
  271. {
  272. throw std::runtime_error("Couldn't find node");
  273. }
  274. IMovieSystem* movieSystem = AZ::Interface<IMovieSystem>::Get();
  275. if (movieSystem)
  276. {
  277. const CAnimParamType paramType = movieSystem->GetParamTypeFromString(paramName);
  278. CTrackViewTrack* pTrack = pNode->GetTrackForParameter(paramType, index);
  279. if (!pTrack)
  280. {
  281. throw std::runtime_error("Could not find track");
  282. }
  283. CUndo undo("Delete TrackView track");
  284. pNode->RemoveTrack(pTrack);
  285. }
  286. }
  287. int PyTrackViewGetNumNodes(AZStd::string_view parentDirectorName)
  288. {
  289. CAnimationContext* pAnimationContext = GetIEditor()->GetAnimation();
  290. CTrackViewSequence* pSequence = pAnimationContext->GetSequence();
  291. if (!pSequence)
  292. {
  293. throw std::runtime_error("No sequence is active");
  294. }
  295. CTrackViewAnimNode* pParentDirector = pSequence;
  296. if (!parentDirectorName.empty())
  297. {
  298. CTrackViewAnimNodeBundle foundNodes = pSequence->GetAnimNodesByName(parentDirectorName.data());
  299. if (foundNodes.GetCount() == 0 || foundNodes.GetNode(0)->GetType() != AnimNodeType::Director)
  300. {
  301. throw std::runtime_error("Director node not found");
  302. }
  303. pParentDirector = foundNodes.GetNode(0);
  304. }
  305. CTrackViewAnimNodeBundle foundNodes = pParentDirector->GetAllAnimNodes();
  306. return foundNodes.GetCount();
  307. }
  308. AZStd::string PyTrackViewGetNodeName(int index, AZStd::string_view parentDirectorName)
  309. {
  310. CAnimationContext* pAnimationContext = GetIEditor()->GetAnimation();
  311. CTrackViewSequence* pSequence = pAnimationContext->GetSequence();
  312. if (!pSequence)
  313. {
  314. throw std::runtime_error("No sequence is active");
  315. }
  316. CTrackViewAnimNode* pParentDirector = pSequence;
  317. if (!parentDirectorName.empty())
  318. {
  319. CTrackViewAnimNodeBundle foundNodes = pSequence->GetAnimNodesByName(parentDirectorName.data());
  320. if (foundNodes.GetCount() == 0 || foundNodes.GetNode(0)->GetType() != AnimNodeType::Director)
  321. {
  322. throw std::runtime_error("Director node not found");
  323. }
  324. pParentDirector = foundNodes.GetNode(0);
  325. }
  326. CTrackViewAnimNodeBundle foundNodes = pParentDirector->GetAllAnimNodes();
  327. if (index < 0 || index >= static_cast<int>(foundNodes.GetCount()))
  328. {
  329. throw std::runtime_error("Invalid node index");
  330. }
  331. return foundNodes.GetNode(index)->GetName();
  332. }
  333. //////////////////////////////////////////////////////////////////////////
  334. // Tracks
  335. //////////////////////////////////////////////////////////////////////////
  336. CTrackViewTrack* GetTrack(const char* paramName, uint32 index, const char* nodeName, const char* parentDirectorName)
  337. {
  338. CTrackViewAnimNode* pNode = GetNodeFromName(nodeName, parentDirectorName);
  339. if (!pNode)
  340. {
  341. throw std::runtime_error("Couldn't find node");
  342. }
  343. IMovieSystem* movieSystem = AZ::Interface<IMovieSystem>::Get();
  344. if (movieSystem)
  345. {
  346. const CAnimParamType paramType = movieSystem->GetParamTypeFromString(paramName);
  347. CTrackViewTrack* pTrack = pNode->GetTrackForParameter(paramType, index);
  348. if (!pTrack)
  349. {
  350. throw std::runtime_error("Track doesn't exist");
  351. }
  352. return pTrack;
  353. }
  354. else
  355. {
  356. throw std::runtime_error("MovieSystem does not exist");
  357. }
  358. }
  359. std::set<float> GetKeyTimeSet(CTrackViewTrack* pTrack)
  360. {
  361. std::set<float> keyTimeSet;
  362. for (uint i = 0; i < pTrack->GetKeyCount(); ++i)
  363. {
  364. CTrackViewKeyHandle keyHandle = pTrack->GetKey(i);
  365. keyTimeSet.insert(keyHandle.GetTime());
  366. }
  367. return keyTimeSet;
  368. }
  369. int PyTrackViewGetNumTrackKeys(const char* paramName, int trackIndex, const char* nodeName, const char* parentDirectorName)
  370. {
  371. CTrackViewTrack* pTrack = GetTrack(paramName, trackIndex, nodeName, parentDirectorName);
  372. return (int)GetKeyTimeSet(pTrack).size();
  373. }
  374. AZStd::any PyTrackViewGetInterpolatedValue(const char* paramName, int trackIndex, float time, const char* nodeName, const char* parentDirectorName)
  375. {
  376. CTrackViewTrack* pTrack = GetTrack(paramName, trackIndex, nodeName, parentDirectorName);
  377. switch (pTrack->GetValueType())
  378. {
  379. case AnimValueType::Float:
  380. case AnimValueType::DiscreteFloat:
  381. {
  382. float value;
  383. pTrack->GetValue(time, value);
  384. return AZStd::make_any<float>(value);
  385. }
  386. break;
  387. case AnimValueType::Bool:
  388. {
  389. bool value;
  390. pTrack->GetValue(time, value);
  391. return AZStd::make_any<bool>(value);
  392. }
  393. break;
  394. case AnimValueType::Quat:
  395. {
  396. AZ::Quaternion value;
  397. pTrack->GetValue(time, value);
  398. const AZ::Vector3 rotation = value.GetEulerDegrees();
  399. return AZStd::make_any<AZ::Vector3>(rotation);
  400. }
  401. case AnimValueType::Vector:
  402. {
  403. AZ::Vector3 value;
  404. pTrack->GetValue(time, value);
  405. return AZStd::make_any<AZ::Vector3>(value);
  406. }
  407. break;
  408. case AnimValueType::Vector4:
  409. {
  410. AZ::Vector4 value;
  411. pTrack->GetValue(time, value);
  412. return AZStd::make_any<AZ::Vector4>(value);
  413. }
  414. break;
  415. case AnimValueType::RGB:
  416. {
  417. AZ::Vector3 value;
  418. pTrack->GetValue(time, value);
  419. return AZStd::make_any<AZ::Color>(value.GetX(), value.GetY(), value.GetZ(), 0.0f);
  420. }
  421. break;
  422. default:
  423. throw std::runtime_error("Unsupported key type");
  424. }
  425. }
  426. AZStd::any PyTrackViewGetKeyValue(const char* paramName, int trackIndex, int keyIndex, const char* nodeName, const char* parentDirectorName)
  427. {
  428. CTrackViewTrack* pTrack = GetTrack(paramName, trackIndex, nodeName, parentDirectorName);
  429. std::set<float> keyTimeSet = GetKeyTimeSet(pTrack);
  430. if (keyIndex < 0 || keyIndex >= keyTimeSet.size())
  431. {
  432. throw std::runtime_error("Invalid key index");
  433. }
  434. auto keyTimeIter = keyTimeSet.begin();
  435. std::advance(keyTimeIter, keyIndex);
  436. const float keyTime = *keyTimeIter;
  437. return PyTrackViewGetInterpolatedValue(paramName, trackIndex, keyTime, nodeName, parentDirectorName);
  438. }
  439. }
  440. namespace AzToolsFramework
  441. {
  442. void TrackViewComponent::Reflect(AZ::ReflectContext* context)
  443. {
  444. if (AZ::BehaviorContext* behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
  445. {
  446. behaviorContext->EBus<EditorLayerTrackViewRequestBus>("EditorLayerTrackViewRequestBus")
  447. ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Automation)
  448. ->Attribute(AZ::Script::Attributes::Module, "track_view")
  449. ->Event("AddNode", &EditorLayerTrackViewRequestBus::Events::AddNode)
  450. ->Event("AddTrack", &EditorLayerTrackViewRequestBus::Events::AddTrack)
  451. ->Event("AddLayerNode", &EditorLayerTrackViewRequestBus::Events::AddLayerNode)
  452. ->Event("AddSelectedEntities", &EditorLayerTrackViewRequestBus::Events::AddSelectedEntities)
  453. ->Event("DeleteNode", &EditorLayerTrackViewRequestBus::Events::DeleteNode)
  454. ->Event("DeleteTrack", &EditorLayerTrackViewRequestBus::Events::DeleteTrack)
  455. ->Event("DeleteSequence", &EditorLayerTrackViewRequestBus::Events::DeleteSequence)
  456. ->Event("GetInterpolatedValue", &EditorLayerTrackViewRequestBus::Events::GetInterpolatedValue)
  457. ->Event("GetKeyValue", &EditorLayerTrackViewRequestBus::Events::GetKeyValue)
  458. ->Event("GetNodeName", &EditorLayerTrackViewRequestBus::Events::GetNodeName)
  459. ->Event("GetNumNodes", &EditorLayerTrackViewRequestBus::Events::GetNumNodes)
  460. ->Event("GetNumSequences", &EditorLayerTrackViewRequestBus::Events::GetNumSequences)
  461. ->Event("GetNumTrackKeys", &EditorLayerTrackViewRequestBus::Events::GetNumTrackKeys)
  462. ->Event("GetSequenceName", &EditorLayerTrackViewRequestBus::Events::GetSequenceName)
  463. ->Event("GetSequenceTimeRange", &EditorLayerTrackViewRequestBus::Events::GetSequenceTimeRange)
  464. ->Event("NewSequence", &EditorLayerTrackViewRequestBus::Events::NewSequence)
  465. ->Event("PlaySequence", &EditorLayerTrackViewRequestBus::Events::PlaySequence)
  466. ->Event("SetCurrentSequence", &EditorLayerTrackViewRequestBus::Events::SetCurrentSequence)
  467. ->Event("SetRecording", &EditorLayerTrackViewRequestBus::Events::SetRecording)
  468. ->Event("SetSequenceTimeRange", &EditorLayerTrackViewRequestBus::Events::SetSequenceTimeRange)
  469. ->Event("SetTime", &EditorLayerTrackViewRequestBus::Events::SetSequenceTime)
  470. ->Event("StopSequence", &EditorLayerTrackViewRequestBus::Events::StopSequence)
  471. ;
  472. }
  473. }
  474. void TrackViewComponent::Activate()
  475. {
  476. EditorLayerTrackViewRequestBus::Handler::BusConnect(GetEntityId());
  477. }
  478. void TrackViewComponent::Deactivate()
  479. {
  480. EditorLayerTrackViewRequestBus::Handler::BusDisconnect();
  481. }
  482. int TrackViewComponent::GetNumSequences()
  483. {
  484. return PyTrackViewGetNumSequences();
  485. }
  486. void TrackViewComponent::NewSequence(const char* name, int sequenceType)
  487. {
  488. return PyTrackViewNewSequence(name, sequenceType);
  489. }
  490. void TrackViewComponent::PlaySequence()
  491. {
  492. return PyTrackViewPlaySequence();
  493. }
  494. void TrackViewComponent::StopSequence()
  495. {
  496. return PyTrackViewStopSequence();
  497. }
  498. void TrackViewComponent::SetSequenceTime(float time)
  499. {
  500. return PyTrackViewSetSequenceTime(time);
  501. }
  502. void TrackViewComponent::AddSelectedEntities()
  503. {
  504. return PyTrackViewAddSelectedEntities();
  505. }
  506. void TrackViewComponent::AddLayerNode()
  507. {
  508. return PyTrackViewAddLayerNode();
  509. }
  510. void TrackViewComponent::AddTrack(const char* paramName, const char* nodeName, const char* parentDirectorName)
  511. {
  512. return PyTrackViewAddTrack(paramName, nodeName, parentDirectorName);
  513. }
  514. void TrackViewComponent::DeleteTrack(const char* paramName, uint32 index, const char* nodeName, const char* parentDirectorName)
  515. {
  516. return PyTrackViewDeleteTrack(paramName, index, nodeName, parentDirectorName);
  517. }
  518. int TrackViewComponent::GetNumTrackKeys(const char* paramName, int trackIndex, const char* nodeName, const char* parentDirectorName)
  519. {
  520. return PyTrackViewGetNumTrackKeys(paramName, trackIndex, nodeName, parentDirectorName);
  521. }
  522. void TrackViewComponent::SetRecording(bool bRecording)
  523. {
  524. return PyTrackViewSetRecording(bRecording);
  525. }
  526. void TrackViewComponent::DeleteSequence(const char* name)
  527. {
  528. return PyTrackViewDeleteSequence(name);
  529. }
  530. void TrackViewComponent::SetCurrentSequence(const char* name)
  531. {
  532. return PyTrackViewSetCurrentSequence(name);
  533. }
  534. AZStd::string TrackViewComponent::GetSequenceName(unsigned int index)
  535. {
  536. return PyTrackViewGetSequenceName(index);
  537. }
  538. Range TrackViewComponent::GetSequenceTimeRange(const char* name)
  539. {
  540. return PyTrackViewGetSequenceTimeRange(name);
  541. }
  542. void TrackViewComponent::AddNode(const char* nodeTypeString, const char* nodeName)
  543. {
  544. return PyTrackViewAddNode(nodeTypeString, nodeName);
  545. }
  546. void TrackViewComponent::DeleteNode(AZStd::string_view nodeName, AZStd::string_view parentDirectorName)
  547. {
  548. return PyTrackViewDeleteNode(nodeName, parentDirectorName);
  549. }
  550. int TrackViewComponent::GetNumNodes(AZStd::string_view parentDirectorName)
  551. {
  552. return PyTrackViewGetNumNodes(parentDirectorName);
  553. }
  554. AZStd::string TrackViewComponent::GetNodeName(int index, AZStd::string_view parentDirectorName)
  555. {
  556. return PyTrackViewGetNodeName(index, parentDirectorName);
  557. }
  558. AZStd::any TrackViewComponent::GetKeyValue(const char* paramName, int trackIndex, int keyIndex, const char* nodeName, const char* parentDirectorName)
  559. {
  560. return PyTrackViewGetKeyValue(paramName, trackIndex, keyIndex, nodeName, parentDirectorName);
  561. }
  562. AZStd::any TrackViewComponent::GetInterpolatedValue(const char* paramName, int trackIndex, float time, const char* nodeName, const char* parentDirectorName)
  563. {
  564. return PyTrackViewGetInterpolatedValue(paramName, trackIndex, time, nodeName, parentDirectorName);
  565. }
  566. void TrackViewComponent::SetSequenceTimeRange(const char* name, float start, float end)
  567. {
  568. return PyTrackViewSetSequenceTimeRange(name, start, end);
  569. }
  570. }
  571. namespace AzToolsFramework
  572. {
  573. void TrackViewFuncsHandler::Reflect(AZ::ReflectContext* context)
  574. {
  575. if (auto behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
  576. {
  577. behaviorContext->Class<Range>("CryRange")
  578. ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Automation)
  579. ->Attribute(AZ::Script::Attributes::Module, "legacy.trackview")
  580. ->Property("start", BehaviorValueProperty(&Range::start))
  581. ->Property("end", BehaviorValueProperty(&Range::end))
  582. ;
  583. // this will put these methods into the 'azlmbr.legacy.trackview' module
  584. auto addLegacyTrackview = [](AZ::BehaviorContext::GlobalMethodBuilder methodBuilder)
  585. {
  586. methodBuilder->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Automation)
  587. ->Attribute(AZ::Script::Attributes::Category, "Legacy/TrackView")
  588. ->Attribute(AZ::Script::Attributes::Module, "legacy.trackview");
  589. };
  590. addLegacyTrackview(behaviorContext->Method("set_recording", PyTrackViewSetRecording, nullptr, "Activates/deactivates TrackView recording mode."));
  591. addLegacyTrackview(behaviorContext->Method("new_sequence", PyTrackViewNewSequence, nullptr, "Creates a new sequence of the given type (0=Object Entity Sequence (Legacy), 1=Component Entity Sequence) with the given name."));
  592. addLegacyTrackview(behaviorContext->Method("delete_sequence", PyTrackViewDeleteSequence, nullptr, "Deletes the specified sequence."));
  593. addLegacyTrackview(behaviorContext->Method("set_current_sequence", PyTrackViewSetCurrentSequence, nullptr, "Sets the specified sequence as a current one in TrackView."));
  594. addLegacyTrackview(behaviorContext->Method("get_num_sequences", PyTrackViewGetNumSequences, nullptr, "Gets the number of sequences."));
  595. addLegacyTrackview(behaviorContext->Method("get_sequence_name", PyTrackViewGetSequenceName, nullptr, "Gets the name of a sequence by its index."));
  596. addLegacyTrackview(behaviorContext->Method("get_sequence_time_range", PyTrackViewGetSequenceTimeRange, nullptr, "Gets the time range of a sequence as a pair."));
  597. addLegacyTrackview(behaviorContext->Method("set_sequence_time_range", PyTrackViewSetSequenceTimeRange, nullptr, "Sets the time range of a sequence."));
  598. addLegacyTrackview(behaviorContext->Method("play_sequence", PyTrackViewPlaySequence, nullptr, "Plays the current sequence in TrackView."));
  599. addLegacyTrackview(behaviorContext->Method("stop_sequence", PyTrackViewStopSequence, nullptr, "Stops any sequence currently playing in TrackView."));
  600. addLegacyTrackview(behaviorContext->Method("set_time", PyTrackViewSetSequenceTime, nullptr, "Sets the time of the sequence currently playing in TrackView."));
  601. addLegacyTrackview(behaviorContext->Method("add_node", PyTrackViewAddNode, nullptr, "Adds a new node with the given type & name to the current sequence."));
  602. addLegacyTrackview(behaviorContext->Method("add_selected_entities", PyTrackViewAddSelectedEntities, nullptr, "Adds an entity node(s) from viewport selection to the current sequence."));
  603. addLegacyTrackview(behaviorContext->Method("add_layer_node", PyTrackViewAddLayerNode, nullptr, "Adds a layer node from the current layer to the current sequence."));
  604. addLegacyTrackview(behaviorContext->Method("delete_node", PyTrackViewDeleteNode, nullptr, "Deletes the specified node from the current sequence."));
  605. addLegacyTrackview(behaviorContext->Method("add_track", PyTrackViewAddTrack, nullptr, "Adds a track of the given parameter ID to the node."));
  606. addLegacyTrackview(behaviorContext->Method("delete_track", PyTrackViewDeleteTrack, nullptr, "Deletes a track of the given parameter ID (in the given index in case of a multi-track) from the node."));
  607. addLegacyTrackview(behaviorContext->Method("get_num_nodes", PyTrackViewGetNumNodes, nullptr, "Gets the number of nodes."));
  608. addLegacyTrackview(behaviorContext->Method("get_node_name", PyTrackViewGetNodeName, nullptr, "Gets the name of a sequence by its index."));
  609. addLegacyTrackview(behaviorContext->Method("get_num_track_keys", PyTrackViewGetNumTrackKeys, nullptr, "Gets number of keys of the specified track."));
  610. addLegacyTrackview(behaviorContext->Method("get_key_value", PyTrackViewGetKeyValue, nullptr, "Gets the value of the specified key."));
  611. addLegacyTrackview(behaviorContext->Method("get_interpolated_value", PyTrackViewGetInterpolatedValue, nullptr, "Gets the interpolated value of a track at the specified time."));
  612. }
  613. }
  614. }