Maintain spline junction state when setting path point positions

This commit is contained in:
2026-05-13 20:02:39 +02:00
parent 8fe74eaa90
commit f8ba2a4b27

View File

@@ -5,9 +5,14 @@ import {
cloneScenePath, cloneScenePath,
getScenePathPointIndex getScenePathPointIndex
} from "../document/paths"; } from "../document/paths";
import type { SplineCorridorJunctionRegistry } from "../document/spline-corridor-junctions";
import type { Vec3 } from "../core/vector"; import type { Vec3 } from "../core/vector";
import type { EditorCommand } from "./command"; import type { EditorCommand } from "./command";
import {
cloneSplineCorridorJunctionRegistry,
setScenePathAndReattachJunctions
} from "./path-junction-maintenance";
interface SetPathPointPositionCommandOptions { interface SetPathPointPositionCommandOptions {
pathId: string; pathId: string;
@@ -40,6 +45,7 @@ export function createSetPathPointPositionCommand(
): EditorCommand { ): EditorCommand {
const nextPosition = cloneVec3(options.position); const nextPosition = cloneVec3(options.position);
let previousPosition: Vec3 | null = null; let previousPosition: Vec3 | null = null;
let previousJunctions: SplineCorridorJunctionRegistry | null = null;
let previousSelection: EditorSelection | null = null; let previousSelection: EditorSelection | null = null;
let previousToolMode: ToolMode | null = null; let previousToolMode: ToolMode | null = null;
@@ -72,11 +78,16 @@ export function createSetPathPointPositionCommand(
previousToolMode = context.getToolMode(); previousToolMode = context.getToolMode();
} }
context.setDocument({ if (previousJunctions === null) {
...currentDocument, previousJunctions = cloneSplineCorridorJunctionRegistry(
paths: { currentDocument.splineCorridorJunctions
...currentDocument.paths, );
[path.id]: cloneScenePath({ }
context.setDocument(
setScenePathAndReattachJunctions(
currentDocument,
cloneScenePath({
...path, ...path,
points: path.points.map((point, index) => points: path.points.map((point, index) =>
index === pointIndex index === pointIndex
@@ -87,8 +98,8 @@ export function createSetPathPointPositionCommand(
: point : point
) )
}) })
} )
}); );
context.setSelection( context.setSelection(
setSelectedPathPointSelection(options.pathId, options.pointId) setSelectedPathPointSelection(options.pathId, options.pointId)
); );
@@ -126,10 +137,14 @@ export function createSetPathPointPositionCommand(
...point, ...point,
position: cloneVec3(restoredPosition) position: cloneVec3(restoredPosition)
} }
: point : point
) )
}) })
} },
splineCorridorJunctions:
previousJunctions === null
? currentDocument.splineCorridorJunctions
: cloneSplineCorridorJunctionRegistry(previousJunctions)
}); });
if (previousSelection !== null) { if (previousSelection !== null) {