AnimationContext.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769
  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 "AnimationContext.h"
  10. // CryCommon
  11. #include <CryCommon/Maestro/Bus/EditorSequenceBus.h>
  12. // Editor
  13. #include "TrackView/TrackViewDialog.h"
  14. #include "ViewManager.h"
  15. #include <AzCore/Serialization/Locale.h>
  16. #include <AzCore/Time/ITime.h>
  17. //////////////////////////////////////////////////////////////////////////
  18. // Movie Callback.
  19. //////////////////////////////////////////////////////////////////////////
  20. class CMovieCallback
  21. : public IMovieCallback
  22. {
  23. protected:
  24. void OnMovieCallback(ECallbackReason reason, [[maybe_unused]] IAnimNode* pNode) override
  25. {
  26. switch (reason)
  27. {
  28. case CBR_CHANGENODE:
  29. // Invalidate nodes
  30. break;
  31. case CBR_CHANGETRACK:
  32. {
  33. // Invalidate tracks
  34. CTrackViewDialog* pTrackViewDialog = CTrackViewDialog::GetCurrentInstance();
  35. if (pTrackViewDialog)
  36. {
  37. pTrackViewDialog->InvalidateDopeSheet();
  38. }
  39. }
  40. break;
  41. }
  42. }
  43. bool IsSequenceCamUsed() const override
  44. {
  45. if (gEnv->IsEditorGameMode() == true)
  46. {
  47. return true;
  48. }
  49. if (GetIEditor()->GetViewManager() == nullptr)
  50. {
  51. return false;
  52. }
  53. CViewport* pRendView = GetIEditor()->GetViewManager()->GetViewport(ET_ViewportCamera);
  54. if (pRendView)
  55. {
  56. return pRendView->IsSequenceCamera();
  57. }
  58. return false;
  59. }
  60. };
  61. static CMovieCallback s_movieCallback;
  62. //////////////////////////////////////////////////////////////////////////
  63. //-----------------------------------------------------------------------------
  64. //!
  65. class CAnimationContextPostRender
  66. : public IPostRenderer
  67. {
  68. public:
  69. CAnimationContextPostRender(CAnimationContext* pAC)
  70. : m_pAC(pAC){}
  71. void OnPostRender() const override { assert(m_pAC); m_pAC->OnPostRender(); }
  72. protected:
  73. CAnimationContext* m_pAC;
  74. };
  75. //////////////////////////////////////////////////////////////////////////
  76. CAnimationContext::CAnimationContext()
  77. {
  78. m_paused = 0;
  79. m_playing = false;
  80. m_recording = false;
  81. m_bSavedRecordingState = false;
  82. m_timeRange.Set(0, 0);
  83. m_timeMarker.Set(0, 0);
  84. m_currTime = 0.0f;
  85. m_lastTimeChangedNotificationTime = .0f;
  86. m_bForceUpdateInNextFrame = false;
  87. m_fTimeScale = 1.0f;
  88. m_pSequence = nullptr;
  89. m_mostRecentSequenceId.SetInvalid();
  90. m_mostRecentSequenceTime = 0.0f;
  91. m_bLooping = false;
  92. m_bAutoRecording = false;
  93. m_fRecordingTimeStep = 0;
  94. m_bSingleFrame = false;
  95. m_bPostRenderRegistered = false;
  96. m_bForcingAnimation = false;
  97. GetIEditor()->GetUndoManager()->AddListener(this);
  98. GetIEditor()->GetSequenceManager()->AddListener(this);
  99. GetIEditor()->RegisterNotifyListener(this);
  100. }
  101. //////////////////////////////////////////////////////////////////////////
  102. CAnimationContext::~CAnimationContext()
  103. {
  104. GetIEditor()->GetSequenceManager()->RemoveListener(this);
  105. GetIEditor()->GetUndoManager()->RemoveListener(this);
  106. GetIEditor()->UnregisterNotifyListener(this);
  107. }
  108. //////////////////////////////////////////////////////////////////////////
  109. void CAnimationContext::Init()
  110. {
  111. if (gEnv->pMovieSystem)
  112. {
  113. gEnv->pMovieSystem->SetCallback(&s_movieCallback);
  114. }
  115. REGISTER_COMMAND("mov_goToFrameEditor", (ConsoleCommandFunc)GoToFrameCmd, 0, "Make a specified sequence go to a given frame time in the editor.");
  116. }
  117. //////////////////////////////////////////////////////////////////////////
  118. void CAnimationContext::AddListener(IAnimationContextListener* pListener)
  119. {
  120. stl::push_back_unique(m_contextListeners, pListener);
  121. }
  122. //////////////////////////////////////////////////////////////////////////
  123. void CAnimationContext::RemoveListener(IAnimationContextListener* pListener)
  124. {
  125. stl::find_and_erase(m_contextListeners, pListener);
  126. }
  127. void CAnimationContext::NotifyTimeChangedListenersUsingCurrTime() const
  128. {
  129. for (size_t i = 0; i < m_contextListeners.size(); ++i)
  130. {
  131. m_contextListeners[i]->OnTimeChanged(m_currTime);
  132. }
  133. m_lastTimeChangedNotificationTime = m_currTime;
  134. }
  135. //////////////////////////////////////////////////////////////////////////
  136. void CAnimationContext::SetSequence(CTrackViewSequence* sequence, bool force, bool noNotify, bool user)
  137. {
  138. float newSeqStartTime = .0f;
  139. CTrackViewSequence* pCurrentSequence = m_pSequence;
  140. if (!force && sequence == pCurrentSequence)
  141. {
  142. return;
  143. }
  144. // Prevent keys being created from time change
  145. const bool bRecording = m_recording;
  146. m_recording = false;
  147. SetRecordingInternal(false);
  148. if (sequence)
  149. {
  150. newSeqStartTime = sequence->GetTimeRange().start;
  151. }
  152. m_currTime = newSeqStartTime;
  153. m_fRecordingCurrTime = newSeqStartTime;
  154. if (!m_bPostRenderRegistered)
  155. {
  156. if (GetIEditor() && GetIEditor()->GetViewManager())
  157. {
  158. CViewport* pViewport = GetIEditor()->GetViewManager()->GetViewport(ET_ViewportCamera);
  159. if (pViewport)
  160. {
  161. pViewport->AddPostRenderer(new CAnimationContextPostRender(this));
  162. m_bPostRenderRegistered = true;
  163. }
  164. }
  165. }
  166. if (m_pSequence)
  167. {
  168. m_pSequence->Deactivate();
  169. if (m_playing)
  170. {
  171. m_pSequence->EndCutScene();
  172. }
  173. m_pSequence->UnBindFromEditorObjects();
  174. }
  175. m_pSequence = sequence;
  176. // Notify a new sequence was just selected.
  177. Maestro::EditorSequenceNotificationBus::Broadcast(&Maestro::EditorSequenceNotificationBus::Events::OnSequenceSelected, m_pSequence ? m_pSequence->GetSequenceComponentEntityId() : AZ::EntityId());
  178. if (m_pSequence)
  179. {
  180. // Set the last valid sequence that was selected.
  181. m_mostRecentSequenceId = m_pSequence->GetSequenceComponentEntityId();
  182. if (m_playing)
  183. {
  184. m_pSequence->BeginCutScene(true);
  185. }
  186. m_timeRange = m_pSequence->GetTimeRange();
  187. m_timeMarker = m_timeRange;
  188. m_pSequence->Activate();
  189. m_pSequence->PrecacheData(newSeqStartTime);
  190. m_pSequence->BindToEditorObjects();
  191. }
  192. else if (user)
  193. {
  194. // If this was a sequence that was selected by the user in Track View
  195. // and it was "No Sequence" clear the m_mostRecentSequenceId so the sequence
  196. // will not be reselected at unwanted events like an undo operation.
  197. m_mostRecentSequenceId.SetInvalid();
  198. }
  199. ForceAnimation();
  200. if (!noNotify)
  201. {
  202. NotifyTimeChangedListenersUsingCurrTime();
  203. for (size_t i = 0; i < m_contextListeners.size(); ++i)
  204. {
  205. m_contextListeners[i]->OnSequenceChanged(m_pSequence);
  206. }
  207. }
  208. TimeChanged(newSeqStartTime);
  209. m_recording = bRecording;
  210. SetRecordingInternal(bRecording);
  211. }
  212. //////////////////////////////////////////////////////////////////////////
  213. void CAnimationContext::UpdateTimeRange()
  214. {
  215. if (m_pSequence)
  216. {
  217. m_timeRange = m_pSequence->GetTimeRange();
  218. // reset the current time to make sure it is clamped
  219. // to the new range.
  220. SetTime(m_currTime);
  221. }
  222. }
  223. //////////////////////////////////////////////////////////////////////////
  224. void CAnimationContext::SetTime(float t)
  225. {
  226. if (t < m_timeRange.start)
  227. {
  228. t = m_timeRange.start;
  229. }
  230. if (t > m_timeRange.end)
  231. {
  232. t = m_timeRange.end;
  233. }
  234. if (fabs(m_currTime - t) < 0.001f)
  235. {
  236. return;
  237. }
  238. m_currTime = t;
  239. m_fRecordingCurrTime = t;
  240. ForceAnimation();
  241. NotifyTimeChangedListenersUsingCurrTime();
  242. }
  243. void CAnimationContext::TimeChanged(float newTime)
  244. {
  245. if (m_pSequence)
  246. {
  247. m_mostRecentSequenceTime = newTime;
  248. m_pSequence->TimeChanged(newTime);
  249. }
  250. }
  251. //////////////////////////////////////////////////////////////////////////
  252. void CAnimationContext::OnSequenceActivated(AZ::EntityId entityId)
  253. {
  254. // If nothing is selected and there is a valid most recent selected
  255. // try to find that sequence by id and select it. This is useful
  256. // for restoring the selected sequence during undo and redo.
  257. if (m_pSequence == nullptr && m_mostRecentSequenceId.IsValid())
  258. {
  259. if (entityId == m_mostRecentSequenceId)
  260. {
  261. auto editor = GetIEditor();
  262. if (editor != nullptr)
  263. {
  264. auto manager = editor->GetSequenceManager();
  265. if (manager != nullptr)
  266. {
  267. auto sequence = manager->GetSequenceByEntityId(m_mostRecentSequenceId);
  268. if (sequence != nullptr)
  269. {
  270. // Hang onto this because SetSequence() will reset it.
  271. float lastTime = m_mostRecentSequenceTime;
  272. SetSequence(sequence, false, false);
  273. // Restore the current time.
  274. SetTime(lastTime);
  275. // Notify time may have changed, use m_currTime incase it was clamped by SetTime()
  276. TimeChanged(m_currTime);
  277. }
  278. }
  279. }
  280. }
  281. }
  282. }
  283. //////////////////////////////////////////////////////////////////////////
  284. void CAnimationContext::Pause()
  285. {
  286. assert(m_paused >= 0);
  287. m_paused++;
  288. if (m_recording)
  289. {
  290. SetRecordingInternal(false);
  291. }
  292. if (GetIEditor()->GetMovieSystem())
  293. {
  294. GetIEditor()->GetMovieSystem()->Pause();
  295. }
  296. if (m_pSequence)
  297. {
  298. m_pSequence->Pause();
  299. }
  300. }
  301. //////////////////////////////////////////////////////////////////////////
  302. void CAnimationContext::Resume()
  303. {
  304. assert(m_paused > 0);
  305. m_paused--;
  306. if (m_recording && m_paused == 0)
  307. {
  308. SetRecordingInternal(true);
  309. }
  310. if (GetIEditor()->GetMovieSystem())
  311. {
  312. GetIEditor()->GetMovieSystem()->Resume();
  313. }
  314. if (m_pSequence)
  315. {
  316. m_pSequence->Resume();
  317. }
  318. }
  319. //////////////////////////////////////////////////////////////////////////
  320. void CAnimationContext::SetRecording(bool recording)
  321. {
  322. if (recording == m_recording)
  323. {
  324. return;
  325. }
  326. m_paused = 0;
  327. m_recording = recording;
  328. m_playing = false;
  329. if (!recording && m_fRecordingTimeStep != 0)
  330. {
  331. SetAutoRecording(false, 0);
  332. }
  333. // If started recording, assume we have modified the document.
  334. GetIEditor()->SetModifiedFlag();
  335. SetRecordingInternal(recording);
  336. }
  337. //////////////////////////////////////////////////////////////////////////
  338. //////////////////////////////////////////////////////////////////////////
  339. void CAnimationContext::SetPlaying(bool playing)
  340. {
  341. if (playing == m_playing)
  342. {
  343. return;
  344. }
  345. m_paused = 0;
  346. m_playing = playing;
  347. m_recording = false;
  348. SetRecordingInternal(false);
  349. IMovieSystem* pMovieSystem = GetIEditor()->GetMovieSystem();
  350. if (pMovieSystem)
  351. {
  352. if (playing)
  353. {
  354. pMovieSystem->Resume();
  355. if (m_pSequence)
  356. {
  357. m_pSequence->Resume();
  358. IMovieUser* pMovieUser = pMovieSystem->GetUser();
  359. if (pMovieUser)
  360. {
  361. m_pSequence->BeginCutScene(true);
  362. }
  363. }
  364. pMovieSystem->ResumeCutScenes();
  365. }
  366. else
  367. {
  368. pMovieSystem->Pause();
  369. if (m_pSequence)
  370. {
  371. m_pSequence->Pause();
  372. }
  373. pMovieSystem->PauseCutScenes();
  374. if (m_pSequence)
  375. {
  376. IMovieUser* pMovieUser = pMovieSystem->GetUser();
  377. if (pMovieUser)
  378. {
  379. m_pSequence->EndCutScene();
  380. }
  381. }
  382. }
  383. }
  384. }
  385. //////////////////////////////////////////////////////////////////////////
  386. void CAnimationContext::Update()
  387. {
  388. if (m_bForceUpdateInNextFrame)
  389. {
  390. ForceAnimation();
  391. m_bForceUpdateInNextFrame = false;
  392. }
  393. if (m_paused > 0 || !(m_playing || m_bAutoRecording))
  394. {
  395. if (m_pSequence)
  396. {
  397. m_pSequence->StillUpdate();
  398. }
  399. if (!m_recording)
  400. {
  401. if (GetIEditor()->GetMovieSystem())
  402. {
  403. GetIEditor()->GetMovieSystem()->StillUpdate();
  404. }
  405. }
  406. return;
  407. }
  408. const AZ::TimeUs frameDeltaTimeUs = AZ::GetSimulationTickDeltaTimeUs();
  409. const float frameDeltaTime = AZ::TimeUsToSeconds(frameDeltaTimeUs);
  410. if (!m_bAutoRecording)
  411. {
  412. AnimateActiveSequence();
  413. m_currTime += frameDeltaTime * m_fTimeScale;
  414. if (!m_recording)
  415. {
  416. if (GetIEditor()->GetMovieSystem())
  417. {
  418. GetIEditor()->GetMovieSystem()->PreUpdate(frameDeltaTime);
  419. GetIEditor()->GetMovieSystem()->PostUpdate(frameDeltaTime);
  420. }
  421. }
  422. }
  423. else
  424. {
  425. m_fRecordingCurrTime += frameDeltaTime * m_fTimeScale;
  426. if (fabs(m_fRecordingCurrTime - m_currTime) > m_fRecordingTimeStep)
  427. {
  428. m_currTime += m_fRecordingTimeStep;
  429. }
  430. }
  431. if (m_currTime > m_timeMarker.end)
  432. {
  433. if (m_bAutoRecording)
  434. {
  435. SetAutoRecording(false, 0);
  436. }
  437. else
  438. {
  439. if (m_bLooping)
  440. {
  441. m_currTime = m_timeMarker.start;
  442. if (m_pSequence)
  443. {
  444. m_pSequence->OnLoop();
  445. }
  446. }
  447. else
  448. {
  449. SetPlaying(false);
  450. m_currTime = m_timeMarker.end;
  451. }
  452. }
  453. }
  454. if (fabs(m_lastTimeChangedNotificationTime - m_currTime) > 0.001f)
  455. {
  456. NotifyTimeChangedListenersUsingCurrTime();
  457. }
  458. }
  459. //////////////////////////////////////////////////////////////////////////
  460. void CAnimationContext::ForceAnimation()
  461. {
  462. if (m_bForcingAnimation)
  463. {
  464. // reentrant calls are possible when using subsequences
  465. return;
  466. }
  467. m_bForcingAnimation = true;
  468. // Before animating node, pause recording.
  469. if (m_bAutoRecording)
  470. {
  471. Pause();
  472. }
  473. AnimateActiveSequence();
  474. // Animate a second time to properly update camera DoF
  475. AnimateActiveSequence();
  476. if (m_bAutoRecording)
  477. {
  478. Resume();
  479. }
  480. m_bForcingAnimation = false;
  481. }
  482. //////////////////////////////////////////////////////////////////////////
  483. void CAnimationContext::SetAutoRecording(bool bEnable, float fTimeStep)
  484. {
  485. if (bEnable)
  486. {
  487. m_bAutoRecording = true;
  488. m_fRecordingTimeStep = fTimeStep;
  489. SetRecording(bEnable);
  490. }
  491. else
  492. {
  493. m_bAutoRecording = false;
  494. m_fRecordingTimeStep = 0;
  495. }
  496. }
  497. //////////////////////////////////////////////////////////////////////////
  498. void CAnimationContext::GoToFrameCmd(IConsoleCmdArgs* pArgs)
  499. {
  500. if (pArgs->GetArgCount() < 2)
  501. {
  502. gEnv->pLog->LogError("GoToFrame: You must provide a 'frame time' to go to");
  503. return;
  504. }
  505. assert(GetIEditor()->GetAnimation());
  506. CTrackViewSequence* pSeq = GetIEditor()->GetAnimation()->GetSequence();
  507. if (!pSeq)
  508. {
  509. gEnv->pLog->LogError("GoToFrame: No active animation sequence");
  510. return;
  511. }
  512. // console commands are in the invariant locale, for atof()
  513. AZ::Locale::ScopedSerializationLocale scopedLocale;
  514. float targetFrame = (float)atof(pArgs->GetArg(1));
  515. scopedLocale.Deactivate();
  516. if (pSeq->GetTimeRange().start > targetFrame || targetFrame > pSeq->GetTimeRange().end)
  517. {
  518. gEnv->pLog->LogError("GoToFrame: requested time %f is outside the range of sequence %s (%f, %f)", targetFrame, pSeq->GetName().c_str(), pSeq->GetTimeRange().start, pSeq->GetTimeRange().end);
  519. return;
  520. }
  521. GetIEditor()->GetAnimation()->m_currTime = targetFrame;
  522. GetIEditor()->GetAnimation()->m_bSingleFrame = true;
  523. GetIEditor()->GetAnimation()->ForceAnimation();
  524. }
  525. //////////////////////////////////////////////////////////////////////////
  526. void CAnimationContext::OnPostRender()
  527. {
  528. if (m_pSequence)
  529. {
  530. SAnimContext ac;
  531. ac.dt = 0;
  532. const AZ::TimeUs frameDeltaTimeUs = AZ::GetSimulationTickDeltaTimeUs();
  533. const float frameDeltaTime = AZ::TimeUsToSeconds(frameDeltaTimeUs);
  534. ac.fps = 1.0f / frameDeltaTime;
  535. ac.time = m_currTime;
  536. ac.singleFrame = true;
  537. ac.forcePlay = true;
  538. m_pSequence->Render(ac);
  539. }
  540. }
  541. void CAnimationContext::BeginUndoTransaction()
  542. {
  543. m_bSavedRecordingState = m_recording;
  544. SetRecordingInternal(false);
  545. }
  546. //////////////////////////////////////////////////////////////////////////
  547. void CAnimationContext::EndUndoTransaction()
  548. {
  549. if (m_pSequence)
  550. {
  551. m_pSequence->BindToEditorObjects();
  552. }
  553. SetRecordingInternal(m_bSavedRecordingState);
  554. }
  555. //////////////////////////////////////////////////////////////////////////
  556. void CAnimationContext::TogglePlay()
  557. {
  558. if (!IsPlaying())
  559. {
  560. SetPlaying(true);
  561. }
  562. else
  563. {
  564. SetPlaying(false);
  565. }
  566. }
  567. //////////////////////////////////////////////////////////////////////////
  568. void CAnimationContext::OnSequenceRemoved(CTrackViewSequence* pSequence)
  569. {
  570. if (m_pSequence == pSequence)
  571. {
  572. SetSequence(nullptr, true, false);
  573. }
  574. }
  575. //////////////////////////////////////////////////////////////////////////
  576. void CAnimationContext::OnEditorNotifyEvent(EEditorNotifyEvent event)
  577. {
  578. switch (event)
  579. {
  580. case eNotify_OnBeginGameMode:
  581. if (m_pSequence)
  582. {
  583. m_pSequence->Resume();
  584. }
  585. case eNotify_OnBeginSceneSave:
  586. case eNotify_OnBeginLayerExport:
  587. if (m_pSequence)
  588. {
  589. m_sequenceToRestore = m_pSequence->GetSequenceComponentEntityId();
  590. }
  591. else
  592. {
  593. m_sequenceToRestore.SetInvalid();
  594. }
  595. m_sequenceRestoreTime = GetTime();
  596. m_bSavedRecordingState = m_recording;
  597. SetRecordingInternal(false);
  598. SetSequence(nullptr, true, true);
  599. break;
  600. case eNotify_OnEndGameMode:
  601. case eNotify_OnEndSceneSave:
  602. case eNotify_OnEndLayerExport:
  603. m_currTime = m_sequenceRestoreTime;
  604. SetSequence(GetIEditor()->GetSequenceManager()->GetSequenceByEntityId(m_sequenceToRestore), true, true);
  605. SetTime(m_sequenceRestoreTime);
  606. SetRecordingInternal(m_bSavedRecordingState);
  607. break;
  608. case eNotify_OnQuit:
  609. case eNotify_OnCloseScene:
  610. SetSequence(nullptr, true, false);
  611. break;
  612. case eNotify_OnBeginNewScene:
  613. SetSequence(nullptr, false, false);
  614. break;
  615. case eNotify_OnBeginLoad:
  616. m_mostRecentSequenceId.SetInvalid();
  617. m_mostRecentSequenceTime = 0.0f;
  618. m_bSavedRecordingState = m_recording;
  619. SetRecordingInternal(false);
  620. GetIEditor()->GetAnimation()->SetSequence(nullptr, false, false);
  621. break;
  622. case eNotify_OnEndLoad:
  623. SetRecordingInternal(m_bSavedRecordingState);
  624. break;
  625. }
  626. }
  627. void CAnimationContext::SetRecordingInternal(bool enableRecording)
  628. {
  629. if (GetIEditor()->GetMovieSystem())
  630. {
  631. GetIEditor()->GetMovieSystem()->SetRecording(enableRecording);
  632. }
  633. if (m_pSequence)
  634. {
  635. m_pSequence->SetRecording(enableRecording);
  636. }
  637. }
  638. void CAnimationContext::AnimateActiveSequence()
  639. {
  640. if (!m_pSequence)
  641. {
  642. return;
  643. }
  644. SAnimContext ac;
  645. ac.dt = 0;
  646. const AZ::TimeUs frameDeltaTimeUs = AZ::GetSimulationTickDeltaTimeUs();
  647. const float frameDeltaTime = AZ::TimeUsToSeconds(frameDeltaTimeUs);
  648. ac.fps = 1.0f / frameDeltaTime;
  649. ac.time = m_currTime;
  650. ac.singleFrame = true;
  651. ac.forcePlay = true;
  652. m_pSequence->Animate(ac);
  653. m_pSequence->SyncToConsole(ac);
  654. }