Skip to content

nodes: the floor plan draws hosted items where they sit in 3D - #1205

Merged
Aymericr merged 3 commits into
pascalorg:mainfrom
officialasishkumar:fix/item-plan-mounted-pose
Dec 3, 2026
Merged

Aymericr merged 3 commits into
pascalorg:mainfrom
officialasishkumar:fix/item-plan-mounted-pose

Conversation

@officialasishkumar

@officialasishkumar officialasishkumar commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Part of #992: the floor-plan half. The catalog drop on a standalone cabinet module is a separate problem and isn't changed here.

The item floor plan built each host's frame by hand in 2D (wall, item, shelf, roof face, block face). Core's nodeLevelFrame, which the viewer, MCP and cabinet hosting use, builds the same frames separately, and the two had drifted apart. I restored the 480-case grid from the deleted differential, but checked it against the committed 3D pose instead of the frozen copy. It fails on exactly the 76 combinations listed in the issue:

  • Block faces. Shelves and items nested under a block-face item, and any item not at the face host's upright rotation, were composed from yaw alone. With a tilted face frame they landed up to ~0.6 m off.
  • Shelf on a wall. An item chain under a transformed wall shelf went through the shelf's level-local pose instead of the wall's, and ended up several metres away.
  • Roof faces. Wall-side items used their stored face depth, but ItemSystem seats them on the roof wall surface, so they were off by half the wall thickness.

Changes:

  • resolveItemTransform now reads the item's level frame through restingNodePlanFrame. The plan uses the pose the viewer mounts, for every host chain, and about 230 lines of per-host 2D composition are gone.
  • nodeLevelFrame (core) now applies the depth ItemSystem gives wall-mounted items: wall items are offset from the wall body's centre, and wall-side items sit on the chosen face of a wall or roof segment. Before this, the frame put them on the stored depth.
    • Side effect: MCP world points for wall-side items are now exact, so the "on the wall centreline" approximation note in node-world-point.ts is removed.
  • Two floor-plan move overrides in floorplan-move.ts only copied the plan pose onto a frame that's now identical, so they're removed.
  • The roof case in floorplan-rendered-exits.test.tsx pinned the stored face depth ("Production plan rendering uses stored roof-face Z…"). It now asserts the rendered pose, like the wall and ceiling cases do.

New tests:

  • column-audit3.test.tsx: block-top, block-bottom, roof-face, shelf-on-wall and wall-back chains, three items deep. Each item's plan pose has to equal its mounted pose. On main, the first four fail and wall-back passes; wall-back guards the new core path.
  • level-frame-wall-mount.test.ts (core): wall-side front/back faces, a wall item on a justified wall, and a wall-side item on a roof face. All four fail on main.
  • measure-world.test.ts (mcp): a wall-side item is measured on its face and isn't flagged as approximate. Fails on main.

How to test

  1. In 2D, put an item on a block's top face, add a shelf on it, and put another item on that shelf. Rotate the block. The nested footprints stay under the items shown in 3D (on main they drift off).
  2. Put a wall-side item on a roof segment's wall face. Its plan footprint starts on the roof wall's outer surface, where 3D draws it (on main it's half the wall thickness inward).
  3. Put a shelf on a rotated wall, then an item, another shelf and another item on it. The whole chain lines up between 2D and 3D.
  4. Run bun --cwd packages/nodes run test, bun --cwd packages/core run test, bun --cwd packages/mcp run test and bun --cwd packages/editor run test.

What I ran (Linux arm64, Bun 1.4.4):

  • Test suites: nodes 5190 pass / 0 fail, editor 2829 / 0, mcp 1383 / 0, and core 6514 pass / 4 fail. The 4 core failures are the clean-bundle and scene-migrations bundle tests. They fail the same way on an unmodified main checkout in my environment (Cannot find package 'undefined' from the bundle eval).
  • check-types for core, nodes and mcp passes.
  • bun check reports no errors.

Screenshots / screen recording

Not added yet.

Checklist

  • I've tested this locally with bun dev
  • My code follows the existing code style (run bun check to verify)
  • I've updated relevant documentation (if applicable)
  • This PR targets the main branch

Note

Medium Risk
Touches shared frame math used by viewer, MCP, and floor plan; behavior change is intentional but broad across hosted item chains.

Overview
Unifies 2D floor-plan item placement with the same level-frame / 3D mounting path the viewer and MCP already use, fixing drift for nested hosts (block faces, wall shelves, roof wall-side items).

Adds getWallMountedItemZ in core and wires it through itemFrame (nodeLevelFrame) and ItemSystem, so wall and wall-side depths match rendering: body-centre offset for attachTo: 'wall', face Z for wall-side on walls and roof segments.

resolveItemTransform drops per-host 2D math (~230 lines) and reads the item pose via restingNodePlanFrame (planOnly: true). Redundant plan-pose overrides in floorplan-move are removed; MCP drops the wall-side “centreline” approximation. Docs and regression tests cover wall/roof mounts, MCP measure, and multi-host item chains (#992).

Reviewed by Cursor Bugbot for commit dcf8e2f. Bugbot is set up for automated code reviews on this repo. Configure here.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-03T10:07:41.021912Z 60e65f7 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Copy link
Copy Markdown
Member

Thanks @officialasishkumar. Drawing hosted items where they actually sit in 3D fixes a real floor-plan mismatch (related: #992), and the Codex review on 60e65f7 came back clean. main has moved about 80 commits since then, and the branch now conflicts in several floor-plan/nodes files. Could you rebase onto current main? Please also add a before/after floor-plan screenshot of a wall-hosted item and a shelf/ceiling-hosted one, since this changes what's drawn. CI for this fork will need maintainer approval once it's updated.

@officialasishkumar

Copy link
Copy Markdown
Contributor Author

Rebased onto current main and resolved the conflict in the item floorplan imports. Item, nodes and MCP tests and tsc pass locally. I haven't attached the before/after floor-plan screenshots yet.

@Aymericr Aymericr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Maintainer] Thanks @officialasishkumar. Reviewed at 53b7b69.

The direction is good: resolveItemTransform now asks restingNodePlanFrame for the pose the 3D scene uses instead of keeping a second, hand-written wall/roof/column calculation, and the net diff is smaller (+238 -266). The new level-frame-wall-mount.test.ts covers the three important cases (wall-side front/back face, wall body centre on a justified wall, roof-face item).

Before this can merge:

  1. Screenshots. This changes what the floor plan draws, which is visible behavior. Please add before/after screenshots of the floor plan with items hung on a wall (both faces), on an offset-justified wall, and on a roof face.
  2. CI. CI has not run on this head: fork workflows are waiting for maintainer approval, only Bugbot is green.
  3. Check the removed cache. resolveItemTransform lost its cache parameter. Please confirm no caller still passes one and that the per-frame cost on a scene with many items has not regressed (a quick note on the number of items you tried is enough).

I am not blocking on the code itself; once the screenshots are in and CI is green this looks ready.

@officialasishkumar
officialasishkumar force-pushed the fix/item-plan-mounted-pose branch from 53b7b69 to 960b089 Compare December 2, 2026 02:37
@officialasishkumar

Copy link
Copy Markdown
Contributor Author

No caller passes one: only the old recursion used it, and as a fresh map per call it never cached across items. On a 2000 item scene (floor, wall, wall-side, shelf, nested and ceiling items) the shared frame took about 2.8 ms per full pass against 0.2 ms on main, so 960b089 has the item plan ask for a plan-only frame, which brings that to about 1.4 ms, and during a drag only the moved subtree rebuilds.

@Aymericr Aymericr added the bot:bugs label Dec 2, 2026 — with Cursor

Aymericr commented Dec 3, 2026

Copy link
Copy Markdown
Member

Review at 960b0894, run with Codex (gpt-6.2-astra) over two rounds: a full review, then each finding re-checked against the diff. Only findings that survived are listed.

  • P2 — packages/nodes/src/item/floorplan.ts:54: atan2 preserves the direction of local +Z but discards its projected length. buildItemFloorplan then offsets a wall-side footprint by the full depth / 2, even when +Z is nearly vertical. The new chain test checks origin and yaw, not polygon vertices. Fix: project the mounted bounds through the full frame and test the emitted corners.
  • P2 — packages/nodes/src/item/floorplan.ts:47: A 34-item acyclic chain trips nodeLevelFrame’s seen.size > 32 guard. The catch returns null, so the builder emits no footprint; the deleted item-to-item branch had no depth cutoff. Fix: resolve ancestors iteratively, reject repeated IDs rather than valid depth, and test both a long chain and a cycle.
  • P2 — packages/nodes/src/item/floorplan.ts:46: The read-only preview resolves a wall from its supplied scene, but restingNodePlanFrame then calls getEffectiveNode(parent), which merges global overrides by ID. A live thickness override therefore changes the saved wall-side item’s offset without changing the saved wall. Fix: let the interactive resolver supply live overrides; test that a snapshot uses its own wall thickness.
  • P2 — packages/editor/src/lib/floorplan/items.ts:117: The reference-floor overlay still calls buildFloorplanItemEntry. Its transform handles wall and item parents, but for a roof segment or shelf it uses the child’s stored X/Z as level coordinates. The active floor now composes the host frame. Fix: use the same item geometry builder for both views and compare their polygons for a translated roof-face host.
  • P3 — packages/core/src/procedural-items/query.ts:176: wallMountedItemZ repeats ItemSystem’s wall-center offset, front-to-a/back-to-b mapping, and wallThickness ?? 0.1 roof fallback. Fix: extract one pure depth helper for both callers and retain the numeric tests as independent checks.

This changes visible UI, so please attach before/after screenshots or a short clip.

P0/P1: 0. CI hasn't run on this fork PR yet because it needs a maintainer to approve the workflow run; it merges once that's green.

The item floor plan rebuilt each host's frame by hand in 2D (wall, item,
shelf, roof face, block face), separately from core's nodeLevelFrame that
the viewer, MCP and cabinet hosting already use. The two drifted apart:
76 of the 480 host/mount combinations listed in pascalorg#992 drew a footprint
away from the item's committed 3D pose.

- Block faces: nested shelves and items, and any item not placed at the
  face host's upright rotation, were composed from yaw alone, so a tilted
  face frame put them up to 0.6 m off.
- Shelf on a wall: an item chain under a transformed wall shelf was
  composed through the shelf's level-local pose instead of the wall's,
  landing several metres away.
- Roof faces: wall-side items used their stored face depth, while
  ItemSystem seats them on the roof wall surface.

resolveItemTransform now reads the item's level frame through
restingNodePlanFrame, so the plan uses the same pose the viewer mounts,
for every host chain. To make that frame complete, core's item frame
now applies the depth ItemSystem gives wall-mounted items: wall items
sit relative to the wall body's centre and wall-side items on the chosen
face of a wall or roof segment. This also corrects MCP world points for
wall-side items, so their "on the wall centreline" approximation note
goes, drops the two matching known limits from the frames doc, and
drops two floor-plan move overrides that only copied the plan pose onto
an identical frame.

The roof case in floorplan-rendered-exits pinned the stored face depth;
it now asserts the rendered pose like the wall and ceiling cases. New
tests cover the failing chains against the mounted scene, the frame's
wall-mount depth in core, and MCP measurement of wall-side items.

Part of pascalorg#992 (the floor-plan half; the catalog drop on a standalone
cabinet module is separate).
resolveItemTransform reads only X, Z and heading from the item's level
frame, but restingNodePlanFrame resolved the full frame, including wall
slab support, ceiling height and floor lift for every item. Let callers
ask for a plan-only frame and use it for the item plan, so those heights
are skipped. Positions in plan and all rotations are unchanged, and this
roughly halves the cost of resolving an item's plan pose.

restingNodePlanFrame keeps the full frame by default, since the floor
plan move session reads its height.
…System

Core's item frame and the viewer's ItemSystem each worked out where a
wall-mounted item sits: a wall item off the wall body's centre, a
wall-side item on the face of its wall or roof segment wall. Move that
into getWallMountedItemZ beside the other wall frame helpers and call it
from both, so the floor plan, MCP and the 3D scene read one rule.

It returns null where the host leaves the stored depth alone, which is
when ItemSystem leaves the mesh's z untouched; ItemSystem still reads a
wall through its live override. A unit test pins the seated depths and
the cases left alone, and the level frame tests stay as independent
numeric checks.
@officialasishkumar
officialasishkumar force-pushed the fix/item-plan-mounted-pose branch from 960b089 to dcf8e2f Compare December 3, 2026 05:04
@officialasishkumar

Copy link
Copy Markdown
Contributor Author

P3 is done: the item frame and ItemSystem now share getWallMountedItemZ in core (dcf8e2f), rebased onto main. I left the P2s: wall-side hosts always keep +Z level, the depth cap is core's shared hosting guard, restingNodePlanFrame reads host previews by design, and the reference-floor overlay is a legacy path this PR doesn't touch.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit dcf8e2f. Configure here.

return {
x: f.position[0],
y: f.position[2],
rotation: Math.atan2(f.axes[2][0], f.axes[2][2]),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tilted footprints ignore projected depth

Medium Severity

resolveItemTransform takes the plan heading from atan2 of the level frame's +Z axis, which keeps that axis's direction but drops its horizontal length. buildItemFloorplan still shifts a wall-side footprint by the full half-depth and draws the full depth along that heading. When +Z is tilted, as on a non-upright block face, the footprint moves by up to half the depth and no longer sits on the mesh.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit dcf8e2f. Configure here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified at dcf8e2f0: real but minor, and not a blocker. wall-side placement on a block face accepts normals with abs(normalY) <= 0.05 (packages/nodes/src/block/face-host.ts:33) and applies zero local rotation, so +Z can be slightly tilted. resolveItemTransform keeps only the heading, so buildItemFloorplan offsets the footprint by the full half-depth instead of the X/Z projection. The error is a small fraction of the depth for faces that pass that gate, and the half-depth offset predates this PR. Tracking as a follow-up: project the mounted bounds through the full frame and assert the emitted polygon corners.

@Aymericr Aymericr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM at dcf8e2f0. Reviewed with Codex (gpt-6.2-astra) in two rounds, a full review and then each finding re-checked against the code. P0/P1: 0. Local CI replica (lint, i18n, types, tests, build, smoke, mcp, viewer-live) passes on a merge with current main.

The earlier P3 is fixed: getWallMountedItemZ is shared by core and ItemSystem. The contributor's reasons for leaving the P2s are acceptable for this PR:

  • Depth cap: the 32-level guard is core's shared frame-walk guard. Normal placement is capped far below it, so this only matters for unusually deep legacy chains.
  • Reference-floor overlay (floorplan-panel.tsx:5839 -> items.ts:116): it's a pre-existing legacy path this PR doesn't touch.
  • Host previews: following a host during a drag is intentional.

Follow-ups, not blocking:

  1. Tilted block-face wall-side footprints (floorplan.ts:54, Bugbot's finding): real but small, since face-host.ts:33 only allows abs(normalY) <= 0.05. Project the bounds through the full frame and assert the polygon corners.
  2. PDF export (floorplan-export.tsx:786/919 -> resting-surface-plan.ts:41): getEffectiveNode(parent) merges global live overrides, so an export during a wall drag can mix preview and committed poses. Use the supplied snapshot's host there.
  3. Move the reference-floor overlay onto the shared item geometry builder.
  4. Allow deep item chains in resolveItemTransform instead of dropping the footprint at depth > 32.

@Aymericr
Aymericr merged commit d63a042 into pascalorg:main Dec 3, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants