home / skills / bbeierle12 / skill-mcp-claude / terrain-integration

terrain-integration skill

/skills/terrain-integration

This skill helps you integrate terrain-aware foundations and slope handling in Three.js builds, auto-leveling and pillar generation for stable ground contact.

npx playbooks add skill bbeierle12/skill-mcp-claude --skill terrain-integration

Review the files below or copy the command above to add this skill to your agents.

Files (7)
SKILL.md
2.3 KB
---
name: terrain-integration
description: Terrain interaction systems for Three.js building games. Use when implementing slope handling, foundation anchoring (Valheim pattern), terrain modification, auto-leveling, or pillar/support generation. Integrates with structural-physics for ground-based stability.
---

# Terrain Integration

Foundation placement, slope handling, and terrain modification for building systems.

## Quick Start

```javascript
import { TerrainAnalyzer } from './scripts/terrain-analyzer.js';
import { FoundationPlacer } from './scripts/foundation-placer.js';

// Analyze terrain at build location
const analyzer = new TerrainAnalyzer(terrainMesh);
const slopeData = analyzer.analyzeSlope(position, { radius: 4 });
// slopeData: { angle: 15, normal: Vector3, canBuild: true }

// Place foundation with auto-leveling
const placer = new FoundationPlacer({ 
  mode: 'valheim', // or 'rust', 'ark'
  maxSlope: 30,
  autoLevel: true 
});
const result = placer.place(foundationPiece, position, analyzer);
// result: { valid: true, height: 2.3, pillarsNeeded: 2 }
```

## Reference

See `references/terrain-integration-advanced.md` for:
- Slope analysis algorithms and thresholds
- Foundation anchoring patterns (Valheim ground contact rule)
- Auto-leveling strategies
- Terrain modification networking
- Pillar generation for uneven terrain

## Scripts

- `scripts/terrain-analyzer.js` - Slope detection, buildability checks, terrain sampling
- `scripts/foundation-placer.js` - Foundation placement with Valheim/Rust/ARK modes
- `scripts/terrain-modifier.js` - Flatten, raise, lower terrain operations
- `scripts/pillar-generator.js` - Auto-generate support pillars for slopes

## Foundation Modes

- **Valheim**: Ground contact = 100% stability, foundations must touch terrain
- **Rust**: Foundations snap to grid, terrain ignored after placement
- **ARK**: Flexible placement with auto-pillars, moderate slope tolerance

## Integration

Works with `structural-physics` for stability calculations. Grounded foundations feed into the support graph as root nodes with maximum stability.

```javascript
// Integration example
const grounded = placer.place(foundation, pos, analyzer);
if (grounded.valid) {
  foundation.isGrounded = true;
  foundation.stability = 1.0; // Feed to structural-physics
  validator.addPiece(foundation);
}
```

Overview

This skill provides terrain interaction systems for Three.js building games, handling slope detection, foundation anchoring, terrain modification, auto-leveling, and pillar/support generation. It integrates with structural-physics to feed grounded foundations into stability calculations and supports multiple foundation placement modes inspired by common survival builders.

How this skill works

The system analyzes terrain samples and normals around a placement point to compute slope, buildability, and ideal contact height. A foundation placer applies placement rules (Valheim/Rust/ARK styles), performs auto-leveling, and decides if pillars or terrain edits are required. Generated grounding information can be passed into structural-physics as root stability inputs.

When to use it

  • Placing player-built foundations on uneven terrain where slope matters
  • Implementing a Valheim-style rule where foundations must contact ground for full stability
  • Auto-generating support pillars for gaps or cliffs beneath structures
  • Allowing players to flatten or raise localized terrain to accommodate builds
  • Snapping foundations to a grid while optionally ignoring terrain (Rust-like behavior)

Best practices

  • Sample terrain within a configurable radius to get robust slope and normal estimates
  • Use mode presets (Valheim, Rust, ARK) to match expected gameplay and stability semantics
  • Limit client-side terrain modification and synchronize edits through authoritative networking
  • Feed grounded foundation outputs into the structural-physics support graph as max-stability roots
  • Expose clear thresholds for maxSlope and pillar spacing so designers can tune feel

Example use cases

  • Auto-level a foundation so a hut sits flush on a gentle slope and spawns two pillars for support
  • Prevent building on steep cliffs by rejecting placement when slope exceeds maxSlope
  • Offer a flatten tool that lowers a small area to place a workshop without large terrain edits
  • Switch to grid-snap mode for base layouts where terrain should not alter final position
  • Generate stacked pillars down a ravine to support a bridge and register supports with physics

FAQ

How does Valheim-style grounding differ from Rust or ARK modes?

Valheim mode requires full ground contact for maximum stability; Rust enforces grid snaps and ignores terrain after placement; ARK balances placement flexibility with auto-pillars and moderate slope tolerance.

Can this system modify terrain at runtime?

Yes—terrain modifier operations include flatten, raise, and lower, but modifications should be coordinated through authoritative networking to keep clients consistent.