Skip to content

Commit

Permalink
[ren.animation_renderer2] added ability to play animations (add them …
Browse files Browse the repository at this point in the history
…to the front of the playback list) aswell as queue
  • Loading branch information
harrand committed Oct 28, 2023
1 parent fc23d27 commit 9fdad2a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/tz/ren/animation2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,20 @@ namespace tz::ren
return this->animated_objects[hanval].playback;
}

//--------------------------------------------------------------------------------------------------

void animation_renderer2::animated_object_play_animation(animated_objects_handle handle, playback_data anim)
{
auto hanval = static_cast<std::size_t>(static_cast<tz::hanval>(handle));
this->animated_objects[hanval].playback.insert(this->animated_objects[hanval].playback.begin(), anim);
}

//--------------------------------------------------------------------------------------------------

void animation_renderer2::animated_object_queue_animation(animated_objects_handle handle, playback_data anim)
{
auto hanval = static_cast<std::size_t>(static_cast<tz::hanval>(handle));
return this->animated_objects[hanval].playback.push_back(anim);
this->animated_objects[hanval].playback.push_back(anim);
}

//--------------------------------------------------------------------------------------------------
Expand Down
22 changes: 21 additions & 1 deletion src/tz/ren/animation2.dbgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ namespace tz::ren
}

ImGui::Spacing();
if(anim_objects.playback.size())
if(anim_objects.playback.size() && ImGui::CollapsingHeader("Playing Animations", ImGuiTreeNodeFlags_DefaultOpen))
{
auto& currently_playing = anim_objects.playback.front();
std::string_view animation_name = this->gltf_get_animation_name(static_cast<tz::hanval>(gltf_id), currently_playing.animation_id);
Expand All @@ -82,6 +82,26 @@ namespace tz::ren
ImGui::Checkbox("Loop", &currently_playing.loop);
ImGui::SliderFloat("Time Warp", &currently_playing.time_warp, -5.0f, 5.0f);
}

if(gltf.data.get_animations().size())
{
// choose an animation to play/queue
ImGui::Separator();
ImGui::TextColored(ImVec4{1.0f, 0.3f, 0.3f, 1.0f}, "Play/Queue Animation");
static playback_data new_anim;
ImGui::Checkbox("Loop", &new_anim.loop);
ImGui::SliderFloat("Time Warp", &new_anim.time_warp, -5.0f, 5.0f);
ImGui::SliderInt("Animation", reinterpret_cast<int*>(&new_anim.animation_id), 0, gltf.data.get_animations().size() - 1, "%zu");
ImGui::Text("%s", this->gltf_get_animation_name(static_cast<tz::hanval>(gltf_id), new_anim.animation_id).data());
if(ImGui::Button("Play"))
{
this->animated_object_play_animation(aoh, new_anim);
}
if(ImGui::Button("Queue"))
{
this->animated_object_queue_animation(aoh, new_anim);
}
}
}
}
ImGui::EndChild();
Expand Down
1 change: 1 addition & 0 deletions src/tz/ren/animation2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ namespace tz::ren
void animated_object_set_playback_time(animated_objects_handle handle, float time);
std::span<const playback_data> animated_object_get_playing_animations(animated_objects_handle handle) const;
std::span<playback_data> animated_object_get_playing_animations(animated_objects_handle handle);
void animated_object_play_animation(animated_objects_handle handle, playback_data anim);
void animated_object_queue_animation(animated_objects_handle handle, playback_data anim);
private:
// query as to whether a gltf handle has been removed before and is still in the free list.
Expand Down

0 comments on commit 9fdad2a

Please sign in to comment.