Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

- Root Motion WIP #798

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 95 additions & 0 deletions Editor/AnimationWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -927,12 +927,70 @@ void AnimationWindow::Create(EditorComponent* _editor)
});
AddWidget(&retargetCombo);

// Root Motion Tick
rootMotionCheckBox.Create("RootMotion: ");
rootMotionCheckBox.SetTooltip("Toggle root bone animation.");
rootMotionCheckBox.SetSize(XMFLOAT2(hei, hei));
//rootMotionCheckBox.SetPos(XMFLOAT2(x, y += step));
rootMotionCheckBox.OnClick([&](wi::gui::EventArgs args) {
AnimationComponent* animation = editor->GetCurrentScene().animations.GetComponent(entity);
if (animation != nullptr)
{
if (args.bValue) {
animation->RootMotionOn();
}
else {
animation->RootMotionOff();
}
}
});
rootMotionCheckBox.SetCheckText(ICON_CHECK);
AddWidget(&rootMotionCheckBox);
// Root Bone selector
rootBoneComboBox.Create("Root Bone: ");
rootBoneComboBox.SetSize(XMFLOAT2(wid, hei));
rootBoneComboBox.SetPos(XMFLOAT2(x, y));
rootBoneComboBox.SetEnabled(false);
rootBoneComboBox.OnSelect([&](wi::gui::EventArgs args) {
AnimationComponent* animation = editor->GetCurrentScene().animations.GetComponent(entity);
if (animation != nullptr)
{
Entity ent = (Entity)args.userdata;
if (ent != wi::ecs::INVALID_ENTITY)
{
animation->rootMotionBone = ent;
}
else
{
animation->rootMotionBone = wi::ecs::INVALID_ENTITY;
}
}
});
rootBoneComboBox.SetTooltip("Choose the root bone to evaluate root motion from.");
AddWidget(&rootBoneComboBox);


SetMinimized(true);
SetVisible(false);

}

// Example function to check if an entity already exists in the list
static bool EntityExistsInList(Entity entity, std::vector<Entity> entityList)
{
// Iterate through the list of entities
for (Entity& e : entityList)
{
if (e == entity)
{
// Entity found in the list
return true;
}
}
// Entity not found in the list
return false;
}

void AnimationWindow::SetEntity(Entity entity)
{
if (this->entity != entity)
Expand All @@ -944,6 +1002,32 @@ void AnimationWindow::SetEntity(Entity entity)
{
this->entity = entity;
RefreshKeyframesList();

rootBoneComboBox.ClearItems();
rootBoneComboBox.AddItem("NO ROOT BONE " ICON_DISABLED, wi::ecs::INVALID_ENTITY);
if (animation != nullptr)
{
// Define a list of entities
std::vector<Entity> bone_list;
// Add items to root bone name combo box.
for (const AnimationComponent::AnimationChannel& channel : animation->channels)
{
if (channel.path == AnimationComponent::AnimationChannel::Path::TRANSLATION ||
channel.path == AnimationComponent::AnimationChannel::Path::ROTATION) {

if (!EntityExistsInList(channel.target, bone_list))
{
bone_list.push_back(channel.target);
const NameComponent* name = scene.names.GetComponent(channel.target);
if (name != nullptr)
{
rootBoneComboBox.AddItem(name->name, channel.target);
}
}
}
}
bone_list.clear();
}
}
}
}
Expand Down Expand Up @@ -985,6 +1069,15 @@ void AnimationWindow::Update()
}

loopedCheckBox.SetCheck(animation.IsLooped());
rootMotionCheckBox.SetCheck(animation.IsRootMotion());
if (animation.rootMotionBone != wi::ecs::INVALID_ENTITY)
{
rootBoneComboBox.SetSelectedByUserdataWithoutCallback(animation.rootMotionBone);
}
else
{
rootBoneComboBox.SetSelectedByUserdataWithoutCallback(wi::ecs::INVALID_ENTITY);
}

timerSlider.SetRange(animation.start, animation.end);
timerSlider.SetValue(animation.timer);
Expand Down Expand Up @@ -1213,5 +1306,7 @@ void AnimationWindow::ResizeLayout()
add(endInput);
add(recordCombo);
add(retargetCombo);
add(rootMotionCheckBox);
add(rootBoneComboBox);
add_fullwidth(keyframesList);
}
3 changes: 3 additions & 0 deletions Editor/AnimationWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ class AnimationWindow : public wi::gui::Window

wi::gui::ComboBox retargetCombo;

wi::gui::CheckBox rootMotionCheckBox;
wi::gui::ComboBox rootBoneComboBox;

void Update();

void RefreshKeyframesList();
Expand Down
Loading
Loading