Fix pass: walkthrough, deck-coupled wall items, live-preview elevation, room snap modes, import validation (#537)
* fix(core): elect wall slab support from the carrying profile, not face coverage An elevated deck drawn against a house wall covers the wall's outer face line end-to-end (boundary contact counts), so the max-across-polylines election handed the wall origin to the deck: every wall-hosted window/door rode along whenever the deck height changed, and placement local-Y was clamped above the deck top. Elect from the carrying profile instead (per arc segment: highest support per face, min across supported faces), with the pointer cap applied inside the profile so a capped-away deck still falls back to the floor that carries the wall. Also pass curveOffset/ thickness/supportSlabId at the window/door tool query sites so their cursor agrees with the rendered wall frame. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix(core): honor live node overrides in spatial-grid support queries Group drags publish translated slab polygons and wall endpoints to useLiveNodeOverrides only; the committed spatial index made floor items and walls re-elect support against the pre-drag slab footprint, so multi-selection moves and room-preset placement jumped vertically until the validating click committed the batch. Support queries now read live-effective slab/wall records and bypass the rendered-polygon cache while a slab or wall on the level has an override; the committed cached path stays the fast path otherwise. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * feat(editor): give the room-preset stamp tool a polygon snap context The host app's room stamp drives placement with tool='room', which has no registry entry, so snapContextOf resolved null: Shift never cycled the snapping mode and the HUD chip stayed hidden during room preset placement. A tool-level context map hands the stamp the no-angle polygon set. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix(editor): only synthesize walkthrough fallback floors for ground levels Every slab-less visible level got a >=30x30m opening-free fallback floor box at its elevation, so a walkthrough spawned on an upper level (the no-spawn-node fallback ray picks the highest surface) stood on a phantom plane it could never descend from. Match the baked-GLB viewer policy: only the lowest level of each building (derived baseY === 0) gets the fallback; upper levels rely on their real slabs, whose stair openings are cut into the geometry. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix(core): fold useLiveTransforms slab deltas into support queries The slab move tool and the room-preset stamp publish a translation DELTA to useLiveTransforms (no polygon override), so the spatial index still elected support against the slab's committed footprint: furniture riding a room-preset preview (or sitting on a dragged deck) dropped to ground under the visually-moved deck until the validating click. Effective slab records now apply the live delta to polygon/holes/elevation, mapped exactly once at each query's loop entry. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix(viewer): reapply floor lift every frame for nodes with live previews FloorElevationSystem only wrote mesh Y for dirty nodes, but the React commit that rebinds a dragged node's base-Y group position can land between frames, after priority-2 systems consumed the dirty mark — the lift then vanished until the next pointer tick re-dirtied the node, blinking the Y of items dragged over elevated slabs. Nodes holding a live override or transform now get the lift reapplied every frame. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix(editor): stop the entry camera swap from insta-cancelling walkthrough Entering walkthrough with a persisted orthographic camera swaps it to perspective, which recreates the interaction callbacks and re-ran the pointer-lock effect: its cleanup called exitPointerLock, and the unlock handler read that as "user left walkthrough" — instantly cancelling the fresh entry and arming the browser's ~1.25s re-lock cooldown (hence needing multiple button presses). The effect is now mount-stable (the changing callback rides a ref, deps down to [gl]), and the entry lock request swallows async cooldown rejections like the P-resume path. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix(core): don't block build-JSON import over plugin-node children Exports from projects with plugins carry nodes like trees:tree whose ids sit in level.children; the import validator parsed parents against the static children id union, so one tree id hard-failed the level schema and blocked the whole import — while the same data loads fine from the DB (setScene never runs this gate). Parents are now validated against a copy with non-static-schema child ids filtered out; those nodes keep surfacing through the unknown-types warning and the imported payload is unchanged. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * feat(core): treat registered plugin kinds as first-class in import validation Nodes of runtime-registered plugin kinds (trees:tree, trees:grass) were lumped into the unknown-types warning even when the plugin is loaded. The validator now consults the node registry: registered kinds validate against their own registered schema (corrupt plugin nodes still block), count under stats.pluginTypes, and raise no warning — only genuinely unregistered types do, which stays correct for hosts without the plugin. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * style: appease biome (format + forEach block body) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> --------- Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5
parent
c3659acdf8
commit
f6d28f6794
@@ -448,10 +448,14 @@ const WALL_SLAB_ELEVATION_POOL_EPSILON = 1e-4
|
||||
* than `WALL_SLAB_MIN_OVERLAP` of the wall is ignored entirely (point
|
||||
* contact, endpoint grazes).
|
||||
*
|
||||
* Same-elevation slabs pool their coverage. `elevation` preserves the
|
||||
* existing wall-relative origin: the highest elevation covering at
|
||||
* least `WALL_SLAB_SUPPORT_MAJORITY` of the wall, or the best-covered
|
||||
* elevation when none reaches majority. `baseElevation` only fills down
|
||||
* Same-elevation slabs pool their coverage. `elevation` is elected from
|
||||
* the wall's carrying profile: per arc segment, the highest support on
|
||||
* each face, then the min across supported faces — so a slab that only
|
||||
* brushes one face (e.g. an elevated deck adjacent along the outer face)
|
||||
* never lifts the wall origin. The highest carrying elevation covering
|
||||
* at least `WALL_SLAB_SUPPORT_MAJORITY` of the wall wins, or the
|
||||
* best-covered carrying elevation when none reaches majority.
|
||||
* `baseElevation` only fills down
|
||||
* where a lower support remains exposed on a wall face after higher,
|
||||
* overlapping support is accounted for. Coincident floor/platform slabs
|
||||
* therefore keep the wall on the platform, while slabs on opposite wall
|
||||
@@ -560,58 +564,13 @@ export function computeWallSlabSupport(
|
||||
}
|
||||
|
||||
type EvaluatedGroup = ElevationGroup & {
|
||||
coverage: number
|
||||
mergedPerPolyline: LengthInterval[][]
|
||||
}
|
||||
const evaluatedGroups: EvaluatedGroup[] = groups.map((group) => {
|
||||
let coverage = 0
|
||||
const mergedPerPolyline = group.perPolyline.map(mergeIntervals)
|
||||
for (let i = 0; i < group.perPolyline.length; i++) {
|
||||
const lineLength = polylineLengths[i]!
|
||||
if (lineLength < 1e-9) continue
|
||||
coverage = Math.max(coverage, intervalsLength(mergedPerPolyline[i]!) / lineLength)
|
||||
}
|
||||
return { ...group, coverage, mergedPerPolyline }
|
||||
})
|
||||
const evaluatedGroups: EvaluatedGroup[] = groups.map((group) => ({
|
||||
...group,
|
||||
mergedPerPolyline: group.perPolyline.map(mergeIntervals),
|
||||
}))
|
||||
|
||||
const electableGroups =
|
||||
maxElevation == null
|
||||
? evaluatedGroups
|
||||
: evaluatedGroups.filter(
|
||||
(group) => group.elevation <= maxElevation + SUPPORT_ELEVATION_EPSILON,
|
||||
)
|
||||
|
||||
let majorityElevation = Number.NEGATIVE_INFINITY
|
||||
let bestElevation = Number.NEGATIVE_INFINITY
|
||||
let bestCoverage = -1
|
||||
for (const group of electableGroups) {
|
||||
if (group.coverage >= WALL_SLAB_SUPPORT_MAJORITY - 1e-6) {
|
||||
majorityElevation = Math.max(majorityElevation, group.elevation)
|
||||
}
|
||||
if (
|
||||
group.coverage > bestCoverage + 1e-6 ||
|
||||
(Math.abs(group.coverage - bestCoverage) <= 1e-6 && group.elevation > bestElevation)
|
||||
) {
|
||||
bestCoverage = group.coverage
|
||||
bestElevation = group.elevation
|
||||
}
|
||||
}
|
||||
|
||||
const elevation =
|
||||
preferredElevation !== null
|
||||
? preferredElevation
|
||||
: majorityElevation !== Number.NEGATIVE_INFINITY
|
||||
? majorityElevation
|
||||
: bestElevation === Number.NEGATIVE_INFINITY
|
||||
? 0
|
||||
: bestElevation
|
||||
const electedSlabId =
|
||||
preferredElectedSlabId ??
|
||||
electableGroups
|
||||
.find((group) => Math.abs(group.elevation - elevation) <= WALL_SLAB_ELEVATION_POOL_EPSILON)
|
||||
?.slabIds.slice()
|
||||
.sort()[0] ??
|
||||
null
|
||||
const normalizedIntervals = (group: EvaluatedGroup, polylineIndex: number) => {
|
||||
const lineLength = polylineLengths[polylineIndex]!
|
||||
if (lineLength < 1e-9) return []
|
||||
@@ -638,9 +597,9 @@ export function computeWallSlabSupport(
|
||||
(value, index) => index === 0 || value - breakpoints[index - 1]! > 1e-7,
|
||||
)
|
||||
|
||||
const highestAt = (polylineIndex: number, t: number) => {
|
||||
const highestAt = (groupList: typeof normalizedByGroup, polylineIndex: number, t: number) => {
|
||||
let highest = Number.NEGATIVE_INFINITY
|
||||
for (const group of normalizedByGroup) {
|
||||
for (const group of groupList) {
|
||||
if (
|
||||
group.perPolyline[polylineIndex]?.some(
|
||||
([intervalStart, intervalEnd]) => t >= intervalStart - 1e-7 && t <= intervalEnd + 1e-7,
|
||||
@@ -652,17 +611,66 @@ export function computeWallSlabSupport(
|
||||
return highest
|
||||
}
|
||||
|
||||
// The pointer cap filters the ELECTION's carrying profile, not the base
|
||||
// profile: with a deck capped away, the floor that also carries the wall
|
||||
// must still win (geometry fill-down stays uncapped).
|
||||
const electableNormalizedGroups =
|
||||
maxElevation == null
|
||||
? normalizedByGroup
|
||||
: normalizedByGroup.filter(
|
||||
(group) => group.elevation <= maxElevation + SUPPORT_ELEVATION_EPSILON,
|
||||
)
|
||||
|
||||
const baseSegments: WallSlabSupportSegment[] = []
|
||||
type CarryCandidate = { elevation: number; length: number }
|
||||
const carryCandidates: CarryCandidate[] = []
|
||||
const accumulateCarry = (elevation: number, length: number) => {
|
||||
let candidate = carryCandidates.find(
|
||||
(existing) => Math.abs(existing.elevation - elevation) <= WALL_SLAB_ELEVATION_POOL_EPSILON,
|
||||
)
|
||||
if (!candidate) {
|
||||
candidate = { elevation, length: 0 }
|
||||
carryCandidates.push(candidate)
|
||||
}
|
||||
candidate.length += length
|
||||
}
|
||||
for (let index = 1; index < uniqueBreakpoints.length; index++) {
|
||||
const start = uniqueBreakpoints[index - 1]!
|
||||
const end = uniqueBreakpoints[index]!
|
||||
if (end - start < 1e-7) continue
|
||||
const midpoint = (start + end) / 2
|
||||
const leftElevation = polylines.length >= 3 ? highestAt(1, midpoint) : Number.NEGATIVE_INFINITY
|
||||
const rightElevation = polylines.length >= 3 ? highestAt(2, midpoint) : Number.NEGATIVE_INFINITY
|
||||
const centerElevation = highestAt(normalizedByGroup, 0, midpoint)
|
||||
const leftElevation =
|
||||
polylines.length >= 3 ? highestAt(normalizedByGroup, 1, midpoint) : Number.NEGATIVE_INFINITY
|
||||
const rightElevation =
|
||||
polylines.length >= 3 ? highestAt(normalizedByGroup, 2, midpoint) : Number.NEGATIVE_INFINITY
|
||||
const faceElevations = [leftElevation, rightElevation].filter(Number.isFinite)
|
||||
const segmentElevation =
|
||||
faceElevations.length > 0 ? Math.min(...faceElevations) : Math.max(highestAt(0, midpoint), 0)
|
||||
faceElevations.length > 0 ? Math.min(...faceElevations) : Math.max(centerElevation, 0)
|
||||
|
||||
if (electableNormalizedGroups === normalizedByGroup) {
|
||||
if (faceElevations.length > 0 || Number.isFinite(centerElevation)) {
|
||||
accumulateCarry(segmentElevation, end - start)
|
||||
}
|
||||
} else {
|
||||
const electCenter = highestAt(electableNormalizedGroups, 0, midpoint)
|
||||
const electLeft =
|
||||
polylines.length >= 3
|
||||
? highestAt(electableNormalizedGroups, 1, midpoint)
|
||||
: Number.NEGATIVE_INFINITY
|
||||
const electRight =
|
||||
polylines.length >= 3
|
||||
? highestAt(electableNormalizedGroups, 2, midpoint)
|
||||
: Number.NEGATIVE_INFINITY
|
||||
const electFaces = [electLeft, electRight].filter(Number.isFinite)
|
||||
if (electFaces.length > 0 || Number.isFinite(electCenter)) {
|
||||
accumulateCarry(
|
||||
electFaces.length > 0 ? Math.min(...electFaces) : Math.max(electCenter, 0),
|
||||
end - start,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
const previous = baseSegments[baseSegments.length - 1]
|
||||
if (
|
||||
previous &&
|
||||
@@ -674,6 +682,42 @@ export function computeWallSlabSupport(
|
||||
}
|
||||
}
|
||||
|
||||
let majorityElevation = Number.NEGATIVE_INFINITY
|
||||
let bestElevation = Number.NEGATIVE_INFINITY
|
||||
let bestCoverage = -1
|
||||
for (const candidate of carryCandidates) {
|
||||
if (candidate.length >= WALL_SLAB_SUPPORT_MAJORITY - 1e-6) {
|
||||
majorityElevation = Math.max(majorityElevation, candidate.elevation)
|
||||
}
|
||||
if (
|
||||
candidate.length > bestCoverage + 1e-6 ||
|
||||
(Math.abs(candidate.length - bestCoverage) <= 1e-6 && candidate.elevation > bestElevation)
|
||||
) {
|
||||
bestCoverage = candidate.length
|
||||
bestElevation = candidate.elevation
|
||||
}
|
||||
}
|
||||
|
||||
const elevation =
|
||||
preferredElevation !== null
|
||||
? preferredElevation
|
||||
: majorityElevation !== Number.NEGATIVE_INFINITY
|
||||
? majorityElevation
|
||||
: bestElevation === Number.NEGATIVE_INFINITY
|
||||
? 0
|
||||
: bestElevation
|
||||
const electedSlabId =
|
||||
preferredElectedSlabId ??
|
||||
evaluatedGroups
|
||||
.filter(
|
||||
(group) =>
|
||||
maxElevation == null || group.elevation <= maxElevation + SUPPORT_ELEVATION_EPSILON,
|
||||
)
|
||||
.find((group) => Math.abs(group.elevation - elevation) <= WALL_SLAB_ELEVATION_POOL_EPSILON)
|
||||
?.slabIds.slice()
|
||||
.sort()[0] ??
|
||||
null
|
||||
|
||||
if (baseSegments.length === 0) baseSegments.push({ start: 0, end: 1, elevation })
|
||||
const baseElevation = Math.min(...baseSegments.map((segment) => segment.elevation))
|
||||
return { elevation, electedSlabId, baseElevation, baseSegments }
|
||||
|
||||
Reference in New Issue
Block a user