Skip to content

Commit abd6eee

Browse files
wass08claude
andauthored
viewer: light open rooms as outdoors, fix open-plan seams and T-junction wall faces (#1286)
* viewer: fix open-air room lighting, open-plan seams and T-junction wall faces - Light porches and rooms left open on a side as outdoors (`isOpenAirRoom`). Wall-detected rooms carry `enclosureStatus: 'enclosed'` whenever their boundary loop closes, so the check reads their unshared separators instead. - Light open-plan rooms as one space (`openPlanRoomGroups`): pool lamps and daylight per group and skip the opening portal between members, which drew a diagonal seam across the threshold. GLB export stamps `open` and `group`. - Count every junction closing point when tagging wall faces (`getWallJunctionClosing`). A T-junction at a wall's start can add two, which put the core material on the front face. Regression test included. - Order the shelf after the kitchen items in "Add to rooms". Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * viewer: write an open-plan group's pooled lamps once so switches reach every room Members of an open-plan group share one pooled lamp list. The data texture wrote it once per member while `lampTexel` kept only the last copy's address, so a lamp switch or time-of-day change updated one room and left the others on the old state. Each distinct lamp list now gets one range that every member's header points at. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 559c0d1 commit abd6eee

11 files changed

Lines changed: 513 additions & 35 deletions

File tree

‎packages/core/src/index.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,13 +476,15 @@ export {
476476
export {
477477
DECK_FLOOR_DROP,
478478
DECKING_THICKNESS,
479+
isOpenAirRoom,
479480
isOutdoorRoom,
480481
isOutdoorRoomType,
481482
nextOutdoorRoomName,
482483
OUTDOOR_ROOM_DEFAULTS,
483484
OUTDOOR_ROOM_TYPES,
484485
type OutdoorRoomDefaults,
485486
type OutdoorRoomType,
487+
openPlanRoomGroups,
486488
PORCH_FLOOR_DROP,
487489
} from './lib/outdoor-room'
488490
export {
@@ -1278,6 +1280,7 @@ export {
12781280
export {
12791281
DEFAULT_WALL_HEIGHT,
12801282
DEFAULT_WALL_THICKNESS,
1283+
getWallJunctionClosing,
12811284
getWallPlanFootprint,
12821285
getWallThickness,
12831286
} from './systems/wall/wall-footprint'

‎packages/core/src/lib/outdoor-room.test.ts‎

Lines changed: 165 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@ import { getWallThickness } from '../systems/wall/wall-footprint'
1111
import { planSeparatorInsertion } from '../systems/wall/wall-topology'
1212
import { beamBottomElevation } from './beam'
1313
import { FRAMING_POST_SIZES } from './framing-post'
14-
import { DECK_FLOOR_DROP, DECKING_THICKNESS, PORCH_FLOOR_DROP } from './outdoor-room'
14+
import {
15+
DECK_FLOOR_DROP,
16+
DECKING_THICKNESS,
17+
isOpenAirRoom,
18+
openPlanRoomGroups,
19+
PORCH_FLOOR_DROP,
20+
} from './outdoor-room'
1521
import { PORCH_POST_SETBACK } from './porch-framing'
1622
import { porchPartOf } from './porch-framing-sync'
1723
import { reconcileLevelStructure } from './structure-kernel'
@@ -552,3 +558,161 @@ describe('deleting a floor plate', () => {
552558
] as never)
553559
})
554560
})
561+
562+
describe('isOpenAirRoom', () => {
563+
const zone = (over: Partial<ZoneNode>): ZoneNode =>
564+
({
565+
type: 'zone',
566+
parentId: LEVEL,
567+
spaceRole: 'room',
568+
roomType: undefined,
569+
enclosureStatus: 'auto',
570+
boundaryWallIds: [],
571+
boundarySeparatorIds: [],
572+
...over,
573+
}) as unknown as ZoneNode
574+
575+
const map = (...list: ZoneNode[]) =>
576+
Object.fromEntries(list.map((z) => [z.id, z])) as Record<string, AnyNode>
577+
578+
test('an outdoor room type is open air, however it is covered', () => {
579+
for (const roomType of ['porch', 'deck', 'patio'] as const) {
580+
const z = zone({ id: `zone_${roomType}`, roomType })
581+
expect(isOpenAirRoom(map(z), z)).toBe(true)
582+
}
583+
})
584+
585+
test('an explicitly open room is open air; a hand-drawn enclosed one never is', () => {
586+
const open = zone({ id: 'zone_open', enclosureStatus: 'open' })
587+
expect(isOpenAirRoom(map(open), open)).toBe(true)
588+
// A person's `enclosed` on a hand-drawn zone wins even with open sides of its own.
589+
const sealed = zone({
590+
id: 'zone_sealed',
591+
enclosureStatus: 'enclosed',
592+
autoFromWalls: false,
593+
boundarySeparatorIds: ['separator_a'],
594+
})
595+
expect(isOpenAirRoom(map(sealed), sealed)).toBe(false)
596+
})
597+
598+
test('a room found from walls with its walls switched off is open air despite `enclosed`', () => {
599+
// The structure kernel stamps `enclosed` on every room whose boundary closes, open sides too:
600+
// one wall kept against the house, three sides open, a ceiling over it.
601+
const shed = zone({
602+
id: 'zone_shed',
603+
enclosureStatus: 'enclosed',
604+
autoFromWalls: true,
605+
boundaryWallIds: ['wall_house'] as never,
606+
boundarySeparatorIds: ['separator_n', 'separator_w', 'separator_s'],
607+
})
608+
expect(isOpenAirRoom(map(shed), shed)).toBe(true)
609+
// Walled all round, the same stamp still reads indoors.
610+
const walled = zone({
611+
id: 'zone_walled_auto',
612+
enclosureStatus: 'enclosed',
613+
autoFromWalls: true,
614+
})
615+
expect(isOpenAirRoom(map(walled), walled)).toBe(false)
616+
})
617+
618+
test('an auto room with no open side is not open air', () => {
619+
const z = zone({ id: 'zone_walled' })
620+
expect(isOpenAirRoom(map(z), z)).toBe(false)
621+
})
622+
623+
test('an open side no other room shares faces outside → open air', () => {
624+
const z = zone({ id: 'zone_terrace', boundarySeparatorIds: ['separator_out'] })
625+
expect(isOpenAirRoom(map(z), z)).toBe(true)
626+
})
627+
628+
test('an open side two rooms share is an interior threshold → not open air', () => {
629+
const a = zone({ id: 'zone_a', boundarySeparatorIds: ['separator_between'] })
630+
const b = zone({ id: 'zone_b', boundarySeparatorIds: ['separator_between'] })
631+
expect(isOpenAirRoom(map(a, b), a)).toBe(false)
632+
expect(isOpenAirRoom(map(a, b), b)).toBe(false)
633+
})
634+
635+
test('a separator shared only with a generic (non-room) zone still faces outside', () => {
636+
const room = zone({ id: 'zone_room', boundarySeparatorIds: ['separator_edge'] })
637+
const generic = zone({
638+
id: 'zone_site',
639+
spaceRole: 'generic',
640+
boundarySeparatorIds: ['separator_edge'],
641+
})
642+
expect(isOpenAirRoom(map(room, generic), room)).toBe(true)
643+
})
644+
645+
test('an open side shared with a room on another level does not seal this one', () => {
646+
const here = zone({ id: 'zone_here', boundarySeparatorIds: ['separator_x'] })
647+
const elsewhere = zone({
648+
id: 'zone_elsewhere',
649+
parentId: 'level_other',
650+
boundarySeparatorIds: ['separator_x'],
651+
})
652+
expect(isOpenAirRoom(map(here, elsewhere), here)).toBe(true)
653+
})
654+
})
655+
656+
describe('openPlanRoomGroups', () => {
657+
const zone = (over: Partial<ZoneNode>): ZoneNode =>
658+
({
659+
type: 'zone',
660+
parentId: LEVEL,
661+
spaceRole: 'room',
662+
roomType: undefined,
663+
enclosureStatus: 'auto',
664+
boundaryWallIds: [],
665+
boundarySeparatorIds: [],
666+
...over,
667+
}) as unknown as ZoneNode
668+
669+
const map = (...list: ZoneNode[]) =>
670+
Object.fromEntries(list.map((z) => [z.id, z])) as Record<string, AnyNode>
671+
672+
test('two indoor rooms sharing a separator are one group', () => {
673+
const a = zone({ id: 'zone_a', boundarySeparatorIds: ['separator_1'] })
674+
const b = zone({ id: 'zone_b', boundarySeparatorIds: ['separator_1'] })
675+
const groups = openPlanRoomGroups(map(a, b))
676+
expect(groups.get('zone_a')).toBe(groups.get('zone_b'))
677+
expect(groups.get('zone_a')).toBe('zone_a') // lowest id is the stable root
678+
})
679+
680+
test('a run of open-plan rooms collapses into one group (transitive)', () => {
681+
const a = zone({ id: 'zone_a', boundarySeparatorIds: ['sep_ab'] })
682+
const b = zone({ id: 'zone_b', boundarySeparatorIds: ['sep_ab', 'sep_bc'] })
683+
const c = zone({ id: 'zone_c', boundarySeparatorIds: ['sep_bc'] })
684+
const groups = openPlanRoomGroups(map(a, b, c))
685+
const root = groups.get('zone_a')
686+
expect(root).toBeDefined()
687+
expect(groups.get('zone_b')).toBe(root)
688+
expect(groups.get('zone_c')).toBe(root)
689+
})
690+
691+
test('a room standing on its own gets no group entry', () => {
692+
const a = zone({ id: 'zone_a', boundarySeparatorIds: ['sep_a'] })
693+
const b = zone({ id: 'zone_b', boundarySeparatorIds: ['sep_b'] })
694+
const groups = openPlanRoomGroups(map(a, b))
695+
expect(groups.has('zone_a')).toBe(false)
696+
expect(groups.has('zone_b')).toBe(false)
697+
})
698+
699+
test('an open-air room is never merged with the indoor room it opens onto', () => {
700+
// Shared separator, but the porch faces outside → it stays out of the group.
701+
const room = zone({ id: 'zone_room', boundarySeparatorIds: ['sep_shared'] })
702+
const porch = zone({
703+
id: 'zone_porch',
704+
roomType: 'porch',
705+
boundarySeparatorIds: ['sep_shared'],
706+
})
707+
const groups = openPlanRoomGroups(map(room, porch))
708+
expect(groups.has('zone_porch')).toBe(false)
709+
expect(groups.has('zone_room')).toBe(false) // nothing left to merge with
710+
})
711+
712+
test('rooms that share only a wall (no separator) are not grouped', () => {
713+
const a = zone({ id: 'zone_a', boundaryWallIds: ['wall_1'] })
714+
const b = zone({ id: 'zone_b', boundaryWallIds: ['wall_1'] })
715+
const groups = openPlanRoomGroups(map(a, b))
716+
expect(groups.size).toBe(0)
717+
})
718+
})

‎packages/core/src/lib/outdoor-room.ts‎

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,114 @@ export function isOutdoorRoom(zone: Pick<ZoneNode, 'roomType'>): boolean {
7171
return isOutdoorRoomType(zone.roomType)
7272
}
7373

74+
/** A room zone, as the lighting enclosure tests read it (type, placement and boundary separators). */
75+
type RoomZoneLike = {
76+
type?: string
77+
id?: string
78+
parentId?: string | null
79+
spaceRole?: string
80+
roomType?: string
81+
enclosureStatus?: string
82+
autoFromWalls?: boolean
83+
boundarySeparatorIds?: readonly string[]
84+
}
85+
86+
/**
87+
* Whether a room is open to the outside, so it should be lit and metered as outdoors — not as a
88+
* sealed interior — however it is covered. A covered porch, a deck, a patio, a room marked `open`,
89+
* or a room left open on a side (a wall switched off, a floor with no wall there) all read as open
90+
* air. A hand-drawn zone marked `enclosed` never does.
91+
*
92+
* The signal is the room's boundary separators (the open sides the room panel counts): a separator
93+
* two rooms share is an interior threshold between them, so a room is open to the outside only when
94+
* it has a separator that no other room on its level lists. A room found from walls carries
95+
* `enclosed` whenever its boundary loop closes — open sides included — so that stamp says nothing
96+
* about walls and is not read here.
97+
*/
98+
export function isOpenAirRoom(
99+
nodes: Record<string, RoomZoneLike | undefined>,
100+
zone: RoomZoneLike,
101+
): boolean {
102+
if (isOutdoorRoomType(zone.roomType)) return true
103+
if (zone.enclosureStatus === 'open') return true
104+
if (zone.enclosureStatus === 'enclosed' && !zone.autoFromWalls) return false
105+
const separators = zone.boundarySeparatorIds ?? []
106+
if (separators.length === 0) return false
107+
const shared = new Set<string>()
108+
for (const id in nodes) {
109+
const other = nodes[id]
110+
if (
111+
other?.type !== 'zone' ||
112+
other.id === zone.id ||
113+
other.parentId !== zone.parentId ||
114+
other.spaceRole !== 'room'
115+
)
116+
continue
117+
for (const sep of other.boundarySeparatorIds ?? []) shared.add(sep)
118+
}
119+
return separators.some((sep) => !shared.has(sep))
120+
}
121+
122+
/**
123+
* Indoor rooms joined by an open side into one open-plan space, so the lighting lights each group as
124+
* one room (a shared light set, no seam where an open threshold cuts a nook off a larger room)
125+
* rather than giving the nook its own imagined ceiling light. Keyed by zone id → a stable group id
126+
* (the lowest member id); only rooms that share a group with another appear. Open-air rooms are left
127+
* out — they are lit as outdoors — so an indoor room open onto a porch is never merged with it.
128+
*
129+
* Two indoor rooms are in one group when they list the same boundary separator (an open side with no
130+
* wall between them); the relation is transitive, so a run of open-plan rooms becomes one group.
131+
*/
132+
export function openPlanRoomGroups(
133+
nodes: Record<string, RoomZoneLike | undefined>,
134+
): Map<string, string> {
135+
const parent = new Map<string, string>()
136+
const find = (x: string): string => {
137+
let root = x
138+
while (parent.get(root) !== root) root = parent.get(root)!
139+
while (parent.get(x) !== root) {
140+
const next = parent.get(x)!
141+
parent.set(x, root)
142+
x = next
143+
}
144+
return root
145+
}
146+
const join = (a: string, b: string) => {
147+
const ra = find(a)
148+
const rb = find(b)
149+
if (ra === rb) return
150+
// Keep the lower id as the root so the group id is stable across rebuilds.
151+
if (ra < rb) parent.set(rb, ra)
152+
else parent.set(ra, rb)
153+
}
154+
const rooms: { id: string; seps: readonly string[] }[] = []
155+
for (const id in nodes) {
156+
const z = nodes[id]
157+
if (z?.type !== 'zone' || z.spaceRole !== 'room' || isOpenAirRoom(nodes, z)) continue
158+
const zid = z.id ?? id
159+
parent.set(zid, zid)
160+
rooms.push({ id: zid, seps: z.boundarySeparatorIds ?? [] })
161+
}
162+
// A separator is one node on one level, so rooms that list it are adjacent across that open side.
163+
const bySeparator = new Map<string, string[]>()
164+
for (const room of rooms)
165+
for (const sep of room.seps) {
166+
const list = bySeparator.get(sep)
167+
if (list) list.push(room.id)
168+
else bySeparator.set(sep, [room.id])
169+
}
170+
for (const ids of bySeparator.values())
171+
for (let i = 1; i < ids.length; i++) join(ids[0]!, ids[i]!)
172+
const groups = new Map<string, string>()
173+
for (const room of rooms) {
174+
const root = find(room.id)
175+
// Only rooms actually merged with another carry a group; singletons stay implicit.
176+
if (root !== room.id || rooms.some((r) => r.id !== room.id && find(r.id) === root))
177+
groups.set(room.id, root)
178+
}
179+
return groups
180+
}
181+
74182
/** "Porch", "Porch 2", …: the next free name for a room of `type` among `names`. */
75183
export function nextOutdoorRoomName(type: OutdoorRoomType, names: Iterable<string>): string {
76184
const base = OUTDOOR_ROOM_DEFAULTS[type].name

‎packages/core/src/systems/wall/wall-footprint.ts‎

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,21 @@ export function getWallPlanFootprint(wallNode: WallNode, miterData: WallMiterDat
7171
}
7272

7373
const polygon: Point2D[] = [pStartRight, pEndRight]
74-
if (endJunction) {
75-
polygon.push(...(endJunction.closingPath ?? [endJunction.closing ?? wallEnd]))
76-
}
74+
if (endJunction) polygon.push(...getWallJunctionClosing(endJunction, wallEnd))
7775
polygon.push(pEndLeft, pStartLeft)
78-
if (startJunction) {
79-
polygon.push(...(startJunction.closingPath ?? [startJunction.closing ?? wallStart]))
80-
}
76+
if (startJunction) polygon.push(...getWallJunctionClosing(startJunction, wallStart))
8177

8278
return polygon
8379
}
80+
81+
/**
82+
* The points that close a wall end at a junction in `getWallPlanFootprint`'s polygon: one point,
83+
* or several where a T-junction's closing path goes around the joint. Readers that index into the
84+
* polygon (front/back edges) must count these rather than assume one.
85+
*/
86+
export function getWallJunctionClosing(
87+
junction: { closing?: Point2D; closingPath?: Point2D[] },
88+
end: Point2D,
89+
): Point2D[] {
90+
return junction.closingPath ?? [junction.closing ?? end]
91+
}

‎packages/editor/src/lib/glb-export.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ import {
99
getLevelDisplayName,
1010
hidesDescendants,
1111
isNodeKindEnabled,
12+
isOpenAirRoom,
1213
isOperationDoorType,
1314
itemClipRegistry,
1415
type LevelNode,
1516
levelBaseElevationAt,
1617
nodeRegistry,
18+
openPlanRoomGroups,
1719
sceneRegistry,
1820
useScene,
1921
type WindowNode,
@@ -1882,6 +1884,8 @@ function stampIdentity(
18821884
}
18831885
})
18841886

1887+
// Open-plan room groups, computed once: /viewer lights each group as one space (see rooms.ts).
1888+
const openPlanGroups = openPlanRoomGroups(nodes)
18851889
for (const [id, original] of registryEntries) {
18861890
const node = nodes[id]
18871891
const target = cloneByOriginal.get(original)
@@ -1933,6 +1937,11 @@ function stampIdentity(
19331937
extras.polygon = zone.polygon
19341938
if (zone.holes?.length) extras.holes = zone.holes
19351939
extras.color = zone.color
1940+
// Open-air rooms (porch/deck/patio, or left open on a side) are lit as outdoors in /viewer,
1941+
// the same as the live editor; stamp it so the bake matches (core `isOpenAirRoom`).
1942+
if (isOpenAirRoom(nodes, zone)) extras.open = true
1943+
const group = openPlanGroups.get(id)
1944+
if (group) extras.group = group
19361945
target.visible = true
19371946
}
19381947
if (node.type === 'spawn') {

‎packages/nodes/src/shelf/definition.render.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,9 @@ export const shelfRenderDefinition: NodeRenderDefinition<typeof ShelfNode> & { k
119119
description: 'A configurable shelving unit. Items host on each row.',
120120
icon: { kind: 'url', src: '/icons/shelf.webp' },
121121
paletteSection: 'furnish',
122-
paletteOrder: 30,
122+
// Furnishing, not structure: sit below the structural "Add to rooms" tiles
123+
// (door/window/roof/stair) so it lands next to Kitchen rather than first.
124+
paletteOrder: 115,
123125
},
124126
mcp: {
125127
description:

0 commit comments

Comments
 (0)