feat(editor): live floor-stacking, unified handle system, slab-hole editing + interaction polish (#375)

- Live slab-stacking Y previews for all floor-placed kinds (item/shelf/spawn/column/stair) during placement + both move pathways, via a shared core resolver; canonical positions unchanged.
- Unified 3D handle system (one drag pipeline + one visual primitive) with forgiving invisible hit-areas on every handle, kept on EDITOR_LAYER so they don't poison the MRT scene pass.
- Hover + click-to-edit slab holes in 3D (manual hole -> hole editor; stair/elevator hole -> select owner); generic cross-arrow polygon-move grip; normalized handle interaction colors.
- NaN-safe node mutations + non-finite shadow-light bounds guard.
- Built on #373 (level-scoped alignment / registry slab tool); #373 owns X/Z alignment, this owns Y floor-stacking.
This commit is contained in:
Aymeric Rabot
2026-06-05 16:24:48 -04:00
committed by GitHub
parent d1b40aa98d
commit 0b338cf647
51 changed files with 3942 additions and 1418 deletions
@@ -103,15 +103,26 @@ export function Lights() {
if (SHADOW_EXCLUDED_TYPES.some((t) => sceneRegistry.byType[t]!.has(id))) continue
box.expandByObject(obj)
}
if (box.isEmpty()) {
// Empty scene: fall back to the origin with a default radius so the
// ground still receives a sensible shadow region.
box.getBoundingSphere(boundsSphere.current)
const center = boundsSphere.current.center
const radius = boundsSphere.current.radius
// Empty scene OR a node with a NaN position/geometry poisoning the union
// box: fall back to the origin with a default radius. The directional
// light's position is derived from `focus`, so a single non-finite mesh
// must NOT be allowed to make `focus`/`radius` NaN — that breaks every
// shadow-casting light's position and renders the whole scene black.
const finiteBounds =
!box.isEmpty() &&
Number.isFinite(center.x) &&
Number.isFinite(center.y) &&
Number.isFinite(center.z) &&
Number.isFinite(radius)
if (finiteBounds) {
shadowFocus.current.copy(center)
shadowRadius.current = radius
} else {
shadowFocus.current.set(0, 0, 0)
shadowRadius.current = SHADOW_FALLBACK_RADIUS
} else {
box.getBoundingSphere(boundsSphere.current)
shadowFocus.current.copy(boundsSphere.current.center)
shadowRadius.current = boundsSphere.current.radius
}
}
@@ -1,15 +1,43 @@
import {
type AnyNode,
type AnyNodeId,
getEffectiveNode,
getFloorStackedPosition,
nodeRegistry,
resolveLevelId,
sceneRegistry,
spatialGridManager,
useLiveTransforms,
useScene,
} from '@pascal-app/core'
import { useFrame } from '@react-three/fiber'
import type * as THREE from 'three'
type PositionedNode = AnyNode & {
position?: [number, number, number]
rotation?: [number, number, number] | number
}
function withLiveTransform(node: AnyNode, id: string): AnyNode {
const liveTransform = useLiveTransforms.getState().get(id)
if (!liveTransform) return node
const currentRotation = (node as PositionedNode).rotation
const rotation = Array.isArray(currentRotation)
? ([currentRotation[0] ?? 0, liveTransform.rotation, currentRotation[2] ?? 0] as [
number,
number,
number,
])
: typeof currentRotation === 'number'
? liveTransform.rotation
: currentRotation
return {
...(node as Record<string, unknown>),
position: liveTransform.position,
...(rotation !== undefined ? { rotation } : {}),
} as AnyNode
}
/**
* Generic floor-elevation system.
*
@@ -25,11 +53,12 @@ import type * as THREE from 'three'
*
* Runs at priority 1 — before the priority-2 systems (`GeometrySystem`,
* `ItemSystem`) so the dirty mark survives long enough for those to do
* their own work. Doesn't clear dirty; the per-kind system (or the
* generic geometry rebuild) is responsible for that.
* their own work. Kinds with no geometry/system have no downstream dirty
* consumer, so this system clears their dirty mark after applying the lift.
*/
export const FloorElevationSystem = () => {
const dirtyNodes = useScene((s) => s.dirtyNodes)
const clearDirty = useScene((s) => s.clearDirty)
useFrame(() => {
if (dirtyNodes.size === 0) return
@@ -43,31 +72,31 @@ export const FloorElevationSystem = () => {
const floorPlaced = def?.capabilities?.floorPlaced
if (!floorPlaced) return
if (floorPlaced.applies && !floorPlaced.applies(node as AnyNode)) return
// Only nodes parented directly to a level get the lift. Children of
// walls / ceilings / other items inherit Y from the parent group.
const parentId = node.parentId as AnyNodeId | null
const parent = parentId ? nodes[parentId] : null
if (parent && parent.type !== 'level') return
const mesh = sceneRegistry.nodes.get(id) as THREE.Object3D | undefined
if (!mesh) return
const position = (node as { position?: [number, number, number] }).position
const effectiveNode = withLiveTransform(getEffectiveNode(node as AnyNode), id)
const position = (effectiveNode as PositionedNode).position
if (!position) return
const levelId = resolveLevelId(node, nodes)
if (!levelId) return
const { dimensions, rotation } = floorPlaced.footprint(node as AnyNode)
const slabElevation = spatialGridManager.getSlabElevationForItem(
levelId,
// This system is the single drag-time authority for floor-stack mesh Y:
// tools publish base positions to live stores, renderers may
// reconcile that base Y onto the group, then this presentation system
// reapplies the resolver-derived visual Y before render. Because the
// override/store position remains base-height, the slab lift is never
// committed or applied twice.
const resolverNodes =
effectiveNode === node ? nodes : { ...nodes, [effectiveNode.id]: effectiveNode }
const visualPosition = getFloorStackedPosition({
node: effectiveNode,
nodes: resolverNodes,
position,
dimensions,
rotation,
)
mesh.position.y = slabElevation + position[1]
})
mesh.position.y = visualPosition[1]
if (!(def.geometry || def.system)) {
clearDirty(id as AnyNodeId)
}
})
}, 1)
@@ -2,11 +2,10 @@ import {
type AnyNode,
type AnyNodeId,
getEffectiveNode,
resolveLevelId,
getFloorStackedPosition,
type StairNode,
type StairSegmentNode,
sceneRegistry,
spatialGridManager,
useScene,
} from '@pascal-app/core'
import { useFrame } from '@react-three/fiber'
@@ -96,9 +95,9 @@ export const StairSystem = () => {
// so slab-elevation spatial queries match where the segments are
// actually being rendered. Without this, dragging the rotate gizmo
// looks up slabs at the pre-drag world XZ — if rotation carries a
// segment off the original slab footprint, getStairSlabElevation
// returns 0 and `group.position.y` collapses, dropping the flight
// or landing below the floor and out of view mid-drag.
// segment off the original slab footprint, the floor-stack
// resolver would otherwise read the pre-drag footprint and drop
// the flight or landing below the floor mid-drag.
const stairNode = getEffectiveNode(baseStairNode as StairNode)
const group = sceneRegistry.nodes.get(stairId) as THREE.Group | undefined
if (group) {
@@ -273,57 +272,20 @@ function syncStairGroupElevation(
group: THREE.Group,
nodes: Record<string, AnyNode>,
) {
const levelId = resolveLevelId(stairNode, nodes)
const slabElevation = getStairSlabElevation(levelId, stairNode, nodes)
group.position.y = stairNode.position[1] + slabElevation
}
function getStairSlabElevation(
levelId: string,
stairNode: StairNode,
nodes: Record<string, AnyNode>,
): number {
// Merge live overrides so slab queries match the visual chain during a drag.
const segments = (stairNode.children ?? [])
.map((childId) => nodes[childId as AnyNodeId] as StairSegmentNode | undefined)
.filter((n): n is StairSegmentNode => n?.type === 'stair-segment')
.map((n) => getEffectiveNode(n))
if (segments.length === 0) return 0
const transforms = computeSegmentTransforms(segments)
let maxElevation = Number.NEGATIVE_INFINITY
for (let i = 0; i < segments.length; i++) {
const segment = segments[i]!
const transform = transforms[i]!
const [centerOffsetX, centerOffsetZ] = rotateXZ(0, segment.length / 2, transform.rotation)
const centerInGroupX = transform.position[0] + centerOffsetX
const centerInGroupZ = transform.position[2] + centerOffsetZ
const [centerOffsetWorldX, centerOffsetWorldZ] = rotateXZ(
centerInGroupX,
centerInGroupZ,
stairNode.rotation,
)
const slabElevation = spatialGridManager.getSlabElevationForItem(
levelId,
[
stairNode.position[0] + centerOffsetWorldX,
stairNode.position[1] + transform.position[1],
stairNode.position[2] + centerOffsetWorldZ,
],
[segment.width, Math.max(segment.height, segment.thickness, 0.01), segment.length],
[0, stairNode.rotation + transform.rotation, 0],
)
if (slabElevation > maxElevation) {
maxElevation = slabElevation
const effectiveNodes: Record<string, AnyNode> = { ...nodes, [stairNode.id]: stairNode }
for (const childId of stairNode.children ?? []) {
const segment = nodes[childId as AnyNodeId]
if (segment?.type === 'stair-segment') {
effectiveNodes[segment.id] = getEffectiveNode(segment as StairSegmentNode)
}
}
return maxElevation === Number.NEGATIVE_INFINITY ? 0 : maxElevation
const visualPosition = getFloorStackedPosition({
node: stairNode,
nodes: effectiveNodes,
position: stairNode.position,
rotation: stairNode.rotation,
})
group.position.y = visualPosition[1]
}
// ============================================================================