Phase 5 Stage C continued: wall, door, window now in registry floor plan

Three remaining kinds at Stage C this session:

wall → C
 - buildWallFloorplan: uses ctx.siblings to gather other walls in the
   level, runs calculateLevelMiters, computes plan footprint via
   getWallPlanFootprint. Same visual output as legacy.
 - getFloorplanWall thickness exaggeration inlined (~25 lines from
   editor/lib/floorplan/walls.ts) to keep nodes/wall self-contained.
 - floorplan-panel.tsx's wallPolygons short-circuits to [] when wall
   is registered.
 - Performance note: recomputes level miter data per wall (O(N²) for N
   walls in a level). Acceptable for typical scenes; ctx.levelData?.
   miters optimization deferred to Stage B's wall design pass.

door → C
 - buildDoorFloorplan: inlines getOpeningFootprint math from
   floorplan-panel.tsx (40 lines, pure math). Uses ctx.parent as the
   wall to compute direction + perpendicular for the cutout footprint.
 - Returns null when parent isn't a wall (orphaned doors during
   placement).

window → C
 - buildWindowFloorplan: same shape as door, glass-blue tint to
   distinguish visually.

Both share the legacy openingsPolygons gating:
 - floorplan-panel.tsx's openingsPolygons useMemo filters per kind so
   a partial migration still works (e.g., if only door registers, only
   doors get skipped). When both registered, returns [] entirely.

Item C intentionally deferred — needs parent-chain transform helpers
(buildFloorplanItemEntry / getItemFloorplanTransform from editor/lib/
floorplan/items.ts) exposed publicly or moved into core. A focused
session is the right place to design that boundary.

Stage B for door / window / wall still pending — each is a focused
session per kind (large geometry math extractions, wall needs ctx.
levelData design).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Wassim SAMAD
2026-05-15 16:43:53 -04:00
co-authored by Claude Opus 4.7
parent 969b154b08
commit 9bcb25d0aa
7 changed files with 274 additions and 124 deletions
+10 -2
View File
@@ -1,4 +1,5 @@
import type { NodeDefinition } from '@pascal-app/core'
import { buildWindowFloorplan } from './floorplan'
import { windowParametrics } from './parametrics'
import { WindowNode } from './schema'
@@ -6,8 +7,12 @@ import { WindowNode } from './schema'
* Window — Phase 5 batch kind. Mirrors door's shape: hosted on walls,
* cuts holes in them, animated open/close state for opening windows.
*
* Capabilities: no `movable` (wall-bound drag is bespoke). Tool field
* absent (legacy WindowTool / MoveWindowTool continue).
* Stages:
* - A: registered.
* - B: deferred — window geometry ~800 lines; extraction is a focused
* session. `def.renderer` + `def.system` wrap-export legacy.
* - C: `def.floorplan` polygon sits in parent wall's cutout. Legacy
* `openingPolygons` short-circuits window entries when registered.
*/
export const windowDefinition: NodeDefinition<typeof WindowNode> = {
kind: 'window',
@@ -39,6 +44,9 @@ export const windowDefinition: NodeDefinition<typeof WindowNode> = {
module: () => import('./system'),
priority: 3,
},
// Stage C: floor-plan polygon. ctx.parent gives the wall for direction
// + thickness — same shape as door.
floorplan: buildWindowFloorplan,
toolHints: [
{ key: 'Left click', label: 'Place window on wall' },
+56
View File
@@ -0,0 +1,56 @@
import type {
FloorplanGeometry,
FloorplanPoint,
GeometryContext,
WallNode,
WindowNode,
} from '@pascal-app/core'
/**
* Stage C floor-plan builder for window. Mirrors door's shape — window
* polygon sits in the wall's cutout, width along wall, depth = wall
* thickness. Visually distinct via a glass-blue tint.
*/
export function buildWindowFloorplan(
node: WindowNode,
ctx: GeometryContext,
): FloorplanGeometry | null {
const wall = ctx.parent as WallNode | null
if (!wall || wall.type !== 'wall') return null
const [x1, z1] = wall.start
const [x2, z2] = wall.end
const dx = x2 - x1
const dz = z2 - z1
const length = Math.sqrt(dx * dx + dz * dz)
if (length < 1e-9) return null
const dirX = dx / length
const dirZ = dz / length
const perpX = -dirZ
const perpZ = dirX
const distance = node.position[0]
const width = node.width
const depth = wall.thickness ?? 0.1
const cx = x1 + dirX * distance
const cz = z1 + dirZ * distance
const halfWidth = width / 2
const halfDepth = depth / 2
const points: readonly FloorplanPoint[] = [
[cx - dirX * halfWidth + perpX * halfDepth, cz - dirZ * halfWidth + perpZ * halfDepth],
[cx + dirX * halfWidth + perpX * halfDepth, cz + dirZ * halfWidth + perpZ * halfDepth],
[cx + dirX * halfWidth - perpX * halfDepth, cz + dirZ * halfWidth - perpZ * halfDepth],
[cx - dirX * halfWidth - perpX * halfDepth, cz - dirZ * halfWidth - perpZ * halfDepth],
]
return {
kind: 'polygon',
points,
fill: '#bae6fd',
stroke: '#0c4a6e',
strokeWidth: 0.015,
opacity: 0.8,
}
}