Added animation selection

This commit is contained in:
Antoine Pilote
2023-09-06 18:49:11 -04:00
parent 62017e0bd8
commit 8718540ac6
3 changed files with 63 additions and 0 deletions

View File

@@ -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();
}

View File

@@ -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<std::string, BoneTransformTrack>& GetTracks() { return m_Tracks; }
};

View File

@@ -20,6 +20,8 @@ namespace Nuake
std::vector<Ref<SkeletalAnimation>> m_Animations;
public:
bool IsPlaying = true;
SkinnedModel();
SkinnedModel(const std::string path);
~SkinnedModel();
@@ -33,10 +35,14 @@ namespace Nuake
void AddMesh(Ref<SkinnedMesh> mesh);
std::vector<Ref<SkinnedMesh>>& GetMeshes();
std::vector<Ref<SkeletalAnimation>> GetAnimations() const { return m_Animations; }
void SetAnimations(const std::vector<Ref<SkeletalAnimation>> animations);
void AddAnimation(Ref<SkeletalAnimation> animation);
Ref<SkeletalAnimation> 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;