From ac815f4260901db18393086663bec2d6e88726d2 Mon Sep 17 00:00:00 2001 From: Victor Giers Date: Mon, 27 Apr 2026 00:02:11 +0200 Subject: [PATCH] Refactor viewport update logic to separate selection handling and simplify document updates --- src/viewport-three/viewport-host.ts | 50 +++++++++++++++++++---------- 1 file changed, 33 insertions(+), 17 deletions(-) diff --git a/src/viewport-three/viewport-host.ts b/src/viewport-three/viewport-host.ts index 87981fc9..193f135f 100644 --- a/src/viewport-three/viewport-host.ts +++ b/src/viewport-three/viewport-host.ts @@ -886,26 +886,46 @@ export class ViewportHost { this.rebuildModelInstances(this.currentDocument, this.currentSelection); } - updateDocument( - document: SceneDocument, - selection: EditorSelection, - activeSelectionId: string | null - ) { + updateSelection(selection: EditorSelection, activeSelectionId: string | null) { + const selectionChanged = !areEditorSelectionsEqual( + this.currentSelection, + selection + ); + const activeSelectionChanged = + this.currentActiveSelectionId !== activeSelectionId; + + this.currentSelection = selection; + this.currentActiveSelectionId = activeSelectionId; + + if (!selectionChanged && !activeSelectionChanged) { + return; + } + + this.activeTerrainBrushStroke = null; + this.setHoveredSelection({ + kind: "none" + }); + this.refreshSelectionPresentation(); + } + + updateDocument(document: SceneDocument) { this.activeTerrainBrushStroke = null; this.currentDocument = document; this.viewportSceneBounds = resolveViewportDocumentBounds(document); - this.currentSelection = selection; - this.currentActiveSelectionId = activeSelectionId; this.setHoveredSelection({ kind: "none" }); this.rebuildLocalLights(document); this.rebuildLightVolumes(document); - this.rebuildBrushMeshes(document, selection); - this.rebuildTerrains(document, selection, activeSelectionId); - this.rebuildPaths(document, selection); - this.rebuildEntityMarkers(document, selection); - this.rebuildModelInstances(document, selection); + this.rebuildBrushMeshes(document, this.currentSelection); + this.rebuildTerrains( + document, + this.currentSelection, + this.currentActiveSelectionId + ); + this.rebuildPaths(document, this.currentSelection); + this.rebuildEntityMarkers(document, this.currentSelection); + this.rebuildModelInstances(document, this.currentSelection); this.applyTransformPreview(); this.syncTransformGizmo(); this.syncTerrainBrushPreview(); @@ -1216,11 +1236,7 @@ export class ViewportHost { this.applyWorld(); if (this.currentDocument !== null) { - this.updateDocument( - this.currentDocument, - this.currentSelection, - this.currentActiveSelectionId - ); + this.updateDocument(this.currentDocument); } }