From a1931185d8f4cf6755e05a8849606c7530880ada Mon Sep 17 00:00:00 2001 From: Martin Felis Date: Sun, 26 Mar 2023 18:53:32 +0200 Subject: [PATCH] Simple AnimationPlayer now working. --- src/main.cc | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/main.cc b/src/main.cc index 32a3995..4401b52 100644 --- a/src/main.cc +++ b/src/main.cc @@ -65,7 +65,7 @@ static struct { struct { ozz::animation::Animation* animation = nullptr; ozz::animation::SamplingJob sampling_job; - ozz::animation::SamplingJob::Context* m_sampling_context = nullptr; + ozz::vector local_matrices; } ozz; sg_pass_action pass_action; Camera camera; @@ -690,6 +690,8 @@ int main() { } if (state.ozz.animation != nullptr) { + ImGui::SameLine(); + ImGui::SliderFloat( "Time", &state.time.absolute, @@ -702,8 +704,20 @@ int main() { ImGui::End(); } - // TODO: add AnimGraph to calculate pose - // skinned_mesh.CalcModelMatrices(); + if (state.ozz.animation != nullptr) { + state.ozz.sampling_job.animation = state.ozz.animation; + state.ozz.sampling_job.ratio = + state.time.absolute / state.ozz.animation->duration(); + state.ozz.sampling_job.context = &skinned_mesh.m_sampling_context; + state.ozz.sampling_job.output = ozz::make_span(skinned_mesh.m_local_matrices); + + if(!state.ozz.sampling_job.Run()) { + ozz::log::Err() << "Error sampling animation." << std::endl; + } + + // TODO: add AnimGraph to calculate pose + skinned_mesh.CalcModelMatrices(); + } sgl_defaults(); sgl_matrix_mode_projection();