diff --git a/Editor/ComponentsWindow.cpp b/Editor/ComponentsWindow.cpp index f5900d21a..cd8b43a43 100644 --- a/Editor/ComponentsWindow.cpp +++ b/Editor/ComponentsWindow.cpp @@ -158,6 +158,20 @@ void ComponentsWindow::Create(EditorComponent* _editor) break; case 5: scene.springs.Create(entity); + + // Springs are special because they are computed in ordered fashion + // So if we add a new spring that was parent of an other one, we move it in memory before the child + for (size_t i = 0; i < scene.springs.GetCount(); ++i) + { + Entity other = scene.springs.GetEntity(i); + const HierarchyComponent* hier = scene.hierarchy.GetComponent(other); + if (hier != nullptr && hier->parentID == entity) + { + size_t entity_index = scene.springs.GetCount() - 1; // last added entity (the parent) + scene.springs.MoveItem(entity_index, i); // will be moved before + break; + } + } break; case 6: scene.inverse_kinematics.Create(entity); diff --git a/WickedEngine/wiScene.cpp b/WickedEngine/wiScene.cpp index 14a422417..d834d604c 100644 --- a/WickedEngine/wiScene.cpp +++ b/WickedEngine/wiScene.cpp @@ -3294,7 +3294,6 @@ namespace wi::scene const HierarchyComponent* hier = hierarchy.GetComponent(entity); size_t parent_index = hier == nullptr ? ~0ull : transforms.GetIndex(hier->parentID); - //TransformComponent* parent_transform = hier == nullptr ? nullptr : transforms.GetComponent(hier->parentID); if (parent_index != ~0ull) { // Spring hierarchy resolve depends on spring component order! @@ -3358,7 +3357,7 @@ namespace wi::scene { for (size_t i = 0; i < transforms.GetCount(); ++i) { - // IK shouldn't modify local space, so only update the world matrices! + // Springs shouldn't modify local space, so only update the world matrices! transforms[i].world = transforms_temp[i].world; } }