From a379af3cc8fe999c1d62d11f66570e53796137e1 Mon Sep 17 00:00:00 2001 From: Victor Giers Date: Tue, 12 May 2026 23:35:56 +0200 Subject: [PATCH] Improve path focus calculation using terrain-resolved segments --- src/viewport-three/viewport-focus.ts | 32 ++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/src/viewport-three/viewport-focus.ts b/src/viewport-three/viewport-focus.ts index 1e41cfa2..d8ab8e6f 100644 --- a/src/viewport-three/viewport-focus.ts +++ b/src/viewport-three/viewport-focus.ts @@ -11,8 +11,8 @@ import { import type { Vec3 } from "../core/vector"; import type { Brush } from "../document/brushes"; import type { SceneDocument } from "../document/scene-document"; -import type { ScenePath } from "../document/paths"; -import { getTerrainBounds, type Terrain } from "../document/terrains"; +import { resolveScenePath, type ScenePath } from "../document/paths"; +import { getTerrainBounds, getTerrains, type Terrain } from "../document/terrains"; import { resolveCameraRigDocumentPosition, type EntityInstance @@ -270,15 +270,33 @@ function createModelInstanceFocusTarget(modelInstance: ModelInstance, asset: Pro ); } -function includePath(bounds: FocusBoundsAccumulator, path: ScenePath) { - for (const point of path.points) { - includeBounds(bounds, point.position, point.position); +function includePath( + bounds: FocusBoundsAccumulator, + path: ScenePath, + terrains: readonly Terrain[] +) { + const resolvedPath = resolveScenePath(path, { + terrains: terrains.filter((terrain) => terrain.enabled) + }); + + for (const segment of resolvedPath.segments) { + includeBounds(bounds, segment.start, segment.start); + includeBounds(bounds, segment.end, segment.end); + } + + if (resolvedPath.segments.length === 0) { + for (const point of resolvedPath.points) { + includeBounds(bounds, point.position, point.position); + } } } -function createPathFocusTarget(path: ScenePath): ViewportFocusTarget | null { +function createPathFocusTarget( + path: ScenePath, + terrains: readonly Terrain[] +): ViewportFocusTarget | null { const bounds = createEmptyBoundsAccumulator(); - includePath(bounds, path); + includePath(bounds, path, terrains); return finishBounds(bounds); }