Phase 5 Stage E: full kind migration into packages/nodes
Wholesale move of every remaining kind into its own subdirectory under
`packages/nodes/src/`, finishing the registry-driven migration. Each
kind now ships its definition, schema (re-exported from core), and any
of `geometry` / `renderer` / `system` / `floorplan` / `tool` /
`move-tool` / `panel` / `floorplan-move` / `floorplan-affordances` /
`parametrics` / `preview` it needs — no per-kind code remains under
`packages/editor/src/components/tools/` or
`packages/viewer/src/components/renderers/`.
Deleted (replaced by registry-driven equivalents):
- `tools/{ceiling,column,door,fence,item,slab,spawn,wall,window}/...`
(boundary editors, hole editors, placement tools, move tools,
endpoint movers, curve tools, helpers, math libs)
- `ui/helpers/{ceiling,slab,wall}-helper.tsx`
- `ui/panels/{column,door,elevator,item,roof,roof-segment,spawn,
stair,stair-segment,wall,window}-panel.tsx`
- `viewer/src/components/renderers/{building,ceiling,column,door,
elevator,fence,guide,item,level,roof,roof-segment,scan,site,slab,
spawn,stair,stair-segment,wall,window,zone}-renderer.tsx`
- `viewer/src/components/viewer/legacy-system.tsx`
Added under `packages/nodes/src/`:
- `building/`, `column/`, `elevator/`, `guide/`, `level/`, `roof/`,
`roof-segment/`, `scan/`, `shared/`, `site/`, `stair/`,
`stair-segment/` packages with definition + schema + renderer / system
/ floorplan / panel as appropriate.
- New `floorplan-move.ts` for every kind that supports 2D moves
(ceiling, door, item, shelf, slab, window) — single registry-driven
dispatch path via `def.floorplanMoveTarget`.
- New `floorplan-affordances.ts` for kinds with polygon / endpoint
drags (ceiling, fence, slab, wall) — using the shared
`polygon-vertex-affordance` factories.
- New per-kind `panel.tsx` for kinds with custom inspector content
(door, item, shelf, spawn, wall, window).
- New per-kind `tool.tsx` for placement (door, item, shelf, window).
- New per-kind `move-tool.tsx` for kinds with custom 3D move flows
(door, item, slab, window).
Coordinator + manager updates in `packages/editor/`:
- `tool-manager.tsx` resolves tools from the registry only — no
hardcoded type→component map.
- `panel-manager.tsx` resolves inspector panels the same way.
- `placement-{coordinator,strategies,types}.ts` extended with
shelf-surface placement.
- `selection-manager.tsx` adds the registry-selectable fallback.
- `floorplan-panel.tsx`, `floorplan-background-placement.ts`,
`floorplan-render-context.tsx` updated for the registry layer's new
contract (props, affordance dispatch, render context).
Viewer updates:
- `viewer/index.tsx` drops legacy renderer mounts.
- `node-renderer.tsx` resolves by registry only.
- `scene-bvh.tsx`, `use-node-events.ts`, `level-system.tsx`,
`wall-cutout.tsx`, `zone-system.tsx`, `materials.ts` adjusted for
the registry-only world.
Sidebar tree nodes for ceiling / fence / slab / shelf / tree-node
updated to read from the registered nodes instead of the deleted
legacy renderer trees.
Wiki: new `plugin-authoring.md` page, README index updated.
Tests in `packages/nodes/src/index.test.ts` validate every registered
kind has the required shape.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.7
parent
11015ea1ed
commit
d747d2f0ea
@@ -13,6 +13,7 @@ import type {
|
||||
LevelNode,
|
||||
RoofNode,
|
||||
RoofSegmentNode,
|
||||
ScanNode,
|
||||
ShelfNode,
|
||||
SiteNode,
|
||||
SlabNode,
|
||||
@@ -36,7 +37,14 @@ export interface GridEvent {
|
||||
*/
|
||||
localPosition: [number, number, number]
|
||||
faceIndex?: number
|
||||
object: Object3D
|
||||
/**
|
||||
* Optional: the hit Three.js object. Present when the grid event was
|
||||
* synthesized from a R3F mesh hit (the legacy grid-plane mesh path);
|
||||
* absent when emitted by the canvas-level raycaster in
|
||||
* `use-grid-events.ts`, where there is no specific mesh to attribute
|
||||
* the intersection to.
|
||||
*/
|
||||
object?: Object3D
|
||||
nativeEvent: ThreeEvent<PointerEvent>
|
||||
}
|
||||
|
||||
@@ -70,6 +78,8 @@ export type StairSegmentEvent = NodeEvent<StairSegmentNode>
|
||||
export type WindowEvent = NodeEvent<WindowNode>
|
||||
export type DoorEvent = NodeEvent<DoorNode>
|
||||
export type ElevatorEvent = NodeEvent<ElevatorNode>
|
||||
export type ScanEvent = NodeEvent<ScanNode>
|
||||
export type GuideEvent = NodeEvent<GuideNode>
|
||||
|
||||
// Event suffixes - exported for use in hooks
|
||||
export const eventSuffixes = [
|
||||
@@ -201,6 +211,8 @@ type EditorEvents = GridEvents &
|
||||
NodeEvents<'stair-segment', StairSegmentEvent> &
|
||||
NodeEvents<'window', WindowEvent> &
|
||||
NodeEvents<'door', DoorEvent> &
|
||||
NodeEvents<'scan', ScanEvent> &
|
||||
NodeEvents<'guide', GuideEvent> &
|
||||
CameraControlEvents &
|
||||
ToolEvents &
|
||||
GuideEvents &
|
||||
|
||||
@@ -3,43 +3,20 @@
|
||||
import { useLayoutEffect } from 'react'
|
||||
import type * as THREE from 'three'
|
||||
|
||||
const KNOWN_NODE_KINDS = [
|
||||
'site',
|
||||
'building',
|
||||
'ceiling',
|
||||
'column',
|
||||
'elevator',
|
||||
'level',
|
||||
'wall',
|
||||
'fence',
|
||||
'item',
|
||||
'slab',
|
||||
'spawn',
|
||||
'zone',
|
||||
'roof',
|
||||
'roof-segment',
|
||||
'stair',
|
||||
'stair-segment',
|
||||
'scan',
|
||||
'guide',
|
||||
'window',
|
||||
'door',
|
||||
] as const
|
||||
// `byType` is a Proxy-backed Map keyed by kind. Sets are created lazily on
|
||||
// first access, so any kind (built-in or plugin-contributed) participates
|
||||
// without needing a hardcoded seed list. The previous `KNOWN_NODE_KINDS`
|
||||
// array was a pre-seed for autocomplete; with every kind now flowing
|
||||
// through `nodeRegistry`, the seed is redundant.
|
||||
//
|
||||
// The type expresses that *any* string key returns a `Set<string>` — the
|
||||
// Proxy auto-creates on first access so there's no `undefined` branch at
|
||||
// runtime. Without this shape, `noUncheckedIndexedAccess` would force
|
||||
// every caller to defend against an impossible undefined.
|
||||
type ByTypeMap = { [kind: string]: Set<string> }
|
||||
const byTypeStore = new Map<string, Set<string>>()
|
||||
|
||||
type KnownNodeKind = (typeof KNOWN_NODE_KINDS)[number]
|
||||
// Allow registry-registered (plugin) kinds while keeping autocomplete for built-ins.
|
||||
type NodeKind = KnownNodeKind | (string & {})
|
||||
|
||||
type ByTypeShape = Record<KnownNodeKind, Set<string>> & Record<string, Set<string>>
|
||||
|
||||
const byTypeStore = new Map<string, Set<string>>(
|
||||
KNOWN_NODE_KINDS.map((k) => [k, new Set<string>()]),
|
||||
)
|
||||
|
||||
// Auto-creates a Set the first time an unknown kind is accessed. This is what
|
||||
// lets registry-registered (and future plugin-contributed) kinds participate
|
||||
// in `byType` without being hardcoded here.
|
||||
const byTypeProxy = new Proxy({} as ByTypeShape, {
|
||||
const byTypeProxy = new Proxy({} as ByTypeMap, {
|
||||
get(_target, key) {
|
||||
if (typeof key !== 'string') return undefined
|
||||
let set = byTypeStore.get(key)
|
||||
@@ -67,9 +44,8 @@ export const sceneRegistry = {
|
||||
// Master lookup: ID -> Object3D
|
||||
nodes: new Map<string, THREE.Object3D>(),
|
||||
|
||||
// Categorized lookups: Kind -> Set of IDs.
|
||||
// Backed by a Proxy so registry-registered kinds get a Set on first touch,
|
||||
// while built-in kinds remain present from module init for fast paths.
|
||||
// Categorized lookups: Kind -> Set of IDs. Backed by a Proxy so any kind
|
||||
// gets a Set on first touch — no hardcoded list.
|
||||
byType: byTypeProxy,
|
||||
|
||||
/** Remove all entries. Call when unloading a scene to prevent stale 3D refs. */
|
||||
@@ -81,7 +57,7 @@ export const sceneRegistry = {
|
||||
},
|
||||
}
|
||||
|
||||
export function useRegistry(id: string, type: NodeKind, ref: React.RefObject<THREE.Object3D>) {
|
||||
export function useRegistry(id: string, type: string, ref: React.RefObject<THREE.Object3D>) {
|
||||
useLayoutEffect(() => {
|
||||
const obj = ref.current
|
||||
if (!obj) return
|
||||
@@ -89,11 +65,10 @@ export function useRegistry(id: string, type: NodeKind, ref: React.RefObject<THR
|
||||
// 1. Add to master map
|
||||
sceneRegistry.nodes.set(id, obj)
|
||||
|
||||
// 2. Add to type-specific set — Proxy auto-creates on first access so the
|
||||
// assertion is safe; TS just can't see through the Proxy.
|
||||
// 2. Add to type-specific set — Proxy auto-creates on first access.
|
||||
sceneRegistry.byType[type]!.add(id)
|
||||
|
||||
// 4. Cleanup when component unmounts
|
||||
// 3. Cleanup when component unmounts
|
||||
return () => {
|
||||
sceneRegistry.nodes.delete(id)
|
||||
sceneRegistry.byType[type]!.delete(id)
|
||||
|
||||
Reference in New Issue
Block a user