# Voxel Castle Under Siege

- Author: @vib3coded
- Card: Creator prompt
- Theme: Dioramas & voxel scenes
- Stack: Not rebuilt
- Interaction: Pointer
- Licence: Credited link (Shared publicly by the author; full text with credit, removed on request)
- Verified: not yet
- Original post: https://x.com/vib3coded/status/2114295834611212692

## Original prompt

```text
Build a single-file HTML voxel toy called "Siege of Greymoor" with three.js r160 (ES modules via import map from jsDelivr). Use OrbitControls, EffectComposer, UnrealBloomPass and OutputPass.

World
- A dense voxel grid of 176×64×148 cells (Uint8 material ids plus a "part" id per cell).
- Mesh it in 16³ chunks: emit only faces toward air, with per-vertex ambient occlusion and vertex colors. Remesh only dirty chunks, under a per-frame budget.
- Add an emissive vertex attribute so glass windows and torches glow at night.
- Lay out an original medieval castle on a mound, ringed by a water moat:
  - curtain walls with a wall-walk, parapet and merlons;
  - four round corner towers on footings; two get red shingle cones and waving cloth banners;
  - a gatehouse with drum towers, a portcullis grid and a raised drawbridge;
  - a tall keep with glowing windows and four slate-roofed turrets;
  - a timber-framed great hall with a thatched roof, a stable, a smithy and a well.
- Outside the castle: a siege camp with striped tents, a pavilion, a palisade, a camp fire and a pile of shot. Add pine and leafy trees and boulders, all on a floating terrain slab.

Physics
- Debris: an InstancedMesh of tumbling cubes. Move each axis separately against the grid. Debris sinks slowly in the moat and settles back into the grid as rubble.
- Structural support: a span-limited 0-1 BFS from grounded columns. Stepping up costs 0; sideways or down costs 1.
- Each material has a maximum span (stone 5, timber 9, iron 12, leaves 14, and so on). Blocks beyond their span detach.
- Small detached sets become debris. Large sets become a rigid falling piece that tips away from the lost support and shatters on impact.
- At startup, run a dry pass and prune any blocks that would be unsupported.
- Fire: timber, thatch, cloth and leaves catch. Fire spreads upward faster than sideways or down. Burnt blocks turn to charcoal or fall in, then trigger a support check.
- Visuals for fire: an additive glow box per burning block, orange flame and ember point sprites, dark smoke, and a few flickering point lights.

Siege
- A box-built trebuchet with a counterweight and a sling that turns to face the target.
- Shot cycle: swing, release on a ballistic arc (gravity 26), follow-through, wind back.
- Three shots:
  - stone, crater radius 3.4;
  - fire pot, ignites what it hits;
  - boulder, crater radius 5.2.
- Craters are ragged and stretched along the line of flight. Hits throw dust and moat spray.
- Archers patrol the wall-walks and fall when the stone under them goes. Banners drop when their pole's base is destroyed.
- The masons rebuild the castle layer by layer from a saved copy, 16 layers per second.

Lighting and UI
- Three hours, each with its own sun direction, hemisphere light, sky gradient, fog, emissive glow, bloom and exposure:
  - Sext (noon);
  - Vespers (dusk);
  - Compline (night).
- Darken unlit particles at night.
- Vellum-and-ink medieval interface using the fonts Alegreya, Alegreya Sans SC and JetBrains Mono:
  - italic title "The siege of Greymoor" top left, which turns light at dusk and night;
  - a "chronicle" log top right that writes plain sentences such as "A 300-lb boulder strikes the south-east tower and breaks it open.", "The banner on the walls comes down." and "Fire takes hold on the great hall.", plus a "Send the masons" button;
  - a bottom dock with these groups: shot type, Loose / Keep loosing, hour, view (Slow time, Circle the walls), and a tally of standing %, shots, fallen and burning.
- Click to aim, drag to orbit. Keyboard: space fires, keys 1–3 pick the shot.
- Responsive down to phone width.
```

Not rebuilt by 3dmotion yet. Credit stays with @vib3coded.

Prompt by @vib3coded (https://x.com/vib3coded/status/2114295834611212692) via 3dmotion.io/e/voxel-castle-under-siege
