diff --git a/src/commands/apply-terrain-brush-patch-command.ts b/src/commands/apply-terrain-brush-patch-command.ts index 84cf73b2..4e9344a3 100644 --- a/src/commands/apply-terrain-brush-patch-command.ts +++ b/src/commands/apply-terrain-brush-patch-command.ts @@ -4,6 +4,7 @@ import type { TerrainBrushPatch, TerrainSampleValuePatch } from "../core/terrain-brush"; +import { updateTerrainBoundsCacheAfterHeightPatch } from "../document/terrains"; import type { ToolMode } from "../core/tool-mode"; import type { CommandContext, EditorCommand } from "./command"; @@ -64,12 +65,20 @@ export function createApplyTerrainBrushPatchCommand( throw new Error(`Terrain ${patch.terrainId} does not exist.`); } + const heightPatchForBounds = patch.heightSamples.map((entry) => ({ + index: entry.index, + before: direction === "forward" ? entry.before : entry.after, + after: direction === "forward" ? entry.after : entry.before + })); + for (const entry of patch.heightSamples) { assertValidPatchEntry(entry, terrain.heights.length, "Terrain height"); terrain.heights[entry.index] = direction === "forward" ? entry.after : entry.before; } + updateTerrainBoundsCacheAfterHeightPatch(terrain, heightPatchForBounds); + for (const entry of patch.paintWeights) { assertValidPatchEntry( entry,