From 396f412f8711cee964bf0a3c2587cdf1ed373313 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Tue, 16 Jun 2026 12:22:04 +0200 Subject: [PATCH] Fix spline editing in large worlds #4132 --- Source/Engine/Debug/DebugDraw.cpp | 16 +++++++++++----- Source/Engine/Debug/DebugDraw.h | 6 ++++-- Source/Engine/Level/Actors/Spline.cpp | 8 +++++--- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/Source/Engine/Debug/DebugDraw.cpp b/Source/Engine/Debug/DebugDraw.cpp index 18552dcec..0e1768f63 100644 --- a/Source/Engine/Debug/DebugDraw.cpp +++ b/Source/Engine/Debug/DebugDraw.cpp @@ -357,7 +357,7 @@ struct DebugDrawContext Vector3 Origin = Vector3::Zero; DebugDrawData DebugDrawDefault; DebugDrawData DebugDrawDepthTest; - Float3 LastViewPos = Float3::Zero; + Vector3 LastViewPosition = Vector3::Zero; Matrix LastViewProjection = Matrix::Identity; BoundingFrustum LastViewFrustum; @@ -790,9 +790,14 @@ bool DebugDraw::CanClear(void* context) #endif -Vector3 DebugDraw::GetViewPos() +Vector3 DebugDraw::GetViewPosition() { - return Context->LastViewPos; + return Context->LastViewPosition; +} + +Vector3 DebugDraw::GetViewOrigin() +{ + return Context->Origin; } BoundingFrustum DebugDraw::GetViewFrustum() @@ -802,7 +807,7 @@ BoundingFrustum DebugDraw::GetViewFrustum() void DebugDraw::SetView(const RenderView& view) { - Context->LastViewPos = view.Position; + Context->LastViewPosition = view.WorldPosition; Context->LastViewProjection = view.Projection; Context->LastViewFrustum = view.Frustum; } @@ -1420,7 +1425,8 @@ void DebugDraw::DrawWireSphere(const BoundingSphere& sphere, const Color& color, int32 index; const Float3 centerF = sphere.Center - Context->Origin; const float radiusF = (float)sphere.Radius; - const float screenRadiusSquared = RenderTools::ComputeBoundsScreenRadiusSquared(centerF, radiusF, Context->LastViewPos, Context->LastViewProjection); + const Float3 drawPos = Context->LastViewPosition - Context->Origin; + const float screenRadiusSquared = RenderTools::ComputeBoundsScreenRadiusSquared(centerF, radiusF, drawPos, Context->LastViewProjection); if (screenRadiusSquared > DEBUG_DRAW_SPHERE_LOD0_SCREEN_SIZE * DEBUG_DRAW_SPHERE_LOD0_SCREEN_SIZE * 0.25f) index = 0; else if (screenRadiusSquared > DEBUG_DRAW_SPHERE_LOD1_SCREEN_SIZE * DEBUG_DRAW_SPHERE_LOD1_SCREEN_SIZE * 0.25f) diff --git a/Source/Engine/Debug/DebugDraw.h b/Source/Engine/Debug/DebugDraw.h index 8e2713ac5..c4ae12283 100644 --- a/Source/Engine/Debug/DebugDraw.h +++ b/Source/Engine/Debug/DebugDraw.h @@ -74,8 +74,10 @@ API_CLASS(Static) class FLAXENGINE_API DebugDraw API_FUNCTION() static bool CanClear(void* context = nullptr); #endif - // Gets the last view position when rendering the current context. Can be used for custom culling or LODing when drawing more complex shapes. - static Vector3 GetViewPos(); + // Gets the last view position (world-space) when rendering the current context. Can be used for custom culling or LODing when drawing more complex shapes. + static Vector3 GetViewPosition(); + // Gets the last view origin (world-space) when rendering the current context. Can be used for custom culling or LODing when drawing more complex shapes. + static Vector3 GetViewOrigin(); // Gets the last view frustum when rendering the current context. Can be used for custom culling or LODing when drawing more complex shapes. static BoundingFrustum GetViewFrustum(); diff --git a/Source/Engine/Level/Actors/Spline.cpp b/Source/Engine/Level/Actors/Spline.cpp index 271609396..9837835c1 100644 --- a/Source/Engine/Level/Actors/Spline.cpp +++ b/Source/Engine/Level/Actors/Spline.cpp @@ -496,7 +496,7 @@ namespace FORCE_INLINE float NodeSizeByDistance(const Vector3& nodePosition, bool scaleByDistance) { if (scaleByDistance) - return (float)(Vector3::Distance(DebugDraw::GetViewPos(), nodePosition) / 100); + return (float)(Vector3::Distance(DebugDraw::GetViewPosition(), nodePosition) / 100); return 5.0f; } @@ -507,7 +507,7 @@ namespace return; Spline::Keyframe* prev = spline->Curve.GetKeyframes().Get(); Vector3 prevPos = transform.LocalToWorld(prev->Value.Translation); - Real distance = Vector3::Distance(prevPos, DebugDraw::GetViewPos()); + Real distance = Vector3::Distance(prevPos, DebugDraw::GetViewPosition()); if (distance < METERS_TO_UNITS(800)) // 800m { // Bezier curve @@ -540,7 +540,9 @@ namespace void Spline::OnDebugDraw() { - if (DebugDraw::GetViewFrustum().Intersects(_sphere)) + BoundingSphere sphere(_sphere); + sphere.Center -= DebugDraw::GetViewOrigin(); + if (DebugDraw::GetViewFrustum().Intersects(sphere)) DrawSpline(this, GetSplineColor().AlphaMultiplied(0.7f), _transform, true); // Base