The 3D MoveDoor/MoveWindow tools wrote useScene every frame during a move (freeFollowAt + applyPreview alternating): the wall:move (R3F) / grid:move (DOM) de-dup compared event.timeStamp across two event systems with different clocks, so it never matched and the floor free-follow ran during on-wall slides too, ping-ponging the host and churning the nodes ref → framerate collapse in both 2D and 3D. Replace it with a single-clock wall-ownership window (performance.now, ~4 frames): the floor follow stands down while a wall/roof hit is fresh. On-wall slides now write no scene per frame (mesh + useLiveTransforms only). Lower the live wall-cutout throttle 120→60ms now that the per-frame churn is gone. Also completes the door/window modifier-model migration (#10): Shift=cycle / Alt=force-place, fully mode-driven snap, snapProfile:'item'; exclude ground-line candidates from along-wall opening alignment; emit the move SFX once per snapped step. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
49 lines
1.4 KiB
TypeScript
49 lines
1.4 KiB
TypeScript
'use client'
|
|
|
|
import { type DoorNode, useLiveNodeOverrides, useRegistry, useScene } from '@pascal-app/core'
|
|
import { useNodeEvents } from '@pascal-app/viewer'
|
|
import { useLayoutEffect, useRef } from 'react'
|
|
import { type Mesh, MeshBasicMaterial } from 'three'
|
|
import { RoofFaceHostFrame } from '../shared/roof-face-host'
|
|
|
|
const doorHitboxMaterial = new MeshBasicMaterial({ visible: false })
|
|
|
|
export const DoorRenderer = ({ node }: { node: DoorNode }) => {
|
|
const ref = useRef<Mesh>(null!)
|
|
|
|
useRegistry(node.id, 'door', ref)
|
|
useLayoutEffect(() => {
|
|
useScene.getState().markDirty(node.id)
|
|
}, [node.id])
|
|
const handlers = useNodeEvents(node, 'door')
|
|
const liveVisible = useLiveNodeOverrides((s) => {
|
|
const visible = s.get(node.id)?.visible
|
|
return typeof visible === 'boolean' ? visible : undefined
|
|
})
|
|
const isTransient = !!(node.metadata as Record<string, unknown> | null)?.isTransient
|
|
|
|
const mesh = (
|
|
<mesh
|
|
castShadow
|
|
material={doorHitboxMaterial}
|
|
position={node.position}
|
|
receiveShadow
|
|
ref={ref}
|
|
rotation={node.rotation}
|
|
visible={liveVisible ?? node.visible}
|
|
{...(isTransient ? {} : handlers)}
|
|
>
|
|
<boxGeometry args={[0, 0, 0]} />
|
|
</mesh>
|
|
)
|
|
|
|
if (!node.roofSegmentId) return mesh
|
|
return (
|
|
<RoofFaceHostFrame roofFace={node.roofFace} roofSegmentId={node.roofSegmentId}>
|
|
{mesh}
|
|
</RoofFaceHostFrame>
|
|
)
|
|
}
|
|
|
|
export default DoorRenderer
|