Brings the wall kind onto the registry path when
NEXT_PUBLIC_USE_REGISTRY_FOR_WALL=true; default-off keeps wall on its
legacy path unchanged.
Files added:
- nodes/src/wall/renderer.tsx — thin placeholder-mesh mount point.
Identical pattern to the legacy WallRenderer: registers ref via
useRegistry, marks dirty on mount, renders hosted children
recursively via NodeRenderer. The legacy WallSystem fills geometry
on the next frame regardless of which mount path is active.
- nodes/src/wall/system.tsx — a bundle component that renders
<WallSystem /> + <WallCutout /> (both re-exported from viewer).
Registered via def.system with priority 4 to mirror the legacy
WallSystem's useFrame priority. Zero logic duplication — the
~970 lines of CSG/mitering/cutaway code stays in viewer.
Files changed:
- packages/viewer/src/index.ts — new exports for WallSystem, WallCutout,
and NodeRenderer. The first two so the registry-driven system bundle
can compose them; NodeRenderer so any parent kind (wall, slab,
ceiling, building) can recursively render hosted children without
reaching into viewer internals.
- nodes/src/wall/definition.ts — adds renderer + system fields. Tool
field stays absent (wall placement / endpoint drag remain bespoke
for now; the affordance port is a later milestone).
- nodes/src/index.ts — conditionally appends wallDefinition to
builtinPlugin.nodes based on isWallRegistryEnabled(). With the flag
off, the array is identical to before this commit; with it on,
Phase 0 dispatch shims switch wall to the registry path:
* <LegacySystem kind="wall"> around WallSystem returns null
* <LegacySystem kind="wall"> around WallCutout returns null
* <NodeRenderer> takes the registry-first branch and mounts the
new renderer instead of the legacy switch case for 'wall'
* RegisteredSystems mounts the new system bundle, which re-mounts
the same WallSystem + WallCutout components from viewer
No behavior change with the flag off. With the flag on, behavior should
be byte-identical (same components, same priority, same geometry path).
Manual verification next: place walls, t-junctions, walls-with-doors
with the flag toggled both ways; confirm visual + interactive parity.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
86 lines
2.8 KiB
TypeScript
86 lines
2.8 KiB
TypeScript
'use client'
|
|
|
|
import { useRegistry, useScene, type WallNode } from '@pascal-app/core'
|
|
import { getVisibleWallMaterials, NodeRenderer, useNodeEvents } from '@pascal-app/viewer'
|
|
import { useEffect, useLayoutEffect, useMemo, useRef } from 'react'
|
|
import { BufferGeometry, Float32BufferAttribute, type Mesh } from 'three'
|
|
|
|
/**
|
|
* Thin wall renderer.
|
|
*
|
|
* Mounts a placeholder mesh, registers it with `sceneRegistry`, marks the
|
|
* node dirty so `WallSystem` fills the geometry on the next frame, and
|
|
* recursively renders hosted children (doors / windows / wall-mounted
|
|
* items) inside the wall's local frame.
|
|
*
|
|
* Behaviorally identical to the legacy `WallRenderer` in
|
|
* `@pascal-app/viewer/components/renderers/wall/wall-renderer.tsx` — same
|
|
* placeholder geometry, same material lookup, same dirty-mark on mount.
|
|
* Phase 6 deletes the legacy file; until then both coexist and the Phase 0
|
|
* shims pick which one renders based on `nodeRegistry.has('wall')`.
|
|
*
|
|
* No `geometry` field on the wall definition yet — wall's geometry depends
|
|
* on level-batch miter data (see `WallSystem.calculateLevelMiters`), which
|
|
* doesn't fit the generic `(node, ctx) => Group` shape without `ctx.levelData`.
|
|
* That decision lands in a later milestone; for now the system retains
|
|
* ownership of the rebuild loop.
|
|
*/
|
|
function createEmptyWallGeometry(): BufferGeometry {
|
|
const geometry = new BufferGeometry()
|
|
geometry.setAttribute('position', new Float32BufferAttribute([], 3))
|
|
geometry.addGroup(0, 0, 0)
|
|
geometry.addGroup(0, 0, 1)
|
|
geometry.addGroup(0, 0, 2)
|
|
return geometry
|
|
}
|
|
|
|
const WallRenderer = ({ node }: { node: WallNode }) => {
|
|
const ref = useRef<Mesh>(null!)
|
|
const placeholderGeometry = useMemo(createEmptyWallGeometry, [])
|
|
const collisionPlaceholderGeometry = useMemo(() => {
|
|
const geometry = new BufferGeometry()
|
|
geometry.setAttribute('position', new Float32BufferAttribute([], 3))
|
|
return geometry
|
|
}, [])
|
|
|
|
useRegistry(node.id, 'wall', ref)
|
|
|
|
useLayoutEffect(() => {
|
|
useScene.getState().markDirty(node.id)
|
|
}, [node.id])
|
|
|
|
useEffect(() => {
|
|
return () => {
|
|
placeholderGeometry.dispose()
|
|
collisionPlaceholderGeometry.dispose()
|
|
}
|
|
}, [collisionPlaceholderGeometry, placeholderGeometry])
|
|
|
|
const handlers = useNodeEvents(node, 'wall')
|
|
const material = getVisibleWallMaterials(node)
|
|
|
|
return (
|
|
<mesh
|
|
castShadow
|
|
geometry={placeholderGeometry}
|
|
material={material}
|
|
receiveShadow
|
|
ref={ref}
|
|
visible={node.visible}
|
|
>
|
|
<mesh
|
|
geometry={collisionPlaceholderGeometry}
|
|
name="collision-mesh"
|
|
visible={false}
|
|
{...handlers}
|
|
/>
|
|
|
|
{node.children.map((childId) => (
|
|
<NodeRenderer key={`${node.id}:${childId}`} nodeId={childId} />
|
|
))}
|
|
</mesh>
|
|
)
|
|
}
|
|
|
|
export default WallRenderer
|