From af465d77a449fc272b1935979105618dae9e7b9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tur=C3=A1nszki=20J=C3=A1nos?= Date: Fri, 12 Aug 2022 10:36:25 +0200 Subject: [PATCH] editor: animation sampling mode --- Editor/AnimationWindow.cpp | 44 ++++++++++++++++++++++++++++++++++++++ Editor/AnimationWindow.h | 1 + Editor/IconDefinitions.h | 2 +- 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/Editor/AnimationWindow.cpp b/Editor/AnimationWindow.cpp index 32806c087..f790acad2 100644 --- a/Editor/AnimationWindow.cpp +++ b/Editor/AnimationWindow.cpp @@ -17,6 +17,42 @@ void AnimationWindow::Create(EditorComponent* _editor) float wid = 200; float step = hei + 2; + modeComboBox.Create("Sampling: "); + modeComboBox.SetSize(XMFLOAT2(wid, hei)); + modeComboBox.SetPos(XMFLOAT2(x, y)); + modeComboBox.SetEnabled(false); + modeComboBox.AddItem("Step", AnimationComponent::AnimationSampler::Mode::STEP); + modeComboBox.AddItem("Linear", AnimationComponent::AnimationSampler::Mode::LINEAR); + modeComboBox.AddItem("Cubic spline", AnimationComponent::AnimationSampler::Mode::CUBICSPLINE); + modeComboBox.OnSelect([&](wi::gui::EventArgs args) { + AnimationComponent* animation = editor->GetCurrentScene().animations.GetComponent(entity); + if (animation != nullptr) + { + for (const AnimationComponent::AnimationChannel& channel : animation->channels) + { + assert(channel.samplerIndex < (int)animation->samplers.size()); + AnimationComponent::AnimationSampler& sampler = animation->samplers[channel.samplerIndex]; + sampler.mode = (AnimationComponent::AnimationSampler::Mode)args.userdata; + + if (sampler.mode == AnimationComponent::AnimationSampler::Mode::CUBICSPLINE) + { + const AnimationDataComponent* animationdata = editor->GetCurrentScene().animation_datas.GetComponent(sampler.data); + if (animationdata == nullptr) + { + sampler.mode = AnimationComponent::AnimationSampler::Mode::LINEAR; + } + else if(animationdata->keyframe_data.size() != animationdata->keyframe_times.size() * 3 * 3) + { + sampler.mode = AnimationComponent::AnimationSampler::Mode::LINEAR; + } + } + + } + } + }); + modeComboBox.SetTooltip("Choose how animation data is interpreted between keyframes.\nNote that Cubic spline sampling requires spline animation data, otherwise, it will fall back to Linear!"); + AddWidget(&modeComboBox); + loopedCheckBox.Create("Looped: "); loopedCheckBox.SetTooltip("Toggle animation looping behaviour."); loopedCheckBox.SetSize(XMFLOAT2(hei, hei)); @@ -142,6 +178,14 @@ void AnimationWindow::Update() playButton.SetText("Play"); } + for (const AnimationComponent::AnimationChannel& channel : animation.channels) + { + assert(channel.samplerIndex < (int)animation.samplers.size()); + AnimationComponent::AnimationSampler& sampler = animation.samplers[channel.samplerIndex]; + modeComboBox.SetSelectedByUserdataWithoutCallback(sampler.mode); + break; // feed back the first sampler's mode into the gui + } + loopedCheckBox.SetCheck(animation.IsLooped()); timerSlider.SetRange(0, animation.GetLength()); diff --git a/Editor/AnimationWindow.h b/Editor/AnimationWindow.h index 325a9dde2..7830f9a66 100644 --- a/Editor/AnimationWindow.h +++ b/Editor/AnimationWindow.h @@ -12,6 +12,7 @@ public: wi::ecs::Entity entity = wi::ecs::INVALID_ENTITY; void SetEntity(wi::ecs::Entity entity); + wi::gui::ComboBox modeComboBox; wi::gui::CheckBox loopedCheckBox; wi::gui::Button playButton; wi::gui::Button stopButton; diff --git a/Editor/IconDefinitions.h b/Editor/IconDefinitions.h index 1fc946737..f8ac08256 100644 --- a/Editor/IconDefinitions.h +++ b/Editor/IconDefinitions.h @@ -16,7 +16,7 @@ #define ICON_DECAL ICON_FA_NOTE_STICKY #define ICON_CAMERA ICON_FA_VIDEO #define ICON_ENVIRONMENTPROBE ICON_FA_EARTH_ASIA -#define ICON_ANIMATION ICON_FA_PLAY +#define ICON_ANIMATION ICON_FA_PERSON_RUNNING #define ICON_ARMATURE ICON_FA_PERSON #define ICON_POINTLIGHT ICON_FA_LIGHTBULB #define ICON_SPOTLIGHT ICON_FA_LIGHTBULB // todo: find better one for spotlight