From 09d1cd36d66aa9a5099b577fe107b58150604caf Mon Sep 17 00:00:00 2001 From: Victor Giers Date: Wed, 13 May 2026 16:35:43 +0200 Subject: [PATCH] Refactor junction influence calculation to use path shoulder width for falloff distance --- src/geometry/spline-road-terrain.ts | 34 ++++++++++------------------- 1 file changed, 11 insertions(+), 23 deletions(-) diff --git a/src/geometry/spline-road-terrain.ts b/src/geometry/spline-road-terrain.ts index 6582f8cd..4ebfeee6 100644 --- a/src/geometry/spline-road-terrain.ts +++ b/src/geometry/spline-road-terrain.ts @@ -364,34 +364,22 @@ export function createSplineRoadTerrainPatch(options: { : patch; } -function getJunctionInfluence( - distance: number, +function getJunctionTerrainFalloffDistance( junction: SplineCorridorJunction, paths: readonly ScenePath[] ): number { - if (distance > junction.radius) { - return 0; - } + return Math.max( + 0.001, + ...junction.connections.map((connection) => { + const path = paths.find((candidate) => candidate.id === connection.pathId); - const coreRadius = Math.min( - junction.radius, - Math.max( - 0.1, - ...junction.connections.map((connection) => { - const path = paths.find((candidate) => candidate.id === connection.pathId); - return path === undefined ? 0 : path.road.width * 0.5; - }) - ) + if (path === undefined) { + return 0; + } + + return Math.max(path.road.shoulderWidth, junction.radius * 0.25); + }) ); - - if (distance <= coreRadius) { - return 1; - } - - const falloffDistance = Math.max(0.001, junction.radius - coreRadius); - const progress = clamp((distance - coreRadius) / falloffDistance, 0, 1); - - return Math.pow(1 - progress, 2); } function getAverageJunctionTargetHeight(options: {