diff --git a/docs/superpowers/plans/2026-11-25-construction-shapes.md b/docs/superpowers/plans/2026-11-25-construction-shapes.md new file mode 100644 index 0000000..5ccbe90 --- /dev/null +++ b/docs/superpowers/plans/2026-11-25-construction-shapes.md @@ -0,0 +1,667 @@ +# Construction shapes implementation plan + +> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking. + +**Goal:** Planes and curves stored on parts that stop Sculpt, Warp and Move from taking the mesh +across them, a Sculpt guide run along a curve, and a Move Follow mode that holds a drag to a shape. + +**Architecture:** Shapes live on `Part.constructions` in mesh-local coordinates and travel through +the existing part paths (save, undo, copy, sync). One pure module, `construction-bounds.ts`, answers +"where does a point moving from A to B stop", and each tool calls it at the single place it sets +new positions: `dabWork` in Sculpt, `evaluateWarp` in Warp, and the `place` closure of +`transformMany` in Move. Curves reuse Refine's plane math, segment drawing and constraint solver. + +**Tech stack:** TypeScript, three.js, react-three-fiber, Zustand, Vitest, Playwright. + +**Spec:** `docs/superpowers/specs/2026-11-25-construction-shapes-design.md`. Background: +`docs/superpowers/specs/2026-11-24-refine-sketch-guides-design.md` (sketch planes, point menu, +constraints) and `docs/superpowers/specs/2026-11-23-browser-sculpting-design.md`. + +## Global constraints + +- Shapes are stored in mesh-local coordinates of the part they were made on. A plane's Offset is + in the part's local units (mm at scale 1). Curve points are stored in their plane's (u, v). +- **The rule:** a point moving in a straight line that crosses a boundary stops on its own side, a + margin short of it: `boundaryMargin(extent) = Math.max(1e-4, extent * 2 ** -21)` mm, where + `extent` is the largest absolute world coordinate of the owning part's bounds. Boundaries are + two-sided; the first boundary met wins; no per-point state is kept between edits. +- Boundaries are every shape with `on: true` on a visible part, except: the guide curve during a + guide run, the shape followed in Follow, and shapes on any part the current Move carries. +- A curve's wall is infinite along its plane's normal both ways and as long as the curve. +- Sculpt, Warp and Move results with no shapes on are bit-identical to today. +- Refine's behaviour and tests are unchanged. Refine keeps its own session planes. +- Copy follows `docs/documentation.md`. Commit subjects `() `, no + attribution. +- Checks per task: `npx tsc --noEmit`, the task's `npx vitest run `, the task's + `npx playwright test `, and `npm run format:check`. The final task runs `npm test`, + `npm run test:e2e` and `npm run build`. + +## Review focus + +1. **A guide run with the brush inside an arc by more than its radius:** the parallel path + vanishes. Expect the run to refuse with a status message and leave the mesh untouched. Test in + Task 8. +2. **A plane at Offset 0 made through mesh vertices:** those vertices lie exactly on it. Expect a + point exactly on a plane to count as behind it (the side opposite the normal), so Draw on a face + with a plane at Offset 0 raises nothing. On a curve's wall, a point exactly on it counts as + inside a closed curve, or to the left of an open curve's drawn direction. Test in Task 6. +3. **Shapes on a part with non-uniform or mirrored scale:** boundaries must hold in world space. + Test in Task 6 with a part scaled `[1, 2, -1]`. +4. **The Sculpt guide or the Move follow shape is deleted, switched off or undone away:** expect + the choice to clear, with no crash. A Move falls back to Boundary. Tests in Tasks 8 and 10. +5. **A part carried by a joint or a pin correction into a plane during a Move, with No clip on:** + expect the carried part to be bounded too. Test in Task 10. + +--- + +### Task 1: Shared sketch plane module + +**Files:** + +- Create: `src/core/sketch-plane.ts` +- Modify: `src/core/refine-sketch.ts` (move the pure exports out, re-export them), + `src/core/refine-constraints.ts:4`, `src/core/refine-band.ts:10` (import from the new module) +- Test: `tests/unit/sketch-plane.test.ts` + +**Interfaces:** + +- Produces, unchanged signatures, from `src/core/sketch-plane.ts`: `SketchPlane`, `planeOf`, + `planeThrough`, `ontoPlane`, `planeCoordinates`, `planePoint`, `rayOnPlane`, `bestPlaneNormal`, + `closestOnTriangle`, `PointLock`, `ontoLine`, `lineThrough`, `lineNearRay`, `heldPoint`. The + module imports only `./types`. `nearestOnSurface`, `nearestTriangle`, `pointAt` and + `planeOfFace` stay in `refine-sketch.ts`. + +- [ ] **Step 1: Write the failing tests** + +```ts +describe('sketch plane', () => { + const plane = planeOf('p', 'Plane 1', [1, 2, 3], [0, 0, 2], [1, 1, 0])!; + it('meets a ray', () => { + expect(rayOnPlane(plane, [0, 0, 10], [0, 0, -1])).toEqual([0, 0, 3]); + expect(rayOnPlane(plane, [0, 0, 10], [1, 0, 0])).toBeNull(); // along the plane + expect(rayOnPlane(plane, [0, 0, 10], [0, 0, 1])).toBeNull(); // plane behind + }); + it('round-trips (u, v)', () => { + const [u, v] = planeCoordinates(plane, planePoint(plane, 0.7, -1.2)); + expect(u).toBeCloseTo(0.7, 12); + expect(v).toBeCloseTo(-1.2, 12); + }); + it('refuses 3 collinear points', () => + expect(planeThrough('p', 'P', [0, 0, 0], [1, 0, 0], [2, 0, 0])).toBeNull()); + it('fits the normal of noisy flat points', () => { + const points = Array.from({ length: 50 }, (_, i) => [ + i % 7, + Math.floor(i / 7), + 0.01 * Math.sin(i * 12.9898), + ]).flat(); + expect(Math.abs(bestPlaneNormal(points)![2])).toBeGreaterThan(0.999); + }); + it('holds a point by its lock', () => { + expect(heldPoint({ kind: 'fixed' }, null, [1, 1, 1], [5, 5, 5])).toEqual([1, 1, 1]); + const line = lineThrough([0, 0, 0], [1, 0, 0])!; + expect(heldPoint(line, null, [0, 0, 0], [4, 2, 1])).toEqual([4, 0, 0]); + expect(heldPoint(undefined, plane, [0, 0, 0], [4, 2, 9])).toEqual([4, 2, 3]); + }); +}); +``` + +- [ ] **Step 2: Run to verify it fails** - `npx vitest run tests/unit/sketch-plane.test.ts`: + FAIL, module not found. +- [ ] **Step 3: Move the pure functions** into `src/core/sketch-plane.ts` and re-export them from + `refine-sketch.ts`. +- [ ] **Step 4: Run** `npx vitest run tests/unit/sketch-plane.test.ts tests/unit/refine-constraints.test.ts tests/unit/refine-sketch-session.test.ts tests/unit/refine-guide-edge.test.ts`: + PASS. +- [ ] **Step 5: Commit** `(refactor) Move sketch plane math out of Refine` + +### Task 2: Construction shapes on parts + +**Files:** + +- Modify: `src/core/types.ts` (types below, `Part.constructions?`) +- Create: `src/core/construction.ts` +- Modify: `src/core/scene-file.ts:356-384` (validate), `src/core/sync.ts:25-37` + (`['constructions']` in `fieldGroups.parts`), `src/core/clipboard.ts:68-122` (deep copy), + `src/core/merge.ts:240-262` and `src/core/store.ts:5388` (carry into the merged part), + `src/core/store.ts:5351-5387` (`applyProcessedMesh` keeps shapes; shapes do not count as + `linked`), `mcp/session.ts:739-748` (pattern copy keeps them), `docs/scene-format.md:31-38` +- Test: `tests/unit/construction.test.ts`, `tests/unit/scene-format.test.ts` + +**Interfaces:** + +- Consumes: Task 1's `SketchPlane`, `planePoint`, `planeCoordinates`; `GuideKind` + (`src/core/refine-curve.ts`), `GuideConstraint`, `GuideShape`, `solvedSegments` + (`src/core/refine-constraints.ts`). +- Produces, in `src/core/types.ts`: + +```ts +export interface ConstructionPlane { + kind: 'plane'; + id: string; + name: string; // 'Plane 1', in the order the part's planes were made + origin: Vec3; // at Offset 0 + normal: Vec3; // unit + u: Vec3; // unit, in the plane + v: Vec3; // normal x u + offset: number; // along normal + on: boolean; +} +export type ConstructionLock = + { kind: 'fixed' } | { kind: 'line'; origin: [number, number]; direction: [number, number] }; +export interface ConstructionPoint { + at: [number, number]; // (u, v) on the curve's plane; a shared joint repeats the same value + lock?: ConstructionLock; +} +export interface ConstructionCurve { + kind: 'curve'; + id: string; + name: string; // 'Curve 1' + plane: string; // a plane id on the same part + segments: { kind: GuideKind; points: ConstructionPoint[] }[]; + closed: boolean; + constraints: GuideConstraint[]; + on: boolean; +} +export type ConstructionShape = ConstructionPlane | ConstructionCurve; +export interface ShapeRef { + partId: string; + shapeId: string; +} +``` + +- Produces, in `src/core/construction.ts`: + - `planeFrame(plane: ConstructionPlane): SketchPlane` - the frame at its Offset, local. + - `curvePlane(shapes: ConstructionShape[], curve: ConstructionCurve): ConstructionPlane | null` + - `curveShape(curve: ConstructionCurve, plane: ConstructionPlane): GuideShape` - points as + `{ triangle: -1, position: planePoint(frame, ...at), lock }` for the solver. + - `fromShape(curve, plane, segments: GuideShape['segments']): ConstructionCurve['segments']` + - `findShape(parts: Part[], ref: ShapeRef): { part: Part; shape: ConstructionShape } | null` + - `nextShapeName(shapes: ConstructionShape[], kind: 'plane' | 'curve'): string` + - `validConstructions(value: unknown): ConstructionShape[]` - throws + `Error('The scene contains invalid construction shapes.')` on a missing or duplicate id, a + non-finite number, a zero normal, a curve whose plane is missing, or a segment with the wrong + point count for its kind. + - `carriedConstructions(shapes: ConstructionShape[], from: Matrix4, to: Matrix4): ConstructionShape[]` + - re-expresses shapes from one part frame in another: transform the plane origin, the offset + origin and every curve point in 3D by `to⁻¹ · from`, rebuild the frame from the transformed + normal and `u`, and read the new Offset and (u, v) from it. An arc's 3 points stay its 3 + points. + +- [ ] **Step 1: Write the failing tests** in `tests/unit/construction.test.ts`: + - `'saves and reopens shapes'`: a part with a plane (Offset 1.5, off) and a closed curve of a + line and an arc with a Parallel constraint survives `sceneFileBlob` then `parseSceneDocument` + with `toEqual`. + - `'refuses invalid shapes'`: a curve with `plane: 'missing'` and a plane with `normal: [0,0,0]` + each make opening throw `'The scene contains invalid construction shapes.'`. + - `'copies shapes with the part'`: `duplicateSelected` gives an equal but not identical + `constructions` array. + - `'shares shapes'`: `diffScenes` of two scenes differing only in `constructions` is non-empty. + - `'carries shapes into a merged part'`: after `replaceWithMerged` of two parts, one rotated 30 + degrees and translated, each plane's world origin, normal and offset point, and each curve + point's world position, match within `1e-9`. + - `'keeps shapes through mesh processing and a sculpt stroke'`, and an in-place + `applyProcessedMesh` is not refused for a part whose only link is shapes. + - `'undoes a shape change'`: `patchParts([id], { constructions })` then `undo` restores the + previous array. +- [ ] **Step 2: Run to verify they fail** - `npx vitest run tests/unit/construction.test.ts`. +- [ ] **Step 3: Implement** the types, `construction.ts`, and the listed file changes. Document + the field in `docs/scene-format.md` next to pins. +- [ ] **Step 4: Run** `npx vitest run tests/unit/construction.test.ts tests/unit/scene-format.test.ts tests/unit/pins.test.ts tests/unit/merge-job.test.ts`: + PASS. +- [ ] **Step 5: Commit** `(feat) Store construction shapes on parts` + +### Task 3: Construct tool and planes + +**Files:** + +- Modify: `src/core/types.ts:7-20` (`'construct'`), `src/core/keybindings.ts` (`construct: +{ group: 'Tools', label: 'Construction shapes', keys: ['C'] }`), `src/hooks/useWorkbench.ts:22-30`, + `src/App.tsx` (toolbar button titled `Make construction shapes` after Pins, shortcut label, + status hint, right panel list), `src/components/Inspector.tsx:951-994`, + `src/components/Dialogs.tsx:646-653`, `src/components/Viewport.tsx` (`toolsPicking`, click + routing at :263-272, overlay mount, `onPointerMissed` exclusions) +- Modify: `src/core/store.ts` (state, actions, `toolChange` clears picking) +- Create: `src/components/ConstructControls.tsx`, `src/components/ConstructOverlay.tsx` +- Modify: `src/core/construction.ts` (`planeOfPartFace`) +- Test: `tests/unit/construct-session.test.ts` + +**Interfaces:** + +- Consumes: Task 2's types, `nextShapeName`, `planeFrame`; Task 1's `planeThrough`, `planeOf`, + `bestPlaneNormal`. +- Produces, store state `construct: { partId: string; selected: string | null; picking: +ConstructPicking | null } | null` (set while the tool is open), with + `ConstructPicking = { kind: 'plane'; from: 'points' | 'face'; points: (SurfacePoint & { face: number })[] }` + for now (Task 5 adds members), and actions: + +```ts +startConstructPlane: (from: 'points' | 'face') => void; +pickConstruct: (point: SurfacePoint & { face: number }) => void; // world point on the part +cancelConstructPicking: () => void; +selectConstructionShape: (shapeId: string | null) => void; +setConstructionShape: ( + shapeId: string, + patch: { name?: string; on?: boolean; offset?: number }, + checkpoint?: boolean, +) => void; +removeConstructionShape: (shapeId: string) => void; // a plane takes its curves +``` + +- Produces `planeOfPartFace(part: Part, face: number, point: Vec3, radius: number): ConstructionPlane | null` + (local `point`): fit `bestPlaneNormal` to the vertices of triangles within `radius` of `point` + whose normals are within 30 degrees of the clicked triangle's; null when any is farther than + `radius / 10` from the fit. The normal points the way the clicked triangle faces; `u` runs along + the longest spread. `radius = Math.max(0.5, 0.02 * partSize(part))`. +- A plane from 3 points has its normal turned to agree with the first pick's surface normal. +- Every shape change is one `patchParts` call; an Offset field commits once per edit, like the pin + priority slider (`checkpoint` false while typing, true on commit). +- `ConstructOverlay` draws, inside each part's ``: with Construct open, the selected part's + shapes (plane as a grid square sized to the part with `u` and `v` marked, curve as a line with + its wall shown faintly a short way either side); in Sculpt, Warp and Move, every shape that is + on, faintly. The plane grid reuses `PlaneGrid` from `RefineSketch.tsx` (moved in Task 4; import + it from its current place here). + +- [ ] **Step 1: Write the failing tests** (store level, fixture as in `tests/unit/pins.test.ts`, + part = `softBox` from `tests/helpers/refine-session.ts`): + - `'makes a plane from 3 points'`: 3 picks on the top face give a plane through them, normal + `[0, 0, 1]` within `1e-9`, named `'Plane 1'`, `on: true`, Offset 0, one undo step. + - `'makes a plane from a flat face and offsets it'`: a face pick then `offset: 1` puts + `planeFrame(plane).origin[2]` at top + 1. + - `'refuses a curved face'`: a pick on the rounded edge makes no shape and notifies. + - `'deletes a plane with its curves'` and `'switches a shape off'`. + - `'leaving the tool clears picking'`. +- [ ] **Step 2: Run to verify they fail** - `npx vitest run tests/unit/construct-session.test.ts`. +- [ ] **Step 3: Implement** the tool wiring, store actions, panel (shape list with On, rename, + delete; New plane with 3 points or face; Offset field) and overlay. +- [ ] **Step 4: Run** the test file, `npx vitest run tests/unit/commands.test.ts`, and + `npx playwright test tests/e2e/pins.spec.ts`: PASS. +- [ ] **Step 5: Commit** `(feat) Add the Construct tool with planes` + +### Task 4: Drawing curves on a plane + +**Files:** + +- Create: `src/components/SketchWidgets.tsx` - moved from `RefineSketch.tsx:33-202, 250-348`: + `squareOf`, `PlaneGrid`, `anchorOf`, `Picked`, and `PointWidget` taking + `{ frame, lock, position, onBegin(), onMove(position: Vec3, first: boolean), onEnd(), onCancel() }`; + and from `RefineOverlay.tsx:50-174, 455-580`: `lineMaterials`, `guidePolyline`, and + `SketchHandles({ items: { key: string; position: Vec3; normal?: Vec3; selected: boolean; first: boolean; chosen: boolean }[] })`. + `RefineSketch.tsx` and `RefineOverlay.tsx` use them. +- Create: `src/core/sketch-chain.ts` - `takesPoints` and `pointsNeeded` moved from + `store.ts:7506`, used by Refine and Construct. +- Create: `src/components/ConstructPointer.tsx` - capture-phase click, handle drag, and Escape, + modelled on `RefinePointer.tsx:1372-1501` but only for curves: rays go to part-local space with + the inverse of `partMatrix(part)` before `rayOnPlane`. +- Modify: `src/core/store.ts`, `src/components/ConstructControls.tsx` +- Test: `tests/unit/construct-session.test.ts`, `tests/e2e/construct.spec.ts` (new) + +**Interfaces:** + +- Consumes: Task 2's `ConstructionCurve`, `curveShape`, `fromShape`; Task 3's `construct` state. +- Produces, store actions: + +```ts +startConstructCurve: (planeId: string, kind: GuideKind) => void; // next segment's kind +setConstructSegmentKind: (kind: GuideKind) => void; +addConstructPoint: (at: [number, number]) => void; // (u, v) on the drawing plane +finishConstructCurve: () => void; // Enter; clicking the first point closes the curve instead +chooseConstructPoint: (ref: ConstructPointRef | null) => void; +beginConstructDrag: () => void; +moveConstructPoint: (ref: ConstructPointRef, at: [number, number]) => void; +endConstructDrag: () => void; +cancelConstructDrag: () => void; // restores the point +// ConstructPointRef = { curveId: string; segment: number; index: number } +``` + +- A drag is one undo step (checkpoint on the first move). A fixed point does not drag; a point + with a line lock slides along it. +- Clicking a point chooses it and shows `PointWidget` at it: two arrows along `u` and `v` and a + square handle for the plane, or one arrow along a line lock; none for a fixed point. Its drag + uses the same begin, move, end and cancel actions. + +- [ ] **Step 1: Write the failing tests:** + - `'draws a line and an arc'`: 2 points as line, kind arc, 2 more points: one curve, segments + `['line', 'arc']`, the arc's first point equal to the line's last. + - `'closes a curve by clicking its first point'`: `closed: true`. + - `'places points off the part'`: `addConstructPoint([500, 500])` works. + - `'a point drag is one undo step'` and `'Escape restores a dragged point'`. + - e2e `'moves a point with the widget'`: the chosen point's `u` arrow moves it along `u` and it + stays on the plane. + - e2e `'draws a closed curve on a plane'`: make a plane from a face, choose New curve, click 4 + screen points (2 off the part), click the first: the part has one closed curve of 4 lines. +- [ ] **Step 2: Run to verify they fail.** +- [ ] **Step 3: Implement** the shared components, chain module, pointer and actions. +- [ ] **Step 4: Run** the new tests and `npx playwright test tests/e2e/refine.spec.ts`, + `npx vitest run tests/unit/refine-sketch-session.test.ts tests/unit/refine-viewport-pointer.test.ts`: + PASS. +- [ ] **Step 5: Commit** `(feat) Draw construction curves on a plane` + +### Task 5: Point menu and constraints for curves + +**Files:** + +- Create: `src/components/SketchMenu.tsx` - `Item`, `Group`, `ConstraintGlyph`, `meeting` from + `RefinePointMenu.tsx`, and `PairItems({ shape: GuideShape, target, onAdd(kind, pair), onPick(kind, segment) })`. + `RefinePointMenu.tsx` uses them. +- Create: `src/components/ConstructPointMenu.tsx` - point menu (Lock > To line, Fixed, Unlock; + Align > Horizontal, Vertical; Constrain; Delete), segment menu, constraint menu; and + `ConstraintIcons` from `RefineSketch.tsx:113` taking `onConstraintMenu(id, e)` and + `onFixedMenu(segment, index, e)` props. +- Modify: `src/core/store.ts:240-252` (`constructPoint`, `constructSegment`, + `constructConstraint` on `EditorContextMenu`), `src/components/EditorContextMenu.tsx:290-313`, + store actions below +- Test: `tests/unit/construct-session.test.ts` + +**Interfaces:** + +- Consumes: `solveGuide`, `solvedSegments`, `constraintRefusal`, `pairFits` from + `refine-constraints.ts` via Task 2's `curveShape` and `fromShape`. +- Produces, store actions (each refusal notifies with `constraintRefusal`'s text and changes + nothing): + +```ts +lockConstructPoint: (ref: ConstructPointRef, lock: ConstructionLock | null) => void; +addConstructConstraint: (curveId: string, constraint: GuideConstraint, heavy?: ConstructPointRef[]) => void; +removeConstructConstraint: (curveId: string, id: string) => void; +removeConstructPoint: (ref: ConstructPointRef) => void; +startConstructPicking: (picking: ConstructPicking) => void; +``` + +- `ConstructPicking` (Task 3 has only the `plane` member) becomes: + +```ts +type ConstructPicking = + | { kind: 'plane'; from: 'points' | 'face'; points: (SurfacePoint & { face: number })[] } + | { kind: 'line'; point: ConstructPointRef; picked: [number, number][] } // 2 clicks on the plane + | { kind: 'align'; axis: LineKind; point: ConstructPointRef } // then click another point + | { kind: 'constrain'; curveId: string; constraint: PairKind | LineKind; segment: number }; +``` + +- Constraints are solved on every point move, added or removed constraint, and plane Offset + change, as in Refine. + +- [ ] **Step 1: Write the failing tests:** `'keeps two lines parallel through a drag'`; + `'refuses a conflicting constraint with nothing changed'` (Parallel then Perpendicular on the + same pair); `'aligns a point horizontally'`; `'keeps constraints through undo and save'`; + `'deletes a point'`. +- [ ] **Step 2: Run to verify they fail.** +- [ ] **Step 3: Implement.** +- [ ] **Step 4: Run** the test file, `npx vitest run tests/unit/refine-sketch-session.test.ts`, + `npx playwright test tests/e2e/refine.spec.ts`: PASS. +- [ ] **Step 5: Commit** `(feat) Lock, align and constrain construction curve points` + +### Task 6: Boundaries + +**Files:** + +- Create: `src/core/construction-bounds.ts` +- Test: `tests/unit/construction-bounds.test.ts` + +**Interfaces:** + +- Consumes: Task 2's types, `planeFrame`, `curvePlane`; `drawnCurve` from `refine-curve.ts` (feed + `[u, v, 0]` points; step `0.02` local units with a display limit of 20,000 samples). +- Produces: + +```ts +export function boundaryMargin(extent: number): number; +export class Boundaries { + static fromParts(parts: Part[], skip?: (ref: ShapeRef) => boolean): Boundaries; + readonly empty: boolean; + /** Where a point moving straight from `from` to `to` (world) stops. */ + limit(from: Vector3, to: Vector3, out?: Vector3): Vector3; +} +``` + +- How `limit` works: each boundary keeps its owning part's matrix and inverse, and tests in that + part's local frame, where the plane and wall are exact. The point's side comes from its signed + distance (plane) or its side of the curve in (u, v) (wall), with the tie rules in Review focus 2. At the first crossing along the line, the point is placed at the crossing, moved back onto its + own side along the boundary's normal by the margin (for a wall, the curve's in-plane normal at + the crossing), and transformed back to world. The result is checked again against every + boundary, up to 4 rounds; if it still crosses, `limit` returns `from`. + +- [ ] **Step 1: Write the failing tests:** + - `'stops a point at a plane'`: plane at z = 1, from `(0,0,0)` to `(0,0,2)` gives z = + `1 - 1e-4` within `1e-9`. + - `'lets a point past the plane move on that side'`: from z = 3 to z = 5 returns z = 5. + - `'keeps a point at the margin from crossing'`: from z = `1 - 1e-4` to z = 2 stays at + `1 - 1e-4`. + - `'treats a point on a plane as behind it'`: plane z = 0 normal +z, from z = 0 to z = 1 stays + at `-1e-4`. A point exactly on a closed curve's wall moving outward stays inside by the + margin; on an open curve's wall, it counts as left of the drawn direction. + - `'stops a point at a curve wall'` for a line, an arc and a spline, each open and closed, at any + height above or below the plane. + - `'lets a point go round an open wall'`: a move that passes beyond the line's end returns `to`. + - `'stops at the first boundary met'`: two planes, z = 1 and z = 2. + - `'bounds a scaled part'`: the owning part scaled `[1, 2, -1]` and rotated; the world result + lies on the right side by at least the margin. + - `'ignores off shapes, hidden parts and skipped shapes'`. +- [ ] **Step 2: Run to verify they fail.** +- [ ] **Step 3: Implement `construction-bounds.ts`.** +- [ ] **Step 4: Run** `npx vitest run tests/unit/construction-bounds.test.ts`: PASS. +- [ ] **Step 5: Commit** `(feat) Stop points at construction shapes` + +### Task 7: Sculpt against boundaries + +**Files:** + +- Modify: `src/core/sculpt-mesh.ts:32-44` (`SculptDab.bounds?: Boundaries`), `:1314` (limit the + world target from the vertex's world position before `applyMatrix4(this.inverse)`) +- Modify: `src/components/SculptPointer.tsx:612-657` (build `Boundaries.fromParts` at stroke + start, cached by scene revision; pass it in every dab, mirrored dabs included) +- Test: `tests/unit/sculpt-bounds.test.ts`, `tests/e2e/construct.spec.ts` + +**Interfaces:** + +- Consumes: Task 6's `Boundaries`. + +- [ ] **Step 1: Write the failing tests**, on a dense flat plate (`PlaneGeometry(10, 10, 80, 80)`) + with a plane 1 mm above it, helpers as in `tests/unit/sculpt-mesh.test.ts:15-35`: + - `'caps every brush at a plane'`: 40 dabs each of Draw, Clay, Inflate, Grab (grab vector + `(0,0,3)`) and Smooth leave no vertex with z > `1 - 1e-4 + 1e-6`. + - `'flattens a long Draw stroke at the cap'`: after 200 Draw dabs, every vertex with z > 0.9 has + z within `1e-6` of `1 - 1e-4`. + - `'floors an inverted Draw at a plane below'` (plane at z = -1). + - `'bounds mirrored dabs'` with symmetry. + - `'leaves positions outside the brush bit-identical'` with a plane present. + - e2e `'sculpts up to a plane'`: make a plane from the top face with Offset 0.5, open Sculpt, + drag Draw across the face 20 times: no vertex higher than the plane. +- [ ] **Step 2: Run to verify they fail.** +- [ ] **Step 3: Implement.** +- [ ] **Step 4: Run** `npx vitest run tests/unit/sculpt-bounds.test.ts tests/unit/sculpt-mesh.test.ts tests/unit/sculpt-session.test.ts` + and `npx playwright test tests/e2e/construct.spec.ts tests/e2e/sculpt.spec.ts`: PASS. +- [ ] **Step 5: Commit** `(feat) Stop Sculpt brushes at construction shapes` + +### Task 8: Guide run in Sculpt + +**Files:** + +- Create: `src/core/construction-path.ts` +- Modify: `src/core/sculpt-session.ts` (`SculptSession.guide: ShapeRef | null`, + `runRequest: { id: number; reverse: boolean } | null`), `src/core/store.ts` (actions below; + clear `guide` when its shape is gone or off after any scene change), + `src/core/keybindings.ts` (`sculptGuideRun: { group: 'Tools', label: 'Run the brush along the guide', keys: ['L'] }` + and `sculptGuideRunBack` with `['Shift+L']`), `src/hooks/useWorkbench.ts`, + `src/components/SculptControls.tsx` (a Guide section between :141 and :142: None or a curve), + `src/components/ConstructOverlay.tsx` (click a curve to choose it while Sculpt is open), + `src/components/SculptPointer.tsx` (the run) +- Test: `tests/unit/construction-path.test.ts`, `tests/unit/sculpt-guide-run.test.ts`, + `tests/e2e/construct.spec.ts` + +**Interfaces:** + +- Consumes: Task 2's `findShape`, `curvePlane`, `planeFrame`; Task 6's `Boundaries` (with the + guide skipped); `drawnCurve`, `closestOnCurve`. +- Produces, in `src/core/construction-path.ts` (all in the plane's (u, v)): + +```ts +export interface PlanarPath { + points: Float64Array; + closed: boolean; +} // u, v pairs +export function curvePath(curve: ConstructionCurve, step: number): PlanarPath; +/** Distance from the path, positive to the left of the drawn direction. */ +export function signedOffset(path: PlanarPath, u: number, v: number): number; +/** The path moved sideways by `offset`; null when it vanishes. */ +export function offsetPath(path: PlanarPath, offset: number): PlanarPath | null; +/** Points from the one nearest (u, v) to the end, or one lap, spaced by `spacing`. */ +export function runFrom( + path: PlanarPath, + u: number, + v: number, + reverse: boolean, + spacing: number, +): Float64Array; +``` + +- `offsetPath`: move each sample along its in-plane normal; where segments meet at an angle, + join the outside of the corner with an arc round the corner point and trim the inside where the + two offsets cross; drop loops the offset makes; return null when nothing is left. +- Store actions: `setSculptGuide(ref: ShapeRef | null)`, `requestSculptGuideRun(reverse: boolean)`. +- The run, in `SculptPointer`: from the last hover hit, offset = `signedOffset` in the guide's + plane; path = `offsetPath`; points = `runFrom` with spacing `radius * aspect * spacing` (world + mm); each point is raycast on the draft along the plane's normal both ways and the hit nearest + the point is used; misses place no dab. Dabs run through the same drain, 6 ms per frame, as a + stroke. Pressure 1, current settings, Crease and Ridge tangent from the path. One commit on + completion; Escape cancels like a stroke. With no guide, no hover hit, or a null path, notify + and do nothing. + +- [ ] **Step 1: Write the failing tests:** + - `'runs parallel to a line'`: line from (0,0) to (10,0), brush at (3, 2): every run point has + v = 2 within `1e-9`, u from 3 to 10. + - `'runs a concentric arc'`: arc of radius 5 centred at the origin, brush 2 outside: every point + at radius 7 within `1e-6`; brush 2 inside: radius 3. + - `'runs back with Shift'`, `'stops after one lap of a closed curve'`. + - `'joins a corner round the outside and trims the inside'`: an L of two lines, offset 1 out + gives a quarter arc of radius 1 at the corner; offset 1 in meets at (1, 1). + - `'refuses a path inside an arc by more than its radius'`: `offsetPath` of the radius-5 arc by + -6 is null; the store run notifies and the mesh is unchanged. + - `'a run is one undo step and Escape leaves the mesh untouched'` (store level). + - `'clears the guide when its curve is deleted, switched off or undone away'`. + - e2e `'runs the brush along an arc'`: draw an arc, choose it as Guide, hover 1 mm outside, press + L: one new undo step and the changed vertices lie near the concentric arc. +- [ ] **Step 2: Run to verify they fail.** +- [ ] **Step 3: Implement.** +- [ ] **Step 4: Run** the new unit files and `npx playwright test tests/e2e/construct.spec.ts tests/e2e/sculpt.spec.ts`: + PASS. +- [ ] **Step 5: Commit** `(feat) Run the Sculpt brush along a construction curve` + +### Task 9: Warp against boundaries + +**Files:** + +- Modify: `src/core/warp-evaluate.ts:292-374` (a trailing `bounds?: Boundaries` on every + `evaluateWarp` overload; limit each moved vertex in `scratch.world` from `model.restWorld` + before the local conversion at :347, so positions, normals and folds agree), `:239-284` + (`writtenLocalPositions` takes `bounds?` and limits the same way) +- Modify: `src/core/store.ts:1533-1559, 1624, 1641, 1730, 3424` (build `Boundaries.fromParts` + once per warp session and scene revision; pass it to every evaluation and to apply), + `src/core/warp-neighbour.ts:288` +- Test: `tests/unit/warp-bounds.test.ts` + +**Interfaces:** + +- Consumes: Task 6's `Boundaries`. `skinnedWorldPositions` stays unbounded (handles move freely). + +- [ ] **Step 1: Write the failing tests**, with the model setup of + `tests/unit/warp-evaluate.test.ts:25-42`: `'stops a warp at a plane'` (a handle lifting the + region 3 mm with a plane at 1 mm leaves no vertex above `1 - 1e-4`); + `'writtenLocalPositions agrees with evaluateWarp when bounded'`; + `'is unchanged with no bounds'` (bit-identical output). +- [ ] **Step 2: Run to verify they fail.** +- [ ] **Step 3: Implement.** +- [ ] **Step 4: Run** `npx vitest run tests/unit/warp-bounds.test.ts tests/unit/warp-evaluate.test.ts` + and `npx playwright test tests/e2e/warp*.spec.ts`: PASS. +- [ ] **Step 5: Commit** `(feat) Stop Warp at construction shapes` + +### Task 10: Move with Boundary and Follow + +**Files:** + +- Modify: `src/core/types.ts:320-338` (`ViewSettings.construction: { mode: 'boundary' | 'follow'; follow: ShapeRef | null }`), + `src/core/store.ts:2201-2225` (default `{ mode: 'boundary', follow: null }`), `:5193-5199` + (wrap `transformMany`'s `place`), `:5129-5135` (the same for typed moves in `transform`) +- Modify: `src/core/clipping.ts:641` (export `smallestStep`) +- Modify: `src/core/construction-bounds.ts` (`limitTranslation`), `src/core/construction-path.ts` + (`followPoint`) +- Modify: `src/components/TransformAdjustments.tsx:210-289` (Boundary / Follow toggle, followed + shape list), `src/components/ConstructOverlay.tsx` (click a shape to follow it in Follow) +- Test: `tests/unit/construction-move.test.ts`, `tests/e2e/construct.spec.ts` + +**Interfaces:** + +- Consumes: Task 6's `Boundaries`, Task 8's `offsetPath`, `signedOffset`, `findShape`; + `transformSelection` (`src/core/transform-selection.ts:82`) for the pivot. +- Produces: + +```ts +/** The correction to add to every moved part's translation so none of its vertices crosses. */ +export function limitTranslation( + bounds: Boundaries, + current: Part[], + proposed: Part[], +): Vec3 | null; +/** Where the pivot may go along the followed shape from `current`, nearest `proposed`. */ +export function followPoint( + parts: Part[], + ref: ShapeRef, + current: Vec3, + proposed: Vec3, +): Vec3 | null; +``` + +- The `place` wrapper: `out = place(poses)`; parts whose pose changed only by translation are + bounded (others are not); `c = limitTranslation(...)`, null when nothing crosses; when `c` is + set, return `place(poses shifted by c)`, re-check, up to 3 rounds; if still crossing, return the + current poses. Bounds skip shapes on every part whose pose changed, and in Follow the followed + shape. In Follow, before `place`, shift the target poses by `followPoint(...) - proposedPivot`; + a missing or off followed shape does nothing. +- `limitTranslation` builds rows `a · c ≥ b` and solves them with `smallestStep` (rows with + `b ≤ 0` already hold), so only the blocked part of the move is removed and the rest slides. For + a plane at height `h` along world normal `n`, with margin `m` and a part's world vertices `p` + moving by `d`: the vertices behind it give `-n · c ≥ max(n · (p + d)) - h + m`; the vertices in + front give `n · c ≥ h + m - min(n · (p + d))`. For a curve wall, the earliest vertex crossing + along `d` gives one row with the wall's in-plane normal at that crossing and that vertex's + distance to the wall. Per drag, cache each part's extreme `n · (R S p)` per plane and a 2D + bucket grid of its vertices in each wall's (u, v), keyed by geometry, quaternion and scale. +- `followPoint`: a plane keeps the current pivot's distance; a curve keeps its height above the + plane and its offset from the curve, and takes the point of `offsetPath` nearest `proposed`. +- Translate only: the part does not turn. + +- [ ] **Step 1: Write the failing tests:** + - `'stops a drag at a plane'`: a box dragged 5 mm toward a plane 2 mm away ends with its nearest + vertex `1e-4` short, with No clip on and off. + - `'slides along a plane'`: a diagonal drag keeps the component along the plane. + - `'stops a fast drag at a thin wall'`: one 50 mm step across a line wall stops at it. + - `'bounds a part carried by a joint'`: dragging the parent pushes the child into the plane; the + child stops at it, No clip on. + - `'ignores the moving part's own shapes'`. + - `'follows a plane'` (pivot keeps its distance) and `'follows an arc'` (pivot keeps radius + and height). + - `'falls back to Boundary when the followed shape is gone'`. + - `'keeps up with a dense part'`: a 700k-vertex part against one plane and one closed 4-line + curve: after the first call of a drag, each `limitTranslation` call takes under 1 ms (median of + 50). + - e2e `'moves along and up to shapes'`: Boundary drag stops at a plane; switch to Follow, choose + an arc, drag: the pivot stays at its radius. +- [ ] **Step 2: Run to verify they fail.** +- [ ] **Step 3: Implement.** +- [ ] **Step 4: Run** `npx vitest run tests/unit/construction-move.test.ts tests/unit/clipping.test.ts tests/unit/assembly.test.ts tests/unit/pins.test.ts` + and `npx playwright test tests/e2e/construct.spec.ts`: PASS. +- [ ] **Step 5: Commit** `(feat) Move parts up to or along construction shapes` + +### Task 11: Documentation + +**Files:** + +- Modify: `src/docs/assembly-guides.ts` (new `construct` article after `pins`: making planes, + Offset, drawing curves, constraints, On, how boundaries work; a `guide-run` section in the + `sculpt` article; Boundary and Follow in the `transforms` article's `blocked-movement` + section), `src/docs/content.ts:80-113` (order), `src/docs/main.tsx:46-71, 445-454` (icon, tool + directory), `src/docs/changelog.ts` (new top entry, `kind: 'new'`, `guide: 'construct'`, no + `commit`) +- Test: `tests/unit/changelog.test.ts` + +- [ ] **Step 1: Write the docs** following `docs/documentation.md`. +- [ ] **Step 2: Run** `npm test`, `npm run test:e2e`, `npm run build`, `npm run format:check`: all + PASS. +- [ ] **Step 3: Commit** `(docs) Explain construction shapes` diff --git a/docs/superpowers/specs/2026-11-25-construction-shapes-design.md b/docs/superpowers/specs/2026-11-25-construction-shapes-design.md new file mode 100644 index 0000000..28c8a4b --- /dev/null +++ b/docs/superpowers/specs/2026-11-25-construction-shapes-design.md @@ -0,0 +1,247 @@ +# Construction shapes + +Added 2026-11-25. + +## Intent + +The user wants shapes placed in the scene that limit what editing tools can do. A plane offset +from a surface sets the maximum height of any modification; another plane below sets the +minimum. Curves drawn on a plane constrain things further, for features like flat curves, and +can guide the brush along a path. + +## What the user asked for (product owner) + +1. **Construction shapes:** planes, and curves drawn on a plane. +2. **Planes as limits:** a plane offset from a surface controls the maximum height of any + modification; another below controls the minimum. +3. **Curves as boundaries:** a curve is a face normal to its plane, going to infinity. The mesh + cannot cross it. +4. **Curves as brush guides:** with a curve selected as the guide, the user places the brush and + presses a key. The brush moves along the curve, starting from where the brush is. The path + is parallel to the curve at the brush's distance from it: for an arc, the same centre and a + radius larger or smaller by that distance. While a curve is the guide it is not a boundary. +5. **Saved with the scene and attached to a part.** Shapes move with their part, last after the + tool closes, and any tool can use them. +6. **Tools constrained:** Sculpt, Warp and Move. +7. **Two methods, togglable, for Move:** Follow, where the shape sets the path you can travel + from where you are now, and Boundary, where the shape stops you. +8. **Approach:** new construction shapes stored on parts, reusing Refine's sketch code. Refine's + own session sketch planes stay as they are. + +## Goals + +- A plane placed a set distance above a surface stops every Sculpt brush, the Warp tool and a + Move drag from taking the mesh past it, so a built-up area comes out flat at that height. +- A curve's wall stops the mesh from crossing it, in the same tools. +- A brush stroke can run exactly along a curve, or parallel to it at a chosen distance. +- A part can be moved along a plane or curve, or up to it and no farther. +- Shapes are part of the scene: saved, undone, copied and shared like a part's pins. + +## Non-goals + +- Constraining Rotate, Scale, Refine, Pins or Anchors. +- Follow for Warp handles. Warp gets Boundary only. +- Shapes other than planes and curves on planes (spheres, cylinders, offset copies of a curved + surface). +- Cutting triangles along a boundary to make the edge where the mesh meets it sharper than the + mesh's density allows. Sculpt's automatic detail still applies. +- Typed dimensions (lengths, radii, angles). +- Moving Refine's sketch planes into the scene. Refine keeps its session planes. + +## Anti-goals + +- An edit that leaves any point of the mesh on the far side of a boundary from where it started. +- A guide run that drifts off its parallel path. +- A Move that jumps through a thin boundary because one drag frame stepped over it. + +## Decisions + +Marked **(product owner)** where the user decided; the rest are the designer's calls. + +### Shapes + +- A part keeps its shapes in a new optional field, next to `pins` and `anchors`, in mesh-local + coordinates, so they move, rotate and scale with the part **(product owner)**. A shape is + attached to the part it was made on. +- **Plane:** an id, a name (Plane 1, Plane 2, in the order the part's shapes were made), an + origin, a unit normal, in-plane axes `u` and `v` (as `SketchPlane` in + `src/core/refine-sketch.ts`), an **Offset** in mm along the normal, and **On**. +- **Curve:** an id, a name (Curve 1, ...), the plane it lies on, its segments, open or closed, + its constraints, and **On**. A curve is a chain of segments of Refine's guide kinds (line, + arc, spline; `GuideKind` in `src/core/refine-curve.ts`). Its points are stored in the plane's + (u, v), so changing the plane's Offset carries the curve with it. +- A shape that is off is hidden and constrains nothing. A plane that is off still carries its + curves; each curve has its own On. +- Deleting a plane deletes its curves. + +### Making and drawing shapes + +- A new toolbar tool, **Construct**, works on the selected part, as Pins does. Its panel lists the + part's shapes with On, rename and delete, and holds the making and drawing controls. +- **New plane:** click 3 points on the part, or click once on a flat face to fit a plane to the + surface around the click (`planeThrough` and `planeOfFace` in `src/core/refine-sketch.ts`). + Then set **Offset** in mm, positive away from the surface on the side the click was made from + **(product owner: offset from a surface)**. Offset stays editable. +- **New curve:** choose a plane and draw as a Refine guide is drawn on a sketch plane: a click + places a point where the cursor's ray meets the plane, whether or not the ray hits the part. + Line, arc and spline segments, open or closed. Points have the move widget, the point menu + (Lock, Align, Constrain, Delete) and the segment constraints of the Refine sketch guides + design, solved by `solveGuide` in `src/core/refine-constraints.ts`. +- While Construct is open, the selected part's shapes are drawn: a plane as a grid square with + its `u` and `v` axes, sized to the part, and a curve as a line on its plane with its wall shown + faintly a short way either side of the plane. In Sculpt, Warp and Move, shapes that are on are + drawn faintly. + +### Boundaries + +- Every shape that is on, on any visible part, is a boundary for Sculpt, Warp and Move. The + exceptions: the guide curve during a guide run, the shape being followed in Follow, and a + moving part's own shapes. +- A plane is infinite. A curve's wall is every point whose projection onto the curve's plane lies + on the curve, infinite along the plane's normal both ways **(product owner)** and as long as + the curve along it. An open curve's wall has ends that the mesh can go around. +- **The rule:** each edit moves a point in a straight line from where it was to where the tool + sends it. If that line crosses a boundary, the point stops on its own side of the boundary, a + small margin short of it (0.0001 mm, or more where float precision at the part's size needs + it). Because no point is ever left exactly on a boundary, the side a point is on is always + known from its position, and no per-point state is kept between edits. +- Boundaries are two-sided. A plane above a surface caps it from below; points of the part that + already lie above the plane cannot be pushed down through it. +- Several boundaries: the point stops at the first one its line meets. +- A curve's wall is crossed when the line's projection onto the curve's plane crosses the curve, + so the crossing test is two-dimensional in the plane's (u, v). + +### Sculpt + +- Every brush that moves the mesh is bounded, including Grab and Smooth, and mirrored dabs under + symmetry. Mask is unchanged. +- The bound is applied where each dab sets a vertex's new position, in `dabWork` in + `src/core/sculpt-mesh.ts`, from the vertex's position before the dab to the displaced one. +- **Guide run (product owner):** + - The Sculpt panel has a **Guide** choice: None, or one of the scene's curves that are on. + Clicking a curve in the viewport while Guide is open also chooses it. + - With a guide chosen, a key runs the brush along it; Shift with the key runs it the other + way. The builder picks a key free in Sculpt. + - The path is the curve offset in its plane by the brush's distance from the curve when the key + is pressed, measured in the plane (option 2, product owner). The run starts at the point of + the path nearest the brush, follows the curve's drawn direction (or the reverse with Shift), + and stops at the curve's end, or after one lap of a closed curve. + - Where two segments of the curve meet at an angle, the outside of the corner is joined by an + arc round the corner point and the inside is trimmed where the offsets cross. + - Each dab lands on the part where the line through the path point along the plane's normal + meets it, at the brush's spacing. The run plays over successive frames at a steady pace so + the user sees the brush move. It is one stroke: one undo step, Escape cancels it, and the + current brush settings apply. Pressure is steady, as with a mouse. Crease and Ridge take + their direction from the path. + - A path point where the line along the normal misses the part places no dab; the run carries + on. + +### Warp + +- The warped surface is bounded: each vertex's line runs from its rest position to its warped + position, so the bound is applied after evaluation, where warped world positions are written + (`evaluateWarp` in `src/core/warp-evaluate.ts`), and before they are shown or committed. +- Warp handles move freely. The surface they drive stops at boundaries. + +### Move + +- Covers the Move tool, the move handles of the combined transform, and Free move. +- **Boundary / Follow toggle (product owner)** in the Move panel. Boundary is the default. +- **Boundary:** a drag into a boundary slides the selection along it: only the part of the + movement that would take a point across is blocked **(product owner)**, the way No clip + (`placeClear` in `src/core/clipping.ts`) slides a part along another part. The check covers the + whole drag from the last allowed position, so a fast drag cannot step through a thin shape. +- Boundaries are one more limit inside No clip's solve, and they win over it: No clip never pushes + a part across a boundary, and parts No clip carries along (joint children, plane constraints, + pin corrections) are bounded too. With No clip off, boundaries still apply. +- **Follow:** the user chooses a plane or curve to follow (from a list in the Move panel, or by + clicking it). The drag then moves the selection's pivot only along the path the shape sets from + where the pivot is now: + - a plane: the drag is held parallel to the plane, keeping the pivot's distance from it; + - a curve: the pivot moves along the curve offset in its plane by the pivot's distance from the + curve, keeping its height above the plane, the same parallel path a guide run uses. +- In Follow, other shapes that are on still act as boundaries. +- Move translates only; the part does not turn to follow a curve. +- The boundary check runs at 60 Hz during a drag for a part of about 700k vertices. + +### Saving, undo and sharing + +- Shapes are saved in the scene file, validated on open like pins (`src/core/scene-file.ts`), and + documented in `docs/scene-format.md`. +- Every change to a shape is one scene undo step, through the same part patch path pins use. +- Copy and paste of a part carries its shapes (`src/core/clipboard.ts`). Shared sessions sync them + (`src/core/sync.ts`). +- A geometry edit (Sculpt, Warp, Refine, mesh processing) keeps the part's shapes, as it keeps + pins and anchors. Merging parts carries each part's shapes into the merged part's coordinates. + +### Reuse from Refine + +- Plane math (`planeOf`, `planeThrough`, `planeOfFace`, `rayOnPlane`, `planeCoordinates`, + `planePoint`) and the constraint solver are reused. Their types tie points to mesh triangles + (`GuidePoint`); the builder generalizes what a construction curve needs, without changing + Refine's behaviour or tests. +- The drawing, point menu and move widget UI in `RefinePointer.tsx`, `RefineSketch.tsx` and + `RefinePointMenu.tsx` are tied to the Refine session. The builder extracts what Construct + needs so both tools share it. + +## Approaches considered + +1. **New construction shapes on each part, reusing Refine's sketch code.** Chosen + **(product owner)**. Reuses the plane math, segments and solver without reworking Refine. Two + kinds of plane exist in the app until Refine is moved over. +2. **Move Refine's sketch planes into the scene and share them.** One plane system, but Refine's + session undo and many of its tests change, and Refine's guides are edges to solve, not + boundaries, so only the planes would be shared. +3. **Make construction shapes parts**, like the reference planes. Selection, moving, hiding and + saving come free, but boundaries need the exact plane and curve anyway, they would clutter + the parts list, and sketch constraints between curves would not fit. + +## Builder's discretion + +- The guide run key, and the pace of the run. +- How the Move boundary check is made fast enough (hull, BVH, or a 2D index of the projected + vertices for curve walls). +- Panel layout, keeping the existing panel patterns, and the look of planes, walls and the + followed shape. +- How the shared sketch types are split out of Refine. +- Status line wording, following `docs/documentation.md`. + +## Build order + +Each step ends with its tests passing and a commit. + +1. Shape model on parts: saving, undo, copy, sync, merge. +2. Construct tool: planes from 3 points and from a face, Offset, On, rename, delete, drawing. +3. Curves on planes: drawing, point editing and constraints, shared with Refine. +4. Boundaries in Sculpt. +5. Guide run in Sculpt. +6. Boundaries in Warp. +7. Move: Boundary and Follow. +8. Docs: a Construct page in `src/docs`, and an entry at the top of `src/docs/changelog.ts`. + +## Verification + +Unit tests (`tests/unit`): + +- Boundary rule: a point moving through a plane stops 0.0001 mm short on its side; a point + already past the plane moves freely on that side; a point crossing a curve's wall (line, arc, + spline, open and closed) stops at it; an open wall can be gone around; two boundaries, the + first met wins. +- Sculpt, on a flat plate with a plane 1 mm above it: Draw, Clay, Inflate, Grab and Smooth + strokes leave no vertex above the plane; a long Draw stroke leaves a plateau flat to the + margin. A plane below: an inverted Draw leaves none below. Symmetry is bounded too. Positions + outside the brush are bit-identical, as today. +- Guide run: a line guide with the brush 2 mm off runs a path 2 mm off the line; an arc guide runs + a concentric arc 2 mm larger; Shift runs the other way; a closed curve stops after one lap; the + run is one undo step and Escape leaves the mesh untouched. +- Warp: a warp that would lift a region through a plane leaves it at the plane. +- Move: a drag toward a plane stops with the nearest vertex at the margin; a fast drag past a + thin wall stops at it; Follow on a plane keeps the pivot's distance; Follow on an arc keeps the + pivot's radius and height. +- Shapes survive save and reopen, undo and redo, copy and paste, a Sculpt stroke and a merge. + +End to end (`tests/e2e`): make a plane from a face with an offset, sculpt against it, and check +the cap; draw an arc and run the brush along it with the key; toggle Move between Boundary and +Follow and drag. + +Existing unit and end-to-end tests keep passing.