Генератор подземелий

Генератор подземелий

Doctor GPT

# PROMPT — Procedural Dungeon Generator for an Isometric Three.js ARPG


## ROLE

You are a senior gameplay/graphics engineer specializing in procedural content generation and real-time WebGL. You write deterministic, allocation-conscious JavaScript and understand Three.js instancing, draw-call budgets, and forward-lighting costs at a deep level. You ship code that self-verifies.


## CONTEXT

Target: an isometric, Diablo-style ARPG built in Three.js (r128+, WebGL2). Camera is orthographic — yaw 45°, pitch 35–40°. World scale: **1 unit = 1 tile**, Y-up, grid (x, y) maps to world (x, z). Generation runs on the main thread on level load. No frameworks, no build step: one self-contained module.


## OBJECTIVE

Implement `generateDungeon(params) → Dungeon` (pure data, zero THREE imports) plus `buildDungeonScene(dungeon) → THREE .Group` (pure presentation). Dungeons must have:

- **Character** — irregular silhouettes, mixed room shapes, themed set-pieces, torch-lit atmosphere, a seeded name.

- **Depth** — branching with dead-end rewards, guaranteed loops (never a pure tree), secrets off the critical path, tension/release pacing.

2. **Connectivity.** Flood fill from the entrance must reach 100% of floor cells. On failure, re-roll internally with a derived seed (max 5 attempts) — never ship a broken layout, never "fix" islands with teleporters.

2. **Room scatter.** Spawn `roomCount × 1.4` candidates inside an ellipse (radius ∝ √roomCount so density stays constant). Archetype table — small 5–7 (45%), medium 8–12 (40%), large 13–18 (15%). Shape table — rectangle 60%, ellipse 22%, chamfered octagon 18%. Force ≥ 2 large rooms.

5. **Semantics before carving.** Boss = largest-area room. Entrance = degree-1 room maximizing graph distance from the boss. Critical path = BFS entrance→boss; remaining leaves → treasure (cap 4); 1–2 shrines mid-depth off-path; 1–2 elite arenas on the critical path at 55–85% depth; everything else combat. `difficulty = 0.15 + 0.85 × (depth / maxDepth)`, boss = 1.0.

8. **Decoration (data only).** Pillar grids in large rooms (only cells whose 8 neighbors are all floor, ≥ 2 cells from any doorway). Torches on floor-facing walls with min Chebyshev spacing 4. Debris density ∝ `decorDensity`, higher in low-difficulty rooms. Braziers ringing the boss arena; one chest per treasure room; shrine crystal; entrance portal ring. Enemy spawns: `round(area / 18 × (0.5 + difficulty))` for combat/elite, none in entrance/treasure/shrine, never on a prop or doorway cell.

- **Lighting:** dim blue hemisphere + faint directional for form; warm point lights (0xff8c3a, distance ≈ 9, decay 2) on a farthest-point-sampled subset of torches within budget, plus entrance/shrine/boss key lights. Per-frame flicker (intensity noise + flame scale jitter). `FogExp2` over a near-black clear color gives ortho depth falloff.

bfs: Int16Array; // per-cell distance from entrance, −1 = non-floor

- Boss depth ≥ 60% of max BFS depth; entrance degree = 1; entrance ≠ boss-adjacent.


## DELIVERABLE

A single self-contained HTML file: generator module + scene builder + minimal control panel (seed input, dice, sliders for roomCount / loopChance / decorDensity, overlay toggles, live stats, legend). Include an optional staged build animation gated behind `animateBuild` — rooms scatter→separate, graph resolves Delaunay→MST+loops, floors flood outward along the BFS field, walls rise, props pop — so the algorithm itself is legible on screen.

Report Page