From 8718540ac609d7961b21210beec3c50e487f59ea Mon Sep 17 00:00:00 2001 From: Antoine Pilote Date: Wed, 6 Sep 2023 18:49:11 -0400 Subject: [PATCH] Added animation selection --- .../src/ComponentsPanel/SkinnedModelPanel.h | 56 +++++++++++++++++++ Nuake/src/Resource/SkeletalAnimation.h | 1 + Nuake/src/Resource/SkinnedModel.h | 6 ++ 3 files changed, 63 insertions(+) diff --git a/Editor/src/ComponentsPanel/SkinnedModelPanel.h b/Editor/src/ComponentsPanel/SkinnedModelPanel.h index 66d9b3da..eaf8e838 100644 --- a/Editor/src/ComponentsPanel/SkinnedModelPanel.h +++ b/Editor/src/ComponentsPanel/SkinnedModelPanel.h @@ -102,6 +102,62 @@ public: ImGui::TableNextColumn(); ComponentTableReset(component.ModelPath, ""); + + if (component.ModelResource) + { + auto& model = component.ModelResource; + ImGui::TableNextColumn(); + + { + ImGui::Text("Playing"); + ImGui::TableNextColumn(); + + ImGui::Checkbox("##playing", &model->IsPlaying); + + ImGui::TableNextColumn(); + ComponentTableReset(model->IsPlaying, true); + ImGui::TableNextColumn(); + } + + { + ImGui::Text("Type"); + ImGui::TableNextColumn(); + + uint32_t animIndex = model->GetCurrentAnimationIndex(); + uint32_t oldAnimIndex = animIndex; + auto& animations = model->GetAnimations(); + if (ImGui::BeginCombo("Type", model->GetCurrentAnimation()->GetName().c_str())) + { + for (int n = 0; n < model->GetAnimationsCount(); n++) + { + bool is_selected = (animIndex == n); + if (ImGui::Selectable(animations[n]->GetName().c_str(), is_selected)) + { + animIndex = n; + } + + if (is_selected) + ImGui::SetItemDefaultFocus(); + } + ImGui::EndCombo(); + } + + if (animIndex != oldAnimIndex) + { + model->PlayAnimation(animIndex); + } + + ImGui::TableNextColumn(); + ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(1, 1, 1, 0)); + std::string resetLabel = std::string(ICON_FA_UNDO) + "##ResetAnimId"; + if (ImGui::Button(resetLabel.c_str())) + { + model->PlayAnimation(0); + } + ImGui::PopStyleColor(); + } + } + } EndComponentTable(); } diff --git a/Nuake/src/Resource/SkeletalAnimation.h b/Nuake/src/Resource/SkeletalAnimation.h index 42c2e941..4ea0419f 100644 --- a/Nuake/src/Resource/SkeletalAnimation.h +++ b/Nuake/src/Resource/SkeletalAnimation.h @@ -123,6 +123,7 @@ namespace Nuake float GetTicksPerSecond() const { return m_TicksPerSecond; } void SetTicksPerSecond(float ticks) { m_TicksPerSecond = ticks; } + const std::string& GetName() const { return m_Name; } BoneTransformTrack& GetTrack(const std::string& name); std::unordered_map& GetTracks() { return m_Tracks; } }; diff --git a/Nuake/src/Resource/SkinnedModel.h b/Nuake/src/Resource/SkinnedModel.h index 99711080..70e30a52 100644 --- a/Nuake/src/Resource/SkinnedModel.h +++ b/Nuake/src/Resource/SkinnedModel.h @@ -20,6 +20,8 @@ namespace Nuake std::vector> m_Animations; public: + bool IsPlaying = true; + SkinnedModel(); SkinnedModel(const std::string path); ~SkinnedModel(); @@ -33,10 +35,14 @@ namespace Nuake void AddMesh(Ref mesh); std::vector>& GetMeshes(); + std::vector> GetAnimations() const { return m_Animations; } void SetAnimations(const std::vector> animations); void AddAnimation(Ref animation); + Ref GetCurrentAnimation(); void PlayAnimation(uint32_t animationId); + uint32_t GetCurrentAnimationIndex() const { return m_CurrentAnimation; } + uint32_t GetAnimationsCount() const { return m_NumAnimation; } json Serialize() override; bool Deserialize(const json& j) override;