Wassim SAMAD cf24b62c44
fix(viewer): UI flicker on camera move from interactive overlays + dirty-mark leaks (#401)
* chore: sync bun.lock with 0.9.1 workspace versions

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* fix(viewer): stop interactive overlays from starving frames and flickering the UI

Every interactive item mounted a drei <Html occlude> overlay
unconditionally — invisible (opacity 0) when no zone was selected, but
still alive. With `occlude` as a bare boolean, drei raycasts the entire
scene per overlay on every camera-move frame, and rewrites each
element's z-index while toggling display when the occlusion flips. On
scenes with hundreds of interactive items (recessed lights, ceiling
fans) this starved the frame budget and made the whole DOM UI blink
during camera moves while the WebGPU canvas stayed healthy.

Overlays now mount only while a zone is selected and the item sits
inside its polygon, fade in/out over 300ms (the child components stay
rendered so the exit transition can play before the <Html> unmounts),
and drop `occlude` entirely. eps=-1 works around a drei mount bug: its
mount path writes the element transform without the distanceFactor
scale, and with a static camera the eps guard never re-applies it, so
freshly mounted overlays stayed mis-scaled until the camera moved.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* feat(viewer): break down dirty nodes by kind in the perf overlay

DIRTY now reads e.g. "29 (12 wall, 9 ceiling, 8 item)" — sorted by
count, only non-zero kinds, with a "missing" bucket for dirty ids whose
node no longer exists. Makes dirty-mark leaks attributable at a glance.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* perf(core): skip dirty marks for kinds with no dirty consumer

dirtyNodes is consumed by GeometrySystem (def.geometry),
FloorElevationSystem (capabilities.floorPlaced), and the legacy
per-kind viewer systems. Site, building, level, zone, and guide match
none of those, so their marks were never cleared: they accumulated for
the whole session (every child create/delete dirties its parent),
permanently defeated every consumer's empty-set early exit each frame,
and polluted the perf overlay's DIRTY readout.

NodeDefinition gains an explicit dirtyTracking?: boolean opt-out
(default tracked — no derivable predicate exists since wall's dirty
consumption lives in the viewer while zone/guide/level declare
def.system for unrelated per-frame work). markDirty consults the
registry; the five structural kinds opt out.

Also fixes a second leak: deleteNodesAction never removed deleted ids
from the dirty set, and every consumer skips missing nodes without
clearing them, so marks on deleted nodes lived forever.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* style: replace concise-arrow forEach with for...of in deleteNodesAction

biome's useIterableCallbackReturn rejects forEach callbacks that
implicitly return a value (Set.add / clearDirty).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-06-12 10:05:06 -04:00

63 lines
2.0 KiB
TypeScript

import { LevelNode as LevelNodeSchema, type NodeDefinition } from '@pascal-app/core'
import { levelParametrics } from './parametrics'
import { LevelNode } from './schema'
/**
* Level — Stage A. Container for walls / slabs / ceilings / etc. on
* a single floor. `LevelSystem` does level-wide work (Y-position
* snapping to true positions when levels reorder); wrap-exported.
*/
export const levelDefinition: NodeDefinition<typeof LevelNode> = {
kind: 'level',
schemaVersion: 1,
schema: LevelNode,
category: 'site',
defaults: () => {
const stub = LevelNodeSchema.parse({ id: 'level_default' as never, type: 'level' })
const { id: _id, type: _type, ...rest } = stub
return rest
},
capabilities: {
// Level is a container — selection happens via the sidebar tree
// and the floating level switcher, never via 3D click. Declaring
// `selectable` here would make `getSelectableKinds()` add the
// kind to `SelectionManager`'s subscription list, and the event
// would fire on every wall/slab/ceiling click that bubbled to the
// level group — selecting the level instead of the actual node
// hit. Legacy `allTypes` deliberately omitted containers; we
// mirror that.
duplicable: false,
deletable: true,
// Container kind — saving a level as a standalone preset has no
// meaning (its contents make sense only inside a building).
presettable: false,
},
parametrics: levelParametrics,
// No dirty consumer rebuilds this kind — see NodeDefinition.dirtyTracking.
dirtyTracking: false,
renderer: {
kind: 'parametric',
module: () => import('./renderer'),
},
system: {
module: () => import('./system'),
priority: 1,
},
presentation: {
label: 'Level',
description: 'A single floor of a building, holding walls / slabs / ceilings / items.',
icon: { kind: 'url', src: '/icons/level.png' },
paletteSection: 'site',
paletteOrder: 7,
},
mcp: {
description: 'A level (floor) container under a building.',
},
}