From 5345e4ba4f7ec1703d4935996f311ec89bd4c442 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tur=C3=A1nszki=20J=C3=A1nos?= Date: Sat, 13 Aug 2022 13:02:03 +0200 Subject: [PATCH] inverse kinematics stability improvement, editor bone size tweaks, default weather gradient --- Editor/AnimationWindow.cpp | 2 +- Editor/Editor.cpp | 2 ++ Editor/WeatherWindow.cpp | 3 +++ WickedEngine/wiScene.cpp | 52 ++++++++++++++++++++++++++++---------- WickedEngine/wiScene.h | 1 + WickedEngine/wiVersion.cpp | 2 +- 6 files changed, 47 insertions(+), 15 deletions(-) diff --git a/Editor/AnimationWindow.cpp b/Editor/AnimationWindow.cpp index 253965761..9c8245d66 100644 --- a/Editor/AnimationWindow.cpp +++ b/Editor/AnimationWindow.cpp @@ -648,7 +648,7 @@ void AnimationWindow::RefreshKeyframesList() for (float time : animation_data->keyframe_times) { wi::gui::TreeList::Item item2; - item2.name = std::to_string(time); + item2.name = std::to_string(time) + " sec"; item2.level = 1; item2.userdata = 0ull; item2.userdata |= channelIndex & 0xFFFFFFFF; diff --git a/Editor/Editor.cpp b/Editor/Editor.cpp index 6f3a5e120..a982006aa 100644 --- a/Editor/Editor.cpp +++ b/Editor/Editor.cpp @@ -955,6 +955,7 @@ void EditorComponent::Update(float dt) wi::primitive::Capsule capsule; capsule.radius = wi::math::Distance(a, b) * 0.1f; + capsule.radius = wi::math::Clamp(capsule.radius, 0.01f, 0.1f); a -= ab * capsule.radius; b += ab * capsule.radius; XMStoreFloat3(&capsule.base, a); @@ -2073,6 +2074,7 @@ void EditorComponent::Render() const wi::primitive::Capsule capsule; capsule.radius = wi::math::Distance(a, b) * 0.1f; + capsule.radius = wi::math::Clamp(capsule.radius, 0.01f, 0.1f); a -= ab * capsule.radius; b += ab * capsule.radius; XMStoreFloat3(&capsule.base, a); diff --git a/Editor/WeatherWindow.cpp b/Editor/WeatherWindow.cpp index df5520031..aef7300a8 100644 --- a/Editor/WeatherWindow.cpp +++ b/Editor/WeatherWindow.cpp @@ -771,6 +771,9 @@ void WeatherWindow::Update() else { scene.weather = {}; + scene.weather.SetSimpleSky(true); + scene.weather.zenith = XMFLOAT3(1, 1, 1); + scene.weather.horizon = wi::Color(20, 20, 20); } } diff --git a/WickedEngine/wiScene.cpp b/WickedEngine/wiScene.cpp index 4c35427cf..c5b3782fe 100644 --- a/WickedEngine/wiScene.cpp +++ b/WickedEngine/wiScene.cpp @@ -1657,10 +1657,10 @@ namespace wi::scene wi::jobsystem::Wait(ctx); // dependencies - RunSpringUpdateSystem(ctx); - RunInverseKinematicsUpdateSystem(ctx); + RunSpringUpdateSystem(ctx); + RunArmatureUpdateSystem(ctx); RunWeatherUpdateSystem(ctx); @@ -3192,6 +3192,12 @@ namespace wi::scene } void Scene::RunInverseKinematicsUpdateSystem(wi::jobsystem::context& ctx) { + if (inverse_kinematics.GetCount() > 0) + { + ik_temp.resize(transforms.GetCount()); + ik_temp = transforms.GetComponentArray(); // make copy + } + bool recompute_hierarchy = false; for (size_t i = 0; i < inverse_kinematics.GetCount(); ++i) { @@ -3201,13 +3207,15 @@ namespace wi::scene continue; } Entity entity = inverse_kinematics.GetEntity(i); - TransformComponent* transform = transforms.GetComponent(entity); - TransformComponent* target = transforms.GetComponent(ik.target); + size_t transform_index = transforms.GetIndex(entity); + size_t target_index = transforms.GetIndex(ik.target); const HierarchyComponent* hier = hierarchy.GetComponent(entity); - if (transform == nullptr || target == nullptr || hier == nullptr) + if (transform_index == ~0ull || target_index == ~0ull || hier == nullptr) { continue; } + TransformComponent* transform = &ik_temp[transform_index]; + TransformComponent* target = &ik_temp[target_index]; const XMVECTOR target_pos = target->GetPositionV(); for (uint32_t iteration = 0; iteration < ik.iteration_count; ++iteration) @@ -3223,7 +3231,10 @@ namespace wi::scene stack[chain] = child_transform; // Compute required parent rotation that moves ik transform closer to target transform: - TransformComponent* parent_transform = transforms.GetComponent(parent_entity); + size_t parent_index = transforms.GetIndex(parent_entity); + if (parent_index == ~0ull) + continue; + TransformComponent* parent_transform = &ik_temp[parent_index]; const XMVECTOR parent_pos = parent_transform->GetPositionV(); const XMVECTOR dir_parent_to_ik = XMVector3Normalize(transform->GetPositionV() - parent_pos); const XMVECTOR dir_parent_to_target = XMVector3Normalize(target_pos - parent_pos); @@ -3241,10 +3252,14 @@ namespace wi::scene if (hier_parent != nullptr) { Entity parent_of_parent_entity = hier_parent->parentID; - const TransformComponent* transform_parent_of_parent = transforms.GetComponent(parent_of_parent_entity); - XMMATRIX parent_of_parent_inverse = XMMatrixInverse(nullptr, XMLoadFloat4x4(&transform_parent_of_parent->world)); - parent_transform->MatrixTransform(parent_of_parent_inverse); - // Do not call UpdateTransform() here, to keep parent world matrix in world space! + size_t parent_of_parent_index = transforms.GetIndex(parent_of_parent_entity); + if (parent_of_parent_index != ~0ull) + { + const TransformComponent* transform_parent_of_parent = &ik_temp[parent_of_parent_index]; + XMMATRIX parent_of_parent_inverse = XMMatrixInverse(nullptr, XMLoadFloat4x4(&transform_parent_of_parent->world)); + parent_transform->MatrixTransform(parent_of_parent_inverse); + // Do not call UpdateTransform() here, to keep parent world matrix in world space! + } } // update chain from parent to children: @@ -3280,14 +3295,25 @@ namespace wi::scene const HierarchyComponent& parentcomponent = hierarchy[i]; Entity entity = hierarchy.GetEntity(i); - TransformComponent* transform_child = transforms.GetComponent(entity); - TransformComponent* transform_parent = transforms.GetComponent(parentcomponent.parentID); - if (transform_child != nullptr && transform_parent != nullptr) + size_t transform_index = transforms.GetIndex(entity); + size_t parent_index = transforms.GetIndex(parentcomponent.parentID); + if (transform_index != ~0ull && parent_index != ~0ull) { + TransformComponent* transform_child = &ik_temp[transform_index]; + TransformComponent* transform_parent = &ik_temp[parent_index]; transform_child->UpdateTransform_Parented(*transform_parent); } } } + + if (inverse_kinematics.GetCount() > 0) + { + for (size_t i = 0; i < transforms.GetCount(); ++i) + { + // IK shouldn't modify local space, so only update the world matrices! + transforms[i].world = ik_temp[i].world; + } + } } void Scene::RunArmatureUpdateSystem(wi::jobsystem::context& ctx) { diff --git a/WickedEngine/wiScene.h b/WickedEngine/wiScene.h index cffe665fb..eb7634165 100644 --- a/WickedEngine/wiScene.h +++ b/WickedEngine/wiScene.h @@ -1445,6 +1445,7 @@ namespace wi::scene uint32_t impostorMaterialOffset = ~0u; mutable std::atomic_bool lightmap_refresh_needed{ false }; + wi::vector ik_temp; // Ocean GPU state: wi::Ocean ocean; diff --git a/WickedEngine/wiVersion.cpp b/WickedEngine/wiVersion.cpp index df4f93f95..e5b38b164 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 = 8; + const int revision = 9; const std::string version_string = std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(revision);