feat(mcp,editor): Option A+B storage + 10 agent deliverables (Phase 7)

Ships the combined filesystem/Supabase storage adapter + MCP scene
lifecycle tools + Next.js API routes + editor /scene/[id] route, so
an MCP save is directly openable at /scene/<id> without any
injection hack. End-to-end verified: 10/10 e2e steps pass.

Storage (A1/A2/A3):
- SceneStore interface + error classes + slug helpers
- FilesystemSceneStore at $PASCAL_DATA_DIR (defaults XDG/~/.pascal)
  with atomic writes, .index sidecar, optimistic locking
- SupabaseSceneStore with scenes + scene_revisions tables, RLS
  migration SQL, mock-backed unit tests
- createSceneStore(env) auto-selects based on SUPABASE_URL +
  SUPABASE_SERVICE_ROLE_KEY

MCP tools (A4, A8, A9, A10):
- save_scene / load_scene / list_scenes / delete_scene / rename_scene
- list_templates / create_from_template (3 seed templates:
  empty-studio, two-bedroom, garden-house)
- generate_variants (7 mutation kinds, seeded RNG, save=true|false)
- photo_to_scene (vision sampling → scene graph → save)

Editor (A5, A6):
- /api/scenes + /api/scenes/[id] with RFC 7232 If-Match locking
- /scene/[id] and /scenes route pages with save button, SceneLoader
- Removed the window.__pascalScene dev injection hack

Security + UX edges (A7, A8):
- AssetUrl Zod validator: asset:// blob: data:image/ /path https:
  (http://localhost for dev) + PASCAL_ALLOWED_ASSET_ORIGINS env
  allowlist. Hardens scan.url, guide.url, item.asset.src,
  material.texture.url, MaterialMaps.*Map
- Auto-frame camera on empty→non-empty scene transition
  (camera-controls:fit-scene emitter event)

Shared utilities:
- rehydrateSiteChildren() extracted to packages/mcp/src/lib/ and
  used by both create-from-template and generate-variants to work
  around the SiteNode.children-as-objects vs. ids inconsistency
  (CROSS_CUTTING §2)
- Storage + MCP subpath exports added to packages/mcp/package.json
  (CROSS_CUTTING §4)

Tests: 293 pass / 0 fail across 40 files (was 142 pre-Phase-7).
Biome: clean.

Phase-7 e2e script at packages/mcp/test-reports/phase7-e2e.ts:
MCP HTTP + editor Next.js both point at $PASCAL_DATA_DIR =
/tmp/pascal-e2e, save_scene from MCP, GET /api/scenes/<id> from
editor server, /scenes list page renders all saved scenes, scene
page renders SceneLoader, delete_scene works.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Adrian Perez
2026-04-18 19:29:28 +02:00
co-authored by Claude Opus 4.7
parent 42bd05db9c
commit e8d0b13ff5
81 changed files with 8933 additions and 1213 deletions
+264
View File
@@ -0,0 +1,264 @@
import type { SceneGraph } from '@pascal-app/core/clone-scene-graph'
import type { AnyNode, AnyNodeId } from '@pascal-app/core/schema'
/**
* 40 m² studio apartment — a single open room with one window, one front door
* and a single "Living/Kitchen" zone. Used as a starting point for small unit
* briefs. Deterministic ids (`site_empty`, `building_empty`, `level_0`, etc.)
* are regenerated by the MCP tool via `cloneSceneGraph` before applying.
*/
// Footprint: 8 m × 5 m = 40 m² (centered at origin).
// Walls traverse the boundary counter-clockwise (right-handed XZ plane).
const W = 4 // half-width
const D = 2.5 // half-depth
type StudioNodes = {
site: AnyNode
building: AnyNode
level: AnyNode
walls: AnyNode[]
zone: AnyNode
door: AnyNode
window: AnyNode
}
function buildNodes(): StudioNodes {
const site: AnyNode = {
object: 'node',
id: 'site_empty' as AnyNodeId,
type: 'site',
parentId: null,
visible: true,
metadata: {},
polygon: {
type: 'polygon',
points: [
[-15, -15],
[15, -15],
[15, 15],
[-15, 15],
],
},
children: ['building_empty' as AnyNodeId],
} as unknown as AnyNode
const building: AnyNode = {
object: 'node',
id: 'building_empty' as AnyNodeId,
type: 'building',
parentId: 'site_empty' as AnyNodeId,
visible: true,
metadata: {},
position: [0, 0, 0],
rotation: [0, 0, 0],
children: ['level_0' as AnyNodeId],
} as unknown as AnyNode
// Walls with deterministic ids; child ids are listed below after doors/windows
// are created, so we fill this array after computing them.
const wallIds = ['wall_n', 'wall_e', 'wall_s', 'wall_w'] as const
// South wall carries the front door; west wall carries the window.
const door: AnyNode = {
object: 'node',
id: 'door_front' as AnyNodeId,
type: 'door',
parentId: 'wall_s' as AnyNodeId,
visible: true,
metadata: {},
wallId: 'wall_s',
position: [0, 1.05, 0],
rotation: [0, 0, 0],
width: 0.9,
height: 2.1,
frameThickness: 0.05,
frameDepth: 0.07,
threshold: true,
thresholdHeight: 0.02,
hingesSide: 'left',
swingDirection: 'inward',
segments: [
{
type: 'panel',
heightRatio: 0.4,
columnRatios: [1],
dividerThickness: 0.03,
panelDepth: 0.01,
panelInset: 0.04,
},
{
type: 'panel',
heightRatio: 0.6,
columnRatios: [1],
dividerThickness: 0.03,
panelDepth: 0.01,
panelInset: 0.04,
},
],
handle: true,
handleHeight: 1.05,
handleSide: 'right',
contentPadding: [0.04, 0.04],
doorCloser: false,
panicBar: false,
panicBarHeight: 1.0,
} as unknown as AnyNode
const windowNode: AnyNode = {
object: 'node',
id: 'window_w' as AnyNodeId,
type: 'window',
parentId: 'wall_w' as AnyNodeId,
visible: true,
metadata: {},
wallId: 'wall_w',
position: [0, 1.2, 0],
rotation: [0, 0, 0],
width: 1.5,
height: 1.2,
frameThickness: 0.05,
frameDepth: 0.07,
columnRatios: [1],
rowRatios: [1],
columnDividerThickness: 0.03,
rowDividerThickness: 0.03,
sill: true,
sillDepth: 0.08,
sillThickness: 0.03,
} as unknown as AnyNode
const wallNorth: AnyNode = {
object: 'node',
id: 'wall_n' as AnyNodeId,
type: 'wall',
parentId: 'level_0' as AnyNodeId,
visible: true,
metadata: {},
children: [],
thickness: 0.1,
height: 2.5,
start: [-W, -D],
end: [W, -D],
frontSide: 'unknown',
backSide: 'unknown',
} as unknown as AnyNode
const wallEast: AnyNode = {
object: 'node',
id: 'wall_e' as AnyNodeId,
type: 'wall',
parentId: 'level_0' as AnyNodeId,
visible: true,
metadata: {},
children: [],
thickness: 0.1,
height: 2.5,
start: [W, -D],
end: [W, D],
frontSide: 'unknown',
backSide: 'unknown',
} as unknown as AnyNode
const wallSouth: AnyNode = {
object: 'node',
id: 'wall_s' as AnyNodeId,
type: 'wall',
parentId: 'level_0' as AnyNodeId,
visible: true,
metadata: {},
children: ['door_front'],
thickness: 0.1,
height: 2.5,
start: [W, D],
end: [-W, D],
frontSide: 'unknown',
backSide: 'unknown',
} as unknown as AnyNode
const wallWest: AnyNode = {
object: 'node',
id: 'wall_w' as AnyNodeId,
type: 'wall',
parentId: 'level_0' as AnyNodeId,
visible: true,
metadata: {},
children: ['window_w'],
thickness: 0.1,
height: 2.5,
start: [-W, D],
end: [-W, -D],
frontSide: 'unknown',
backSide: 'unknown',
} as unknown as AnyNode
const zone: AnyNode = {
object: 'node',
id: 'zone_living' as AnyNodeId,
type: 'zone',
parentId: 'level_0' as AnyNodeId,
visible: true,
metadata: {},
name: 'Living / Kitchen',
color: '#60a5fa',
polygon: [
[-W, -D],
[W, -D],
[W, D],
[-W, D],
],
} as unknown as AnyNode
const level: AnyNode = {
object: 'node',
id: 'level_0' as AnyNodeId,
type: 'level',
parentId: 'building_empty' as AnyNodeId,
visible: true,
metadata: {},
level: 0,
children: [...wallIds, 'zone_living'] as AnyNodeId[],
} as unknown as AnyNode
return {
site,
building,
level,
walls: [wallNorth, wallEast, wallSouth, wallWest],
zone,
door,
window: windowNode,
}
}
function buildTemplate(): SceneGraph {
const n = buildNodes()
const nodes: Record<AnyNodeId, AnyNode> = {}
for (const node of [n.site, n.building, n.level, ...n.walls, n.zone, n.door, n.window]) {
nodes[node.id as AnyNodeId] = node
}
// SiteNode.children is a discriminatedUnion of BuildingNode/ItemNode objects
// (not string ids) — so the site must embed the full building node. The
// rest of the tree uses string ids per the BaseNode/LevelNode/WallNode
// schemas. We mutate the flat-dict copy of the site here so the nested
// representation round-trips through AnyNode.safeParse.
const siteInDict = nodes['site_empty' as AnyNodeId] as unknown as {
children: unknown[]
}
siteInDict.children = [nodes['building_empty' as AnyNodeId]]
return {
nodes,
rootNodeIds: ['site_empty'] as AnyNodeId[],
}
}
export const template: SceneGraph = buildTemplate()
export const metadata = {
id: 'empty-studio',
name: 'Empty studio',
description:
'40 m² single-room studio apartment: 4 walls, 1 living/kitchen zone, 1 window, 1 front door.',
} as const
+283
View File
@@ -0,0 +1,283 @@
import type { SceneGraph } from '@pascal-app/core/clone-scene-graph'
import type { AnyNode, AnyNodeId } from '@pascal-app/core/schema'
/**
* "Garden house" — a simplified take on the Casa del Sol layout used in the
* MCP research fixtures.
*
* Footprint: 12 m × 8 m house centered at the origin, with a 12 m × 6 m
* back garden zone immediately to the north of the house, surrounded by a
* privacy fence on three sides.
*
* Contents:
* - 4 perimeter walls around the house
* - 1 front door (south wall), 1 large garden door (north wall)
* - 2 windows on the south wall, 1 window on each of east and west
* - 1 indoor "living" zone, 1 outdoor "garden" zone
* - 3 fence segments bounding the north/east/west of the garden
*/
const HOUSE_W = 6 // half-width of the house (12 m total)
const HOUSE_D = 4 // half-depth of the house (8 m total)
const GARDEN_DEPTH = 6 // depth of the back-garden zone along +z direction
const WALL_THICKNESS = 0.15
const WALL_HEIGHT = 2.7
type NodeMap = Record<string, AnyNode>
function wall(
id: string,
start: [number, number],
end: [number, number],
children: string[] = [],
): AnyNode {
return {
object: 'node',
id,
type: 'wall',
parentId: 'level_0',
visible: true,
metadata: {},
children,
thickness: WALL_THICKNESS,
height: WALL_HEIGHT,
start,
end,
frontSide: 'unknown',
backSide: 'unknown',
} as unknown as AnyNode
}
function door(id: string, parentWallId: string, width = 0.9): AnyNode {
return {
object: 'node',
id,
type: 'door',
parentId: parentWallId,
visible: true,
metadata: {},
wallId: parentWallId,
position: [0, 1.05, 0],
rotation: [0, 0, 0],
width,
height: 2.1,
frameThickness: 0.05,
frameDepth: 0.07,
threshold: true,
thresholdHeight: 0.02,
hingesSide: 'left',
swingDirection: 'inward',
segments: [
{
type: 'panel',
heightRatio: 0.5,
columnRatios: [1],
dividerThickness: 0.03,
panelDepth: 0.01,
panelInset: 0.04,
},
{
type: 'panel',
heightRatio: 0.5,
columnRatios: [1],
dividerThickness: 0.03,
panelDepth: 0.01,
panelInset: 0.04,
},
],
handle: true,
handleHeight: 1.05,
handleSide: 'right',
contentPadding: [0.04, 0.04],
doorCloser: false,
panicBar: false,
panicBarHeight: 1.0,
} as unknown as AnyNode
}
function makeWindow(id: string, parentWallId: string, width = 1.2): AnyNode {
return {
object: 'node',
id,
type: 'window',
parentId: parentWallId,
visible: true,
metadata: {},
wallId: parentWallId,
position: [0, 1.2, 0],
rotation: [0, 0, 0],
width,
height: 1.2,
frameThickness: 0.05,
frameDepth: 0.07,
columnRatios: [1],
rowRatios: [1],
columnDividerThickness: 0.03,
rowDividerThickness: 0.03,
sill: true,
sillDepth: 0.08,
sillThickness: 0.03,
} as unknown as AnyNode
}
function fence(id: string, start: [number, number], end: [number, number]): AnyNode {
return {
object: 'node',
id,
type: 'fence',
parentId: 'level_0',
visible: true,
metadata: {},
start,
end,
height: 1.8,
thickness: 0.08,
baseHeight: 0.22,
postSpacing: 2,
postSize: 0.1,
topRailHeight: 0.04,
groundClearance: 0,
edgeInset: 0.015,
baseStyle: 'grounded',
color: '#f3f4f6',
style: 'privacy',
} as unknown as AnyNode
}
function buildTemplate(): SceneGraph {
const nodes: NodeMap = {}
nodes.site_garden = {
object: 'node',
id: 'site_garden',
type: 'site',
parentId: null,
visible: true,
metadata: {},
polygon: {
type: 'polygon',
points: [
[-15, -15],
[15, -15],
[15, 15],
[-15, 15],
],
},
children: ['building_garden'],
} as unknown as AnyNode
nodes.building_garden = {
object: 'node',
id: 'building_garden',
type: 'building',
parentId: 'site_garden',
visible: true,
metadata: {},
position: [0, 0, 0],
rotation: [0, 0, 0],
children: ['level_0'],
} as unknown as AnyNode
// Openings
nodes.door_front = door('door_front', 'wall_s', 1.0)
nodes.door_garden = door('door_garden', 'wall_n', 1.6)
nodes.window_s1 = makeWindow('window_s1', 'wall_s', 1.2)
nodes.window_s2 = makeWindow('window_s2', 'wall_s', 1.2)
nodes.window_e = makeWindow('window_e', 'wall_e', 1.0)
nodes.window_w = makeWindow('window_w', 'wall_w', 1.0)
// House perimeter (south is front, north opens to the garden)
nodes.wall_n = wall('wall_n', [-HOUSE_W, -HOUSE_D], [HOUSE_W, -HOUSE_D], ['door_garden'])
nodes.wall_e = wall('wall_e', [HOUSE_W, -HOUSE_D], [HOUSE_W, HOUSE_D], ['window_e'])
nodes.wall_s = wall(
'wall_s',
[HOUSE_W, HOUSE_D],
[-HOUSE_W, HOUSE_D],
['door_front', 'window_s1', 'window_s2'],
)
nodes.wall_w = wall('wall_w', [-HOUSE_W, HOUSE_D], [-HOUSE_W, -HOUSE_D], ['window_w'])
// Zones
nodes.zone_living = {
object: 'node',
id: 'zone_living',
type: 'zone',
parentId: 'level_0',
visible: true,
metadata: {},
name: 'Living',
color: '#60a5fa',
polygon: [
[-HOUSE_W, -HOUSE_D],
[HOUSE_W, -HOUSE_D],
[HOUSE_W, HOUSE_D],
[-HOUSE_W, HOUSE_D],
],
} as unknown as AnyNode
nodes.zone_garden = {
object: 'node',
id: 'zone_garden',
type: 'zone',
parentId: 'level_0',
visible: true,
metadata: {},
name: 'Back garden',
color: '#86efac',
polygon: [
[-HOUSE_W, -HOUSE_D - GARDEN_DEPTH],
[HOUSE_W, -HOUSE_D - GARDEN_DEPTH],
[HOUSE_W, -HOUSE_D],
[-HOUSE_W, -HOUSE_D],
],
} as unknown as AnyNode
// Privacy fence along 3 sides of the garden.
nodes.fence_n = fence(
'fence_n',
[-HOUSE_W, -HOUSE_D - GARDEN_DEPTH],
[HOUSE_W, -HOUSE_D - GARDEN_DEPTH],
)
nodes.fence_e = fence('fence_e', [HOUSE_W, -HOUSE_D - GARDEN_DEPTH], [HOUSE_W, -HOUSE_D])
nodes.fence_w = fence('fence_w', [-HOUSE_W, -HOUSE_D], [-HOUSE_W, -HOUSE_D - GARDEN_DEPTH])
nodes.level_0 = {
object: 'node',
id: 'level_0',
type: 'level',
parentId: 'building_garden',
visible: true,
metadata: {},
level: 0,
children: [
'wall_n',
'wall_e',
'wall_s',
'wall_w',
'zone_living',
'zone_garden',
'fence_n',
'fence_e',
'fence_w',
],
} as unknown as AnyNode
// SiteNode.children is a discriminatedUnion of BuildingNode/ItemNode objects
// (not string ids) per the schema — embed the full building node here.
;(nodes.site_garden as unknown as { children: unknown[] }).children = [nodes.building_garden!]
return {
nodes: nodes as Record<AnyNodeId, AnyNode>,
rootNodeIds: ['site_garden'] as AnyNodeId[],
}
}
export const template: SceneGraph = buildTemplate()
export const metadata = {
id: 'garden-house',
name: 'Garden house',
description:
'12 × 8 m single-level house with a fenced back-garden zone; 4 walls, 2 doors, 4 windows, 3 privacy fences.',
} as const
+41
View File
@@ -0,0 +1,41 @@
import type { SceneGraph } from '@pascal-app/core/clone-scene-graph'
import * as emptyStudio from './empty-studio'
import * as gardenHouse from './garden-house'
import * as twoBedroom from './two-bedroom'
export type TemplateMetadata = {
id: string
name: string
description: string
}
export type TemplateEntry = {
/** Stable template id used by `create_from_template`. */
id: string
name: string
description: string
/** Static SceneGraph — ids are placeholders; regenerate via `cloneSceneGraph`. */
template: SceneGraph
}
function makeEntry(template: SceneGraph, metadata: TemplateMetadata): TemplateEntry {
return {
id: metadata.id,
name: metadata.name,
description: metadata.description,
template,
}
}
export const TEMPLATES = {
'empty-studio': makeEntry(emptyStudio.template, emptyStudio.metadata),
'two-bedroom': makeEntry(twoBedroom.template, twoBedroom.metadata),
'garden-house': makeEntry(gardenHouse.template, gardenHouse.metadata),
} as const
export type TemplateId = keyof typeof TEMPLATES
/** Type guard for external callers that receive arbitrary string ids. */
export function isTemplateId(id: string): id is TemplateId {
return Object.hasOwn(TEMPLATES, id)
}
@@ -0,0 +1,85 @@
import { describe, expect, test } from 'bun:test'
import { AnyNode } from '@pascal-app/core/schema'
import { TEMPLATES, type TemplateId } from './index'
describe('scene templates', () => {
const ids: TemplateId[] = Object.keys(TEMPLATES) as TemplateId[]
for (const id of ids) {
const entry = TEMPLATES[id]
test(`${id} has required metadata`, () => {
expect(entry.id).toBe(id)
expect(typeof entry.name).toBe('string')
expect(entry.name.length).toBeGreaterThan(0)
expect(typeof entry.description).toBe('string')
expect(entry.description.length).toBeGreaterThan(0)
})
test(`${id} template nodes all pass AnyNode.safeParse`, () => {
const { nodes, rootNodeIds } = entry.template
expect(rootNodeIds.length).toBeGreaterThan(0)
expect(Object.keys(nodes).length).toBeGreaterThan(0)
for (const [nodeId, node] of Object.entries(nodes)) {
const res = AnyNode.safeParse(node)
if (!res.success) {
// Surface the path/message of the first issue for debuggability.
const first = res.error.issues[0]
throw new Error(
`template ${id} node ${nodeId} failed AnyNode.safeParse at ${first?.path.join('.')}: ${first?.message}`,
)
}
expect(res.success).toBe(true)
}
})
test(`${id} root ids resolve and parent links point to existing nodes`, () => {
const { nodes, rootNodeIds } = entry.template
for (const rid of rootNodeIds) {
expect(nodes[rid]).toBeDefined()
}
for (const node of Object.values(nodes)) {
if (node.parentId && !(node.parentId in nodes)) {
throw new Error(
`template ${id} node ${node.id} has parentId ${node.parentId} which does not exist`,
)
}
}
})
}
test('empty-studio has 4 walls, 1 zone, 1 door, 1 window', () => {
const { nodes } = TEMPLATES['empty-studio'].template
const byType = groupByType(nodes)
expect(byType.wall ?? 0).toBe(4)
expect(byType.zone ?? 0).toBe(1)
expect(byType.door ?? 0).toBe(1)
expect(byType.window ?? 0).toBe(1)
})
test('two-bedroom has 9 walls, 4 zones, 4 doors, 5 windows', () => {
const { nodes } = TEMPLATES['two-bedroom'].template
const byType = groupByType(nodes)
expect(byType.wall ?? 0).toBe(9)
expect(byType.zone ?? 0).toBe(4)
expect(byType.door ?? 0).toBe(4)
expect(byType.window ?? 0).toBe(5)
})
test('garden-house has a fenced garden zone', () => {
const { nodes } = TEMPLATES['garden-house'].template
const byType = groupByType(nodes)
expect(byType.zone ?? 0).toBeGreaterThanOrEqual(2)
expect(byType.fence ?? 0).toBeGreaterThanOrEqual(3)
expect(byType.wall ?? 0).toBeGreaterThanOrEqual(4)
})
})
function groupByType(nodes: Record<string, { type: string }>): Record<string, number> {
const out: Record<string, number> = {}
for (const node of Object.values(nodes)) {
out[node.type] = (out[node.type] ?? 0) + 1
}
return out
}
+311
View File
@@ -0,0 +1,311 @@
import type { SceneGraph } from '@pascal-app/core/clone-scene-graph'
import type { AnyNode, AnyNodeId } from '@pascal-app/core/schema'
/**
* 80 m² two-bedroom apartment.
*
* Footprint: 10 m × 8 m = 80 m², centered near the origin.
* Contents: 9 walls (4 perimeter + 5 interior), 4 zones
* (living/kitchen, bedroom1, bedroom2, bath), 4 doors (front + 3 interior),
* 5 windows (2 on the living/kitchen, 1 per bedroom, 1 on the bath).
* Interior partitions split the north half into two bedrooms and a bath.
*
* Coordinate system: `[x, z]` on the XZ plane, with `x` running east/west
* and `z` running north/south (positive z points south).
*/
// Perimeter extents: 10 m × 8 m.
const X_MIN = -5
const X_MAX = 5
const Z_MIN = -4
const Z_MAX = 4
// Interior split lines.
const CORRIDOR_Z = 0 // horizontal wall separating north half (bedrooms+bath) from south (living)
const BED_X = -1 // vertical wall between bedroom 1 (west) and bath (east of it)
const BATH_X = 2 // vertical wall between bath (middle) and bedroom 2 (east)
const WALL_THICKNESS = 0.1
const WALL_HEIGHT = 2.5
type NodeMap = Record<string, AnyNode>
function wall(
id: string,
start: [number, number],
end: [number, number],
children: string[] = [],
): AnyNode {
return {
object: 'node',
id,
type: 'wall',
parentId: 'level_0',
visible: true,
metadata: {},
children,
thickness: WALL_THICKNESS,
height: WALL_HEIGHT,
start,
end,
frontSide: 'unknown',
backSide: 'unknown',
} as unknown as AnyNode
}
function door(id: string, parentWallId: string): AnyNode {
return {
object: 'node',
id,
type: 'door',
parentId: parentWallId,
visible: true,
metadata: {},
wallId: parentWallId,
position: [0, 1.05, 0],
rotation: [0, 0, 0],
width: 0.8,
height: 2.1,
frameThickness: 0.05,
frameDepth: 0.07,
threshold: true,
thresholdHeight: 0.02,
hingesSide: 'left',
swingDirection: 'inward',
segments: [
{
type: 'panel',
heightRatio: 0.5,
columnRatios: [1],
dividerThickness: 0.03,
panelDepth: 0.01,
panelInset: 0.04,
},
{
type: 'panel',
heightRatio: 0.5,
columnRatios: [1],
dividerThickness: 0.03,
panelDepth: 0.01,
panelInset: 0.04,
},
],
handle: true,
handleHeight: 1.05,
handleSide: 'right',
contentPadding: [0.04, 0.04],
doorCloser: false,
panicBar: false,
panicBarHeight: 1.0,
} as unknown as AnyNode
}
function makeWindow(id: string, parentWallId: string, width = 1.2): AnyNode {
return {
object: 'node',
id,
type: 'window',
parentId: parentWallId,
visible: true,
metadata: {},
wallId: parentWallId,
position: [0, 1.2, 0],
rotation: [0, 0, 0],
width,
height: 1.2,
frameThickness: 0.05,
frameDepth: 0.07,
columnRatios: [1],
rowRatios: [1],
columnDividerThickness: 0.03,
rowDividerThickness: 0.03,
sill: true,
sillDepth: 0.08,
sillThickness: 0.03,
} as unknown as AnyNode
}
function buildTemplate(): SceneGraph {
const nodes: NodeMap = {}
// Root nodes
nodes.site_2br = {
object: 'node',
id: 'site_2br',
type: 'site',
parentId: null,
visible: true,
metadata: {},
polygon: {
type: 'polygon',
points: [
[-15, -15],
[15, -15],
[15, 15],
[-15, 15],
],
},
children: ['building_2br'],
} as unknown as AnyNode
nodes.building_2br = {
object: 'node',
id: 'building_2br',
type: 'building',
parentId: 'site_2br',
visible: true,
metadata: {},
position: [0, 0, 0],
rotation: [0, 0, 0],
children: ['level_0'],
} as unknown as AnyNode
// Openings — declared up front so walls can list them as children.
nodes.door_front = door('door_front', 'wall_s')
nodes.door_bed1 = door('door_bed1', 'wall_corr_1')
nodes.door_bath = door('door_bath', 'wall_corr_2')
nodes.door_bed2 = door('door_bed2', 'wall_corr_3')
nodes.window_living_a = makeWindow('window_living_a', 'wall_s', 1.5)
nodes.window_living_b = makeWindow('window_living_b', 'wall_e', 1.2)
nodes.window_bed1 = makeWindow('window_bed1', 'wall_n', 1.2)
nodes.window_bath = makeWindow('window_bath', 'wall_n', 0.6)
nodes.window_bed2 = makeWindow('window_bed2', 'wall_n', 1.2)
// Perimeter walls (N, E, S, W) — 4 walls.
// Interior partitions — 5 walls (the east/west corridor wall is split into
// three segments by the two vertical partitions so doors have a clear host).
nodes.wall_n = wall(
'wall_n',
[X_MIN, Z_MIN],
[X_MAX, Z_MIN],
['window_bed1', 'window_bath', 'window_bed2'],
)
nodes.wall_e = wall('wall_e', [X_MAX, Z_MIN], [X_MAX, Z_MAX], ['window_living_b'])
nodes.wall_s = wall('wall_s', [X_MAX, Z_MAX], [X_MIN, Z_MAX], ['door_front', 'window_living_a'])
nodes.wall_w = wall('wall_w', [X_MIN, Z_MAX], [X_MIN, Z_MIN])
// Corridor wall is broken into 3 segments so each has its own interior door.
// Segment 1: from west to BED_X (bedroom-1 wall)
nodes.wall_corr_1 = wall('wall_corr_1', [X_MIN, CORRIDOR_Z], [BED_X, CORRIDOR_Z], ['door_bed1'])
// Segment 2: from BED_X to BATH_X (bath wall)
nodes.wall_corr_2 = wall('wall_corr_2', [BED_X, CORRIDOR_Z], [BATH_X, CORRIDOR_Z], ['door_bath'])
// Segment 3: from BATH_X to east (bedroom-2 wall)
nodes.wall_corr_3 = wall('wall_corr_3', [BATH_X, CORRIDOR_Z], [X_MAX, CORRIDOR_Z], ['door_bed2'])
// Two vertical partitions between the three north rooms.
nodes.wall_part_1 = wall('wall_part_1', [BED_X, Z_MIN], [BED_X, CORRIDOR_Z])
nodes.wall_part_2 = wall('wall_part_2', [BATH_X, Z_MIN], [BATH_X, CORRIDOR_Z])
// Zones: one per room.
nodes.zone_living = {
object: 'node',
id: 'zone_living',
type: 'zone',
parentId: 'level_0',
visible: true,
metadata: {},
name: 'Living / Kitchen',
color: '#60a5fa',
polygon: [
[X_MIN, CORRIDOR_Z],
[X_MAX, CORRIDOR_Z],
[X_MAX, Z_MAX],
[X_MIN, Z_MAX],
],
} as unknown as AnyNode
nodes.zone_bed1 = {
object: 'node',
id: 'zone_bed1',
type: 'zone',
parentId: 'level_0',
visible: true,
metadata: {},
name: 'Bedroom 1',
color: '#f472b6',
polygon: [
[X_MIN, Z_MIN],
[BED_X, Z_MIN],
[BED_X, CORRIDOR_Z],
[X_MIN, CORRIDOR_Z],
],
} as unknown as AnyNode
nodes.zone_bath = {
object: 'node',
id: 'zone_bath',
type: 'zone',
parentId: 'level_0',
visible: true,
metadata: {},
name: 'Bath',
color: '#a7f3d0',
polygon: [
[BED_X, Z_MIN],
[BATH_X, Z_MIN],
[BATH_X, CORRIDOR_Z],
[BED_X, CORRIDOR_Z],
],
} as unknown as AnyNode
nodes.zone_bed2 = {
object: 'node',
id: 'zone_bed2',
type: 'zone',
parentId: 'level_0',
visible: true,
metadata: {},
name: 'Bedroom 2',
color: '#fcd34d',
polygon: [
[BATH_X, Z_MIN],
[X_MAX, Z_MIN],
[X_MAX, CORRIDOR_Z],
[BATH_X, CORRIDOR_Z],
],
} as unknown as AnyNode
nodes.level_0 = {
object: 'node',
id: 'level_0',
type: 'level',
parentId: 'building_2br',
visible: true,
metadata: {},
level: 0,
children: [
'wall_n',
'wall_e',
'wall_s',
'wall_w',
'wall_corr_1',
'wall_corr_2',
'wall_corr_3',
'wall_part_1',
'wall_part_2',
'zone_living',
'zone_bed1',
'zone_bath',
'zone_bed2',
],
} as unknown as AnyNode
// SiteNode.children is a discriminatedUnion of BuildingNode/ItemNode objects
// (not string ids) per the schema — embed the full building node here.
;(nodes.site_2br as unknown as { children: unknown[] }).children = [nodes.building_2br!]
return {
nodes: nodes as Record<AnyNodeId, AnyNode>,
rootNodeIds: ['site_2br'] as AnyNodeId[],
}
}
export const template: SceneGraph = buildTemplate()
export const metadata = {
id: 'two-bedroom',
name: 'Two-bedroom apartment',
description:
'80 m² two-bedroom flat: 9 walls, 4 zones (living/kitchen, 2 bedrooms, bath), 4 doors and 5 windows.',
} as const