Skip to content

Commit abb6947

Browse files
USD Viewer: added animation controls
1 parent e58e6a3 commit abb6947

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

Samples/USDViewer/src/USDViewer.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,11 @@ void USDViewer::LoadStage()
341341
{
342342
m_Camera.SetRotation(PI_F * 3.f / 4.f, PI_F / 6.f);
343343
}
344+
345+
m_Stage.Animation.TimeCodesPerSecond = m_Stage.Stage->GetTimeCodesPerSecond();
346+
m_Stage.Animation.StartTime = static_cast<float>(m_Stage.Stage->GetStartTimeCode() / m_Stage.Animation.TimeCodesPerSecond);
347+
m_Stage.Animation.EndTime = static_cast<float>(m_Stage.Stage->GetEndTimeCode() / m_Stage.Animation.TimeCodesPerSecond);
348+
m_Stage.Animation.Time = m_Stage.Animation.StartTime;
344349
}
345350

346351
// Render a frame
@@ -539,6 +544,19 @@ void USDViewer::UpdateUI()
539544
}
540545
}
541546

547+
if (m_Stage.Animation.EndTime > m_Stage.Animation.StartTime)
548+
{
549+
ImGui::Spacing();
550+
551+
ImGui::SetNextItemOpen(true, ImGuiCond_FirstUseEver);
552+
if (ImGui::TreeNode("Animation"))
553+
{
554+
ImGui::Checkbox("Play", &m_Stage.Animation.Play);
555+
ImGui::SliderFloat("Time", &m_Stage.Animation.Time, m_Stage.Animation.StartTime, m_Stage.Animation.EndTime);
556+
ImGui::TreePop();
557+
}
558+
}
559+
542560
ImGui::Spacing();
543561

544562
ImGui::SetNextItemOpen(true, ImGuiCond_FirstUseEver);
@@ -827,9 +845,23 @@ void USDViewer::Update(double CurrTime, double ElapsedTime)
827845
m_Camera.SetZoomSpeed(m_Camera.GetDist() * 0.1f);
828846
m_Camera.Update(m_InputController);
829847
UpdateCamera();
848+
849+
const float LastAnimationTime = m_Stage.Animation.Time;
850+
if (m_Stage.Animation.Play)
851+
{
852+
m_Stage.Animation.Time += static_cast<float>(ElapsedTime);
853+
if (m_Stage.Animation.Time > m_Stage.Animation.EndTime)
854+
m_Stage.Animation.Time = m_Stage.Animation.StartTime;
855+
}
856+
830857
// Update camera first as TRS widget needs camera view/proj matrices.
831858
UpdateUI();
832859

860+
if (LastAnimationTime != m_Stage.Animation.Time)
861+
{
862+
m_Stage.ImagingDelegate->SetTime(m_Stage.Animation.Time * m_Stage.Animation.TimeCodesPerSecond);
863+
}
864+
833865
if (!m_Stage)
834866
return;
835867

Samples/USDViewer/src/USDViewer.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,17 @@ class USDViewer final : public SampleBase
9898

9999
float4x4 RootTransform = float4x4::Identity();
100100

101+
struct AnimationInfo
102+
{
103+
double TimeCodesPerSecond = 0;
104+
105+
float Time = 0;
106+
float StartTime = 0;
107+
float EndTime = 0;
108+
109+
bool Play = false;
110+
} Animation;
111+
101112
explicit operator bool() const
102113
{
103114
return Stage && RenderDelegate && RenderIndex && ImagingDelegate && TaskManager;

0 commit comments

Comments
 (0)