Add snapToGrid option to create and move box brush commands

This commit is contained in:
2026-04-04 19:26:18 +02:00
parent cc9b200bae
commit c19dae0df6
2 changed files with 16 additions and 5 deletions

View File

@@ -11,11 +11,14 @@ import type { EditorCommand } from "./command";
interface MoveBoxBrushCommandOptions {
brushId: string;
center: Vec3;
snapToGrid?: boolean;
gridSize?: number;
label?: string;
}
export function createMoveBoxBrushCommand(options: MoveBoxBrushCommandOptions): EditorCommand {
const snappedCenter = snapVec3ToGrid(options.center, options.gridSize ?? DEFAULT_GRID_SIZE);
const resolvedCenter =
options.snapToGrid === false ? options.center : snapVec3ToGrid(options.center, options.gridSize ?? DEFAULT_GRID_SIZE);
let previousCenter: Vec3 | null = null;
let previousSelection: EditorSelection | null = null;
@@ -23,7 +26,7 @@ export function createMoveBoxBrushCommand(options: MoveBoxBrushCommandOptions):
return {
id: createOpaqueId("command"),
label: "Move box brush",
label: options.label ?? "Move box brush",
execute(context) {
const currentDocument = context.getDocument();
const brush = getBoxBrushOrThrow(currentDocument, options.brushId);
@@ -46,7 +49,7 @@ export function createMoveBoxBrushCommand(options: MoveBoxBrushCommandOptions):
replaceBrush(currentDocument, {
...brush,
center: {
...snappedCenter
...resolvedCenter
}
})
);