From c19dae0df605c61bfc750968dbb241af9b3171b7 Mon Sep 17 00:00:00 2001 From: Victor Giers Date: Sat, 4 Apr 2026 19:26:18 +0200 Subject: [PATCH] Add snapToGrid option to create and move box brush commands --- src/commands/create-box-brush-command.ts | 12 ++++++++++-- src/commands/move-box-brush-command.ts | 9 ++++++--- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/commands/create-box-brush-command.ts b/src/commands/create-box-brush-command.ts index e981085b..7f857ab8 100644 --- a/src/commands/create-box-brush-command.ts +++ b/src/commands/create-box-brush-command.ts @@ -12,13 +12,21 @@ import type { EditorCommand } from "./command"; interface CreateBoxBrushCommandOptions { center?: Vec3; size?: Vec3; + snapToGrid?: boolean; gridSize?: number; } export function createCreateBoxBrushCommand(options: CreateBoxBrushCommandOptions = {}): EditorCommand { + const snapToGrid = options.snapToGrid ?? true; const brush = createBoxBrush({ - center: snapVec3ToGrid(options.center ?? DEFAULT_BOX_BRUSH_CENTER, options.gridSize ?? DEFAULT_GRID_SIZE), - size: snapPositiveSizeToGrid(options.size ?? DEFAULT_BOX_BRUSH_SIZE, options.gridSize ?? DEFAULT_GRID_SIZE) + center: + snapToGrid === false + ? options.center ?? DEFAULT_BOX_BRUSH_CENTER + : snapVec3ToGrid(options.center ?? DEFAULT_BOX_BRUSH_CENTER, options.gridSize ?? DEFAULT_GRID_SIZE), + size: + snapToGrid === false + ? options.size ?? DEFAULT_BOX_BRUSH_SIZE + : snapPositiveSizeToGrid(options.size ?? DEFAULT_BOX_BRUSH_SIZE, options.gridSize ?? DEFAULT_GRID_SIZE) }); let previousSelection: EditorSelection | null = null; diff --git a/src/commands/move-box-brush-command.ts b/src/commands/move-box-brush-command.ts index a85d68c8..15465ea3 100644 --- a/src/commands/move-box-brush-command.ts +++ b/src/commands/move-box-brush-command.ts @@ -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 } }) );