Skip to content

terrain: add planar ground slope, slope brush, and two-point grade picker - #1321

Open
kruschdev wants to merge 2 commits into
pascalorg:mainfrom
kruschdev:feat/terrain-slope-grade
Open

kruschdev wants to merge 2 commits into
pascalorg:mainfrom
kruschdev:feat/terrain-slope-grade

Conversation

@kruschdev

@kruschdev kruschdev commented Nov 25, 2026 •

Copy link
Copy Markdown

What does this PR do?

Adds deterministic ground slope and elevation controls to the existing terrain heightfield (site.terrain) with zero schema changes, complementing the existing raise, lower, flatten, and smooth sculpting verbs.

  • Pure planar slope and two-point grade math (@pascal-app/core): Adds packages/core/src/lib/terrain-slope.ts with clampTerrainSlopePitch (0..45°), normalizeTerrainSlopeDirection (0° = +X, 90° = +Z), terrainSlopeGradePercent, compileTerrainSlopePlane (hoisting trig out of per-sample loops), resolveLotSlopePlane (center datum anchor matching USGS DEM imports or low-edge anchor), terrainSlopeBaseElevationForPlane, terrainSlopeElevationRange, deriveTerrainSlopeFromPoints, and buildSlopedTerrainField.
  • 5th slope brush verb (@pascal-app/core): Extends TerrainVerb in packages/core/src/lib/terrain-brush.ts with 'slope' using the same saturating snapshot-and-falloff kernel (re-crossing strokes never compound). Exports BaseTerrainVerb so useEditor.terrainVerb stays narrowed to the four original verbs for full type and runtime compatibility with @webxr/plugin, while editor consumers read selectActiveTerrainVerb and setActiveTerrainVerb.
  • Whole-lot grading, two-point A -> B picker, cursor feedback, and UI (@pascal-app/editor, i18n):
    • Adds slopeSite (grades the full padded heightfield in a single undo step and drops in-flight live strokes) and resolveSlopeStrokePlane in packages/editor/src/lib/terrain-sculpt.ts.
    • Adds a teal (#14b8a6) brush ring color, a draped uphill direction arrow inside the brush ring (hidden when pitch is 0°), an amber A -> B guide line, and a live grade % readout in the cursor pill during two-point picking (TerrainBrushCursor).
    • Adds the Slope tab in TerrainSculptPanel (Flat, 2%, 5%, 1:12, and 12% presets, Pitch, wrapping Direction with Rotate 90° and Flip 180°, Elevation, Anchor: Center / Low edge, live Grade % and lot elevation range readout, two-point Pick A -> B eyedropper with locked anchor indicator, and Slope lot), updates useTerrainPanelRows, and extracts/compiles Lingui catalogs across all 5 locales.

How to test

  1. Open any project, switch to Build -> Outdoor -> Terrain, and select the Slope tab.
  2. Pick a preset (such as 5% or 12%) or adjust Pitch, Direction (Rotate 90° / Flip 180°), Elevation, and Anchor (Center vs Low edge), then click Slope lot. Verify the terrain grades smoothly across the lot, the readout shows the exact grade % and min-to-max elevation range, and Ctrl+Z / Cmd+Z undoes it in a single step.
  3. Hover the cursor over the lot with a non-zero pitch: confirm the teal brush ring draws an uphill direction arrow pointing along Direction (and hides the arrow when Flat / 0° is selected). Drag across the lot to locally grade along the inclined plane.
  4. Click the eyedropper button (Pick A -> B slope), click a start point on the ground, move to a second point (confirming the amber guide line and live grade % pill), and click to lock the derived pitch, direction, lot base elevation, and plane anchor.
  5. Run the automated verification suite I executed:
    • bun run check (0 errors across 4,595 files)
    • bun run check-types (14/14 packages pass, including apps/editor and @webxr/plugin)
    • bun run i18n:check (5/5 catalogs in sync, literal guard pass)
    • bun run skills:validate (75/75 pass)
    • bun test packages/core/src/lib/terrain*.test.ts packages/core/src/store/use-live-terrain.test.ts (147/147 pass)
    • bun run --cwd packages/core test (7,688 pass, 3 skip, 0 fail)
    • bun run --cwd packages/editor test (2,797 pass, 0 fail)
    • bun test scripts/i18n.test.ts scripts/i18n-provider.test.ts scripts/i18n-literals.test.ts apps/editor/proxy.test.ts (81/81 pass)
    • bun run --cwd apps/editor build && bun run --cwd apps/editor smoke (8/8 pass)
    • bun run check:render-bundle (pass)

Screenshots / screen recording

Verified live in Chrome against the Next.js 16 production build with 0 console or page errors:

1. Whole-lot planar grading (Slope lot) on a 12% hillside lot: shows the Slope panel controls (Flat / 2% / 5% / 1:12 / 12% presets, Pitch, Direction with Rotate 90° / Flip 180°, Elevation, Anchor: Center / Low edge, live Grade 11.9% and 0'0" -> 9'5" range readout, and Slope lot), 3D topographic contours, a hillside pavilion with fillToTerrain deck foundation, and the teal brush ring with draped uphill direction arrow and elevation pill.

Whole-lot 12% planar slope with hillside pavilion, 3D contours, Slope panel controls, and teal uphill arrow

2. Two-point A -> B grade picker on a terraced hillside ramp: clicking near the foot of the carved ramp and moving uphill drapes the amber A -> B guide line and brush ring across the terrain, displays the live elevation and grade readout pill (H 3'7" · 8.6%), and shows the contextual Pick end point to match slope HUD prompt.

Two-point A to B slope picker with draped amber guide line and live grade percent readout on a carved terrace ramp

3. Locked A -> B anchor and rotated Slope brush: completing point B locks the derived Pitch (4.9°), Direction (302°), Elevation (3.87ft), and Anchored at 0'0" [x Clear] plane reference in the sidebar, rotating the teal brush ring's draped uphill arrow to match the picked slope for local touch-up strokes.

Anchored slope brush after two-point pick with locked anchor indicator and rotated teal uphill arrow on the terrace ramp

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 terrain heightfield mutation and editor pointer/state flows; scope is additive with tests, but incorrect slope math or stroke plane resolution could visibly corrupt site terrain.

Overview
Adds a slope terrain sculpt verb on top of the existing heightfield brush pipeline, plus pure planar slope math in @pascal-app/core.

The core layer introduces terrain-slope.ts (pitch/direction clamping, lot plane resolution with center vs low-edge anchors, two-point deriveTerrainSlopeFromPoints, and buildSlopedTerrainField for whole-field grading). terrain-brush extends strokes with a slope verb that lerps brushed samples toward a compiled inclined plane using the same non-compounding mask as flatten.

The editor wires slope through sculpt state (terrainSlope, A→B pick anchor, selectActiveTerrainVerb / setActiveTerrainVerb so terrainVerb stays narrowed for WebXR), slopeSite and resolveSlopeStrokePlane, panel controls (presets, pitch/direction/elevation, Slope lot), cursor feedback (uphill arrow, pick guide line, live grade %), HUD/i18n, and teal ring color for the new verb.

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

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.

1 participant