From c31024f5b1520c8d8b05a4ad10e49492a4067ed8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tur=C3=A1nszki=20J=C3=A1nos?= Date: Fri, 12 Aug 2022 09:29:05 +0200 Subject: [PATCH] animation and gui fixes --- Editor/AnimationWindow.cpp | 71 +++++++--------------------- Editor/AnimationWindow.h | 2 +- Editor/Editor.cpp | 3 ++ Editor/OptionsWindow.cpp | 14 ++++-- Editor/OptionsWindow.h | 4 ++ Editor/RendererWindow.cpp | 20 ++++---- WickedEngine/wiGUI.cpp | 12 ++++- WickedEngine/wiScene.cpp | 10 +--- WickedEngine/wiScene_Serializers.cpp | 22 +++++++++ WickedEngine/wiVersion.cpp | 2 +- 10 files changed, 80 insertions(+), 80 deletions(-) diff --git a/Editor/AnimationWindow.cpp b/Editor/AnimationWindow.cpp index c572bcc2e..32806c087 100644 --- a/Editor/AnimationWindow.cpp +++ b/Editor/AnimationWindow.cpp @@ -17,17 +17,6 @@ void AnimationWindow::Create(EditorComponent* _editor) float wid = 200; float step = hei + 2; - - animationsComboBox.Create("Animation: "); - animationsComboBox.SetSize(XMFLOAT2(wid, hei)); - animationsComboBox.SetPos(XMFLOAT2(x, y)); - animationsComboBox.SetEnabled(false); - animationsComboBox.OnSelect([&](wi::gui::EventArgs args) { - entity = editor->GetCurrentScene().animations.GetEntity(args.iValue); - }); - animationsComboBox.SetTooltip("Choose an animation clip..."); - AddWidget(&animationsComboBox); - loopedCheckBox.Create("Looped: "); loopedCheckBox.SetTooltip("Toggle animation looping behaviour."); loopedCheckBox.SetSize(XMFLOAT2(hei, hei)); @@ -123,18 +112,16 @@ void AnimationWindow::Create(EditorComponent* _editor) } +void AnimationWindow::SetEntity(Entity entity) +{ + this->entity = entity; +} + void AnimationWindow::Update() { - animationsComboBox.ClearItems(); - Scene& scene = editor->GetCurrentScene(); if (!scene.animations.Contains(entity)) - { - entity = INVALID_ENTITY; - } - - if (scene.animations.GetCount() == 0) { SetEnabled(false); return; @@ -144,43 +131,21 @@ void AnimationWindow::Update() SetEnabled(true); } - for (size_t i = 0; i < scene.animations.GetCount(); ++i) - { - Entity e = scene.animations.GetEntity(i); - NameComponent& name = *scene.names.GetComponent(e); - animationsComboBox.AddItem(name.name.empty() ? std::to_string(e) : name.name); + AnimationComponent& animation = *scene.animations.GetComponent(entity); - if (e == entity) - { - animationsComboBox.SetSelected((int)i); - } + if (animation.IsPlaying()) + { + playButton.SetText("Pause"); + } + else + { + playButton.SetText("Play"); } - if (entity == INVALID_ENTITY && scene.animations.GetCount() > 0) - { - entity = scene.animations.GetEntity(0); - animationsComboBox.SetSelected(0); - } + loopedCheckBox.SetCheck(animation.IsLooped()); - int selected = animationsComboBox.GetSelected(); - if (selected >= 0 && selected < (int)scene.animations.GetCount()) - { - AnimationComponent& animation = scene.animations[selected]; - - if (animation.IsPlaying()) - { - playButton.SetText("Pause"); - } - else - { - playButton.SetText("Play"); - } - - loopedCheckBox.SetCheck(animation.IsLooped()); - - timerSlider.SetRange(0, animation.GetLength()); - timerSlider.SetValue(animation.timer); - amountSlider.SetValue(animation.amount); - speedSlider.SetValue(animation.speed); - } + timerSlider.SetRange(0, animation.GetLength()); + timerSlider.SetValue(animation.timer); + amountSlider.SetValue(animation.amount); + speedSlider.SetValue(animation.speed); } diff --git a/Editor/AnimationWindow.h b/Editor/AnimationWindow.h index c1444dd5b..325a9dde2 100644 --- a/Editor/AnimationWindow.h +++ b/Editor/AnimationWindow.h @@ -10,8 +10,8 @@ public: EditorComponent* editor = nullptr; wi::ecs::Entity entity = wi::ecs::INVALID_ENTITY; + void SetEntity(wi::ecs::Entity entity); - wi::gui::ComboBox animationsComboBox; wi::gui::CheckBox loopedCheckBox; wi::gui::Button playButton; wi::gui::Button stopButton; diff --git a/Editor/Editor.cpp b/Editor/Editor.cpp index 360d7c3b9..b36350ea3 100644 --- a/Editor/Editor.cpp +++ b/Editor/Editor.cpp @@ -409,6 +409,7 @@ void EditorComponent::Load() componentsWnd.transformWnd.SetEntity(INVALID_ENTITY); componentsWnd.layerWnd.SetEntity(INVALID_ENTITY); componentsWnd.nameWnd.SetEntity(INVALID_ENTITY); + componentsWnd.animWnd.SetEntity(INVALID_ENTITY); optionsWnd.RefreshEntityTree(); ResetHistory(); @@ -1338,6 +1339,7 @@ void EditorComponent::Update(float dt) componentsWnd.layerWnd.SetEntity(INVALID_ENTITY); componentsWnd.nameWnd.SetEntity(INVALID_ENTITY); componentsWnd.weatherWnd.SetEntity(INVALID_ENTITY); + componentsWnd.animWnd.SetEntity(INVALID_ENTITY); } else { @@ -1370,6 +1372,7 @@ void EditorComponent::Update(float dt) componentsWnd.layerWnd.SetEntity(picked.entity); componentsWnd.nameWnd.SetEntity(picked.entity); componentsWnd.weatherWnd.SetEntity(picked.entity); + componentsWnd.animWnd.SetEntity(picked.entity); if (picked.subsetIndex >= 0) { diff --git a/Editor/OptionsWindow.cpp b/Editor/OptionsWindow.cpp index 00138f119..4c81c1757 100644 --- a/Editor/OptionsWindow.cpp +++ b/Editor/OptionsWindow.cpp @@ -262,6 +262,10 @@ void OptionsWindow::Create(EditorComponent* _editor) filterCombo.AddItem("Sound " ICON_SOUND, (uint64_t)Filter::Sound); filterCombo.AddItem("Weather " ICON_WEATHER, (uint64_t)Filter::Weather); filterCombo.AddItem("Light " ICON_POINTLIGHT, (uint64_t)Filter::Light); + filterCombo.AddItem("Animation " ICON_ANIMATION, (uint64_t)Filter::Animation); + filterCombo.AddItem("Force " ICON_FORCE, (uint64_t)Filter::Force); + filterCombo.AddItem("Emitter " ICON_EMITTER, (uint64_t)Filter::Emitter); + filterCombo.AddItem("Hairparticle " ICON_HAIR, (uint64_t)Filter::Hairparticle); filterCombo.SetTooltip("Apply filtering to the Entities"); filterCombo.OnSelect([&](wi::gui::EventArgs args) { filter = (Filter)args.userdata; @@ -1006,7 +1010,7 @@ void OptionsWindow::RefreshEntityTree() } } - if (has_flag(filter, Filter::All)) + if (has_flag(filter, Filter::Hairparticle)) { for (size_t i = 0; i < scene.hairs.GetCount(); ++i) { @@ -1014,7 +1018,7 @@ void OptionsWindow::RefreshEntityTree() } } - if (has_flag(filter, Filter::All)) + if (has_flag(filter, Filter::Emitter)) { for (size_t i = 0; i < scene.emitters.GetCount(); ++i) { @@ -1022,7 +1026,7 @@ void OptionsWindow::RefreshEntityTree() } } - if (has_flag(filter, Filter::All)) + if (has_flag(filter, Filter::Animation)) { for (size_t i = 0; i < scene.animations.GetCount(); ++i) { @@ -1030,7 +1034,7 @@ void OptionsWindow::RefreshEntityTree() } } - if (has_flag(filter, Filter::All)) + if (has_flag(filter, Filter::EnvironmentProbe)) { for (size_t i = 0; i < scene.probes.GetCount(); ++i) { @@ -1038,7 +1042,7 @@ void OptionsWindow::RefreshEntityTree() } } - if (has_flag(filter, Filter::All)) + if (has_flag(filter, Filter::Force)) { for (size_t i = 0; i < scene.forces.GetCount(); ++i) { diff --git a/Editor/OptionsWindow.h b/Editor/OptionsWindow.h index 3feeaee0f..1f7aab669 100644 --- a/Editor/OptionsWindow.h +++ b/Editor/OptionsWindow.h @@ -51,6 +51,10 @@ public: Sound = 1 << 6, Weather = 1 << 7, Light = 1 << 8, + Animation = 1 << 9, + Force = 1 << 10, + Emitter = 1 << 11, + Hairparticle = 1 << 12, All = ~0ull, } filter = Filter::All; diff --git a/Editor/RendererWindow.cpp b/Editor/RendererWindow.cpp index 517fa14a4..6060cb958 100644 --- a/Editor/RendererWindow.cpp +++ b/Editor/RendererWindow.cpp @@ -49,8 +49,8 @@ void RendererWindow::Create(EditorComponent* _editor) occlusionCullingCheckBox.SetCheck(wi::renderer::GetOcclusionCullingEnabled()); AddWidget(&occlusionCullingCheckBox); - visibilityComputeShadingCheckBox.Create("VCS: "); - visibilityComputeShadingCheckBox.SetTooltip("Visibility Compute Shading (experimental)\nThis will shade the scene in compute shaders instead of pixel shaders\nThis has a higher initial performance cost, but it will be faster in high polygon scenes"); + visibilityComputeShadingCheckBox.Create("Visibility CS: "); + visibilityComputeShadingCheckBox.SetTooltip("Visibility Compute Shading (experimental)\nThis will shade the scene in compute shaders instead of pixel shaders\nThis has a higher initial performance cost, but it will be faster in high polygon scenes.\nIt is not compatible with MSAA and tessellation."); visibilityComputeShadingCheckBox.SetPos(XMFLOAT2(x, y += step)); visibilityComputeShadingCheckBox.SetSize(XMFLOAT2(itemheight, itemheight)); visibilityComputeShadingCheckBox.OnClick([=](wi::gui::EventArgs args) { @@ -103,7 +103,7 @@ void RendererWindow::Create(EditorComponent* _editor) surfelGIDebugComboBox.Create(""); surfelGIDebugComboBox.SetTooltip("Choose Surfel GI debug visualization."); - surfelGIDebugComboBox.SetPos(XMFLOAT2(x + 40, y)); + surfelGIDebugComboBox.SetPos(XMFLOAT2(x + 30, y)); surfelGIDebugComboBox.SetSize(XMFLOAT2(80, itemheight)); surfelGIDebugComboBox.AddItem("No Debug", SURFEL_DEBUG_NONE); surfelGIDebugComboBox.AddItem("Normal", SURFEL_DEBUG_NORMAL); @@ -129,7 +129,7 @@ void RendererWindow::Create(EditorComponent* _editor) ddgiDebugCheckBox.Create("DEBUG: "); ddgiDebugCheckBox.SetTooltip("Toggle DDGI probe visualization."); - ddgiDebugCheckBox.SetPos(XMFLOAT2(x + 120, y)); + ddgiDebugCheckBox.SetPos(XMFLOAT2(x + wid + 1, y)); ddgiDebugCheckBox.SetSize(XMFLOAT2(itemheight, itemheight)); ddgiDebugCheckBox.OnClick([](wi::gui::EventArgs args) { wi::renderer::SetDDGIDebugEnabled(args.bValue); @@ -159,7 +159,7 @@ void RendererWindow::Create(EditorComponent* _editor) voxelRadianceDebugCheckBox.Create("DEBUG: "); voxelRadianceDebugCheckBox.SetTooltip("Toggle Voxel GI visualization."); - voxelRadianceDebugCheckBox.SetPos(XMFLOAT2(x + 120, y)); + voxelRadianceDebugCheckBox.SetPos(XMFLOAT2(x + wid + 1, y)); voxelRadianceDebugCheckBox.SetSize(XMFLOAT2(itemheight, itemheight)); voxelRadianceDebugCheckBox.OnClick([](wi::gui::EventArgs args) { wi::renderer::SetToDrawVoxelHelper(args.bValue); @@ -179,7 +179,7 @@ void RendererWindow::Create(EditorComponent* _editor) voxelRadianceReflectionsCheckBox.Create("Reflections: "); voxelRadianceReflectionsCheckBox.SetTooltip("Toggle specular reflections computation for Voxel GI."); - voxelRadianceReflectionsCheckBox.SetPos(XMFLOAT2(x + 120, y)); + voxelRadianceReflectionsCheckBox.SetPos(XMFLOAT2(x + wid + 1, y)); voxelRadianceReflectionsCheckBox.SetSize(XMFLOAT2(itemheight, itemheight)); voxelRadianceReflectionsCheckBox.OnClick([](wi::gui::EventArgs args) { wi::renderer::SetVoxelRadianceReflectionsEnabled(args.bValue); @@ -251,7 +251,7 @@ void RendererWindow::Create(EditorComponent* _editor) variableRateShadingClassificationDebugCheckBox.Create("DEBUG: "); variableRateShadingClassificationDebugCheckBox.SetTooltip("Toggle visualization of variable rate shading classification feature"); - variableRateShadingClassificationDebugCheckBox.SetPos(XMFLOAT2(x + 120, y)); + variableRateShadingClassificationDebugCheckBox.SetPos(XMFLOAT2(x + wid + 1, y)); variableRateShadingClassificationDebugCheckBox.SetSize(XMFLOAT2(itemheight, itemheight)); variableRateShadingClassificationDebugCheckBox.OnClick([](wi::gui::EventArgs args) { wi::renderer::SetVariableRateShadingClassificationDebug(args.bValue); @@ -272,7 +272,7 @@ void RendererWindow::Create(EditorComponent* _editor) debugLightCullingCheckBox.Create("DEBUG: "); debugLightCullingCheckBox.SetTooltip("Toggle visualization of the screen space light culling heatmap grid (Tiled renderer only)"); - debugLightCullingCheckBox.SetPos(XMFLOAT2(x + 120, y)); + debugLightCullingCheckBox.SetPos(XMFLOAT2(x + wid + 1, y)); debugLightCullingCheckBox.SetSize(XMFLOAT2(itemheight, itemheight)); debugLightCullingCheckBox.OnClick([](wi::gui::EventArgs args) { wi::renderer::SetDebugLightCulling(args.bValue); @@ -312,7 +312,7 @@ void RendererWindow::Create(EditorComponent* _editor) AddWidget(&transparentShadowsCheckBox); shadowTypeComboBox.Create("Shadow type: "); - shadowTypeComboBox.SetSize(XMFLOAT2(100, itemheight)); + shadowTypeComboBox.SetSize(XMFLOAT2(wid, itemheight)); shadowTypeComboBox.SetPos(XMFLOAT2(x, y += step)); shadowTypeComboBox.AddItem("Shadowmaps"); if (wi::graphics::GetDevice()->CheckCapability(wi::graphics::GraphicsDeviceCapability::RAYTRACING)) @@ -463,7 +463,7 @@ void RendererWindow::Create(EditorComponent* _editor) temporalAADebugCheckBox.Create("DEBUGJitter: "); temporalAADebugCheckBox.SetText("DEBUG: "); temporalAADebugCheckBox.SetTooltip("Disable blending of frame history. Camera Subpixel jitter will be visible."); - temporalAADebugCheckBox.SetPos(XMFLOAT2(x + 120, y)); + temporalAADebugCheckBox.SetPos(XMFLOAT2(x + wid + 1, y)); temporalAADebugCheckBox.SetSize(XMFLOAT2(itemheight, itemheight)); temporalAADebugCheckBox.OnClick([](wi::gui::EventArgs args) { wi::renderer::SetTemporalAADebugEnabled(args.bValue); diff --git a/WickedEngine/wiGUI.cpp b/WickedEngine/wiGUI.cpp index c2cf708ea..41357c57c 100644 --- a/WickedEngine/wiGUI.cpp +++ b/WickedEngine/wiGUI.cpp @@ -1121,6 +1121,11 @@ namespace wi::gui if (IsEnabled() && dt > 0) { + if (state == ACTIVE) + { + Deactivate(); + } + Hitbox2D pointerHitbox = GetPointerHitbox(); if (scroll_allowed && scrollbar.IsScrollbarRequired() && pointerHitbox.intersects(hitBox)) { @@ -1133,6 +1138,11 @@ namespace wi::gui { state = IDLE; } + + if (pointerHitbox.intersects(hitBox) && wi::input::Press(wi::input::MOUSE_BUTTON_LEFT)) + { + Activate(); + } } if (scrollbar.IsScrollbarRequired()) @@ -1165,7 +1175,7 @@ namespace wi::gui ApplyScissor(canvas, scissorRect, cmd); - sprites[state].Draw(cmd); + sprites[IDLE].Draw(cmd); font.Draw(cmd); scrollbar.Render(canvas, cmd); diff --git a/WickedEngine/wiScene.cpp b/WickedEngine/wiScene.cpp index 3d8340f97..455bc9a6a 100644 --- a/WickedEngine/wiScene.cpp +++ b/WickedEngine/wiScene.cpp @@ -2745,15 +2745,7 @@ namespace wi::scene for (const AnimationComponent::AnimationChannel& channel : animation.channels) { assert(channel.samplerIndex < (int)animation.samplers.size()); - AnimationComponent::AnimationSampler& sampler = animation.samplers[channel.samplerIndex]; - if (sampler.data == INVALID_ENTITY) - { - // backwards-compatibility mode - sampler.data = CreateEntity(); - animation_datas.Create(sampler.data) = sampler.backwards_compatibility_data; - sampler.backwards_compatibility_data.keyframe_times.clear(); - sampler.backwards_compatibility_data.keyframe_data.clear(); - } + const AnimationComponent::AnimationSampler& sampler = animation.samplers[channel.samplerIndex]; const AnimationDataComponent* animationdata = animation_datas.GetComponent(sampler.data); if (animationdata == nullptr) { diff --git a/WickedEngine/wiScene_Serializers.cpp b/WickedEngine/wiScene_Serializers.cpp index 8336dc843..7310f7f4d 100644 --- a/WickedEngine/wiScene_Serializers.cpp +++ b/WickedEngine/wiScene_Serializers.cpp @@ -1452,6 +1452,28 @@ namespace wi::scene animation_datas.Serialize(archive, seri); } + if (archive.GetVersion() < 46) + { + // Fixing the animation import from archive that didn't have separate animation data components: + for (size_t i = 0; i < animations.GetCount(); ++i) + { + AnimationComponent& animation = animations[i]; + for (const AnimationComponent::AnimationChannel& channel : animation.channels) + { + assert(channel.samplerIndex < (int)animation.samplers.size()); + AnimationComponent::AnimationSampler& sampler = animation.samplers[channel.samplerIndex]; + if (sampler.data == INVALID_ENTITY) + { + // backwards-compatibility mode + sampler.data = CreateEntity(); + animation_datas.Create(sampler.data) = sampler.backwards_compatibility_data; + sampler.backwards_compatibility_data.keyframe_times.clear(); + sampler.backwards_compatibility_data.keyframe_data.clear(); + } + } + } + } + wi::backlog::post("Scene serialize took " + std::to_string(timer.elapsed_seconds()) + " sec"); } diff --git a/WickedEngine/wiVersion.cpp b/WickedEngine/wiVersion.cpp index 3f19d9e00..99eaf735a 100644 --- a/WickedEngine/wiVersion.cpp +++ b/WickedEngine/wiVersion.cpp @@ -9,7 +9,7 @@ namespace wi::version // minor features, major updates, breaking compatibility changes const int minor = 71; // minor bug fixes, alterations, refactors, updates - const int revision = 5; + const int revision = 6; const std::string version_string = std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(revision);