Skip to content

slab: add planar slope support (direction and pitch) - #1318

Open
kruschdev wants to merge 9 commits into
pascalorg:mainfrom
kruschdev:feat/sloped-slabs
Open

kruschdev wants to merge 9 commits into
pascalorg:mainfrom
kruschdev:feat/sloped-slabs

Conversation

@kruschdev

@kruschdev kruschdev commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Adds planar sloped slab support for manual solid slabs (ramps, driveways, sloped terraces, and flat-roof drainage falls), following the design suggested in #260 (Relates to #260; leaves roof-driven wall tops open in #260).

  • Schema and pure plane math (@pascal-app/core): Adds optional slope: { direction, pitch } (pitch in 0..45 degrees, direction uphill azimuth in degrees where 0 = +X and 90 = +Z) to SlabNode, keeping legacy flat scenes unchanged (E-003). packages/core/src/systems/slab/slab-slope.ts anchors slab.elevation at the low-edge projection (minProj) of the stored polygon so adding slope or extending the high edge never sinks a ramp below the floor plane, and keeps recessed slabs and reconciler-owned floor plates flat.
  • Position-dependent support, raycasting, and dirtying (@pascal-app/core): Updates selectSlabSupportForItem, SpatialGridManager (getSlabElevationAt, getSlabSupportForItem, getPointedSupportSurface exact analytical ray-plane intersection, getSupportCandidatesForFootprint, getHostSlabElevationForFootprint), floor-placed-elevation, usage-field (floorUnder and approx region tagging), layout-clearance, procedural-items/query, clampSlabElevationForWalls, and spatial-grid-sync dirty triggers so floor-placed items and cursor picks follow the inclined surface live.
  • 3D solid and terrain-fill geometry (@pascal-app/viewer, @pascal-app/nodes): Extrudes coplanar sloped top/bottom caps, sloped outer/hole side walls, and per-vertex sloped fillToTerrain skirts (buildTerrainPerimeterFillGeometry). Keeps top vs. side face splitting clean up to 45 degrees (cos(45°) > 0.5).
  • 2D floor plan, 3D handles, and Inspector UI (@pascal-app/nodes, i18n): Draws an uphill direction arrow on sloped slabs in 2D floor plans, places 3D thickness/base handles on the sloped surface, clears slope when toggling a slab to recessed, and adds a Slope section to SlabPanel (Pitch, Direction, Rotate 90°, Flip 180°, live Grade % and total rise readout, and Flat / Drainage 2% / Ramp 1:12 / Driveway 12% presets) with extracted and compiled Lingui catalogs.
  • IFC export, MCP, and agent authoring (@pascal-app/ifc-converter, @pascal-app/mcp, skills/pascal-3d): Exports sloped slabs as inclined IFCSLAB mesh geometry rather than flat SweptSolid, evaluates node-world-point on the sloped surface centroid, accepts optional slope in author_scene using shared measurement('angle', 'deg') notation, and documents the field in skills/pascal-3d/SKILL.md.

How to test

  1. Select a manual solid slab (or create one via the Slab tool) and open its inspector panel.
  2. In the Slope section, pick a preset (such as Ramp 1:12 or Driveway (12%)) or drag Pitch and Direction: the slab top and underside tilt from the low edge at elevation, Grade updates with the percentage and rise, and Rotate 90° / Flip 180° reorient the uphill direction.
  3. Enable Follows terrain on a sloped ramp: the perimeter fill skirt meets the sloped underside cleanly.
  4. Place floor items or columns at the low, middle, and high ends of the ramp: each lifts to the exact sloped surface height at its plan position and updates immediately when slope changes.
  5. Switch to 2D or Split view: sloped slabs display an uphill direction arrow that flips immediately when Flip 180° is clicked.
  6. Run the automated verification suite I executed:
    • bun run check
    • bun run check-types
    • bun run i18n:check
    • bun run skills:validate
    • bun run check:render-bundle
    • bun run --cwd packages/core test (7,692 pass, 3 skip, 0 fail)
    • bun run --cwd packages/viewer test (1,769 pass, 0 fail)
    • bun run --cwd packages/editor test (2,792 pass, 0 fail)
    • bun run --cwd packages/mcp test (1,576 pass, 0 fail)
    • bun test packages/nodes/src/slab packages/nodes/src/index.test.ts packages/ifc-converter/tests scripts/i18n.test.ts scripts/i18n-provider.test.ts scripts/i18n-literals.test.ts apps/editor/proxy.test.ts
    • bun run --cwd apps/editor build && bun run --cwd apps/editor smoke (8/8 pass)

Screenshots / screen recording

Verified live in Chrome (WebGPU) against the Next.js 16 production build (node next start) with zero console or page errors across 3D, 2D, and Split views:

3D view showing a 12° entry ramp with fillToTerrain skirt meeting a flat upper landing, three columns stepping up the sloped surface, a hosted balustrade railing climbing the ramp, and a 15° sloped terrace with a rectangular cutout:

3D view of sloped ramp with fillToTerrain skirt, stepped columns, hosted railing, and sloped terrace with cutout

2D floor plan and Slab inspector Slope controls (Pitch, Direction, Rotate 90°, Flip 180°, live Grade and rise readout, and presets), with uphill arrows anchored cleanly inside the solid slab regions (avoiding the terrace cutout):

2D floor plan with uphill slope arrows and Slab inspector Slope section

Split 2D + 3D view immediately after clicking Flip 180° (both the 2D uphill arrow and 3D ramp/railing/columns reorient live to 180°):

Split 2D and 3D view after clicking Flip 180°

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 core floor-placement, wall-support, and spatial-grid election paths; regressions could mis-lift items, walls, or stairs, though behavior is heavily regression-tested.

Overview
Adds optional planar slab slope (direction + pitch up to 45°) on manual solid slabs, with elevation anchored at the low-edge walking surface and slope ignored on recessed/auto floor plates.

Core plumbing introduces slab-slope plane math and threads per-(x,z) elevation sampling through spatial-grid support (item election, pointer ray hits, host slabs), layout clearance, usage-field floors (approx regions), stairs, fences, and procedural placement. Wall–slab support gains a sloped path with interpolated baseSegments / faceDatum, tighter elevation clamps against storey height, and author_scene validation that compares overlap height to wall half-height on sloped caps.

Editor/agent/export: author_scene persists slope; PolygonEditor can place handles on a sloped surface; slab panel i18n strings; IFC export keeps mesh geometry for sloped slabs; MCP world points sample sloped centroids. Large integration test coverage accompanies the changes.

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

@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.

Stale Bugbot comment from a previous run.

@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.

Stale Bugbot comment from a previous run.

@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.

Stale Bugbot comment from a previous run.

@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.

Stale Bugbot comment from a previous run.

@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 @kruschdev. Planar slab slope (direction and pitch) is a real step towards #260 and the screenshots help. This is a large change (50 files, +2.9k / -296) that touches support election for walls and items, so I want to be careful. Status at 7ead760:

  1. Merge conflicts. The branch is dirty against main; please rebase.
  2. Bugbot findings (Medium) across the series that I would like confirmed fixed at the head, since each one is a wrong-height bug: walls ignoring the sloped slab height and the wall clamp using the full-slab rise (slab-support.ts); the probe ignoring sloped sibling high edges (slab-support.ts); support sampled from the plane outside the slab and the pointer cap rejecting a sloped host slab (item-slab-support.ts); level-mode fence handles ignoring slope flattening (definition.render.ts). Please reply to each (fixed in / not applicable because ...), with a test where it is a behavior fix.
  3. Overlap to coordinate. #1288 (AxiomeCG, terrain for discussion) introduces a draped slab (slab.terrainMode) that also changes slab support election, and #1321 adds planar terrain slope. These three should agree on one meaning of "slab elevation on a slope" before any of them lands; a short note in the PR on how you see them interacting would help.

CI: GitHub Actions have not run on this head (fork workflows are waiting for maintainer approval).

@kruschdev

Copy link
Copy Markdown
Contributor Author

Thanks @Aymericr! I rebased onto main (de48a7c), adapted floorLift in packages/core/src/procedural-items/node-frames.ts (moved from query.ts in #1343) and preserved surfaceNodes as the 5th arg of resolveFenceLiftElevation in packages/nodes/src/fence/lift.ts.

Here is the commit-by-commit status for each Bugbot finding at HEAD (de48a7c):

  • Walls ignoring sloped slab height (slab-support.ts): fixed in 7278bd8 (computeWallSlabSupport samples sloped heights along wall polylines and emits sloped baseSegments / faceDatum with endElevation; tested in sloped-slab-support.test.ts and wall-support-extension.test.ts).
  • Level-mode fence handles ignoring slope flattening (definition.render.ts): fixed in 0ddb80d (handles align with level-mode flattening; tested in packages/nodes/src/fence/__tests__/lift.test.ts).
  • Support sampling plane outside slab (item-slab-support.ts): fixed in 0ddb80d (clamps out-of-span slope queries to [minTop, maxTop]; tested in slab-slope.test.ts).
  • Probe ignoring sloped sibling high edges (slab-support.ts): fixed in 35867fd (getSlabElevationUpperBound probes with sloped max elevation; tested in sloped-slab-support.test.ts and elevation-limit.test.ts).
  • Pointer cap rejecting sloped host slab (item-slab-support.ts): fixed in f0e07e0 (tested in sloped-slab-support.test.ts: pointer cap keeps a sloped host slab when cursor grabs downhill within the item footprint).
  • Wall clamp using full-slab rise (slab-support.ts): fixed in f0e07e0 (subtracts only the rise along overlapping plane-bound walls; tested in sloped-slab-support.test.ts).

Interaction with #1288 (and #1321): I closed #1321 so there is no terrain overlap there. Between #1318 and #1288's draped slab (slab.terrainMode), I see them as orthogonal elevation sources on a slab: slope represents an authored planar incline relative to the level (ramps, pitched garage/patio slabs, ADA walkways) with a single getSlabElevationAtPoint(slab, x, z) query, whereas a draped slab in #1288 follows the underlying terrain surface. Keeping getSlabElevationAtPoint as the single elevation-at-XZ entry point (and treating terrainMode === 'draped' as mutually exclusive with planar slope, just as recessed and reconciler-owned plateRole slabs already ignore slope) gives walls, items, stairs, and fences one consistent query contract for both.

Verified locally after rebase: bun run check-types (14/14 packages pass), 96/96 tests passing across all 8 slab/fence/wall/IFC test suites, and Biome clean on the resolved files.

@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 2 potential issues.

Fix All in Cursor

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

Reviewed by Cursor Bugbot for commit de48a7c. Configure here.

@kruschdev

Copy link
Copy Markdown
Contributor Author

Fixed both new Bugbot findings in 2078f6d:

  • author-scene.ts (slab_over_wall): replaced the whole-slab getSlabMaxElevation check with the maximum slab elevation specifically over intersection(polygon, wallFootprint) (falling back to contained vertices on edge touches), so steep ramps or driveways that touch a wall only at their low landing are placed cleanly while high-end wall overlaps still report slab_over_wall. Added a regression test in packages/core/src/hooks/spatial-grid/sloped-slab-support.test.ts.
  • PolygonEditor / boundary-editor.tsx / hole-editor.tsx: added an optional surfaceHeightAt?: (x, z) => number prop (and pure resolvePolygonHandleHeight helper) to PolygonEditor, wired to getSlabElevationAtPoint for sloped slabs so vertex, midpoint, edge bar/arrow, highlighted-edge, center-move, and border-line handles follow the sloped surface instead of floating at getSlabMaxElevation. Added unit tests in packages/editor/src/components/tools/shared/polygon-editor.test.ts.

Verified locally: bun run check-types (14/14 packages pass), 99/99 tests passing across all 9 slab/fence/wall/IFC/editor test suites, and Biome clean.

Aymericr commented Dec 3, 2026

Copy link
Copy Markdown
Member

Review at 2078f6d8, 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.

  • P1 — packages/core/src/systems/slab/slab-support.ts:100 — The clamp checks the elected slab ID or whether the elected elevation matches the probe. A flat floor can win both the ID and elevation while baseSegments still includes a ramp-supported end above the storey ceiling. Fix: track the highest segment endpoint carried by the edited slab and enforce MIN_WALL_HEIGHT there, regardless of which slab wins the wall.
  • P1 — packages/core/src/systems/slab/slab-slope.ts:113 — Every sloped height sample calls getSlabSlopePlane, which scans the entire polygon. The mesh builder samples every cap vertex for both top and bottom, so those two loops alone perform Θ(n²) projection work. Fix: compute the plane once per slab per build or support query and reuse it for constant-time samples.
  • P2 — packages/core/src/systems/slab/slab-support.ts:1259 — The flat path pools coverage by elevation; the sloped path keys slabCarry by slab ID. Two adjoining equal-height slabs carrying 30% each beat a higher slab carrying 40%, but adding an eligible ramp underneath switches paths and makes the 40% slab win without changing any supporting surface. Fix: pool equal-height flat supports in both election paths before choosing the winning slab.
  • P2 — packages/core/src/lib/item-slab-support.ts:40 — The pointer-cap minimum includes every footprint corner without checking the slab boundary or holes. The subsequent overlap check does not recompute that minimum, so an unsupported downhill corner can admit a ramp whose entire contact area is above the cap. Fix: minimize height over the footprint’s intersection with the solid slab, excluding holes.
  • P2 — packages/core/src/hooks/spatial-grid/spatial-grid-sync.ts:446 — A polygon edit triggers overlap-based invalidation but not markDeckAttachedStairs. Moving a sloped deck’s downhill edge changes minProj and therefore the sampled landing height even when the stair’s base footprint stays outside the deck. Fix: invalidate stairs referencing the deck when its sloped polygon changes.
  • P2 — packages/core/src/systems/slab/slab-slope.ts:83 — The schema accepts Number.MAX_VALUE as a finite direction, but multiplying it by Math.PI before division produces Infinity; the resulting sine, cosine, normals, and sampled heights are NaN. Fix: call normalizeSlabSlopeDirection before converting to radians.
  • P2 — packages/nodes/src/slab/panel.tsx:346 — The “Ramp 1:12” preset passes 4.8° as the actual pitch. Over a 12 m horizontal run, that produces about 1.008 m of rise rather than 1 m. Fix: derive each labeled grade’s pitch with Math.atan(grade) * 180 / Math.PI and round only for display.
  • P2 — packages/nodes/src/slab/floorplan.ts:318 — The fast path validates the chord midpoint but returns the outer vertices’ average. For a 10 m square with an eastward arrow and a hole starting at x = 5.2 across the centerline, it validates x = 2.6 but draws the shaft from x = 4.3 to 5.7, crossing the hole. Fix: return centerCandidate.x and centerCandidate.z.

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

P0/P1: 2. Those need fixing before this can land. 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.

- Sample sloped slab surfaces along wall polylines in computeWallSlabSupport
  and emit sloped baseSegments/faceDatum (endElevation) honored by wall CSG cutouts.
- Treat sloped slabs as non-grounded in isFloatingSlab so drawn polygons stay
  verbatim and never expand into adjacent walls or sibling floor seams.
- Guard all reconciler plateRole values (base, platform, sunken) in hasSlabSlope.
- Sample point elevation in stairBaseElevation, resolveStairTotalRise,
  resolveFenceConstructionSupport, fence lift/geometry, and inline slab.railing.
- Harden clampSlabElevationForWalls for steep rise > storeyHeight and add
  clampSlabSlope for inspector pitch/direction edits; remove static [0,360] clamp
  on Direction slider so scrubbing wraps modulo 360.
- Anchor 2D floorplan slope arrows on the widest solid interior chord to avoid
  interior cutouts and concave exteriors.
- Account for slope rise in author-scene slab_over_wall validation.
- Compare pointer-cap maxElevation against the lowest sloped slab point across
  the item/fence footprint (planFootprintCorners) so downhill grabs on a ramp
  do not drop to ground while overhead decks/ramps are still rejected.
- Subtract only the overlapping plane-bound wall local rise in
  clampSlabElevationForWalls, getSlabElevationUpperBound, and clampSlabSlope
  so a wall touching only the low end of a long ramp does not over-clamp.
…flat pooling, solid cap, stair sync, presets, arrow)
…ng filter, exact slope clamp, and tilted edge handle
@kruschdev

Copy link
Copy Markdown
Contributor Author

Thanks for the detailed review. I rebased onto main (3b31a48), resolved the conflicts with #1343, and pushed d5c8862 + 1fa6738 addressing all 8 review findings (plus follow-up audit checks):

  • Precomputed slope planes (P1): Exported sampleSlabSlopePlane(plane, x, z) from @pascal-app/core and hoisted getSlabSlopePlane once per slab across slab-system.tsx, slab-support.ts, slab/geometry.ts, fence/geometry.ts, boundary-editor.tsx (useMemo), hole-editor.tsx (useMemo), author-scene.ts, and item-slab-support.ts.
  • Ramp-carried wall clamp & per-wall ceiling filter (P1): Added carriedMaxBySlab on WallSlabSupport so clampSlabElevationForWalls enforces MIN_WALL_HEIGHT on ramp-carried segments even when a flat floor wins wall election, and updated the ceiling-slab filter in slab-support.ts to test minOverlapElevation along wall overlap intervals rather than global minTop.
  • Flat support pooling & per-polyline pointer cap (P2): Pooled equal-height flat supports (flatCarryPools) in the sloped election path so two 30% flats still beat a 40% higher flat when a ramp sits underneath, and enforced maxElevation per polyline inside pickHighest.
  • Solid-contact footprint cap & ground/platform precedence (P2): Intersected the item footprint quad with the slab's outer polygon minus holes via intersection() in getSlabMinElevationForFootprint so overhanging downhill corners over holes are excluded, while preserving selectSlabSupportForItem's ground pin and platform-over-base precedence.
  • Large direction overflow, deck stair sync, exact slope clamp, inspector presets, tilted edge bar, and floorplan arrow midpoint (P2): Normalized direction before radians conversion, dirtied deck-attached stairs on sloped polygon edits (and sloped recessed/autoFromWalls transitions) in spatial-grid-sync.ts, guarded non-finite inputs and used exact binary search in clampSlabSlope, derived exact atan(grade) preset angles and explicit min={0} max={360} direction bounds in panel.tsx, tilted EDGE_HANDLE_GEOMETRY flush with sloped edges in polygon-editor.tsx, and returned centerCandidate.x/z in floorplan.ts.

Note on screenshots: the PR description already includes before/after 3D, 2D floorplan, and flipped split-view captures. Added 8 regression tests covering each fix and verified green with bun run check-types (14/14), bun test packages/core/src/systems/slab/ packages/core/src/hooks/spatial-grid/ packages/nodes/src/slab/ packages/nodes/src/fence/ packages/editor/src/components/tools/shared/polygon-editor.test.ts packages/core/src/agent-operations/author-scene.test.ts (485/485 pass), and packages/ifc-converter/.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants