Three one-shot console.info calls so the Phase 3 milestone-B parity check is unambiguous from the browser console alone: - [wall:registry] system bundle mounted — fires when RegisteredSystems lazy-loads nodes/src/wall/system.tsx (exactly once per viewer mount when the flag is on). - [wall:registry] first WallRenderer mounted — fires once when the first registry-driven WallRenderer mounts. - [wall:legacy] first legacy WallRenderer mounted — fires once if the legacy path is active (flag off, or kind not registered). Module-level booleans gate the renderer logs so they don't spam in scenes with many walls. Drop all three alongside the feature flag at Phase 3 sign-off. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
78 lines
2.4 KiB
TypeScript
78 lines
2.4 KiB
TypeScript
import { useRegistry, useScene, type WallNode } from '@pascal-app/core'
|
|
import { useEffect, useLayoutEffect, useMemo, useRef } from 'react'
|
|
import { BufferGeometry, Float32BufferAttribute, type Mesh } from 'three'
|
|
import { useNodeEvents } from '../../../hooks/use-node-events'
|
|
import { getVisibleWallMaterials } from '../../../systems/wall/wall-materials'
|
|
import { NodeRenderer } from '../node-renderer'
|
|
|
|
// Phase 3 verification — see the matching `[wall:registry]` log in
|
|
// nodes/src/wall/renderer.tsx. When this fires, wall is on the legacy
|
|
// path; the registry-driven WallRenderer is not in use. Drop alongside
|
|
// the legacy file at Phase 6.
|
|
let didLogFirstLegacyWallMount = false
|
|
|
|
function createEmptyWallGeometry() {
|
|
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
|
|
}
|
|
|
|
export 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(() => {
|
|
if (didLogFirstLegacyWallMount) return
|
|
didLogFirstLegacyWallMount = true
|
|
console.info(
|
|
'[wall:legacy] first legacy WallRenderer mounted — registry-driven WallRenderer is NOT in use',
|
|
)
|
|
}, [])
|
|
|
|
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>
|
|
)
|
|
}
|