home / skills / bbeierle12 / skill-mcp-claude / 3d-building-advanced

3d-building-advanced skill

/skills/3d-building-advanced

This skill provides a complete 3D building system with spatial indexing, structural physics, and multiplayer synchronization to speed up survival game

npx playbooks add skill bbeierle12/skill-mcp-claude --skill 3d-building-advanced

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

Files (17)
SKILL.md
3.0 KB
---
name: building-mechanics
description: Three.js 3D building system with spatial indexing, structural physics, and multiplayer networking. Use when creating survival games, sandbox builders, or any game with player-constructed structures. Covers performance optimization (spatial hash grids, octrees, chunk loading), structural validation (arcade/heuristic/realistic physics modes), and multiplayer sync (delta compression, client prediction, conflict resolution).
---

# 3D Building Mechanics

Complete building system for Three.js games with performance optimization, structural physics, and multiplayer networking.

## Quick Start

```javascript
import { SpatialHashGrid } from './scripts/spatial-hash-grid.js';
import { HeuristicValidator } from './scripts/heuristic-validator.js';

// Spatial indexing for fast queries
const spatialIndex = new SpatialHashGrid(10);
spatialIndex.insert(piece, piece.position);
const nearby = spatialIndex.queryRadius(position, 15);

// Structural validation (Rust/Valheim style)
const validator = new HeuristicValidator({ mode: 'heuristic' });
validator.addPiece(piece);
const canPlace = validator.validatePlacement(newPiece);
```

## Reference Files

Read these for detailed implementation guidance:

- `references/performance-at-scale.md` - Spatial partitioning, chunk loading, instancing, LOD
- `references/structural-physics-advanced.md` - Arcade vs heuristic vs realistic physics
- `references/multiplayer-networking.md` - Authority models, delta sync, conflict resolution

## Scripts

### Performance (references/performance-at-scale.md)
- `scripts/spatial-hash-grid.js` - O(1) queries for uniform distribution
- `scripts/octree.js` - Adaptive queries for clustered bases
- `scripts/chunk-manager.js` - World streaming for large maps
- `scripts/performance-profiler.js` - Benchmarking utilities

### Structural Physics (references/structural-physics-advanced.md)
- `scripts/heuristic-validator.js` - Fast validation (Fortnite/Rust/Valheim modes)
- `scripts/stability-optimizer.js` - Caching and batch updates
- `scripts/damage-propagation.js` - Damage states, cascading collapse
- `scripts/physics-engine-lite.js` - Optional realistic physics

### Multiplayer (references/multiplayer-networking.md)
- `scripts/delta-compression.js` - Only send changed state
- `scripts/client-prediction.js` - Optimistic placement with rollback
- `scripts/conflict-resolver.js` - Handle simultaneous builds
- `scripts/building-network-manager.js` - Complete server/client system

## Key Patterns

### Spatial Indexing Selection
| Pieces | Distribution | Use |
|--------|-------------|-----|
| <1,000 | Any | Array |
| 1-5k | Uniform | SpatialHashGrid |
| 1-5k | Clustered | Octree |
| 5k+ | Any | ChunkManager + Octree |

### Physics Mode Selection
- **Arcade** (Fortnite): Connectivity only, instant collapse, best for combat
- **Heuristic** (Rust/Valheim): Stability %, predictable, best for survival
- **Realistic**: Full stress/strain, expensive, best for engineering sims

### Multiplayer Pattern
Server-authoritative with client prediction. Use delta compression for sync.

Overview

This skill provides a complete building mechanics suite for Three.js games, combining spatial indexing, structural validation, and multiplayer networking. It targets survival, sandbox, and player-built-structure games and is optimized for large-scale worlds. The system is modular so you can choose between lightweight arcade behavior or realistic physics and plug in networking helpers for authoritative multiplayer.

How this skill works

Spatial modules (spatial-hash grid, octree, chunk manager) index pieces for fast proximity queries and scalable streaming. Structural modules offer three physics modes—arcade, heuristic, and realistic—plus validators, stability caching, and damage propagation. Networking components implement delta compression, client prediction, and conflict resolution with a server-authoritative pattern.

When to use it

  • Building survival or sandbox games where players construct persistent bases
  • Large worlds that require chunk loading, instancing, and spatial partitioning
  • Projects needing tunable stability models (fast gameplay vs realistic simulation)
  • Multiplayer games requiring efficient state sync and robust conflict handling
  • Prototyping different physics fidelity without reworking core systems

Best practices

  • Choose spatial index by scale: arrays for <1k pieces, spatial-hash for uniform 1–5k, octree for clustered data, chunk+octree for 5k+
  • Use heuristic physics for balanced gameplay; enable realistic mode only for engineering sims due to CPU cost
  • Batch validation and use stability caches to minimize per-frame work during mass edits
  • Apply delta compression and event coalescing to reduce bandwidth; combine with client prediction for responsive placement
  • Keep authoritative logic on server and resolve conflicts deterministically to avoid desync

Example use cases

  • A survival game with base building and raid mechanics using heuristic stability and damage propagation
  • A sandbox builder with large player cities using chunk streaming and octree queries
  • A fast-paced PvP game using arcade mode for instant connectivity-based collapse
  • A co-op engineering sim enabling realistic stress/strain calculations for structures
  • Multiplayer prototypes demonstrating client prediction and rollback for placement UX

FAQ

Which physics mode should I pick for multiplayer?

Use heuristic mode for a balance of predictability and performance; reserve realistic mode for small-scale or server-side-only simulations.

How do I scale to tens of thousands of pieces?

Partition the world into chunks, use an octree per chunk for clustered queries, and stream geometry plus instancing to reduce draw and memory cost.