editor: building rotation, alt-click single wall, world-grid alignment, tap-to-engage move (#388)

* Add roof surface placement support for items

Items (e.g. solar panels) can now be placed on sloped roof surfaces.
The placement system computes euler rotation from the roof surface
normal so items sit flush on the slope instead of going inside.

- Add roofStrategy to placement-strategies with enter/move/click/leave
- Wire roof:enter/move/click/leave events in the placement coordinator
- Add calculateRoofRotation in placement-math using surface normals
- Support full 3D cursor rotation for sloped surfaces
- Items on roofs are parented to the level with world-space rotation

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fixed conflict

* Snapshot: ridge vent locks to segment ridge during placement, free sliders after

Placement tool clamps the cursor to the segment's ridge line for all roof
types (gable, hip, shed, gambrel, dutch, mansard; flat rejected). Renderer
re-derives Y from the live surface plus a small lift, and treats stored
position[1] / position[2] as user offsets so the inspector sliders move
the vent after placement.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(roof): contribute outer silhouette to alignment-guide candidates

Roof has no centred-box footprint (it's the union of its `roof-segment`
children) so the capability bridge needs the resolved AABB directly. We
build it from the children's corners in roof-local space, then transform
to world coords. Roofs only contribute as static candidates — the
move-roof tool drives them by origin, so the relocatable-box path never
applies.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(floorplan): upright text geometry that stays horizontal under scene rotation

Floor-plan text labels were rotating with the 90° default scene rotation,
making zone names read sideways. Add an `upright` flag to text geometry:
when set, the registry layer counter-rotates the label by sceneRotationDeg
around its anchor so it reads horizontally on screen. Zone labels opt in.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(editor): redesign material-paint cursor badge and gate floor-plan paint mode

Paint cursor swaps the inline icon+label chip for a stacked badge — a
glowing accent stem pointing down to the hit point with the paint icon
above — so the cue reads as "pointer" rather than "tooltip". Switches
the accent to indigo. The 2D floor-plan now also shows the paint-icon
overlay and routes pointer interactions to the painter when in
material-paint mode.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(editor): 90° rotate action on the floating building menu

Adds a Rotate button to the building action menu (and a generic `onRotate`
slot to NodeActionMenu). Each click rotates the building 90° CW around
its world-bbox center, mirroring the offset compensation
`MoveBuildingContent` uses during R/T-rotate drags — so the building
spins in place instead of orbiting its (often off-centre) origin.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(column,shelf): show cursor sphere during placement preview

Matches the placement affordance other floor-placed tools already have
so users see the snap point as a discrete dot alongside the ghost mesh.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* chore(ifc-converter): update next-env types path to .next/dev/types

Next.js moved generated route types under `.next/dev/types/` — regenerate
the reference so the type-check resolves them again.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* fix(ridge-vent): track parent segment's live overrides for real-time follow

While dragging a roof-segment resize handle (width / depth / pitch /
wallHeight / rotation), the new dimensions stream through
useLiveNodeOverrides and only flush to the store on release — so the
ridge vent was snapping to the new ridge only after the drag ended.
Merge segment overrides into the renderer's segment view so the vent
rides the resize in real time.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(editor): step building rotation in 15° increments

Cuts the floating building menu's rotate-step from 90° to 15° so each
click nudges the building rather than slamming it to the next cardinal.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(editor): world-frame alignment guides and grid snap under building rotation

Brings the 2D floor-plan alignment + grid behaviour in line with 3D so
guides and snap follow the world XZ grid regardless of how the active
building is rotated.

Core: adds resolveAlignmentInBuildingWorld + snapWorldXZToBuildingLocal,
plus a shared BuildingPose type, so callers can resolve in world space
while staying in building-local coords downstream.

Editor: introduces packages/editor/src/lib/world-grid-snap.ts as the
single entry point for tools that need world-frame alignment / grid
snap (resolveAlignmentForActiveBuilding, getActiveBuildingPose,
snapWorldXZForActiveBuilding, snapBuildingLocalToWorldGrid). Honours
useLiveTransforms and resolves the active building via level.parentId
first so the helper stays in sync with the floor-plan panel.

Alignment store unification: applyFloorplanAlignment and the registry
move overlay now publish guides in world XZ — the same frame the 3D
tools already use — so the shared useAlignmentGuides store carries one
consistent coordinate system. The 2D layer renders world XZ via the
fixed world → SVG transform (a 90° rotation around the building's
world position; independent of building rotation), so guides come out
parallel to the world-axis-aligned floor-plan grid in every case.

Drafting + move sessions across walls, fences, slabs, ceilings,
columns, items, shelves, roofs, stairs, zones and elevators are
re-routed through the new helpers so cursor placement, grid snap,
draft endpoints, and move commits all land on the world XZ grid
even when the building has been rotated.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* revert(editor): drop building drag-rotate and grid building-XZ chase

Two behaviours added recently were causing the world grid to slide
around during building edits. Reverts both, keeping the rest of the
world-frame alignment work intact.

- floating-building-action-menu / node-action-menu: roll the rotate
  button back to a single click that increments rotation by 15°
  around the bbox center (state at 3eb02fde). The drag-rotate from
  b50c0d5a streamed live position updates per frame, which the
  floor plan and grid both followed.
- grid: stop chasing the active building's world XZ each frame
  (pre-c00a2469 behaviour). The grid stays anchored at world (0, 0)
  so it doesn't visibly sweep when the building origin moves —
  during a drag, an R/T rotation in the move tool, or a click
  rotate that re-anchors the origin to the bbox-pivot. Y still
  lerps to the active level's floor height.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(editor): consistent building rotation pivot + 2D position sync

Several connected fixes to building rotate/move so the 3D mesh, the
2D floor plan, and alignment guides all stay visually consistent
across rotations and drags.

Rotation-invariant pivot
- New `getBuildingLocalBboxCenter` helper walks descendant mesh
  geometry bounds in the building's LOCAL frame, returning a
  centroid that doesn't depend on the building's current world
  rotation. The previous approach derived the pivot from the world
  AABB at the current rotation, which made the local pivot subtly
  drift each time the building was rotated.
- Floating menu click-rotate and move-tool R/T rotation now seed
  their pivot from this helper, so successive rotations stay
  pinned at the same world point.

Move-tool stability
- R/T rotation always pivots around the current world bbox center,
  even before the cursor has moved onto the grid (previously it
  fell back to rotating around the origin in that case).
- Commit (`onGridClick`) now writes the mesh's actual on-screen
  pose instead of recomputing it from the click event's grid
  coords, removing a one-cell snap on release.

Alignment resolver
- Tie-break is now perp-first, primary-second. The previous order
  was reliable when wall faces shared an exact axis-aligned coord
  (pre-rotation), but post-rotation float deltas meant primary
  never tied and the resolver could lock onto the far corner of a
  candidate. Perp-first picks the visually closest point.

2D ↔ 3D sync
- The floor-plan SVG scene group now applies a live `translate(...)`
  derived from `(committedBuildingPosition → live buildingPosition)`,
  in addition to the existing live rotation. Building-local content
  slides in lockstep with the 3D mesh during a drag.
- The alignment-guide layer projects from world XZ using the
  COMMITTED building position, so guides stay locked to their world
  coordinates while the building slides past them.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* Merge remote-tracking branch 'origin/main' into fix/fir-5-june

* feat(wall): alt-click commits a single wall instead of chaining

Holding Alt on the click that completes a segment now stops drafting
instead of starting a new segment from the just-placed endpoint. Same
behaviour wired in both the 3D wall tool and the 2D floor-plan
placement hook (which already passed `singleWall: event.altKey` —
the 2D handler was ignoring the flag).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* revert(editor): drop 15° rotate from floating building action menu

Removes the rotate button on the floating building menu and the
`getBuildingLocalBboxCenter` pivot helper that only existed to support
it. The selected-group rotate handle remains the way to rotate a
building.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* chore(ifc-converter): point next-env at .next/types instead of .next/dev/types

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(editor): unify 3D move grip with floating-menu Move via tap-to-engage

The translate gizmo on the 3D bounding box now hands the node to the
registry move tool (same path as the floating action menu's Move
button) instead of running its own plane-drag. One move flow — green
bounding box, cursor follow, alignment guides, R/T rotation,
click-to-commit — drives both entry points.

Adds a `dragBounds` capability on the node registry so kinds whose
rendered mesh contains extras (per-level landing assemblies on an
elevator, etc.) can declare the box the user thinks of as "the thing
being dragged." Elevator and stair opt in; everything else still
auto-measures. `MoveRoofTool` now shows the green box for whole-stair
and whole-roof moves, and aligns roofs by their footprint corners
(previously only stairs did). Slab floor-plan moves clear
`autoFromWalls` on commit so space-detection doesn't snap the slab
back, via a new `extraCommitFields` hook on the polygon-centroid
move target.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(editor): 2D alignment guides in building-local frame + world-grid wall snap

The 2D floor-plan alignment layer now mounts inside the rotated scene
<g> and reads from an editor-local `useAlignmentGuides` store —
guides are stored in building-local meters and follow the SVG
transform that already carries the rest of the floor-plan geometry.
Pill labels are counter-rotated by the scene rotation so they stay
upright under building rotation. The 3D pipeline keeps its own
world-frame store; the two surfaces no longer share frames.

Wall drafting picks up an optional `gridSnap` override so the 2D
floor-plan can snap drafts onto the world-XZ grid even when the
active building is rotated — without it, a rotated building's
drafted wall would chase the local grid and miss the visible lines.
`snapPointTo45Degrees` and `snapWallDraftPointDetailed` route through
the override when supplied; otherwise the prior local-axis grid snap
is unchanged. The floor-plan panel wires `snapBuildingLocalToWorldGrid`
through the placement hook and exports `WALL_GRID_STEP` to support it.

Also fixes the minor/major grid stroke palette swap so minor lines
render with the minor palette and majors with the major palette.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* chore(editor): drop dead onRotate slot, memoize dragBounds snapshot

Removes the unreachable `onRotate` prop, `RotateCw` import, and
rotate button from `NodeActionMenu` — its only caller was the
floating building menu's 15° rotate, which was removed in d65fd5fe.

Memoizes `MoveRegistryNodeTool`'s `dragBounds` lookup so it captures
the scene snapshot once per node instead of re-reading
`useScene.getState().nodes` on every render. Bounds depend only on
`node` (locked for the tool's lifetime) and start-time sibling state
(elevator shaft height from the level set), so a one-shot snapshot is
the right semantics — and it avoids implying a live subscription that
isn't there.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* chore: biome check --write (import order, formatting, unused import)

Auto-fixes from `bun check:fix`:
- import-order normalization in editor/nodes/core
- unused `snapToGrid` / `useLayoutEffect` imports dropped
- minor whitespace/wrapping tweaks

No behavioural change.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Sudhir Yadav
2026-06-09 11:05:27 -04:00
committed by GitHub
co-authored by Claude Opus 4.7
parent b620c9d502
commit 555cf06c12
43 changed files with 948 additions and 295 deletions
+22
View File
@@ -241,6 +241,12 @@ export type FloorplanGeometry =
stroke?: string
strokeWidth?: number
paintOrder?: 'stroke' | 'fill' | 'normal'
/**
* When true, the registry layer counter-rotates the label by
* `sceneRotationDeg` so it reads horizontally on screen regardless
* of the floor-plan's scene rotation (default 90°).
*/
upright?: boolean
}
/**
* Bitmap overlay — captured top-down asset thumbnail, AI-generated
@@ -981,6 +987,22 @@ export type Capabilities = {
* `AlignmentFootprintConfig`.
*/
alignmentFootprint?: AlignmentFootprintConfig
/**
* Bounds drawn by the 3D drag bounding box during a move. Opt-in: when
* omitted, the box auto-measures the rendered mesh, which is correct for
* most kinds. Set this when the rendered mesh tree contains extras the
* user wouldn't think of as "the thing being dragged" — e.g. an elevator
* whose mesh includes per-level landing assemblies, and the user expects
* the box to wrap just the shaft they're moving.
*
* `size`: `[width, height, depth]` in the node's local frame.
* `centerY`: optional Y center; defaults to `size[1] / 2` (box sits on
* the ground plane). Override when the local origin isn't at the base.
*/
dragBounds?: (
node: AnyNode,
nodes?: Readonly<Record<string, AnyNode>>,
) => { size: [number, number, number]; centerY?: number }
roofAccessory?: RoofAccessoryConfig
/**
* Kind cuts a hole in the ceiling surface it is attached to (e.g. recessed
+100 -7
View File
@@ -75,15 +75,108 @@ export type ResolveAlignmentResult = {
const EMPTY: ResolveAlignmentResult = { guides: [], snap: null }
/** Forward rotation: local XZ → world XZ for a node whose parent has
* position `bx,_,bz` and rotation-Y `rotY` (radians). Matches the
* transform used throughout the editor's tools / floor-plan. */
function localToWorld(
x: number,
z: number,
bx: number,
bz: number,
cos: number,
sin: number,
): { x: number; z: number } {
return {
x: bx + x * cos + z * sin,
z: bz - x * sin + z * cos,
}
}
function transformAnchorToWorld(
anchor: AlignmentAnchor,
bx: number,
bz: number,
cos: number,
sin: number,
): AlignmentAnchor {
const w = localToWorld(anchor.x, anchor.z, bx, bz, cos, sin)
return { nodeId: anchor.nodeId, kind: anchor.kind, x: w.x, z: w.z }
}
export type BuildingPose = {
position: readonly [number, number, number]
rotationY: number
}
export type ResolveAlignmentInBuildingResult = {
/** Guides in WORLD coordinates. Renderers must be in a world-space group. */
guides: AlignmentGuide[]
/** Snap delta in the BUILDING-LOCAL frame, ready to add to a local position. */
snap: { dx: number; dz: number } | null
}
/**
* Resolve alignment in WORLD space while accepting BUILDING-LOCAL anchors.
*
* Why this exists: the floor-plan grid lives in world XZ (rendered outside
* the rotated scene group), so alignment must follow the same axes —
* otherwise rotating a building drags the alignment guides off the visible
* grid and onto the rotated wall's local axes (the bug the user hit). The
* resolver itself is frame-agnostic; this wrapper just transforms anchors
* to world, resolves, then rotates the snap delta back into building-local
* so callers can add it to a local position without further math.
*
* `pose === null` → resolve in the caller's frame as-is (no transform).
*/
export function resolveAlignmentInBuildingWorld(input: {
moving: readonly AlignmentAnchor[]
candidates: readonly AlignmentAnchor[]
threshold: number
pose: BuildingPose | null
}): ResolveAlignmentInBuildingResult {
const { moving, candidates, threshold, pose } = input
if (!pose) {
return resolveAlignment({ moving, candidates, threshold })
}
const cos = Math.cos(pose.rotationY)
const sin = Math.sin(pose.rotationY)
const bx = pose.position[0]
const bz = pose.position[2]
const movingWorld = moving.map((a) => transformAnchorToWorld(a, bx, bz, cos, sin))
const candidatesWorld = candidates.map((a) => transformAnchorToWorld(a, bx, bz, cos, sin))
const result = resolveAlignment({
moving: movingWorld,
candidates: candidatesWorld,
threshold,
})
if (!result.snap) return { guides: result.guides, snap: null }
// World → local rotation (orthogonal matrix → transpose). The inverse of
// `localToWorld` above maps (dx_world, dz_world) → (dx_local, dz_local).
const dxW = result.snap.dx
const dzW = result.snap.dz
const dxL = dxW * cos - dzW * sin
const dzL = dxW * sin + dzW * cos
return { guides: result.guides, snap: { dx: dxL, dz: dzL } }
}
export function resolveAlignment(input: ResolveAlignmentInput): ResolveAlignmentResult {
const { moving, candidates, threshold } = input
if (threshold <= 0 || moving.length === 0 || candidates.length === 0) return EMPTY
// Best match per axis: smallest |Δ| on the matched axis (tightest
// alignment), then — crucially — tie-break to the candidate anchor NEAREST
// on the perpendicular axis. Anchors are real points (corners / endpoints /
// midpoints), so the guide always connects to the closest actual point of
// the candidate, never a far one that merely shares the same coordinate.
// Best match per axis: among all candidate anchors within `threshold` of
// the moving anchor on the matched axis, pick the one CLOSEST in the
// perpendicular direction — so the guide always connects to the visually
// nearest actual point of the candidate. Primary delta only breaks perp
// ties.
//
// Why perp-first: a wall pre-rotation contributes anchors that share an
// exact X (vertical wall) or Z (horizontal wall), so primary deltas tie
// and perp picks the nearer endpoint. Post-rotation, the same wall's
// anchors are at slightly-different world coordinates after a float
// rotation — primary deltas differ by tiny amounts and a primary-first
// tie-break would lock onto whichever happens to be marginally tighter,
// often the far endpoint. Perp-first keeps the "closest point of
// reference" behaviour stable through rotation.
type Best = {
delta: number
primary: number
@@ -102,13 +195,13 @@ export function resolveAlignment(input: ResolveAlignmentInput): ResolveAlignment
const adz = Math.abs(dz)
if (
adx <= threshold &&
(bestX === null || adx < bestX.primary || (adx === bestX.primary && adz < bestX.perp))
(bestX === null || adz < bestX.perp || (adz === bestX.perp && adx < bestX.primary))
) {
bestX = { delta: dx, primary: adx, perp: adz, m, c }
}
if (
adz <= threshold &&
(bestZ === null || adz < bestZ.primary || (adz === bestZ.primary && adx < bestZ.perp))
(bestZ === null || adx < bestZ.perp || (adx === bestZ.perp && adz < bestZ.primary))
) {
bestZ = { delta: dz, primary: adz, perp: adx, m, c }
}
+4
View File
@@ -3,11 +3,14 @@ export {
type AlignmentGuide,
type AlignmentGuideAxis,
type AnchorKind,
type BuildingPose,
bboxAnchors,
bboxCornerAnchors,
type ResolveAlignmentInBuildingResult,
type ResolveAlignmentInput,
type ResolveAlignmentResult,
resolveAlignment,
resolveAlignmentInBuildingWorld,
} from './alignment'
export {
collectAlignmentAnchors,
@@ -56,4 +59,5 @@ export {
snapScalar,
snapServices,
snapVec3ToGrid,
snapWorldXZToBuildingLocal,
} from './snap'
+47
View File
@@ -36,6 +36,53 @@ export function snapVec3ToGrid(point: Vec3, step: number = DEFAULT_GRID_STEP): V
return [snapScalar(point[0], step), point[1], snapScalar(point[2], step)]
}
/**
* Snap a world XZ point to the grid, then express it in the local frame of
* a building positioned at `buildingPosition` with rotation `buildingRotationY`
* (radians, around the Y axis). Returns both the snapped world point and its
* local-frame equivalent, so callers can render in either frame without
* recomputing the rotation.
*
* Use when a tool needs to keep snapping on the world grid (the grid the
* editor renders) even when the active building is rotated. Snapping in the
* building's local frame would otherwise chase the rotated axes and miss
* the visible grid lines.
*/
export function snapWorldXZToBuildingLocal(
worldX: number,
worldZ: number,
buildingPosition: Vec3,
buildingRotationY: number,
step: number = DEFAULT_GRID_STEP,
): { world: [number, number]; local: [number, number] } {
if (step <= 0) {
const dx = worldX - buildingPosition[0]
const dz = worldZ - buildingPosition[2]
const cos = Math.cos(buildingRotationY)
const sin = Math.sin(buildingRotationY)
return {
world: [worldX, worldZ],
local: [dx * cos - dz * sin, dx * sin + dz * cos],
}
}
const snappedWX = Math.round(worldX / step) * step
const snappedWZ = Math.round(worldZ / step) * step
const dx = snappedWX - buildingPosition[0]
const dz = snappedWZ - buildingPosition[2]
const cos = Math.cos(buildingRotationY)
const sin = Math.sin(buildingRotationY)
// The forward (local → world) rotation used in the editor is
// wx = bx + lx*cos + lz*sin
// wz = bz - lx*sin + lz*cos
// so the inverse (orthogonal, so transpose) is
// lx = dx*cos - dz*sin
// lz = dx*sin + dz*cos
return {
world: [snappedWX, snappedWZ],
local: [dx * cos - dz * sin, dx * sin + dz * cos],
}
}
// ─── Angle snap ───────────────────────────────────────────────────────
/**