From c8b581f8b16878aa4522a84170aa0575803b3fad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tur=C3=A1nszki=20J=C3=A1nos?= Date: Fri, 2 Aug 2024 07:19:43 +0200 Subject: [PATCH] some improvements --- Editor/GeneralWindow.cpp | 8 +++++++ Editor/MeshWindow.cpp | 11 ++------- Editor/TransformWindow.cpp | 37 ++++++++++++++++++++++++++++++- Editor/TransformWindow.h | 2 ++ WickedEngine/wiApplication.cpp | 7 ++++-- WickedEngine/wiScene.cpp | 35 +++++++++++++++++------------ WickedEngine/wiScene_Components.h | 1 + WickedEngine/wiVersion.cpp | 2 +- 8 files changed, 76 insertions(+), 27 deletions(-) diff --git a/Editor/GeneralWindow.cpp b/Editor/GeneralWindow.cpp index 78db415e9..b8a5e2c5e 100644 --- a/Editor/GeneralWindow.cpp +++ b/Editor/GeneralWindow.cpp @@ -651,6 +651,14 @@ void GeneralWindow::Create(EditorComponent* _editor) sprite.params.corners_rounding[3].radius = 10; } + editor->componentsWnd.transformWnd.resetScaleUniformButton.SetColor(wi::Color::Error(), wi::gui::WIDGETSTATE::FOCUS); + for (auto& sprite : editor->componentsWnd.transformWnd.resetScaleUniformButton.sprites) + { + sprite.params.enableCornerRounding(); + sprite.params.corners_rounding[1].radius = 10; + sprite.params.corners_rounding[3].radius = 10; + } + editor->componentsWnd.transformWnd.resetRotationButton.SetColor(wi::Color::Error(), wi::gui::WIDGETSTATE::FOCUS); for (auto& sprite : editor->componentsWnd.transformWnd.resetRotationButton.sprites) { diff --git a/Editor/MeshWindow.cpp b/Editor/MeshWindow.cpp index e9b53398c..1e5ced7e8 100644 --- a/Editor/MeshWindow.cpp +++ b/Editor/MeshWindow.cpp @@ -26,7 +26,7 @@ void MeshWindow::Create(EditorComponent* _editor) { editor = _editor; wi::gui::Window::Create(ICON_MESH " Mesh", wi::gui::Window::WindowControls::COLLAPSE | wi::gui::Window::WindowControls::CLOSE); - SetSize(XMFLOAT2(580, 800)); + SetSize(XMFLOAT2(580, 880)); closeButton.SetTooltip("Delete MeshComponent"); OnClose([=](wi::gui::EventArgs args) { @@ -48,7 +48,7 @@ void MeshWindow::Create(EditorComponent* _editor) float step = hei + 2; float wid = 170; - float infolabel_height = 200; + float infolabel_height = 280; meshInfoLabel.Create("Mesh Info"); meshInfoLabel.SetPos(XMFLOAT2(20, y)); meshInfoLabel.SetSize(XMFLOAT2(260, infolabel_height)); @@ -373,7 +373,6 @@ void MeshWindow::Create(EditorComponent* _editor) Entity prev_subset_material = INVALID_ENTITY; // Search for first object with a mesh from selection, that will be the base: - Entity baseEntityParent = INVALID_ENTITY; Entity baseEntity = INVALID_ENTITY; TransformComponent* baseTransform = nullptr; ObjectComponent* baseObject = nullptr; @@ -387,11 +386,6 @@ void MeshWindow::Create(EditorComponent* _editor) if (mesh == nullptr) continue; baseEntity = picked.entity; - HierarchyComponent* hier = scene.hierarchy.GetComponent(baseEntity); - if (hier != nullptr) - { - baseEntityParent = hier->parentID; - } baseTransform = scene.transforms.GetComponent(picked.entity); baseObject = object; baseMesh = mesh; @@ -581,7 +575,6 @@ void MeshWindow::Create(EditorComponent* _editor) { baseTransform->ClearTransform(); } - scene.Component_Attach(baseEntity, baseEntityParent); } for (auto& x : entities_to_remove) diff --git a/Editor/TransformWindow.cpp b/Editor/TransformWindow.cpp index 8ec2fc823..46ac8d15c 100644 --- a/Editor/TransformWindow.cpp +++ b/Editor/TransformWindow.cpp @@ -8,7 +8,7 @@ void TransformWindow::Create(EditorComponent* _editor) { editor = _editor; wi::gui::Window::Create(ICON_TRANSFORM " Transform" , wi::gui::Window::WindowControls::COLLAPSE | wi::gui::Window::WindowControls::CLOSE); - SetSize(XMFLOAT2(480, 260)); + SetSize(XMFLOAT2(480, 280)); closeButton.SetTooltip("Delete TransformComponent\nNote that a lot of components won't work correctly without a TransformComponent!"); OnClose([=](wi::gui::EventArgs args) { @@ -141,6 +141,23 @@ void TransformWindow::Create(EditorComponent* _editor) }); AddWidget(&szInput); + suInput.Create(""); + suInput.SetDescription("Uniform Scale: "); + suInput.SetValue(1); + suInput.SetPos(XMFLOAT2(x, y += step)); + suInput.SetSize(XMFLOAT2(siz, hei)); + suInput.OnInputAccepted([&](wi::gui::EventArgs args) { + TransformComponent* transform = editor->GetCurrentScene().transforms.GetComponent(entity); + if (transform != nullptr) + { + transform->scale_local.x = args.fValue; + transform->scale_local.y = args.fValue; + transform->scale_local.z = args.fValue; + transform->SetDirty(); + } + }); + AddWidget(&suInput); + x = xx; y = step * 4; @@ -341,6 +358,20 @@ void TransformWindow::Create(EditorComponent* _editor) }); AddWidget(&resetScaleButton); + resetScaleUniformButton.Create("ResetScaleUniform"); + resetScaleUniformButton.SetText("X"); + resetScaleUniformButton.SetTooltip("Reset scale"); + resetScaleUniformButton.SetSize(XMFLOAT2(hei, hei)); + resetScaleUniformButton.OnClick([=](wi::gui::EventArgs args) { + TransformComponent* transform = editor->GetCurrentScene().transforms.GetComponent(entity); + if (transform != nullptr) + { + transform->scale_local = XMFLOAT3(1, 1, 1); + transform->SetDirty(); + } + }); + AddWidget(&resetScaleUniformButton); + resetRotationButton.Create("ResetRotation"); resetRotationButton.SetText("X"); resetRotationButton.SetTooltip("Reset rotation"); @@ -389,6 +420,7 @@ void TransformWindow::SetEntity(Entity entity) sxInput.SetValue(transform->scale_local.x); syInput.SetValue(transform->scale_local.y); szInput.SetValue(transform->scale_local.z); + suInput.SetValue(transform->scale_local.x); SetEnabled(true); } @@ -445,6 +477,7 @@ void TransformWindow::ResizeLayout() sxInput.SetSize(XMFLOAT2(safe_width / 3.0f - padding, txInput.GetSize().y)); syInput.SetSize(XMFLOAT2(safe_width / 3.0f - padding, txInput.GetSize().y)); szInput.SetSize(XMFLOAT2(safe_width / 3.0f - padding, txInput.GetSize().y)); + suInput.SetSize(XMFLOAT2(safe_width - padding, txInput.GetSize().y)); rollInput.SetSize(XMFLOAT2(safe_width / 3.0f - padding, txInput.GetSize().y)); pitchInput.SetSize(XMFLOAT2(safe_width / 3.0f - padding, txInput.GetSize().y)); @@ -464,6 +497,8 @@ void TransformWindow::ResizeLayout() szInput.SetPos(XMFLOAT2(resetScaleButton.GetPos().x - szInput.GetSize().x - padding, resetScaleButton.GetPos().y)); syInput.SetPos(XMFLOAT2(szInput.GetPos().x - syInput.GetSize().x - padding, szInput.GetPos().y)); sxInput.SetPos(XMFLOAT2(syInput.GetPos().x - sxInput.GetSize().x - padding, syInput.GetPos().y)); + add_right(resetScaleUniformButton); + suInput.SetPos(XMFLOAT2(resetScaleUniformButton.GetPos().x - suInput.GetSize().x - padding, resetScaleUniformButton.GetPos().y)); add_right(resetRotationButton); yawInput.SetPos(XMFLOAT2(resetRotationButton.GetPos().x - yawInput.GetSize().x - padding, resetRotationButton.GetPos().y)); pitchInput.SetPos(XMFLOAT2(yawInput.GetPos().x - pitchInput.GetSize().x - padding, yawInput.GetPos().y)); diff --git a/Editor/TransformWindow.h b/Editor/TransformWindow.h index c8848ae3a..923577452 100644 --- a/Editor/TransformWindow.h +++ b/Editor/TransformWindow.h @@ -28,6 +28,7 @@ public: wi::gui::TextInputField sxInput; wi::gui::TextInputField syInput; wi::gui::TextInputField szInput; + wi::gui::TextInputField suInput; wi::gui::TextInputField snapScaleInput; wi::gui::TextInputField snapRotateInput; @@ -35,6 +36,7 @@ public: wi::gui::Button resetTranslationButton; wi::gui::Button resetScaleButton; + wi::gui::Button resetScaleUniformButton; wi::gui::Button resetRotationButton; void ResizeLayout() override; diff --git a/WickedEngine/wiApplication.cpp b/WickedEngine/wiApplication.cpp index 7ad09758a..ee30d7c90 100644 --- a/WickedEngine/wiApplication.cpp +++ b/WickedEngine/wiApplication.cpp @@ -149,15 +149,18 @@ namespace wi wi::profiler::BeginFrame(); - deltaTime = float(std::max(0.0, timer.record_elapsed_seconds())); + deltaTime = float(timer.record_elapsed_seconds()); const float target_deltaTime = 1.0f / targetFrameRate; if (framerate_lock && deltaTime < target_deltaTime) { wi::helper::QuickSleep((target_deltaTime - deltaTime) * 1000); - deltaTime += float(std::max(0.0, timer.record_elapsed_seconds())); + deltaTime += float(timer.record_elapsed_seconds()); } + // avoid instability caused by large delta time + deltaTime = clamp(deltaTime, 0.0f, 0.5f); + wi::input::Update(window, canvas); // Wake up the events that need to be executed on the main thread, in thread safe manner: diff --git a/WickedEngine/wiScene.cpp b/WickedEngine/wiScene.cpp index a8889fc6d..2c844ed75 100644 --- a/WickedEngine/wiScene.cpp +++ b/WickedEngine/wiScene.cpp @@ -6801,22 +6801,29 @@ namespace wi::scene float Scene::GetHumanoidDefaultFacing(const HumanoidComponent& humanoid, Entity humanoidEntity) const { - Entity left_shoulder = humanoid.bones[(size_t)HumanoidComponent::HumanoidBone::LeftUpperArm]; - Entity right_shoulder = humanoid.bones[(size_t)HumanoidComponent::HumanoidBone::RightUpperArm]; - XMVECTOR left_shoulder_pos = GetRestPose(left_shoulder).r[3]; - XMVECTOR right_shoulder_pos = GetRestPose(right_shoulder).r[3]; - const TransformComponent* transform = transforms.GetComponent(humanoidEntity); - if (transform != nullptr) + if (humanoid.default_facing == 0) { - XMVECTOR S = transform->GetScaleV(); - left_shoulder_pos *= S; - right_shoulder_pos *= S; + Entity left_shoulder = humanoid.bones[(size_t)HumanoidComponent::HumanoidBone::LeftUpperArm]; + Entity right_shoulder = humanoid.bones[(size_t)HumanoidComponent::HumanoidBone::RightUpperArm]; + XMVECTOR left_shoulder_pos = GetRestPose(left_shoulder).r[3]; + XMVECTOR right_shoulder_pos = GetRestPose(right_shoulder).r[3]; + const TransformComponent* transform = transforms.GetComponent(humanoidEntity); + if (transform != nullptr) + { + XMVECTOR S = transform->GetScaleV(); + left_shoulder_pos *= S; + right_shoulder_pos *= S; + } + if (XMVectorGetX(right_shoulder_pos) < XMVectorGetX(left_shoulder_pos)) + { + humanoid.default_facing = -1; + } + else + { + humanoid.default_facing = 1; + } } - if (XMVectorGetX(right_shoulder_pos) < XMVectorGetX(left_shoulder_pos)) - { - return -1; - } - return 1; + return humanoid.default_facing; } void Scene::ScanAnimationDependencies() diff --git a/WickedEngine/wiScene_Components.h b/WickedEngine/wiScene_Components.h index 0b7ce80e3..b32b163ff 100644 --- a/WickedEngine/wiScene_Components.h +++ b/WickedEngine/wiScene_Components.h @@ -1961,6 +1961,7 @@ namespace wi::scene XMFLOAT4 lookAtDeltaRotationState_LeftEye = XMFLOAT4(0, 0, 0, 1); XMFLOAT4 lookAtDeltaRotationState_RightEye = XMFLOAT4(0, 0, 0, 1); std::shared_ptr ragdoll = nullptr; // physics system implementation-specific object + mutable float default_facing = 0; // 0 = not yet computed void Serialize(wi::Archive& archive, wi::ecs::EntitySerializer& seri); }; diff --git a/WickedEngine/wiVersion.cpp b/WickedEngine/wiVersion.cpp index 1cf4cd12d..7ef0d1c29 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 = 530; + const int revision = 531; const std::string version_string = std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(revision);