Prompt specification
Build or customize the Three.js 3D scene "Sequence a building bay with limited workers" inside the active workspace.
Engineering Constraints:
1. Runtime & Orbit: Use Three.js r160 with OrbitControls (damping enabled) and ACESFilmicToneMapping.
2. Frame Timing: Drive all motion strictly with clock.getDelta() so animation speed is FPS-independent.
3. Viewport Hygiene: Handle window resize cleanly, cap DPR at Math.min(window.devicePixelRatio, 2), and dispose geometries/materials/renderer on unmount.
Scene Metadata:
Scene: Sequence a building bay with limited workers
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/sequence-a-building-bay-with-limited-workers-x2348
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring a Gothic church construction workshop. Let users assign a small fictional crew to masonry, carpentry, and lifting tasks. Unlock dependent stages only when prerequisite components and safe schematic access paths are complete. Voxel style.
Working Three.js Starter (sequence-a-building-bay-with-limited-workers-x2348):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Gothic Works — Voxel Church Workshop</title>
<style>
:root {
--ink: #101721;
--panel: rgba(15, 22, 31, 0.94);
--panel-soft: rgba(26, 35, 47, 0.88);
--line: #3b4857;
--line-bright: #647486;
--paper: #eee7d7;
--muted: #9ba8b6;
--gold: #d9b96f;
--gold-dark: #8c7142;
--green: #79c7a5;
--red: #e48176;
--blue: #83b9dc;
--purple: #ae91d2;
--shadow: 0 18px 55px rgba(0, 0, 0, 0.35);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #101821;
color: var(--paper);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button, select { font: inherit; }
button {
color: inherit;
cursor: pointer;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene canvas:active { cursor: grabbing; }
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(circle at 52% 48%, transparent 38%, rgba(4, 8, 13, 0.28) 100%),
linear-gradient(180deg, rgba(5, 9, 14, 0.18), transparent 30%, rgba(5, 9, 14, 0.25));
z-index: 2;
}
.topbar {
position: fixed;
z-index: 10;
top: 18px;
left: 20px;
right: 20px;
display: grid;
grid-template-columns: 300px 1fr auto;
align-items: center;
gap: 16px;
pointer-events: none;
}
.brand {
display: flex;
align-items: center;
gap: 12px;
min-width: 0;
}
.brand-mark {
width: 44px;
height: 44px;
position: relative;
flex: 0 0 auto;
border: 1px solid rgba(217, 185, 111, 0.52);
background: rgba(12, 18, 26, 0.9);
box-shadow: inset 0 0 0 3px rgba(217, 185, 111, 0.06);
}
.brand-mark::before {
content: "";
position: absolute;
left: 9px;
right: 9px;
top: 8px;
height: 20px;
border: 3px solid var(--gold);
border-bottom: 0;
clip-path: polygon(0 100%, 0 65%, 30% 65%, 50% 0, 70% 65%, 100% 65%, 100% 100%);
}
.brand-mark::after {
content: "";
position: absolute;
left: 18px;
right: 18px;
bottom: 7px;
height: 8px;
border: 2px solid var(--gold);
border-bottom: 0;
}
.eyebrow {
color: var(--gold);
text-transform: uppercase;
letter-spacing: 0.17em;
font-size: 10px;
font-weight: 800;
}
.brand h1 {
margin: 2px 0 0;
font-family: Georgia, "Times New Roman", serif;
font-size: 22px;
line-height: 1;
letter-spacing: 0.025em;
white-space: nowrap;
}
.top-stats {
justify-self: center;
display: flex;
gap: 8px;
pointer-events: auto;
}
.stat {
min-width: 96px;
padding: 8px 12px;
border: 1px solid var(--line);
background: rgba(14, 20, 29, 0.84);
backdrop-filter: blur(10px);
box-shadow: var(--shadow);
}
.stat b {
display: block;
font-size: 13px;
letter-spacing: 0.02em;
}
.stat small {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 10px;
text-transform: uppercase;
letter-spacing: 0.12em;
}
.top-actions {
display: flex;
gap: 7px;
pointer-events: auto;
}
.icon-btn,
.small-btn {
border: 1px solid var(--line);
background: rgba(15, 22, 31, 0.92);
padding: 9px 11px;
font-size: 11px;
font-weight: 750;
letter-spacing: 0.04em;
transition: border-color 140ms, background 140ms, transform 140ms;
}
.icon-btn:hover,
.small-btn:hover {
border-color: var(--gold-dark);
background: rgba(41, 48, 57, 0.96);
}
.icon-btn:active,
.small-btn:active { transform: translateY(1px); }
.mobile-btn { display: none; }
.panel {
position: fixed;
z-index: 8;
top: 88px;
bottom: 154px;
width: 318px;
padding: 16px;
overflow-y: auto;
overscroll-behavior: contain;
border: 1px solid var(--line);
background:
linear-gradient(180deg, rgba(255,255,255,0.025), transparent 90px),
var(--panel);
box-shadow: var(--shadow);
backdrop-filter: blur(14px);
scrollbar-width: thin;
scrollbar-color: var(--line-bright) transparent;
}
#crew-panel { left: 20px; }
#build-panel { right: 20px; width: 330px; }
.panel-heading {
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 12px;
padding-bottom: 12px;
margin-bottom: 13px;
border-bottom: 1px solid var(--line);
}
.panel-heading h2 {
margin: 3px 0 0;
font-family: Georgia, "Times New Roman", serif;
font-size: 20px;
font-weight: 500;
}
.panel-heading small {
color: var(--muted);
font-size: 10px;
line-height: 1.4;
text-align: right;
}
.section-label {
display: flex;
align-items: center;
justify-content: space-between;
margin: 17px 0 9px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.section-label:first-child { margin-top: 0; }
.task-summary {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 7px;
}
.task {
padding: 9px 7px;
border: 1px solid var(--line);
background: var(--panel-soft);
}
.task b {
display: block;
font-size: 15px;
margin-bottom: 2px;
}
.task small {
display: block;
color: var(--muted);
font-size: 9px;
text-transform: uppercase;
letter-spacing: 0.08em;
}
.task.masonry b { color: #c9b28e; }
.task.carpentry b { color: #d39b71; }
.task.lifting b { color: #8fc6d8; }
.crew-list {
display: grid;
gap: 7px;
}
.crew-card {
display: grid;
grid-template-columns: 36px 1fr 108px;
align-items: center;
gap: 9px;
min-height: 52px;
padding: 7px;
border: 1px solid rgba(59, 72, 87, 0.8);
background: rgba(29, 38, 49, 0.72);
}
.avatar {
width: 34px;
height: 34px;
display: grid;
place-items: center;
border: 1px solid rgba(255,255,255,0.16);
color: white;
font-size: 11px;
font-weight: 850;
box-shadow: inset 0 -8px 14px rgba(0,0,0,0.18);
}
.crew-meta {
min-width: 0;
}
.crew-meta b {
display: block;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
font-size: 12px;
}
.crew-meta small {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 9px;
}
select {
width: 100%;
height: 32px;
padding: 0 7px;
color: var(--paper);
border: 1px solid var(--line-bright);
border-radius: 0;
background: #151e28;
font-size: 10px;
font-weight: 700;
outline: none;
}
select:focus { border-color: var(--gold); }
.hint {
margin-top: 12px;
padding: 10px 11px;
border-left: 2px solid var(--gold-dark);
background: rgba(217, 185, 111, 0.055);
color: var(--muted);
font-size: 10px;
line-height: 1.55;
}
.hint b { color: var(--paper); }
.selected-stage {
border: 1px solid var(--line);
padding: 13px;
background: var(--panel-soft);
}
.stage-title-row {
display: flex;
justify-content: space-between;
gap: 10px;
align-items: flex-start;
}
.stage-title-row h3 {
margin: 3px 0 0;
font-family: Georgia, "Times New Roman", serif;
font-size: 20px;
font-weight: 500;
}
.state-pill {
flex: 0 0 auto;
padding: 4px 6px;
border: 1px solid var(--line-bright);
color: var(--muted);
font-size: 9px;
font-weight: 850;
text-transform: uppercase;
letter-spacing: 0.09em;
}
.state-pill.ready {
border-color: rgba(121,199,165,.55);
color: var(--green);
}
.state-pill.complete {
border-color: rgba(217,185,111,.6);
color: var(--gold);
}
.state-pill.locked {
border-color: rgba(228,129,118,.45);
color: var(--red);
}
.stage-description {
color: var(--muted);
font-size: 11px;
line-height: 1.5;
margin: 10px 0 12px;
}
.progress-track {
height: 7px;
overflow: hidden;
background: #0b1118;
border: 1px solid #303c49;
}
.progress-fill {
width: 0;
height: 100%;
background: linear-gradient(90deg, var(--gold-dark), var(--gold));
transition: width 100ms linear;
}
.progress-fill.green {
background: linear-gradient(90deg, #397b62, var(--green));
}
.progress-meta {
display: flex;
justify-content: space-between;
gap: 10px;
margin-top: 6px;
color: var(--muted);
font-size: 9px;
}
.checks {
display: flex;
flex-wrap: wrap;
gap: 6px;
margin-top: 12px;
}
.check {
padding: 5px 7px;
border: 1px solid var(--line);
color: var(--muted);
background: rgba(10, 16, 23, 0.42);
font-size: 9px;
}
.check.done {
border-color: rgba(121,199,165,.45);
color: var(--green);
background: rgba(121,199,165,.07);
}
.need-row {
display: flex;
flex-wrap: wrap;
gap: 6px;
margin-top: 9px;
}
.need {
padding: 5px 7px;
border: 1px solid var(--line);
font-size: 9px;
color: var(--muted);
}
.need.ready {
color: var(--paper);
border-color: var(--line-bright);
}
.active-order {
margin-top: 10px;
padding: 11px 12px;
border: 1px solid rgba(217,185,111,.38);
background: rgba(217,185,111,.065);
}
.active-order .order-label {
color: var(--gold);
font-size: 9px;
font-weight: 850;
letter-spacing: .13em;
text-transform: uppercase;
}
.active-order strong {
display: block;
margin-top: 4px;
font-size: 12px;
}
.active-order small {
display: block;
margin-top: 4px;
color: var(--muted);
font-size: 9px;
line-height: 1.4;
}
.path-list {
display: grid;
gap: 7px;
}
.path-row {
padding: 9px;
border: 1px solid var(--line);
background: rgba(20, 29, 39, .76);
transition: border-color 140ms, background 140ms;
}
.path-row.active {
border-color: rgba(217,185,111,.65);
background: rgba(217,185,111,.055);
}
.path-row.complete { border-color: rgba(121,199,165,.4); }
.path-top {
display: grid;
grid-template-columns: 18px 1fr auto;
align-items: center;
gap: 7px;
}
.path-icon {
width: 17px;
height: 17px;
display: grid;
place-items: center;
border: 1px solid var(--line-bright);
color: var(--muted);
font-size: 9px;
}
.path-row.complete .path-icon {
border-color: var(--green);
color: var(--green);
}
.path-row.active .path-icon {
border-color: var(--gold);
color: var(--gold);
}
.path-name {
min-width: 0;
font-size: 10px;
font-weight: 750;
}
.path-action {
padding: 4px 6px;
border: 1px solid var(--line-bright);
background: #151e28;
font-size: 8px;
font-weight: 850;
text-transform: uppercase;
letter-spacing: .06em;
}
.path-action:hover { border-color: var(--gold); }
.path-status {
margin: 6px 0 0 25px;
color: var(--muted);
font-size: 9px;
line-height: 1.35;
}
.path-progress {
height: 3px;
margin-top: 8px;
background: #090e14;
}
.path-progress div {
height: 100%;
background: var(--green);
}
.stage-rail {
position: fixed;
z-index: 9;
left: 356px;
right: 368px;
bottom: 18px;
display: flex;
gap: 7px;
overflow-x: auto;
padding: 8px;
border: 1px solid var(--line);
background: rgba(12, 18, 26, .88);
box-shadow: var(--shadow);
backdrop-filter: blur(12px);
scrollbar-width: thin;
}
.stage-card {
flex: 1 0 118px;
min-width: 118px;
padding: 9px 10px;
text-align: left;
border: 1px solid var(--line);
background: rgba(27, 36, 47, .88);
transition: transform 140ms, border-color 140ms, background 140ms;
}
.stage-card:hover {
transform: translateY(-2px);
border-color: var(--line-bright);
}
.stage-card.selected { border-color: var(--gold-dark); }
.stage-card.ready { background: rgba(34, 52, 51, .88); }
.stage-card.active { border-color: var(--gold); box-shadow: inset 0 0 0 1px rgba(217,185,111,.16); }
.stage-card.complete { background: rgba(42, 48, 48, .9); }
.stage-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 5px;
}
.stage-no {
color: var(--gold);
font-size: 9px;
font-weight: 850;
letter-spacing: .08em;
}
.stage-status {
color: var(--muted);
font-size: 8px;
font-weight: 850;
text-transform: uppercase;
letter-spacing: .08em;
}
.stage-card.ready .stage-status { color: var(--green); }
.stage-card.complete .stage-status { color: var(--gold); }
.stage-card.locked .stage-status { color: var(--red); }
.stage-name {
min-height: 28px;
margin-top: 5px;
font-size: 10px;
font-weight: 750;
line-height: 1.3;
}
.mini-progress {
height: 3px;
margin-top: 8px;
background: #080d12;
}
.mini-progress div {
height: 100%;
background: var(--gold);
}
#toast {
position: fixed;
z-index: 30;
left: 50%;
top: 84px;
transform: translate(-50%, -12px);
max-width: min(520px, calc(100vw - 32px));
padding: 11px 15px;
border: 1px solid rgba(217,185,111,.55);
background: rgba(12, 18, 25, .96);
color: var(--paper);
box-shadow: var(--shadow);
font-size: 11px;
line-height: 1.45;
opacity: 0;
pointer-events: none;
transition: opacity 180ms, transform 180ms;
}
#toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
@media (max-width: 1120px) {
.topbar { grid-template-columns: 260px 1fr auto; }
.stat { min-width: 78px; padding-inline: 9px; }
#crew-panel { width: 285px; }
#build-panel { width: 300px; }
.stage-rail { left: 323px; right: 338px; }
}
@media (max-width: 860px) {
.top-stats { display: none; }
.topbar { grid-template-columns: 1fr auto; }
.mobile-btn { display: inline-block; }
.stage-rail { left: 20px; right: 20px; }
}
@media (max-width: 760px) {
.topbar { top: 10px; left: 10px; right: 10px; }
.brand h1 { font-size: 18px; }
.brand-mark { width: 38px; height: 38px; }
.brand-mark::before { left: 7px; right: 7px; top: 6px; height: 18px; }
.brand-mark::after { left: 15px; right: 15px; bottom: 5px; height: 7px; }
.panel {
top: 66px;
bottom: 137px;
width: min(330px, calc(100vw - 20px));
transition: transform 180ms, opacity 180ms;
}
#crew-panel {
left: 10px;
transform: translateX(calc(-100% - 20px));
opacity: 0;
pointer-events: none;
}
#build-panel {
right: 10px;
transform: translateX(calc(100% + 20px));
opacity: 0;
pointer-events: none;
}
body.show-left #crew-panel,
body.show-build #build-panel {
transform: translateX(0);
opacity: 1;
pointer-events: auto;
}
.stage-rail {
left: 10px;
right: 10px;
bottom: 10px;
padding: 6px;
}
.stage-card { flex-basis: 112px; }
#toast { top: 68px; }
}
</style>
</head>
<body>
<div id="scene"></div>
<div class="vignette"></div>
<header class="topbar">
<div class="brand">
<div class="brand-mark"></div>
<div>
<div class="eyebrow">Voxel Construction Guild</div>
<h1>Gothic Works</h1>
</div>
</div>
<div class="top-stats">
<div class="stat">
<b id="stat-masonry">1 / 2</b>
<small>Masonry</small>
</div>
<div class="stat">
<b id="stat-carpentry">1 / 2</b>
<small>Carpentry</small>
</div>
<div class="stat">
<b id="stat-lifting">1 / 2</b>
<small>Lifting</small>
</div>
<div class="stat">
<b id="stat-routes">0 / 6</b>
<small>Safe routes</small>
</div>
</div>
<div class="top-actions">
<button class="icon-btn mobile-btn" id="crew-toggle">Crew</button>
<button class="icon-btn mobile-btn" id="build-toggle">Build</button>
<button class="icon-btn" id="pause-btn">Pause</button>
<button class="icon-btn" id="camera-btn">Reset view</button>
<button class="icon-btn" id="restart-btn">Restart</button>
</div>
</header>
<aside class="panel" id="crew-panel">
<div class="panel-heading">
<div>
<div class="eyebrow">Field Office</div>
<h2>Guild Crew</h2>
</div>
<small>Two workers<br>per trade</small>
</div>
<div class="section-label">
<span>Assigned labor</span>
<span id="assigned-total">3 / 6</span>
</div>
<div class="task-summary">
<div class="task masonry"><b id="count-masonry">1</b><small>Masonry</small></div>
<div class="task carpentry"><b id="count-carpentry">1</b><small>Carpentry</small></div>
<div class="task lifting"><b id="count-lifting">1</b><small>Lifting</small></div>
</div>
<div class="section-label"><span>Available artisans</span></div>
<div class="crew-list" id="crew-list"></div>
<div class="hint">
<b>Natural trades work 25% faster.</b>
Cross-trained workers can fill shortages. A component or access route only advances
while it is the active order.
</div>
</aside>
<aside class="panel" id="build-panel">
<div class="panel-heading">
<div>
<div class="eyebrow">Master Plan</div>
<h2>Construction Order</h2>
</div>
<small>Schematic-gated<br>build sequence</small>
</div>
<div class="selected-stage" id="selected-stage"></div>
<div class="active-order" id="active-order"></div>
<div class="section-label">
<span>Safe access schematics</span>
<span id="route-summary">0 certified</span>
</div>
<div class="path-list" id="path-list"></div>
<div class="hint">
<b>Dependencies matter.</b> A component unlocks only after its required build
components and its certified access route are complete.
</div>
</aside>
<nav class="stage-rail" id="stage-rail" aria-label="Construction stages"></nav>
<div id="toast" role="status" aria-live="polite"></div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Game data
// ------------------------------------------------------------
const CREW = [
{ id: "ada", name: "Ada Flint", initials: "AF", natural: "masonry", speed: 1.15, color: 0xb87962 },
{ id: "odo", name: "Odo Marsh", initials: "OM", natural: "masonry", speed: 1.00, color: 0x8eaa79 },
{ id: "wren", name: "Wren Vale", initials: "WV", natural: "carpentry", speed: 1.20, color: 0x688eb2 },
{ id: "pip", name: "Pip Hart", initials: "PH", natural: "carpentry", speed: 0.95, color: 0xc4a15f },
{ id: "tessa", name: "Tessa Rook", initials: "TR", natural: "lifting", speed: 1.25, color: 0x9e78aa },
{ id: "hal", name: "Hal Crane", initials: "HC", natural: "lifting", speed: 1.00, color: 0x5f9e9a }
];
const STAGES = [
{
id: 0,
name: "Footings & Plinths",
description: "Lay the stepped foundation, footings, and lower plinth around the future nave.",
needs: ["masonry"],
deps: [],
path: null
},
{
id: 1,
name: "Nave Wall Courses",
description: "Raise the nave piers and wall courses, leaving bays for the lancet windows.",
needs: ["masonry"],
deps: [0],
path: "ground"
},
{
id: 2,
name: "Roof Trusses",
description: "Raise the king-post trusses and steep, stepped nave roof over the walls.",
needs: ["carpentry"],
deps: [1],
path: "scaffold"
},
{
id: 3,
name: "Flying Buttresses",
description: "Install the exterior piers and arched flying buttresses that carry the roof thrust.",
needs: ["masonry", "lifting"],
deps: [2],
path: "roofWalk"
},
{
id: 4,
name: "Rose & Tracery",
description: "Set the glazed rose window and delicate stone tracery into the west tower.",
needs: ["masonry", "carpentry"],
deps: [3],
path: "roseWalk"
},
{
id: 5,
name: "Tower Spire",
description: "Lift the timber spire frame and stack the slate flèche over the crossing.",
needs: ["carpentry", "lifting"],
deps: [4],
path: "spireCradle"
},
{
id: 6,
name: "Doors & Bell",
description: "Hang the great doors, fit the bell, and complete the church fittings.",
needs: ["masonry", "carpentry"],
deps: [5],
path: "chapelWalk"
}
];
const PATHS = [
{ id: "ground", name: "Ground Haul Route", discipline: "masonry", after: null, nextStage: 1 },
{ id: "scaffold", name: "Nave Scaffold Walk", discipline: "carpentry", after: 1, nextStage: 2 },
{ id: "roofWalk", name: "Roof Catwalk", discipline: "carpentry", after: 2, nextStage: 3 },
{ id: "roseWalk", name: "Rose Tower Scaffold", discipline: "carpentry", after: 3, nextStage: 4 },
{ id: "spireCradle", name: "Spire Lifting Cradle", discipline: "lifting", after: 4, nextStage: 5 },
{ id: "chapelWalk", name: "Chapel Side Deck", discipline: "carpentry", after: 5, nextStage: 6 }
];
const state = {
assignments: {
ada: "masonry",
odo: null,
wren: "carpentry",
pip: null,
tessa: "lifting",
hal: null
},
stages: STAGES.map(s => ({ ...s, progress: 0, complete: false })),
paths: PATHS.map(p => ({ ...p, progress: 0, complete: false })),
selectedStage: 0,
selectedPath: "ground",
activeWork: { type: "stage", id: 0 },
paused: false
};
const $ = selector => document.querySelector(selector);
const $$ = selector => [...document.querySelectorAll(selector)];
const clamp = (v, a, b) => Math.min(b, Math.max(a, v));
const tradeLabel = trade => trade.charAt(0).toUpperCase() + trade.slice(1);
let toastTimer;
function toast(message) {
const element = $("#toast");
element.textContent = message;
element.classList.add("show");
clearTimeout(toastTimer);
toastTimer = setTimeout(() => element.classList.remove("show"), 3400);
}
function crewCounts() {
const counts = { masonry: 0, carpentry: 0, lifting: 0 };
Object.values(state.assignments).forEach(trade => {
if (trade) counts[trade]++;
});
return counts;
}
function stageUnlocked(stage) {
const depsDone = stage.deps.every(id => state.stages[id].complete);
const pathDone = !stage.path || state.paths.find(p => p.id === stage.path)?.complete;
return depsDone && pathDone;
}
function pathBuildable(path) {
return path.after === null || state.stages[path.after].complete;
}
function workRate(needs) {
let rate = 0;
CREW.forEach(worker => {
const assigned = state.assignments[worker.id];
if (assigned && needs.includes(assigned)) {
rate += worker.speed * (assigned === worker.natural ? 1.25 : 0.78);
}
});
return rate;
}
function missingDependencies(stage) {
const missing = stage.deps
.filter(id => !state.stages[id].complete)
.map(id => state.stages[id].name);
if (stage.path) {
const path = state.paths.find(p => p.id === stage.path);
if (!path.complete) missing.push(path.name);
}
return missing;
}
// ------------------------------------------------------------
// Interface
// ------------------------------------------------------------
function renderCrew() {
$("#crew-list").innerHTML = CREW.map(worker => {
const assignment = state.assignments[worker.id] || "";
return `
<div class="crew-card">
<div class="avatar" style="background:#${worker.color.toString(16).padStart(6, "0")}">
${worker.initials}
</div>
<div class="crew-meta">
<b>${worker.name}</b>
<small>${tradeLabel(worker.natural)} · ${worker.speed >= 1.15 ? "swift" : "steady"}</small>
</div>
<select data-crew="${worker.id}" aria-label="Assign ${worker.name}">
<option value="" ${assignment === "" ? "selected" : ""}>Reserve</option>
<option value="masonry" ${assignment === "masonry" ? "selected" : ""}>Masonry</option>
<option value="carpentry" ${assignment === "carpentry" ? "selected" : ""}>Carpentry</option>
<option value="lifting" ${assignment === "lifting" ? "selected" : ""}>Lifting</option>
</select>
</div>
`;
}).join("");
$$("#crew-list select").forEach(select => {
select.addEventListener("change", event => {
const id = event.target.dataset.crew;
const trade = event.target.value || null;
if (trade) {
const counts = crewCounts();
if (state.assignments[id] !== trade && counts[trade] >= 2) {
event.target.value = state.assignments[id] || "";
toast(`${tradeLabel(trade)} already has two assigned workers. Move one worker first.`);
return;
}
}
state.assignments[id] = trade;
const worker = CREW.find(c => c.id === id);
toast(trade
? `${worker.name} assigned to ${tradeLabel(trade)}.`
: `${worker.name} returned to the reserve bench.`);
renderUI();
});
});
}
function renderStageRail() {
$("#stage-rail").innerHTML = state.stages.map(stage => `
<button class="stage-card" data-stage="${stage.id}">
<div class="stage-top">
<span class="stage-no">${String(stage.id + 1).padStart(2, "0")}</span>
<span class="stage-status">Locked</span>
</div>
<div class="stage-name">${stage.name}</div>
<div class="mini-progress"><div></div></div>
</button>
`).join("");
$$("#stage-rail [data-stage]").forEach(button => {
button.addEventListener("click", () => selectStage(Number(button.dataset.stage)));
});
}
function renderPaths() {
$("#path-list").innerHTML = state.paths.map(path => `
<div class="path-row" data-path-row="${path.id}">
<div class="path-top">
<span class="path-icon">◇</span>
<span class="path-name">${path.name}</span>
<button class="path-action" data-path="${path.id}">Build</button>
</div>
<div class="path-status"></div>
<div class="path-progress"><div></div></div>
</div>
`).join("");
$$("#path-list [data-path]").forEach(button => {
button.addEventListener("click", () => selectPath(button.dataset.path));
});
}
function selectStage(id) {
const stage = state.stages[id];
state.selectedStage = id;
if (stage.complete) {
toast(`${stage.name} is already complete.`);
} else if (!stageUnlocked(stage)) {
const missing = missingDependencies(stage);
toast(`${stage.name} is locked. Complete ${missing.join(" and ")} first.`);
} else {
state.activeWork = { type: "stage", id };
toast(`${stage.name} is now the active construction order.`);
}
renderUI();
}
function selectPath(id) {
const path = state.paths.find(p => p.id === id);
state.selectedPath = id;
state.selectedStage = path.nextStage;
if (path.complete) {
toast(`${path.name} is already certified safe.`);
} else if (!pathBuildable(path)) {
toast(`${path.name} cannot be built until ${state.stages[path.after].name} is complete.`);
} else if (crewCounts()[path.discipline] === 0) {
toast(`${path.name} needs an assigned ${tradeLabel(path.discipline).toLowerCase()} worker.`);
} else {
state.activeWork = { type: "path", id };
toast(`${path.name} is now the active access order.`);
}
renderUI();
}
function renderUI() {
const counts = crewCounts();
const assignedTotal = Object.values(state.assignments).filter(Boolean).length;
const completedRoutes = state.paths.filter(path => path.complete).length;
$("#count-masonry").textContent = counts.masonry;
$("#count-carpentry").textContent = counts.carpentry;
$("#count-lifting").textContent = counts.lifting;
$("#assigned-total").textContent = `${assignedTotal} / 6`;
$("#stat-masonry").textContent = `${counts.masonry} / 2`;
$("#stat-carpentry").textContent = `${counts.carpentry} / 2`;
$("#stat-lifting").textContent = `${counts.lifting} / 2`;
$("#stat-routes").textContent = `${completedRoutes} / ${state.paths.length}`;
$("#route-summary").textContent = `${completedRoutes} certified`;
$$("#crew-list select").forEach(select => {
select.value = state.assignments[select.dataset.crew] || "";
});
const stage = state.stages[state.selectedStage];
const unlocked = stageUnlocked(stage);
const stageState = stage.complete ? "complete" : unlocked ? "ready" : "locked";
const stateText = stage.complete ? "Complete" : unlocked ? "Ready" : "Locked";
const dependencyItems = stage.deps.map(id => {
const dep = state.stages[id];
return `<span class="check ${dep.complete ? "done" : ""}">${dep.complete ? "✓" : "○"} ${dep.name}</span>`;
});
if (stage.path) {
const path = state.paths.find(p => p.id === stage.path);
dependencyItems.push(
`<span class="check ${path.complete ? "done" : ""}">${path.complete ? "✓" : "◇"} ${path.name}</span>`
);
}
$("#selected-stage").innerHTML = `
<div class="stage-title-row">
<div>
<div class="eyebrow">Selected component</div>
<h3>${stage.name}</h3>
</div>
<span class="state-pill ${stageState}">${stateText}</span>
</div>
<p class="stage-description">${stage.description}</p>
<div class="progress-track"><div class="progress-fill" style="width:${stage.progress}%"></div></div>
<div class="progress-meta">
<span>${stage.complete ? "Construction certified" : unlocked ? "Component progress" : "Awaiting prerequisites"}</span>
<span>${Math.floor(stage.progress)}%</span>
</div>
<div class="checks">${dependencyItems.join("") || `<span class="check done">✓ Starting order</span>`}</div>
<div class="need-row">
${stage.needs.map(trade => `
<span class="need ${counts[trade] ? "ready" : ""}">
${counts[trade]} ${tradeLabel(trade).toLowerCase()}${counts[trade] === 1 ? "" : "s"}
</span>
`).join("")}
</div>
`;
const order = $("#active-order");
if (state.paused) {
order.innerHTML = `
<div class="order-label">Workshop paused</div>
<strong>All work is suspended</strong>
<small>Press Pause in the top bar to resume.</small>
`;
} else if (state.activeWork.type === "stage") {
const active = state.stages[state.activeWork.id];
order.innerHTML = `
<div class="order-label">Active component</div>
<strong>${active.name}</strong>
<small>${active.needs.map(trade => `${crewCounts()[trade]} ${tradeLabel(trade).toLowerCase()}`).join(" + ")} assigned</small>
<div class="progress-track" style="margin-top:8px"><div class="progress-fill" style="width:${active.progress}%"></div></div>
`;
} else if (state.activeWork.type === "path") {
const active = state.paths.find(p => p.id === state.activeWork.id);
order.innerHTML = `
<div class="order-label">Active access schematic</div>
<strong>${active.name}</strong>
<small>${crewCounts()[active.discipline]} ${tradeLabel(active.discipline).toLowerCase()} worker(s) on route</small>
<div class="progress-track" style="margin-top:8px"><div class="progress-fill green" style="width:${active.progress}%"></div></div>
`;
} else {
order.innerHTML = `
<div class="order-label">No active order</div>
<strong>Select a ready component or route</strong>
<small>Complete the highlighted access schematic to unlock the next build.</small>
`;
}
$$("#stage-rail [data-stage]").forEach(button => {
const id = Number(button.dataset.stage);
const item = state.stages[id];
const ready = stageUnlocked(item);
const active = state.activeWork.type === "stage" && state.activeWork.id === id;
button.classList.toggle("selected", id === state.selectedStage);
button.classList.toggle("ready", ready && !item.complete);
button.classList.toggle("locked", !ready && !item.complete);
button.classList.toggle("complete", item.complete);
button.classList.toggle("active", active);
button.querySelector(".stage-status").textContent =
item.complete ? "Complete" : ready ? (active ? "Building" : "Ready") : "Locked";
button.querySelector(".mini-progress div").style.width = `${item.progress}%`;
});
state.paths.forEach(path => {
const row = $(`[data-path-row="${path.id}"]`);
const button = row.querySelector(".path-action");
const status = row.querySelector(".path-status");
const active = state.activeWork.type === "path" && state.activeWork.id === path.id;
const count = crewCounts()[path.discipline];
row.classList.toggle("active", active);
row.classList.toggle("complete", path.complete);
row.querySelector(".path-icon").textContent = path.complete ? "✓" : active ? "◆" : "◇";
row.querySelector(".path-progress div").style.width = `${path.progress}%`;
if (path.complete) {
status.textContent = "Certified safe for the next component.";
button.textContent = "Done";
} else if (!pathBuildable(path)) {
status.textContent = `Schematic locked until ${state.stages[path.after].name}.`;
button.textContent = "Locked";
} else if (!count) {
status.textContent = `Needs one assigned ${tradeLabel(path.discipline).toLowerCase()} worker.`;
button.textContent = "Assign";
} else {
status.textContent = active
? `Route under construction · ${Math.floor(path.progress)}%`
: `Buildable now · ${count} ${tradeLabel(path.discipline).toLowerCase()} worker(s)`;
button.textContent = active ? "Active" : "Build";
}
});
}
// ------------------------------------------------------------
// Three.js scene
// ------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x121c27);
scene.fog = new THREE.Fog(0x121c27, 54, 105);
const renderer = new THREE.WebGLRenderer({ antialias: true, powerPreference: "high-performance" });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.65));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
$("#scene").appendChild(renderer.domElement);
const camera = new THREE.PerspectiveCamera(43, window.innerWidth / window.innerHeight, 0.1, 180);
const cameraState = {
target: new THREE.Vector3(0, 4.6, 0),
yaw: 0.78,
pitch: 0.56,
distance: 43
};
function updateCamera() {
const { target, yaw, pitch, distance } = cameraState;
camera.position.set(
target.x + Math.sin(yaw) * Math.cos(pitch) * distance,
target.y + Math.sin(pitch) * distance,
target.z + Math.cos(yaw) * Math.cos(pitch) * distance
);
camera.lookAt(target);
}
function resetCamera() {
cameraState.target.set(0, 4.6, 0);
cameraState.yaw = 0.78;
cameraState.pitch = 0.56;
cameraState.distance = 43;
updateCamera();
}
updateCamera();
const hemi = new THREE.HemisphereLight(0xbad4e8, 0x394432, 1.35);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xffe6ba, 2.5);
sun.position.set(-24, 34, 22);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -34;
sun.shadow.camera.right = 34;
sun.shadow.camera.top = 34;
sun.shadow.camera.bottom = -34;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 90;
sun.shadow.bias = -0.00035;
scene.add(sun);
const rim = new THREE.DirectionalLight(0x7fa6d8, 0.85);
rim.position.set(20, 13, -24);
scene.add(rim);
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const material = (color, options = {}) => new THREE.MeshStandardMaterial({
color,
roughness: 0.92,
metalness: 0,
...options
});
const MAT = {
grass: material(0x536b4c),
grassDark: material(0x415840),
grassLight: material(0x66785a),
stone: material(0x9b978a),
stoneLight: material(0xb2ad9c),
stoneDark: material(0x767b76),
mortar: material(0x6f746f),
timber: material(0x8c5f3d),
timberLight: material(0xaa7950),
timberDark: material(0x594334),
slate: material(0x405469),
slateLight: material(0x587187),
roof: material(0x354a5c),
gold: material(0xc8a65b, { metalness: 0.35, roughness: 0.5 }),
glass: material(0x6ea7bc, { emissive: 0x173e51, emissiveIntensity: 0.7, roughness: 0.25 }),
crane: material(0xd6a53c),
craneDark: material(0x725a29),
safety: material(0x72c39d, { emissive: 0x173f2d, emissiveIntensity: 0.55 }),
leaf: material(0x365846),
leafLight: material(0x4f7456),
fire: material(0xffa34b, { emissive: 0xd65a1f, emissiveIntensity: 1.8 })
};
function box(parent, mat, x, y, z, width, height, depth, options = {}) {
const mesh = new THREE.Mesh(unitBox, mat);
mesh.position.set(x, y, z);
mesh.scale.set(width, height, depth);
mesh.castShadow = options.castShadow !== false;
mesh.receiveShadow = options.receiveShadow !== false;
if (options.rotation) mesh.rotation.set(...options.rotation);
parent.add(mesh);
return mesh;
}
// Ground and tiled construction platform.
box(scene, MAT.grass, 0, -0.35, 0, 110, 0.5, 100, { castShadow: false });
const tileGeometry = new THREE.BoxGeometry(1.88, 0.28, 1.88);
const tileMaterial = material(0xffffff);
const tiles = new THREE.InstancedMesh(tileGeometry, tileMaterial, 19 * 14);
const dummy = new THREE.Object3D();
const tileColors = [0x64745a, 0x5b6d55, 0x6d7b61, 0x52664f];
let tileIndex = 0;
for (let x = -18; x <= 18; x += 2) {
for (let z = -13; z <= 13; z += 2) {
dummy.position.set(x, -0.08, z);
dummy.updateMatrix();
tiles.setMatrixAt(tileIndex, dummy.matrix);
const color = new THREE.Color(tileColors[(tileIndex * 7 + x + z) % tileColors.length]);
color.offsetHSL(0, 0, ((x + z) % 3) * 0.012);
tiles.setColorAt(tileIndex, color);
tileIndex++;
}
}
tiles.instanceMatrix.needsUpdate = true;
if (tiles.instanceColor) tiles.instanceColor.needsUpdate = true;
tiles.receiveShadow = true;
scene.add(tiles);
// Distant voxel trees.
const treePositions = [
[-25, -20], [-20, -27], [24, -23], [29, -15], [-28, 17], [27, 20],
[-31, 3], [32, 2], [-18, 26], [20, 29]
];
treePositions.forEach(([x, z], index) => {
const tree = new THREE.Group();
tree.position.set(x, 0, z);
box(tree, MAT.timberDark, 0, 2.2, 0, 1.1, 4.4, 1.1);
const size = 4.8 + (index % 3) * 0.7;
box(tree, index % 2 ? MAT.leaf : MAT.leafLight, 0, 5, 0, size, 3.3, size);
box(tree, MAT.leaf, -1.5, 6.4, .3, size * .65, 2.1, size * .65);
scene.add(tree);
});
// Small square stars.
const starMaterial = material(0xc8d8e5, { emissive: 0x839bad, emissiveIntensity: 0.8 });
for (let i = 0; i < 34; i++) {
const angle = i * 2.399;
const radius = 47 + (i % 4) * 5;
box(
scene,
starMaterial,
Math.cos(angle) * radius,
13 + (i * 7 % 17),
Math.sin(angle) * radius,
.28,
.28,
.28,
{ castShadow: false, receiveShadow: false }
);
}
// Church root and construction groups.
const church = new THREE.Group();
church.position.z = -0.5;
scene.add(church);
const stageGroups = state.stages.map(() => new THREE.Group());
stageGroups.forEach(group => church.add(group));
box(church, MAT.stoneDark, 0, 0.12, 0, 15.5, .25, 21.5);
// Stage 0: footings and plinths.
const s0 = stageGroups[0];
for (const x of [-7.4, 7.4]) {
for (let z = -9; z <= 9; z += 1.8) {
const mat = (Math.round(z) % 3 === 0) ? MAT.stoneDark : MAT.stone;
box(s0, mat, x, .35, z, 1.7, .65, 1.65);
box(s0, MAT.stoneLight, x, .72, z, 1.35, .28, 1.3);
}
}
for (const z of [-9.6, 9.6]) {
for (let x = -6.6; x <= 6.6; x += 1.8) {
const mat = Math.round(x) % 3 === 0 ? MAT.stoneDark : MAT.stone;
box(s0, mat, x, .35, z, 1.65, .65, 1.65);
box(s0, MAT.stoneLight, x, .72, z, 1.3, .28, 1.35);
}
}
// Stage 1: nave walls, tower piers, and pointed openings.
const s1 = stageGroups[1];
const wallMaterials = [MAT.stone, MAT.stoneLight, MAT.stone, MAT.stoneDark];
for (const side of [-1, 1]) {
let segment = 0;
for (let z = -8; z <= 8; z += 2) {
for (let level = 0; level < 6; level++) {
const windowGap = level === 3 && segment % 4 === 1;
const windowGap2 = level === 4 && segment % 4 === 3;
if (!windowGap && !windowGap2) {
box(
s1,
wallMaterials[(segment + level) % wallMaterials.length],
side * 6.4,
1.05 + level * 1.03,
z,
.9,
.98,
1.88
);
}
}
segment++;
}
}
for (let level = 0; level < 10; level++) {
for (const side of [-1, 1]) {
box(s1, wallMaterials[level % 4], side * 3.05, 1 + level * 1.02, 9.25, 1.15, .98, 1.05);
}
}
for (let x = -2.5; x <= 2.5; x += 1) {
for (let level = 8; level < 10; level++) {
if (Math.abs(x) > 1.7 || level < 9) {
box(s1, MAT.stoneDark, x, 1 + level * 1.02, 9.25, .98, .98, 1.05);
}
}
}
// Gothic pointed arch over the portal.
function pointedArch(parent, mat, cx, baseY, z, width, height, depth, thickness = .42) {
for (const side of [-1, 1]) {
box(parent, mat, cx + side * width / 2, baseY + height * .25, z, thickness, height * .5, depth);
}
const steps = 5;
for (let i = 0; i < steps; i++) {
const offset = width / 2 - (i + .25) * (width / (steps + 2));
const y = baseY + height * .52 + i * (height * .09);
box(parent, mat, cx - offset, y, z, thickness * 1.45, height * .11, depth);
box(parent, mat, cx + offset, y, z, thickness * 1.45, height * .11, depth);
}
box(parent, mat, cx, baseY + height * .98, z, thickness * 1.7, thickness * 1.25, depth);
}
pointedArch(s1, MAT.stoneLight, 0, .85, 9.95, 3.3, 4.3, .62, .5);
// Rear wall and lancet opening.
for (let x = -5.5; x <= 5.5; x += 1.1) {
if (Math.abs(x) > 1.4) {
box(s1, MAT.stone, x, 2.2, -9.1, 1.05, 3.3, .85);
}
}
box(s1, MAT.stoneLight, 0, 4.35, -9.1, 3.5, .65, .85);
pointedArch(s1, MAT.stoneLight, 0, 2.6, -9.58, 2.6, 3.2, .3, .35);
// Stage 2: roof trusses and stepped roof.
const s2 = stageGroups[2];
for (let z = -7.5; z <= 8; z += 2.5) {
box(s2, MAT.timber, 0, 8.2, z, 13.4, .38, .42);
box(s2, MAT.timberDark, 0, 8.2, z, .38, 3.8, .42);
for (const side of [-1, 1]) {
for (let i = 0; i < 5; i++) {
box(s2, MAT.timber, side * (5.8 - i), 8.55 + i * .43, z, .58, .55, .4);
}
}
}
for (const side of [-1, 1]) {
for (let xAbs = 1; xAbs <= 6; xAbs++) {
const y = 9.15 + (6 - xAbs) * .55;
box(s2, xAbs % 2 ? MAT.roof : MAT.slate, side * xAbs, y, 0, 1.08, .48, 19.3);
}
}
// Stage 3: exterior flying buttresses.
const s3 = stageGroups[3];
for (const side of [-1, 1]) {
for (const z of [-6.2, -.2, 5.8]) {
box(s3, MAT.stoneDark, side * 9.2, 2.5, z, 1.25, 4.8, 1.4);
box(s3, MAT.stoneLight, side * 9.2, 4.85, z, 1.55, .45, 1.7);
for (let i = 0; i < 6; i++) {
const x = side * (8.9 - i * .43);
const y = 5.1 + i * .43;
box(s3, i % 2 ? MAT.stone : MAT.stoneLight, x, y, z, .72, .58, .72);
}
box(s3, MAT.stoneLight, side * 6.55, 7.45, z, 1.15, .5, .82);
}
}
// Stage 4: rose window and side tracery.
const s4 = stageGroups[4];
const roseY = 8.35;
const roseZ = 9.94;
for (let x = -3; x <= 3; x++) {
for (let y = -3; y <= 3; y++) {
const radius = Math.hypot(x, y);
const ring = radius >= 1.75 && radius <= 2.65;
const spoke = Math.abs(x) <= .1 || Math.abs(y) <= .1;
const center = radius < 1.65;
if (ring || spoke || center) {
const mat = ring ? MAT.stoneLight : MAT.glass;
box(s4, mat, x * .48, roseY + y * .48, roseZ, .43, .43, .3);
}
}
}
// Voxel tracery in the side lancet openings.
for (const side of [-1, 1]) {
for (const z of [-6, 0, 6]) {
box(s4, MAT.stoneLight, side * 6.45, 4.4, z, .28, 2.5, .18);
box(s4, MAT.glass, side * 6.43, 4.2, z, .16, 2.1, .12);
for (let y = 3.3; y < 5.2; y += .55) {
box(s4, MAT.stoneLight, side * 6.5, y, z, .3, .16, .24);
}
}
}
// Stage 5: timber spire frame and slate flèche.
const s5 = stageGroups[5];
for (let level = 0; level < 7; level++) {
const half = 2.65 - level * .35;
const y = 12 + level * 1.05;
const mat = level % 2 ? MAT.slate : MAT.slateLight;
for (let x = -half; x <= half; x += .85) {
for (let z = -half; z <= half; z += .85) {
if (Math.abs(x) >= half - .3 || Math.abs(z) >= half - .3) {
box(s5, mat, x, y, 8.7 + z, .9, 1.05, .9);
}
}
}
}
box(s5, MAT.gold, 0, 19.55, 8.7, .34, 2, .34);
box(s5, MAT.gold, 0, 20.4, 8.7, 1.2, .24, .24);
// Stage 6: doors, bell, and pews.
const s6 = stageGroups[6];
for (let x = -1.25; x <= 1.25; x += .5) {
box(s6, MAT.timberDark, x, 2.35, 9.98, .46, 3.7, .35);
}
box(s6, MAT.gold, -.7, 2.3, 10.2, .12, .12, .12);
box(s6, MAT.gold, .7, 2.3, 10.2, .12, .12, .12);
box(s6, MAT.gold, 0, 5.9, 9.96, 5.9, .32, .7);
box(s6, MAT.gold, 0, 5.15, 9.98, .15, 1.1, .15);
box(s6, MAT.gold, 0, 4.75, 9.98, .72, .6, .58);
box(s6, MAT.stoneLight, 0, 3.7, 9.98, .9, .35, .6);
for (const z of [-5, -2.5, 0]) {
for (const x of [-2.8, 2.8]) {
box(s6, MAT.timber, x, 1.25, z, 1.2, .25, 2.4);
box(s6, MAT.timberDark, x, .85, z, .24, .8, .24);
}
}
// Tag each component child for progressive reveal.
const stageParts = stageGroups.map(group => {
const parts = [];
group.traverse(object => {
if (object.isMesh) parts.push(object);
});
parts.forEach((part, index) => {
part.userData.revealAt = ((index + 1) / parts.length) * 100;
});
return parts;
});
// ------------------------------------------------------------
// Access route visuals
// ------------------------------------------------------------
const pathGroups = {};
function makePathGroup(id) {
const group = new THREE.Group();
scene.add(group);
pathGroups[id] = group;
return group;
}
const groundPath = makePathGroup("ground");
for (let z = 11; z >= -11; z -= 1.3) {
box(groundPath, MAT.safety, -11, .12, z, .55, .18, .75);
}
for (let x = -10; x <= -6; x += 1) {
box(groundPath, MAT.safety, x, .12, 9.2, .65, .18, .55);
}
const scaffoldPath = makePathGroup("scaffold");
for (let z = -7; z <= 8; z += 2) {
for (const x of [8.1, 10.1]) {
for (const y of [.5, 3.1, 5.7, 8.3]) {
box(scaffoldPath, MAT.timber, x, y, z, .2, 3.2, .2);
}
}
for (const y of [2.9, 5.5, 8.1]) {
box(scaffoldPath, MAT.timberLight, 9.1, y, z, 2.35, .18, .55);
box(scaffoldPath, MAT.timber, 9.1, y + .55, z, 2.35, .13, .16);
}
}
const roofWalk = makePathGroup("roofWalk");
for (let z = -8; z <= 9; z += 1.15) {
box(roofWalk, MAT.safety, 0, 12.2, z, .65, .16, .7);
}
for (let z = -7; z <= 8; z += 2.4) {
box(roofWalk, MAT.timber, 0, 11.65, z, 2.2, .16, .35);
}
const roseWalk = makePathGroup("roseWalk");
for (const x of [-4.4, 4.4]) {
for (let y = .5; y < 10; y += 2) {
box(roseWalk, MAT.timber, x, y, 11.15, .2, 2.5, .2);
}
}
for (let y = 2; y < 10; y += 2) {
box(roseWalk, MAT.timberLight, 0, y, 11.15, 9, .18, .55);
box(roseWalk, MAT.timber, 0, y + .55, 11.15, 9, .12, .14);
}
const spireCradle = makePathGroup("spireCradle");
box(spireCradle, MAT.crane, 0, 11.5, 8.7, 7.5, .35, 7.5);
for (const x of [-3.3, 3.3]) {
box(spireCradle, MAT.craneDark, x, 12.7, 8.7, .22, 2.4, .22);
}
const chapelWalk = makePathGroup("chapelWalk");
for (let z = -8; z <= 7; z += 1.25) {
box(chapelWalk, MAT.safety, -8.2, 1.15, z, .65, .18, .7);
}
for (const z of [-7, -3, 1, 5]) {
box(chapelWalk, MAT.timber, -8.2, .55, z, .25, 1.2, .25);
}
const pathParts = {};
Object.entries(pathGroups).forEach(([id, group]) => {
const parts = [];
group.traverse(object => {
if (object.isMesh) parts.push(object);
});
parts.forEach((part, index) => {
part.userData.revealAt = ((index + 1) / parts.length) * 100;
});
pathParts[id] = parts;
});
// ------------------------------------------------------------
// Blueprint previews
// ------------------------------------------------------------
const blueprintMaterial = new THREE.MeshBasicMaterial({
color: 0x82bddd,
transparent: true,
opacity: 0.12,
depthWrite: false,
wireframe: true
});
const blueprints = state.stages.map(() => new THREE.Group());
blueprints.forEach(group => church.add(group));
function blueprintBox(group, x, y, z, w, h, d) {
box(group, blueprintMaterial, x, y, z, w, h, d, { castShadow: false, receiveShadow: false });
}
blueprintBox(blueprints[0], 0, .4, 0, 15.5, .8, 21);
blueprintBox(blueprints[1], -6.4, 4, 0, 1, 7, 18);
blueprintBox(blueprints[1], 6.4, 4, 0, 1, 7, 18);
blueprintBox(blueprints[1], 0, 5, 9.25, 7, 10, 1.2);
for (const side of [-1, 1]) {
for (let i = 1; i <= 6; i++) {
blueprintBox(blueprints[2], side * i, 9 + (6 - i) * .55, 0, 1.05, .5, 19);
}
}
for (const side of [-1, 1]) {
blueprintBox(blueprints[3], side * 8.7, 4.8, 0, 1.2, 6, 16);
}
for (let x = -3; x <= 3; x++) {
for (let y = -3; y <= 3; y++) {
const r = Math.hypot(x, y);
if (r >= 1.75 && r <= 2.65) {
blueprintBox(blueprints[4], x * .48, 8.35 + y * .48, 9.94, .45, .45, .35);
}
}
}
for (let level = 0; level < 7; level++) {
const half = 2.65 - level * .35;
blueprintBox(blueprints[5], 0, 12 + level * 1.05, 8.7, half * 2, 1.05, half * 2);
}
blueprintBox(blueprints[6], 0, 2.4, 10, 3, 4, .5);
blueprintBox(blueprints[6], 0, 5.2, 9.9, 1, 1.2, 1);
// ------------------------------------------------------------
// Workshop props
// ------------------------------------------------------------
// Crane.
const crane = new THREE.Group();
crane.position.set(13.5, 0, 3.8);
scene.add(crane);
box(crane, MAT.craneDark, 0, .35, 0, 3.3, .7, 3.3);
box(crane, MAT.crane, 0, 5.9, 0, .65, 11.2, .65);
box(crane, MAT.crane, -4.7, 11.2, 0, 10, .55, .55);
box(crane, MAT.craneDark, -8.8, 10.95, 0, 1.8, .7, .7);
box(crane, MAT.timberDark, 0, 11.5, 0, 1.4, 1.4, 1.4);
box(crane, MAT.craneDark, -6.5, 7.1, 0, .18, 8, .18);
const hook = new THREE.Group();
hook.position.set(-6.5, 6.9, 0);
box(hook, MAT.timberDark, 0, -1.5, 0, .07, 3, .07);
box(hook, MAT.crane, 0, -3.1, 0, .45, .45, .45);
crane.add(hook);
// Stone pallets.
function pallet(x, z, count, stone = true) {
box(scene, MAT.timberDark, x, .22, z, 3.2, .38, 2.4);
for (let i = 0; i < count; i++) {
if (stone) {
for (let layer = 0; layer < 2; layer++) {
for (let j = 0; j < 3; j++) {
box(
scene,
layer % 2 ? MAT.stoneLight : MAT.stone,
x - 1 + j,
.65 + layer * .62,
z + (i % 2 ? .22 : -.22),
.92,
.58,
.9
);
}
}
} else {
for (let layer = 0; layer < 3; layer++) {
box(scene, layer % 2 ? MAT.timberLight : MAT.timber, x, .65 + layer * .45, z, 3, .4, .65);
}
}
}
}
pallet(-14.2, -6.5, 3, true);
pallet(-14.2, -2.5, 2, true);
pallet(14.2, -8, 3, false);
pallet(-14.4, 4.8, 2, false);
// Workbench and tools.
box(scene, MAT.timber, -12.2, 1.05, 8.2, 4.3, .28, 1.8);
for (const x of [-13.8, -10.6]) {
box(scene, MAT.timberDark, x, .5, 8.2, .28, 1, 1.4);
}
box(scene, MAT.stoneLight, -12.9, 1.28, 8.2, .8, .18, .55);
box(scene, MAT.timberDark, -11.3, 1.35, 8.2, .8, .12, .25);
// Fence posts around the site.
for (let x = -18; x <= 18; x += 4) {
if (Math.abs(x) < 11) continue;
box(scene, MAT.timberDark, x, .8, -14, .28, 1.7, .28);
}
box(scene, MAT.timberDark, -17.8, 1.15, -14, .15, .15, 15);
box(scene, MAT.timberDark, 17.8, 1.15, -14, .15, .15, 15);
// Supply tent.
const tent = new THREE.Group();
tent.position.set(-12.8, 0, 12.2);
box(tent, MAT.timberDark, 0, 1.3, 0, 4.5, .22, 3.4);
for (const x of [-2, 2]) {
for (const z of [-1.5, 1.5]) {
box(tent, MAT.timber, x, 1.4, z, .18, 2.8, .18);
}
}
box(tent, MAT.crane, 0, 2.8, 0, 4.8, .22, 3.8, { rotation: [0, 0, 0] });
scene.add(tent);
// Brazier.
const brazier = new THREE.Group();
brazier.position.set(-10.7, 0, 10.7);
box(brazier, MAT.craneDark, 0, .65, 0, 1.1, 1.3, 1.1);
box(brazier, MAT.fire, 0, 1.45, 0, .8, .8, .8);
box(brazier, MAT.fire, .2, 2.0, -.1, .45, .6, .45);
scene.add(brazier);
// ------------------------------------------------------------
// Voxel crew
// ------------------------------------------------------------
const workerMeshes = CREW.map((worker, index) => {
const group = new THREE.Group();
const clothing = material(worker.color);
const skin = material(index % 2 ? 0xc79576 : 0x9e6f56);
const boots = MAT.timberDark;
box(group, boots, -.18, .25, 0, .25, .5, .32);
box(group, boots, .18, .25, 0, .25, .5, .32);
box(group, clothing, 0, .75, 0, .65, .75, .42);
box(group, skin, 0, 1.34, 0, .42, .42, .42);
box(group, MAT.crane, 0, 1.62, 0, .52, .18, .52);
box(group, MAT.crane, 0, 1.72, 0, .32, .15, .42);
const leftArm = new THREE.Group();
leftArm.position.set(-.43, 1, 0);
box(leftArm, clothing, 0, -.25, 0, .2, .65, .22);
group.add(leftArm);
const rightArm = new THREE.Group();
rightArm.position.set(.43, 1, 0);
box(rightArm, clothing, 0, -.25, 0, .2, .65, .22);
group.add(rightArm);
scene.add(group);
return { group, leftArm, rightArm, index };
});
const workerTargets = {
masonry: [
new THREE.Vector3(-7.8, .05, 2.2),
new THREE.Vector3(7.9, .05, -4.2)
],
carpentry: [
new THREE.Vector3(9.7, .05, 2.2),
new THREE.Vector3(-8.7, .05, -6.4)
],
lifting: [
new THREE.Vector3(12.3, .05, 2.1),
new THREE.Vector3(8.2, .05, 6.4)
],
reserve: [
new THREE.Vector3(-11.1, .05, 8.9),
new THREE.Vector3(-10.2, .05, 9.5),
new THREE.Vector3(-9.3, .05, 10.1)
]
};
// Route marker.
const routeMarker = new THREE.Mesh(
new THREE.BoxGeometry(.42, .42, .42),
new THREE.MeshBasicMaterial({ color: 0xffd77e })
);
routeMarker.castShadow = false;
scene.add(routeMarker);
const markerPositions = {
ground: new THREE.Vector3(-10.8, 1.5, 8),
scaffold: new THREE.Vector3(9.1, 9.2, 3),
roofWalk: new THREE.Vector3(0, 13.1, 2),
roseWalk: new THREE.Vector3(0, 11, 11.2),
spireCradle: new THREE.Vector3(0, 13.2, 8.7),
chapelWalk: new THREE.Vector3(-8.2, 2.1, 0)
};
// ------------------------------------------------------------
// Simulation and visual updates
// ------------------------------------------------------------
function updateWork(delta) {
if (state.paused) return;
if (state.activeWork.type === "stage") {
const stage = state.stages[state.activeWork.id];
if (stage.complete || !stageUnlocked(stage)) return;
const rate = workRate(stage.needs) * 5.5;
if (rate <= 0) return;
stage.progress = Math.min(100, stage.progress + rate * delta);
if (stage.progress >= 100) {
stage.progress = 100;
stage.complete = true;
toast(`${stage.name} completed. The next schematic is now available.`);
const next = state.stages[stage.id + 1];
if (next) {
state.selectedStage = next.id;
state.activeWork = stageUnlocked(next)
? { type: "stage", id: next.id }
: { type: "none" };
} else {
state.activeWork = { type: "none" };
toast("The church is complete. The guild raises a voxel banner!");
}
renderUI();
}
}
if (state.activeWork.type === "path") {
const path = state.paths.find(p => p.id === state.activeWork.id);
if (path.complete || !pathBuildable(path)) return;
const rate = workRate([path.discipline]) * 4.2;
if (rate <= 0) return;
path.progress = Math.min(100, path.progress + rate * delta);
if (path.progress >= 100) {
path.progress = 100;
path.complete = true;
toast(`${path.name} certified safe. ${state.stages[path.nextStage].name} is unlocked.`);
const next = state.stages[path.nextStage];
state.selectedStage = next.id;
state.activeWork = stageUnlocked(next)
? { type: "stage", id: next.id }
: { type: "none" };
renderUI();
}
}
}
function updateConstructionVisuals() {
state.stages.forEach((stage, index) => {
stageParts[index].forEach(part => {
part.visible = stage.progress >= part.userData.revealAt;
});
});
state.paths.forEach(path => {
pathParts[path.id].forEach(part => {
part.visible = path.progress >= part.userData.revealAt;
});
});
blueprints.forEach((blueprint, index) => {
blueprint.visible = index === state.selectedStage && !state.stages[index].complete;
});
}
function updateWorkers(delta, elapsed) {
const counters = { masonry: 0, carpentry: 0, lifting: 0, reserve: 0 };
workerMeshes.forEach(worker => {
const data = CREW[worker.index];
const assigned = state.assignments[data.id];
const category = assigned || "reserve";
const slot = counters[category]++;
const targets = workerTargets[category];
const target = targets[slot % targets.length].clone();
// Assigned workers gather near their current work area.
if (assigned === "masonry" && state.activeWork.type === "path" && state.activeWork.id === "ground") {
target.set(-10 + (worker.index % 2) * 1.4, .05, 6 - worker.index * .65);
}
if (assigned === "carpentry" && state.activeWork.type === "path") {
target.set(8.8, .05, -2 + worker.index * 2);
}
if (assigned === "lifting" && state.activeWork.type === "path" && state.activeWork.id === "spireCradle") {
target.set(10.8, .05, 3.8);
}
const speed = 1 - Math.exp(-delta * 3.2);
worker.group.position.lerp(target, speed);
worker.group.position.y = .05 + Math.sin(elapsed * 5 + worker.index) * .025;
worker.group.rotation.y = Math.atan2(
target.x - worker.group.position.x,
target.z - worker.group.position.z
);
const swing = assigned ? Math.sin(elapsed * 6 + worker.index) * .45 : 0;
worker.leftArm.rotation.x = swing;
worker.rightArm.rotation.x = -swing;
});
hook.rotation.z = Math.sin(elapsed * .65) * .045;
routeMarker.position.copy(markerPositions[state.selectedPath] || markerPositions.ground);
routeMarker.position.y += Math.sin(elapsed * 3) * .18;
routeMarker.rotation.set(elapsed * .4, elapsed * .6, 0);
}
// ------------------------------------------------------------
// Direct camera controls — no addon imports
// ------------------------------------------------------------
const canvas = renderer.domElement;
let pointer = null;
canvas.addEventListener("contextmenu", event => event.preventDefault());
canvas.addEventListener("pointerdown", event => {
pointer = {
id: event.pointerId,
x: event.clientX,
y: event.clientY,
mode: event.shiftKey || event.button === 2 ? "pan" : "orbit"
};
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", event => {
if (!pointer || pointer.id !== event.pointerId) return;
const dx = event.clientX - pointer.x;
const dy = event.clientY - pointer.y;
pointer.x = event.clientX;
pointer.y = event.clientY;
if (pointer.mode === "orbit") {
cameraState.yaw -= dx * .005;
cameraState.pitch = clamp(cameraState.pitch + dy * .004, .22, 1.25);
} else {
const right = new THREE.Vector3(Math.cos(cameraState.yaw), 0, -Math.sin(cameraState.yaw));
const forward = new THREE.Vector3(-Math.sin(cameraState.yaw), 0, -Math.cos(cameraState.yaw));
const scale = cameraState.distance * .0015;
cameraState.target.addScaledVector(right, -dx * scale);
cameraState.target.addScaledVector(forward, -dy * scale);
cameraState.target.x = clamp(cameraState.target.x, -13, 13);
cameraState.target.z = clamp(cameraState.target.z, -12, 12);
}
updateCamera();
});
function endPointer(event) {
if (pointer && pointer.id === event.pointerId) pointer = null;
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener("wheel", event => {
event.preventDefault();
cameraState.distance = clamp(
cameraState.distance * Math.exp(event.deltaY * .001),
24,
70
);
updateCamera();
}, { passive: false });
canvas.addEventListener("dblclick", resetCamera);
// ------------------------------------------------------------
// UI events and lifecycle
// ------------------------------------------------------------
$("#pause-btn").addEventListener("click", () => {
state.paused = !state.paused;
$("#pause-btn").textContent = state.paused ? "Resume" : "Pause";
renderUI();
});
$("#camera-btn").addEventListener("click", resetCamera);
$("#restart-btn").addEventListener("click", () => {
if (confirm("Restart the construction workshop and reset all progress?")) {
location.reload();
}
});
$("#crew-toggle").addEventListener("click", () => {
document.body.classList.toggle("show-left");
document.body.classList.remove("show-build");
});
$("#build-toggle").addEventListener("click", () => {
document.body.classList.toggle("show-build");
document.body.classList.remove("show-left");
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.65));
});
renderCrew();
renderStageRail();
renderPaths();
renderUI();
updateConstructionVisuals();
const clock = new THREE.Clock();
let elapsed = 0;
let uiAccumulator = 0;
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), .05);
elapsed += delta;
updateWork(delta);
updateConstructionVisuals();
updateWorkers(delta, elapsed);
uiAccumulator += delta;
if (uiAccumulator > .12) {
uiAccumulator = 0;
renderUI();
}
renderer.render(scene, camera);
}
animate();
toast("Welcome to the workshop. Assign the crew, then build the first component.");
</script>
</body>
</html>
```