Prompt specification
Build or customize the Three.js 3D scene "Compare resource use across production batches" 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: Compare resource use across production batches
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/compare-resource-use-across-production-batches-x2284
Scene Description Prompt:
Run illustrative voxel Meroitic ironworking batches, tracking ore, fuel, remaining stock, and waste with fictional quantities. Build one HTML file using Three.js from cdnjs.
Working Three.js Starter (compare-resource-use-across-production-batches-x2284):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Meroitic Ironworks — Voxel Batch Simulator</title>
<style>
:root {
color-scheme: dark;
--bg: #11100e;
--panel: #1b1916;
--panel-2: #24211d;
--panel-3: #2b2722;
--line: rgba(255, 238, 211, 0.11);
--text: #f2e9db;
--muted: #a79d8e;
--faint: #71695f;
--accent: #d87845;
--accent-2: #f0ad67;
--ore: #aa5838;
--fuel: #716b61;
--iron: #b9c8c7;
--waste: #76675a;
--green: #8ca879;
--radius: 20px;
--shadow: 0 22px 60px rgba(0, 0, 0, 0.28);
}
* {
box-sizing: border-box;
}
html {
min-width: 320px;
background: var(--bg);
}
body {
margin: 0;
min-height: 100vh;
background:
radial-gradient(circle at 12% 0%, rgba(216, 120, 69, 0.08), transparent 28rem),
radial-gradient(circle at 88% 18%, rgba(185, 200, 199, 0.05), transparent 30rem),
var(--bg);
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
-webkit-font-smoothing: antialiased;
}
button,
input {
font: inherit;
}
button {
color: inherit;
}
.app {
width: min(1540px, 100%);
margin: 0 auto;
padding: 22px;
}
.topbar {
display: flex;
align-items: center;
justify-content: space-between;
gap: 24px;
margin-bottom: 18px;
}
.brand {
display: flex;
align-items: center;
gap: 14px;
min-width: 0;
}
.brand-mark {
position: relative;
width: 48px;
height: 48px;
flex: 0 0 auto;
}
.brand-mark i {
position: absolute;
display: block;
width: 20px;
height: 20px;
border-radius: 4px;
transform: rotate(30deg) skew(-8deg, -8deg);
box-shadow: inset -5px -5px 0 rgba(0, 0, 0, 0.16);
}
.brand-mark i:nth-child(1) {
left: 2px;
top: 15px;
background: #8e462f;
}
.brand-mark i:nth-child(2) {
left: 15px;
top: 7px;
background: #d87845;
}
.brand-mark i:nth-child(3) {
right: 1px;
top: 16px;
background: #c8d1cd;
}
.eyebrow {
margin: 0 0 4px;
color: var(--accent-2);
font-size: 0.69rem;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(1.35rem, 2.3vw, 2rem);
line-height: 1.05;
letter-spacing: -0.035em;
}
.subtitle {
margin: 7px 0 0;
color: var(--muted);
font-size: 0.83rem;
}
.header-summary {
display: flex;
align-items: center;
gap: 24px;
}
.header-stat {
text-align: right;
}
.header-stat strong {
display: block;
font-size: 1.08rem;
font-variant-numeric: tabular-nums;
}
.header-stat span {
display: block;
margin-top: 3px;
color: var(--faint);
font-size: 0.68rem;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.fiction-badge {
padding: 9px 12px;
border: 1px solid rgba(240, 173, 103, 0.26);
border-radius: 999px;
background: rgba(216, 120, 69, 0.08);
color: #dfb98f;
font-size: 0.66rem;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
white-space: nowrap;
}
.dashboard {
display: grid;
grid-template-columns: minmax(0, 1.7fr) minmax(330px, 0.72fr);
gap: 18px;
align-items: stretch;
}
.scene-card,
.side-panel,
.batch-section {
border: 1px solid var(--line);
border-radius: var(--radius);
background: linear-gradient(145deg, rgba(39, 35, 30, 0.95), rgba(25, 23, 20, 0.96));
box-shadow: var(--shadow);
}
.scene-card {
overflow: hidden;
}
.scene-wrap {
position: relative;
height: clamp(490px, 66vh, 730px);
min-height: 490px;
overflow: hidden;
isolation: isolate;
background: #24201b;
}
.scene-wrap > canvas {
position: absolute;
inset: 0;
z-index: 0;
width: 100%;
height: 100%;
display: block;
cursor: grab;
touch-action: none;
}
.scene-wrap > canvas:active {
cursor: grabbing;
}
.scene-vignette {
position: absolute;
inset: 0;
z-index: 1;
pointer-events: none;
background:
linear-gradient(to bottom, rgba(12, 10, 8, 0.42), transparent 23%),
linear-gradient(to top, rgba(12, 10, 8, 0.62), transparent 25%),
radial-gradient(circle, transparent 48%, rgba(12, 10, 8, 0.3) 100%);
}
.scene-overlay {
position: absolute;
z-index: 2;
pointer-events: none;
}
.scene-heading {
top: 20px;
left: 22px;
}
.scene-kicker {
display: flex;
align-items: center;
gap: 8px;
color: #d6b994;
font-size: 0.66rem;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.scene-kicker::before {
content: "";
width: 7px;
height: 7px;
border-radius: 2px;
background: var(--accent);
box-shadow: 0 0 15px rgba(216, 120, 69, 0.9);
}
.scene-batch-label {
margin-top: 8px;
color: rgba(245, 237, 223, 0.92);
font-size: 1rem;
font-weight: 700;
text-shadow: 0 2px 12px #000;
}
.scene-state {
top: 20px;
right: 20px;
display: flex;
align-items: center;
gap: 8px;
padding: 8px 10px;
border: 1px solid rgba(255, 255, 255, 0.11);
border-radius: 999px;
background: rgba(18, 15, 12, 0.6);
backdrop-filter: blur(10px);
color: #d6ccbd;
font-size: 0.67rem;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.state-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: #81796e;
}
.state-dot.running {
background: #ef9b5a;
box-shadow: 0 0 12px #ef9b5a;
animation: pulse 1.15s ease-in-out infinite;
}
.state-dot.complete {
background: #9fbd8a;
box-shadow: 0 0 10px rgba(159, 189, 138, 0.65);
}
@keyframes pulse {
50% { opacity: 0.42; }
}
.legend {
left: 22px;
bottom: 86px;
display: flex;
flex-wrap: wrap;
gap: 8px;
}
.legend-item {
display: flex;
align-items: center;
gap: 6px;
padding: 6px 8px;
border: 1px solid rgba(255, 255, 255, 0.08);
border-radius: 8px;
background: rgba(18, 15, 12, 0.56);
backdrop-filter: blur(8px);
color: #cfc5b7;
font-size: 0.65rem;
font-weight: 700;
}
.legend-swatch {
width: 9px;
height: 9px;
border-radius: 2px;
box-shadow: inset -2px -2px 0 rgba(0, 0, 0, 0.18);
}
.control-dock {
position: absolute;
z-index: 4;
left: 18px;
right: 18px;
bottom: 18px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
padding: 10px;
border: 1px solid rgba(255, 255, 255, 0.11);
border-radius: 15px;
background: rgba(20, 17, 14, 0.82);
backdrop-filter: blur(14px);
box-shadow: 0 12px 30px rgba(0, 0, 0, 0.28);
}
.control-group {
display: flex;
align-items: center;
gap: 8px;
}
.control-button,
.speed-button {
min-height: 38px;
border: 1px solid rgba(255, 255, 255, 0.12);
border-radius: 10px;
background: rgba(255, 255, 255, 0.055);
cursor: pointer;
transition: background 150ms ease, border-color 150ms ease, transform 150ms ease;
}
.control-button {
padding: 0 13px;
color: #e8dfd2;
font-size: 0.76rem;
font-weight: 750;
}
.control-button:hover,
.speed-button:hover {
background: rgba(255, 255, 255, 0.1);
border-color: rgba(255, 255, 255, 0.2);
}
.control-button:active,
.speed-button:active {
transform: translateY(1px);
}
.control-button.primary {
min-width: 126px;
border-color: transparent;
background: linear-gradient(135deg, #d97843, #b95632);
color: #fff8ee;
box-shadow: 0 7px 20px rgba(183, 82, 43, 0.25);
}
.control-button.primary:hover {
background: linear-gradient(135deg, #e4864e, #c45f37);
}
.speed-group {
display: flex;
align-items: center;
padding: 3px;
border: 1px solid rgba(255, 255, 255, 0.08);
border-radius: 11px;
background: rgba(0, 0, 0, 0.16);
}
.speed-button {
min-width: 39px;
min-height: 31px;
padding: 0 8px;
border: 0;
background: transparent;
color: #91887c;
font-size: 0.69rem;
font-weight: 800;
}
.speed-button.active {
background: rgba(216, 120, 69, 0.18);
color: #efb17d;
}
.scene-footer {
display: flex;
align-items: center;
justify-content: space-between;
gap: 18px;
padding: 13px 18px;
border-top: 1px solid var(--line);
color: var(--faint);
font-size: 0.7rem;
}
.scene-footer strong {
color: #a89d8d;
font-weight: 650;
}
.side-panel {
display: flex;
flex-direction: column;
padding: 20px;
}
.panel-label {
color: var(--faint);
font-size: 0.65rem;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.batch-heading {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 14px;
margin-top: 7px;
}
.batch-heading h2 {
margin: 4px 0 0;
font-size: clamp(1.25rem, 2vw, 1.7rem);
line-height: 1.1;
letter-spacing: -0.03em;
}
.batch-site {
margin: 7px 0 0;
color: var(--muted);
font-size: 0.75rem;
}
.progress-ring {
--p: 0%;
position: relative;
display: grid;
width: 68px;
height: 68px;
flex: 0 0 auto;
place-items: center;
border-radius: 50%;
background: conic-gradient(var(--accent) var(--p), rgba(255, 255, 255, 0.08) 0);
}
.progress-ring::before {
content: "";
position: absolute;
inset: 6px;
border-radius: inherit;
background: #211e1a;
}
.progress-ring span {
position: relative;
z-index: 1;
font-size: 0.75rem;
font-weight: 850;
font-variant-numeric: tabular-nums;
}
.stage-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-top: 19px;
padding: 10px 12px;
border: 1px solid var(--line);
border-radius: 11px;
background: rgba(255, 255, 255, 0.025);
}
.stage-row span:first-child {
color: var(--faint);
font-size: 0.67rem;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
}
#stageName {
color: #d9cdbd;
font-size: 0.73rem;
font-weight: 700;
text-align: right;
}
.metric-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 10px;
margin-top: 14px;
}
.metric-card {
position: relative;
min-height: 112px;
overflow: hidden;
padding: 14px;
border: 1px solid var(--line);
border-radius: 14px;
background: rgba(255, 255, 255, 0.027);
}
.metric-card::after {
content: "";
position: absolute;
right: -15px;
bottom: -17px;
width: 55px;
height: 55px;
border-radius: 12px;
background: var(--tone);
opacity: 0.1;
transform: rotate(15deg);
}
.metric-name {
display: flex;
align-items: center;
gap: 7px;
color: #a79e91;
font-size: 0.68rem;
font-weight: 700;
}
.metric-dot {
width: 8px;
height: 8px;
border-radius: 2px;
background: var(--tone);
}
.metric-value {
display: block;
margin-top: 10px;
font-size: clamp(1.4rem, 2.4vw, 1.85rem);
font-weight: 780;
letter-spacing: -0.045em;
font-variant-numeric: tabular-nums;
}
.metric-value small {
margin-left: 3px;
color: #877f74;
font-size: 0.65rem;
font-weight: 700;
letter-spacing: 0;
}
.metric-note {
display: block;
margin-top: 5px;
color: var(--faint);
font-size: 0.62rem;
}
.ledger-section {
margin-top: 19px;
padding-top: 17px;
border-top: 1px solid var(--line);
}
.ledger-title {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 12px;
}
.ledger-title strong {
font-size: 0.75rem;
letter-spacing: 0.01em;
}
.ledger-title span {
color: var(--faint);
font-size: 0.63rem;
}
.resource-row + .resource-row {
margin-top: 12px;
}
.resource-meta {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 6px;
color: #9f968a;
font-size: 0.67rem;
}
.resource-meta strong {
color: #d4c9b9;
font-weight: 700;
font-variant-numeric: tabular-nums;
}
.resource-track {
height: 7px;
overflow: hidden;
border-radius: 999px;
background: rgba(255, 255, 255, 0.065);
}
.resource-fill {
width: 0;
height: 100%;
border-radius: inherit;
transition: width 90ms linear;
}
.balance-box {
margin-top: 18px;
padding: 13px;
border: 1px solid var(--line);
border-radius: 13px;
background: rgba(0, 0, 0, 0.13);
}
.balance-box h3 {
margin: 0 0 10px;
font-size: 0.73rem;
}
.balance-bar {
display: flex;
height: 9px;
overflow: hidden;
border-radius: 999px;
background: rgba(255, 255, 255, 0.05);
}
.balance-bar span {
height: 100%;
transition: width 100ms linear;
}
.balance-rows {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 7px 12px;
margin-top: 11px;
}
.balance-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
color: #8f877d;
font-size: 0.62rem;
}
.balance-row strong {
color: #d3c8b8;
font-variant-numeric: tabular-nums;
}
.mass-note {
margin: 11px 0 0;
padding-top: 10px;
border-top: 1px solid var(--line);
color: #716a61;
font-size: 0.6rem;
line-height: 1.45;
}
.batch-section {
margin-top: 18px;
padding: 20px;
}
.section-header {
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 18px;
margin-bottom: 15px;
}
.section-header h2 {
margin: 5px 0 0;
font-size: 1.1rem;
letter-spacing: -0.02em;
}
.section-header p {
max-width: 520px;
margin: 0;
color: var(--faint);
font-size: 0.7rem;
line-height: 1.5;
text-align: right;
}
.batch-grid {
display: grid;
grid-template-columns: repeat(4, minmax(0, 1fr));
gap: 11px;
}
.batch-card {
position: relative;
min-width: 0;
padding: 14px;
border: 1px solid var(--line);
border-radius: 14px;
background: rgba(255, 255, 255, 0.025);
cursor: pointer;
transition: border-color 150ms ease, background 150ms ease, transform 150ms ease;
}
.batch-card:hover {
transform: translateY(-2px);
border-color: rgba(255, 238, 211, 0.21);
}
.batch-card.selected {
border-color: rgba(216, 120, 69, 0.62);
background: rgba(216, 120, 69, 0.07);
box-shadow: inset 0 0 0 1px rgba(216, 120, 69, 0.08);
}
.batch-card:focus-visible,
.control-button:focus-visible,
.speed-button:focus-visible,
.mini-run:focus-visible {
outline: 2px solid var(--accent-2);
outline-offset: 2px;
}
.batch-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
}
.batch-number {
color: #7f766b;
font-size: 0.64rem;
font-weight: 850;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.batch-status {
padding: 4px 7px;
border-radius: 999px;
background: rgba(255, 255, 255, 0.055);
color: #8d857b;
font-size: 0.57rem;
font-weight: 800;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.batch-status.running {
background: rgba(216, 120, 69, 0.14);
color: #e5a06f;
}
.batch-status.complete {
background: rgba(140, 168, 121, 0.13);
color: #a7c396;
}
.batch-card h3 {
min-height: 36px;
margin: 12px 0 4px;
font-size: 0.92rem;
line-height: 1.2;
}
.batch-source {
color: var(--faint);
font-size: 0.62rem;
}
.batch-quantities {
display: flex;
flex-wrap: wrap;
gap: 5px;
margin-top: 12px;
}
.batch-quantity {
padding: 5px 6px;
border-radius: 6px;
background: rgba(0, 0, 0, 0.18);
color: #9e9589;
font-size: 0.59rem;
}
.batch-quantity strong {
color: #cfc4b4;
font-weight: 700;
}
.batch-progress {
height: 4px;
margin-top: 14px;
overflow: hidden;
border-radius: 999px;
background: rgba(255, 255, 255, 0.06);
}
.batch-progress-fill {
width: 0;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, #a95132, #e19759);
transition: width 90ms linear;
}
.batch-bottom {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-top: 10px;
}
.batch-output {
color: #777066;
font-size: 0.6rem;
}
.batch-output strong {
color: #c9c0b3;
font-weight: 700;
}
.mini-run {
min-height: 27px;
padding: 0 9px;
border: 1px solid rgba(255, 255, 255, 0.12);
border-radius: 8px;
background: rgba(255, 255, 255, 0.045);
color: #cfc3b4;
cursor: pointer;
font-size: 0.61rem;
font-weight: 750;
}
.mini-run:hover {
background: rgba(216, 120, 69, 0.13);
border-color: rgba(216, 120, 69, 0.3);
}
.footer-note {
display: flex;
justify-content: space-between;
gap: 20px;
padding: 17px 3px 2px;
color: #625b53;
font-size: 0.63rem;
line-height: 1.55;
}
.footer-note strong {
color: #83796d;
}
.webgl-error {
display: grid;
width: 100%;
height: 100%;
place-items: center;
padding: 30px;
color: #d7c9b7;
text-align: center;
}
@media (max-width: 1120px) {
.dashboard {
grid-template-columns: minmax(0, 1.45fr) minmax(320px, 0.8fr);
}
.batch-grid {
grid-template-columns: repeat(2, minmax(0, 1fr));
}
}
@media (max-width: 860px) {
.app {
padding: 14px;
}
.topbar {
align-items: flex-start;
}
.header-summary {
gap: 12px;
}
.header-stat {
display: none;
}
.fiction-badge {
white-space: normal;
text-align: center;
}
.dashboard {
grid-template-columns: 1fr;
}
.scene-wrap {
height: 570px;
}
.side-panel {
padding: 18px;
}
.metric-grid {
grid-template-columns: repeat(4, 1fr);
}
}
@media (max-width: 620px) {
.topbar {
flex-direction: column;
}
.header-summary {
width: 100%;
justify-content: space-between;
}
.fiction-badge {
margin-left: auto;
}
.scene-wrap {
height: 500px;
min-height: 500px;
}
.scene-heading {
top: 16px;
left: 16px;
}
.scene-state {
top: 16px;
right: 16px;
}
.legend {
left: 14px;
bottom: 84px;
}
.control-dock {
left: 10px;
right: 10px;
bottom: 10px;
flex-wrap: wrap;
}
.control-group {
flex: 1 1 auto;
}
.control-button.primary {
flex: 1;
}
.scene-footer {
align-items: flex-start;
flex-direction: column;
}
.metric-grid {
grid-template-columns: 1fr 1fr;
}
.section-header {
align-items: flex-start;
flex-direction: column;
}
.section-header p {
text-align: left;
}
.batch-grid {
grid-template-columns: 1fr;
}
.footer-note {
flex-direction: column;
}
}
</style>
</head>
<body>
<div class="app">
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true">
<i></i><i></i><i></i>
</div>
<div>
<p class="eyebrow">Illustrative production ledger</p>
<h1>Meroitic Ironworks</h1>
<p class="subtitle">Voxel bloomery batches · material tracking · fictional quantities</p>
</div>
</div>
<div class="header-summary">
<div class="header-stat">
<strong id="headerIron">0 kg</strong>
<span>Iron stock</span>
</div>
<div class="header-stat">
<strong id="headerBatches">0 / 4</strong>
<span>Batches complete</span>
</div>
<div class="fiction-badge">Fictional model data</div>
</div>
</header>
<main>
<section class="dashboard">
<div class="scene-card">
<div class="scene-wrap" id="sceneWrap">
<div class="scene-vignette"></div>
<div class="scene-overlay scene-heading">
<div class="scene-kicker">Meroitic-inspired voxel workshop</div>
<div class="scene-batch-label" id="sceneBatchLabel">01 · Red-hill trial</div>
</div>
<div class="scene-overlay scene-state">
<span class="state-dot" id="sceneStateDot"></span>
<span id="sceneStateText">Ready</span>
</div>
<div class="scene-overlay legend" aria-label="Scene legend">
<div class="legend-item">
<span class="legend-swatch" style="background:#aa5838"></span>
Ore
</div>
<div class="legend-item">
<span class="legend-swatch" style="background:#3e3a35"></span>
Charcoal
</div>
<div class="legend-item">
<span class="legend-swatch" style="background:#b9c8c7"></span>
Iron
</div>
<div class="legend-item">
<span class="legend-swatch" style="background:#76675a"></span>
Waste
</div>
</div>
<div class="control-dock">
<div class="control-group">
<button class="control-button primary" id="playButton" type="button">
▶ Run batches
</button>
<button class="control-button" id="resetButton" type="button">
Reset
</button>
</div>
<div class="control-group">
<div class="speed-group" aria-label="Simulation speed">
<button class="speed-button" data-speed="0.5" type="button">0.5×</button>
<button class="speed-button active" data-speed="1" type="button">1×</button>
<button class="speed-button" data-speed="2" type="button">2×</button>
<button class="speed-button" data-speed="4" type="button">4×</button>
</div>
</div>
</div>
</div>
<div class="scene-footer">
<span><strong>Controls:</strong> drag to orbit · shift-drag to pan · wheel or pinch to zoom</span>
<span>Procedural teaching model — not an archaeological reconstruction</span>
</div>
</div>
<aside class="side-panel">
<div class="panel-label">Selected batch</div>
<div class="batch-heading">
<div>
<div class="eyebrow" id="batchKicker">Batch 01</div>
<h2 id="batchName">Red-hill trial</h2>
<p class="batch-site" id="batchSite">Fictional ore spur</p>
</div>
<div class="progress-ring" id="progressRing">
<span id="progressPercent">0%</span>
</div>
</div>
<div class="stage-row">
<span>Current stage</span>
<span id="stageName">Ready</span>
</div>
<div class="metric-grid">
<article class="metric-card" style="--tone: var(--ore)">
<div class="metric-name">
<span class="metric-dot"></span>
Ore remaining
</div>
<strong class="metric-value">
<span id="oreValue">120</span><small>kg</small>
</strong>
<span class="metric-note" id="oreNote">of 120 kg starting ore</span>
</article>
<article class="metric-card" style="--tone: var(--fuel)">
<div class="metric-name">
<span class="metric-dot"></span>
Fuel remaining
</div>
<strong class="metric-value">
<span id="fuelValue">48</span><small>kg</small>
</strong>
<span class="metric-note" id="fuelNote">of 48 kg starting charcoal</span>
</article>
<article class="metric-card" style="--tone: var(--iron)">
<div class="metric-name">
<span class="metric-dot"></span>
Remaining iron stock
</div>
<strong class="metric-value">
<span id="ironValue">0</span><small>kg</small>
</strong>
<span class="metric-note" id="ironNote">target output: 42 kg</span>
</article>
<article class="metric-card" style="--tone: var(--waste)">
<div class="metric-name">
<span class="metric-dot"></span>
Waste accumulated
</div>
<strong class="metric-value">
<span id="wasteValue">0</span><small>kg</small>
</strong>
<span class="metric-note" id="wasteNote">final balance target: 126 kg</span>
</article>
</div>
<section class="ledger-section">
<div class="ledger-title">
<strong>Input consumption</strong>
<span>Illustrative rates</span>
</div>
<div class="resource-row">
<div class="resource-meta">
<span>Ore processed</span>
<strong id="oreProcessedText">0 / 120 kg</strong>
</div>
<div class="resource-track">
<div class="resource-fill" id="oreProcessedBar" style="background:var(--ore)"></div>
</div>
</div>
<div class="resource-row">
<div class="resource-meta">
<span>Charcoal consumed</span>
<strong id="fuelProcessedText">0 / 48 kg</strong>
</div>
<div class="resource-track">
<div class="resource-fill" id="fuelProcessedBar" style="background:var(--fuel)"></div>
</div>
</div>
</section>
<section class="balance-box">
<h3>Material balance</h3>
<div class="balance-bar" aria-hidden="true">
<span id="balanceRemaining" style="width:100%;background:var(--fuel)"></span>
<span id="balanceIron" style="width:0%;background:var(--iron)"></span>
<span id="balanceWaste" style="width:0%;background:var(--waste)"></span>
</div>
<div class="balance-rows">
<div class="balance-row">
<span>Starting inputs</span>
<strong id="balanceInput">168 kg</strong>
</div>
<div class="balance-row">
<span>Remaining inputs</span>
<strong id="balanceRemainingText">168 kg</strong>
</div>
<div class="balance-row">
<span>Iron stock</span>
<strong id="balanceIronText">0 kg</strong>
</div>
<div class="balance-row">
<span>Waste</span>
<strong id="balanceWasteText">0 kg</strong>
</div>
</div>
<p class="mass-note">
Remaining inputs + iron stock + waste always equals the starting input mass.
Values represent simplified instructional quantities, not measured production.
</p>
</section>
</aside>
</section>
<section class="batch-section">
<div class="section-header">
<div>
<div class="panel-label">Production queue</div>
<h2>Four illustrative batches</h2>
</div>
<p>
Select a card to inspect it. “Run” starts that batch; the main control processes
remaining batches in sequence.
</p>
</div>
<div class="batch-grid" id="batchGrid"></div>
</section>
</main>
<footer class="footer-note">
<span>
<strong>Historical note:</strong> the scene is a generalized Meroitic-inspired ironworking
interpretation. It is not a reconstruction of a documented workshop.
</span>
<span>
<strong>Data note:</strong> batch names, ore sources, fuel amounts, yields, wastes, and
production times are entirely fictional.
</span>
</footer>
</div>
<noscript>This interactive model requires JavaScript.</noscript>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const batchDefinitions = [
{
name: "Red-hill trial",
site: "Fictional ore spur · low charcoal ratio",
ore: 120,
fuel: 48,
iron: 42,
duration: 12
},
{
name: "Riverbank bloom",
site: "Fictional river gravel zone · dense slag",
ore: 96,
fuel: 40,
iron: 35,
duration: 11
},
{
name: "Quarry workshop",
site: "Fictional quarry court · larger furnace load",
ore: 144,
fuel: 54,
iron: 51,
duration: 14
},
{
name: "Workshop lot IV",
site: "Fictional finishing yard · mixed ore stock",
ore: 108,
fuel: 46,
iron: 39,
duration: 12.5
}
];
const batches = batchDefinitions.map((definition) => ({
...definition,
progress: 0,
status: "ready"
}));
const clamp = THREE.MathUtils.clamp;
const sceneWrap = document.getElementById("sceneWrap");
const batchGrid = document.getElementById("batchGrid");
const playButton = document.getElementById("playButton");
const resetButton = document.getElementById("resetButton");
let selectedIndex = 0;
let activeIndex = null;
let running = false;
let speed = 1;
let interBatchWait = 0;
const formatKg = (value) => {
if (value >= 100) return Math.round(value).toLocaleString();
if (value >= 10) return value.toFixed(0);
return value.toFixed(1);
};
function smoothSegment(progress, start, end) {
const t = clamp((progress - start) / (end - start), 0, 1);
return t * t * (3 - 2 * t);
}
function calculate(batch) {
const p = batch.progress;
const oreFraction =
0.28 * smoothSegment(p, 0.00, 0.20) +
0.72 * smoothSegment(p, 0.20, 0.72);
const fuelFraction =
0.18 * smoothSegment(p, 0.08, 0.25) +
0.82 * smoothSegment(p, 0.25, 0.72);
const ironFraction = smoothSegment(p, 0.48, 0.93);
const oreConsumed = batch.ore * oreFraction;
const fuelConsumed = batch.fuel * fuelFraction;
const iron = batch.iron * ironFraction;
const consumed = oreConsumed + fuelConsumed;
const waste = Math.max(0, consumed - iron);
return {
oreConsumed,
fuelConsumed,
oreRemaining: batch.ore - oreConsumed,
fuelRemaining: batch.fuel - fuelConsumed,
iron,
waste,
totalInput: batch.ore + batch.fuel,
finalWaste: batch.ore + batch.fuel - batch.iron
};
}
function getStage(batch) {
if (batch.status === "complete") return "Batch complete";
if (batch.progress < 0.18) return "Charging ore";
if (batch.progress < 0.36) return "Preparing charcoal";
if (batch.progress < 0.66) return "Roasting and reduction";
if (batch.progress < 0.84) return "Consolidating the bloom";
if (batch.progress < 0.98) return "Collecting iron";
return "Final weighing";
}
function allComplete() {
return batches.every((batch) => batch.status === "complete");
}
function nextReadyIndex() {
return batches.findIndex((batch) => batch.status === "ready");
}
function resetAll() {
running = false;
activeIndex = null;
interBatchWait = 0;
batches.forEach((batch) => {
batch.progress = 0;
batch.status = "ready";
});
updateUI();
}
function toggleRunning() {
if (running) {
running = false;
} else {
if (allComplete()) resetAll();
activeIndex = nextReadyIndex();
if (activeIndex === -1) {
running = false;
} else {
batches[activeIndex].status = "running";
running = true;
interBatchWait = 0;
}
}
updateUI();
}
function runBatch(index) {
if (batches[index].status === "complete") {
batches[index].progress = 0;
batches[index].status = "ready";
}
if (
activeIndex !== null &&
activeIndex !== index &&
batches[activeIndex].status === "running"
) {
batches[activeIndex].status = "ready";
}
selectedIndex = index;
activeIndex = index;
batches[activeIndex].status = "running";
batches[activeIndex].progress = 0;
running = true;
interBatchWait = 0;
updateUI();
}
function updateSimulation(dt) {
if (!running) return;
if (activeIndex === null) {
if (interBatchWait > 0) {
interBatchWait -= dt;
return;
}
const next = nextReadyIndex();
if (next === -1) {
running = false;
return;
}
activeIndex = next;
batches[activeIndex].status = "running";
}
const batch = batches[activeIndex];
batch.progress += (dt * speed) / batch.duration;
if (batch.progress >= 1) {
batch.progress = 1;
batch.status = "complete";
activeIndex = null;
interBatchWait = 0.65;
}
}
function selectBatch(index) {
selectedIndex = index;
updateUI();
}
// Build the batch cards once, then update their contents without replacing buttons.
batchGrid.innerHTML = batches.map((batch, index) => `
<article
class="batch-card"
data-select="${index}"
tabindex="0"
role="button"
aria-label="Inspect ${batch.name}"
>
<div class="batch-top">
<span class="batch-number">
Batch ${String(index + 1).padStart(2, "0")}
</span>
<span class="batch-status">Queued</span>
</div>
<h3>${batch.name}</h3>
<div class="batch-source">${batch.site}</div>
<div class="batch-quantities">
<span class="batch-quantity"><strong>${batch.ore}</strong> kg ore</span>
<span class="batch-quantity"><strong>${batch.fuel}</strong> kg fuel</span>
<span class="batch-quantity"><strong>${batch.iron}</strong> kg iron</span>
</div>
<div class="batch-progress">
<div class="batch-progress-fill"></div>
</div>
<div class="batch-bottom">
<span class="batch-output">
Output target: <strong>${batch.iron} kg</strong>
</span>
<button class="mini-run" data-run="${index}" type="button">Run</button>
</div>
</article>
`).join("");
batchGrid.addEventListener("click", (event) => {
const runButton = event.target.closest("[data-run]");
if (runButton) {
event.stopPropagation();
runBatch(Number(runButton.dataset.run));
return;
}
const card = event.target.closest("[data-select]");
if (card) {
selectBatch(Number(card.dataset.select));
}
});
batchGrid.addEventListener("keydown", (event) => {
if (event.key !== "Enter" && event.key !== " ") return;
const card = event.target.closest("[data-select]");
if (card) {
event.preventDefault();
selectBatch(Number(card.dataset.select));
}
});
playButton.addEventListener("click", toggleRunning);
resetButton.addEventListener("click", resetAll);
document.querySelectorAll("[data-speed]").forEach((button) => {
button.addEventListener("click", () => {
speed = Number(button.dataset.speed);
document.querySelectorAll("[data-speed]").forEach((item) => {
item.classList.toggle("active", item === button);
});
});
});
window.addEventListener("keydown", (event) => {
if (event.target instanceof HTMLButtonElement) return;
if (event.code === "Space") {
event.preventDefault();
toggleRunning();
}
if (event.key.toLowerCase() === "r") resetAll();
if (["1", "2", "3", "4"].includes(event.key)) {
selectBatch(Number(event.key) - 1);
}
});
// -------------------------------------------------------------------------
// Three.js scene
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x29241e);
scene.fog = new THREE.Fog(0x29241e, 18, 38);
const camera = new THREE.PerspectiveCamera(42, 1, 0.1, 100);
let renderer;
try {
renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
} catch (error) {
sceneWrap.innerHTML = `
<div class="webgl-error">
<div>
<strong>WebGL could not be initialized.</strong><br>
Try opening this file in a browser with hardware acceleration enabled.
</div>
</div>
`;
throw error;
}
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
sceneWrap.appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xf4d6ae, 0x332820, 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffddb0, 3.1);
sun.position.set(-7, 12, 7);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -13;
sun.shadow.camera.right = 13;
sun.shadow.camera.top = 13;
sun.shadow.camera.bottom = -13;
sun.shadow.camera.near = 0.5;
sun.shadow.camera.far = 38;
sun.shadow.bias = -0.0005;
scene.add(sun);
const rimLight = new THREE.DirectionalLight(0x8fa6a6, 0.7);
rimLight.position.set(9, 6, -9);
scene.add(rimLight);
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const materialCache = new Map();
function getMaterial(color, options = {}) {
const key = `${color}-${JSON.stringify(options)}`;
if (!materialCache.has(key)) {
materialCache.set(
key,
new THREE.MeshStandardMaterial({
color,
roughness: 0.86,
metalness: 0.03,
...options
})
);
}
return materialCache.get(key);
}
function addBox(parent, x, y, z, sx, sy, sz, color, material = null) {
const mesh = new THREE.Mesh(
unitBox,
material || getMaterial(color)
);
mesh.position.set(x, y, z);
mesh.scale.set(sx, sy, sz);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function mulberry32(seed) {
return function random() {
let value = seed += 0x6D2B79F5;
value = Math.imul(value ^ (value >>> 15), value | 1);
value ^= value + Math.imul(value ^ (value >>> 7), value | 61);
return ((value ^ (value >>> 14)) >>> 0) / 4294967296;
};
}
const random = mulberry32(48271);
// Sandy voxel ground and a narrow blue-green river along one edge.
const tileColumns = 22;
const tileRows = 18;
const tileSpacing = 0.84;
const tileCount = tileColumns * tileRows;
const groundMaterial = new THREE.MeshStandardMaterial({
roughness: 1,
metalness: 0,
color: 0xffffff
});
const ground = new THREE.InstancedMesh(
unitBox,
groundMaterial,
tileCount
);
ground.receiveShadow = true;
ground.castShadow = false;
const dummy = new THREE.Object3D();
let tileIndex = 0;
for (let row = 0; row < tileRows; row++) {
for (let column = 0; column < tileColumns; column++) {
const x = (column - (tileColumns - 1) / 2) * tileSpacing;
const z = (row - (tileRows - 1) / 2) * tileSpacing;
dummy.position.set(x, -0.11, z);
dummy.scale.set(0.8, 0.22, 0.8);
dummy.updateMatrix();
ground.setMatrixAt(tileIndex, dummy.matrix);
let color;
if (x > 7.1) {
color = new THREE.Color().setHSL(
0.52 + random() * 0.025,
0.28,
0.25 + random() * 0.05
);
} else {
color = new THREE.Color().setHSL(
0.095 + random() * 0.025,
0.25,
0.34 + random() * 0.065
);
}
ground.setColorAt(tileIndex, color);
tileIndex++;
}
}
ground.instanceMatrix.needsUpdate = true;
ground.instanceColor.needsUpdate = true;
scene.add(ground);
// Distant stepped mud-brick enclosure.
const enclosure = new THREE.Group();
scene.add(enclosure);
for (let level = 0; level < 3; level++) {
for (let i = 0; i < 10; i++) {
const x = -5.4 + i * 1.18;
addBox(
enclosure,
x,
0.18 + level * 0.42,
-5.6,
1.08,
0.4,
0.55,
level % 2 ? 0x9a6848 : 0xa9714d
);
}
}
for (let i = 0; i < 7; i++) {
addBox(
enclosure,
-6.2,
0.18 + (i % 2) * 0.42,
-4.5 + i * 0.65,
0.55,
0.4,
0.59,
i % 2 ? 0x8e5f43 : 0xa16b4c
);
}
// Central clay shaft furnace.
const furnace = new THREE.Group();
furnace.position.set(0, 0, -0.75);
scene.add(furnace);
for (let i = 0; i < 9; i++) {
addBox(
furnace,
-2.4 + i * 0.6,
0.12,
0,
0.55,
0.28,
3.1,
i % 2 ? 0x68594c : 0x756357
);
}
for (let level = 0; level < 6; level++) {
const y = 0.48 + level * 0.46;
const clay = level % 3 === 0 ? 0xa45e39 : 0xb56b42;
addBox(furnace, -1.5, y, -1.05, 0.5, 0.44, 0.58, clay);
addBox(furnace, 1.5, y, -1.05, 0.5, 0.44, 0.58, clay);
addBox(furnace, 0, y, -1.48, 0.5, 0.44, 0.5, clay);
if (level < 5) {
addBox(furnace, -1.0, y, -1.48, 0.5, 0.44, 0.5, 0x9f5938);
addBox(furnace, 1.0, y, -1.48, 0.5, 0.44, 0.5, 0x9f5938);
}
}
addBox(furnace, 0, 3.15, -1.05, 3.55, 0.38, 0.72, 0x8c4c31);
addBox(furnace, 0, 0.27, -0.35, 1.95, 0.25, 1.8, 0x3f3933);
// Small hearth arch and side supports.
addBox(furnace, -1.0, 0.52, 0.3, 0.45, 0.75, 0.52, 0x8d5d40);
addBox(furnace, 1.0, 0.52, 0.3, 0.45, 0.75, 0.52, 0x8d5d40);
addBox(furnace, 0, 0.95, 0.3, 2.4, 0.28, 0.5, 0x9b633f);
// Workbench and tools.
const bench = new THREE.Group();
bench.position.set(3.1, 0, 2.65);
scene.add(bench);
addBox(bench, 0, 1.05, 0, 2.3, 0.2, 0.85, 0x70503a);
addBox(bench, -0.8, 0.52, 0, 0.22, 1.0, 0.55, 0x59412f);
addBox(bench, 0.8, 0.52, 0, 0.22, 1.0, 0.55, 0x59412f);
addBox(bench, 0.55, 1.23, 0, 0.65, 0.18, 0.22, 0x7e8580);
addBox(bench, -0.45, 1.23, -0.08, 0.22, 0.2, 0.22, 0x5a5046);
function createVoxelPile(count, origin, palette, type = "pile") {
const group = new THREE.Group();
group.position.set(origin[0], origin[1], origin[2]);
scene.add(group);
for (let i = 0; i < count; i++) {
const layer = Math.floor(i / 7);
const within = i % 7;
const jitterX = (random() - 0.5) * 0.14;
const jitterZ = (random() - 0.5) * 0.14;
let x;
let y;
let z;
let sx;
let sy;
let sz;
if (type === "ingot") {
x = (within % 3 - 1) * 0.48;
z = (Math.floor(within / 3) - 0.5) * 0.55;
y = 0.18 + layer * 0.22;
sx = 0.52;
sy = 0.2;
sz = 0.32;
} else {
x = (within - 3) * 0.37 + jitterX;
z = (layer - 1) * 0.35 + jitterZ;
y = 0.18 + layer * 0.31;
sx = 0.31 + random() * 0.1;
sy = 0.27 + random() * 0.11;
sz = 0.3 + random() * 0.1;
}
const color = palette[Math.floor(random() * palette.length)];
const mesh = addBox(group, x, y, z, sx, sy, sz, color);
mesh.rotation.y = (random() - 0.5) * 0.2;
}
return group;
}
const orePile = createVoxelPile(
28,
[-4.0, 0, 1.25],
[0x9e4930, 0xae5839, 0x84402d, 0xbd6842]
);
const fuelPile = createVoxelPile(
21,
[4.05, 0, 1.0],
[0x292724, 0x38342f, 0x45403a, 0x211f1d]
);
const ironPile = createVoxelPile(
12,
[3.75, 0, -3.55],
[0xaebbb9, 0xc6d0cd, 0x929f9e, 0xd1d8d3],
"ingot"
);
const wastePile = createVoxelPile(
28,
[-3.8, 0, -3.65],
[0x685d51, 0x78685a, 0x514b44, 0x8a725d]
);
// Stylized workers.
function createWorker(x, z, clothColor, rotation = 0) {
const worker = new THREE.Group();
worker.position.set(x, 0, z);
worker.rotation.y = rotation;
scene.add(worker);
addBox(worker, -0.13, 0.34, 0, 0.2, 0.65, 0.24, 0x4e3d2e);
addBox(worker, 0.13, 0.34, 0, 0.2, 0.65, 0.24, 0x4e3d2e);
addBox(worker, 0, 0.95, 0, 0.58, 0.72, 0.35, clothColor);
addBox(worker, 0, 1.55, 0, 0.42, 0.42, 0.4, 0x9a694b);
addBox(worker, 0, 1.77, 0, 0.48, 0.12, 0.44, 0x3a2e24);
addBox(worker, -0.38, 1.02, 0, 0.18, 0.58, 0.2, clothColor);
addBox(worker, 0.38, 1.02, 0, 0.18, 0.58, 0.2, clothColor);
const hammerArm = new THREE.Group();
hammerArm.position.set(0.38, 1.28, 0);
hammerArm.rotation.z = -0.8;
worker.add(hammerArm);
addBox(hammerArm, 0, -0.22, 0, 0.17, 0.52, 0.18, clothColor);
addBox(hammerArm, 0, -0.54, 0, 0.52, 0.16, 0.23, 0x777b75);
return { worker, hammerArm };
}
const workerA = createWorker(2.45, 2.0, 0xb76c43, -0.8);
const workerB = createWorker(-1.45, 3.0, 0x6c786b, 0.25);
// Fire cubes.
const fireGroup = new THREE.Group();
fireGroup.position.set(0, 0, -0.9);
scene.add(fireGroup);
const flameCubes = [];
for (let i = 0; i < 18; i++) {
const material = new THREE.MeshStandardMaterial({
color: i % 3 === 0 ? 0xffd05b : 0xff7b27,
emissive: i % 3 === 0 ? 0xff9b25 : 0xe84b12,
emissiveIntensity: 2.1,
roughness: 0.8,
transparent: true,
opacity: 0.88,
depthWrite: false
});
const mesh = new THREE.Mesh(unitBox, material);
const base = new THREE.Vector3(
(random() - 0.5) * 1.45,
0.42 + random() * 0.78,
(random() - 0.5) * 1.0
);
mesh.position.copy(base);
mesh.scale.set(
0.18 + random() * 0.23,
0.24 + random() * 0.34,
0.18 + random() * 0.23
);
mesh.userData.baseScale = mesh.scale.clone();
mesh.userData.baseY = base.y;
mesh.userData.phase = random() * Math.PI * 2;
fireGroup.add(mesh);
flameCubes.push(mesh);
}
const fireLight = new THREE.PointLight(0xff762e, 0, 7, 2);
fireLight.position.set(0, 1.3, -0.8);
scene.add(fireLight);
// Voxel smoke.
const smokeGroup = new THREE.Group();
scene.add(smokeGroup);
const smokeCubes = [];
for (let i = 0; i < 15; i++) {
const material = new THREE.MeshStandardMaterial({
color: 0x68645d,
roughness: 1,
transparent: true,
opacity: 0,
depthWrite: false
});
const mesh = new THREE.Mesh(unitBox, material);
mesh.userData.phase = random();
mesh.userData.offsetX = (random() - 0.5) * 0.9;
mesh.userData.offsetZ = (random() - 0.5) * 0.7;
smokeGroup.add(mesh);
smokeCubes.push(mesh);
}
// Small voxel sparks.
const sparkGroup = new THREE.Group();
scene.add(sparkGroup);
const sparkCubes = [];
for (let i = 0; i < 12; i++) {
const material = new THREE.MeshBasicMaterial({
color: i % 2 ? 0xffd56b : 0xff7b2f,
transparent: true,
opacity: 0
});
const mesh = new THREE.Mesh(unitBox, material);
mesh.scale.setScalar(0.06 + random() * 0.07);
mesh.userData.phase = random();
mesh.userData.offset = (random() - 0.5) * 0.8;
sparkGroup.add(mesh);
sparkCubes.push(mesh);
}
function setVisibleCount(group, count) {
group.children.forEach((child, index) => {
child.visible = index < count;
});
}
// Custom camera controller: orbit, pan and zoom without external addons.
const cameraState = {
yaw: 0.76,
pitch: 0.5,
radius: 15.2,
target: new THREE.Vector3(0, 1.1, 0)
};
function updateCamera() {
const { yaw, pitch, radius, target } = cameraState;
camera.position.set(
target.x + radius * Math.sin(yaw) * Math.cos(pitch),
target.y + radius * Math.sin(pitch),
target.z + radius * Math.cos(yaw) * Math.cos(pitch)
);
camera.lookAt(target);
camera.updateMatrixWorld();
}
function panCamera(dx, dy) {
camera.updateMatrixWorld();
const right = new THREE.Vector3()
.setFromMatrixColumn(camera.matrix, 0);
right.y = 0;
right.normalize();
const forward = new THREE.Vector3();
camera.getWorldDirection(forward);
forward.y = 0;
forward.normalize();
const scale = cameraState.radius * 0.0015;
cameraState.target.addScaledVector(right, -dx * scale);
cameraState.target.addScaledVector(forward, dy * scale);
cameraState.target.x = clamp(cameraState.target.x, -6, 6);
cameraState.target.z = clamp(cameraState.target.z, -5.5, 5.5);
}
const pointerMap = new Map();
let gesture = null;
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.setPointerCapture(event.pointerId);
pointerMap.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointerMap.size === 1) {
gesture = {
mode: event.button === 2 || event.shiftKey ? "pan" : "rotate",
lastX: event.clientX,
lastY: event.clientY
};
} else if (pointerMap.size === 2) {
const points = [...pointerMap.values()];
gesture = {
mode: "pinch",
distance: Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
),
midpointX: (points[0].x + points[1].x) / 2,
midpointY: (points[0].y + points[1].y) / 2
};
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointerMap.has(event.pointerId)) return;
pointerMap.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointerMap.size === 1 && gesture?.mode !== "pinch") {
const dx = event.clientX - gesture.lastX;
const dy = event.clientY - gesture.lastY;
if (gesture.mode === "pan") {
panCamera(dx, dy);
} else {
cameraState.yaw -= dx * 0.006;
cameraState.pitch = clamp(
cameraState.pitch + dy * 0.0045,
0.18,
1.08
);
}
gesture.lastX = event.clientX;
gesture.lastY = event.clientY;
} else if (pointerMap.size === 2 && gesture?.mode === "pinch") {
const points = [...pointerMap.values()];
const distance = Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
const midpointX = (points[0].x + points[1].x) / 2;
const midpointY = (points[0].y + points[1].y) / 2;
if (gesture.distance > 0) {
cameraState.radius = clamp(
cameraState.radius * (gesture.distance / distance),
8,
27
);
}
panCamera(
midpointX - gesture.midpointX,
midpointY - gesture.midpointY
);
gesture.distance = distance;
gesture.midpointX = midpointX;
gesture.midpointY = midpointY;
}
});
function endPointer(event) {
pointerMap.delete(event.pointerId);
if (pointerMap.size === 1) {
const remaining = [...pointerMap.values()][0];
gesture = {
mode: "rotate",
lastX: remaining.x,
lastY: remaining.y
};
} else if (pointerMap.size === 0) {
gesture = null;
}
}
renderer.domElement.addEventListener("pointerup", endPointer);
renderer.domElement.addEventListener("pointercancel", endPointer);
renderer.domElement.addEventListener("wheel", (event) => {
event.preventDefault();
cameraState.radius = clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
8,
27
);
}, { passive: false });
function resizeScene() {
const width = sceneWrap.clientWidth;
const height = sceneWrap.clientHeight;
if (!width || !height) return;
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
}
new ResizeObserver(resizeScene).observe(sceneWrap);
resizeScene();
updateCamera();
// -------------------------------------------------------------------------
// Interface updates and animated scene state
// -------------------------------------------------------------------------
const ui = {
sceneBatchLabel: document.getElementById("sceneBatchLabel"),
sceneStateDot: document.getElementById("sceneStateDot"),
sceneStateText: document.getElementById("sceneStateText"),
batchKicker: document.getElementById("batchKicker"),
batchName: document.getElementById("batchName"),
batchSite: document.getElementById("batchSite"),
progressRing: document.getElementById("progressRing"),
progressPercent: document.getElementById("progressPercent"),
stageName: document.getElementById("stageName"),
oreValue: document.getElementById("oreValue"),
fuelValue: document.getElementById("fuelValue"),
ironValue: document.getElementById("ironValue"),
wasteValue: document.getElementById("wasteValue"),
oreNote: document.getElementById("oreNote"),
fuelNote: document.getElementById("fuelNote"),
ironNote: document.getElementById("ironNote"),
wasteNote: document.getElementById("wasteNote"),
oreProcessedText: document.getElementById("oreProcessedText"),
fuelProcessedText: document.getElementById("fuelProcessedText"),
oreProcessedBar: document.getElementById("oreProcessedBar"),
fuelProcessedBar: document.getElementById("fuelProcessedBar"),
balanceRemaining: document.getElementById("balanceRemaining"),
balanceIron: document.getElementById("balanceIron"),
balanceWaste: document.getElementById("balanceWaste"),
balanceInput: document.getElementById("balanceInput"),
balanceRemainingText: document.getElementById("balanceRemainingText"),
balanceIronText: document.getElementById("balanceIronText"),
balanceWasteText: document.getElementById("balanceWasteText"),
headerIron: document.getElementById("headerIron"),
headerBatches: document.getElementById("headerBatches")
};
function updateUI() {
const batch = batches[selectedIndex];
const values = calculate(batch);
const percent = Math.round(batch.progress * 100);
ui.sceneBatchLabel.textContent =
`${String(selectedIndex + 1).padStart(2, "0")} · ${batch.name}`;
ui.sceneStateDot.className =
`state-dot ${batch.status === "running" ? "running" : ""} ${
batch.status === "complete" ? "complete" : ""
}`;
ui.sceneStateText.textContent =
batch.status === "running"
? getStage(batch)
: batch.status === "complete"
? "Complete"
: "Ready";
ui.batchKicker.textContent =
`Batch ${String(selectedIndex + 1).padStart(2, "0")}`;
ui.batchName.textContent = batch.name;
ui.batchSite.textContent = batch.site;
ui.progressRing.style.setProperty("--p", `${percent}%`);
ui.progressPercent.textContent = `${percent}%`;
ui.stageName.textContent = getStage(batch);
ui.oreValue.textContent = formatKg(values.oreRemaining);
ui.fuelValue.textContent = formatKg(values.fuelRemaining);
ui.ironValue.textContent = formatKg(values.iron);
ui.wasteValue.textContent = formatKg(values.waste);
ui.oreNote.textContent = `of ${batch.ore} kg starting ore`;
ui.fuelNote.textContent = `of ${batch.fuel} kg starting charcoal`;
ui.ironNote.textContent = `target output: ${batch.iron} kg`;
ui.wasteNote.textContent = `final balance target: ${values.finalWaste} kg`;
ui.oreProcessedText.textContent =
`${formatKg(values.oreConsumed)} / ${batch.ore} kg`;
ui.fuelProcessedText.textContent =
`${formatKg(values.fuelConsumed)} / ${batch.fuel} kg`;
ui.oreProcessedBar.style.width =
`${(values.oreConsumed / batch.ore) * 100}%`;
ui.fuelProcessedBar.style.width =
`${(values.fuelConsumed / batch.fuel) * 100}%`;
const remainingInputs = values.oreRemaining + values.fuelRemaining;
const total = values.totalInput;
ui.balanceRemaining.style.width = `${(remainingInputs / total) * 100}%`;
ui.balanceIron.style.width = `${(values.iron / total) * 100}%`;
ui.balanceWaste.style.width = `${(values.waste / total) * 100}%`;
ui.balanceInput.textContent = `${formatKg(total)} kg`;
ui.balanceRemainingText.textContent = `${formatKg(remainingInputs)} kg`;
ui.balanceIronText.textContent = `${formatKg(values.iron)} kg`;
ui.balanceWasteText.textContent = `${formatKg(values.waste)} kg`;
const totalIron = batches.reduce(
(sum, item) => sum + calculate(item).iron,
0
);
const completeCount = batches.filter(
(item) => item.status === "complete"
).length;
ui.headerIron.textContent = `${formatKg(totalIron)} kg`;
ui.headerBatches.textContent = `${completeCount} / ${batches.length}`;
playButton.textContent = running
? "❚❚ Pause"
: allComplete()
? "↻ Run again"
: "▶ Run batches";
document.querySelectorAll(".batch-card").forEach((card, index) => {
const item = batches[index];
const status = card.querySelector(".batch-status");
const fill = card.querySelector(".batch-progress-fill");
const run = card.querySelector(".mini-run");
card.classList.toggle("selected", index === selectedIndex);
card.setAttribute(
"aria-pressed",
index === selectedIndex ? "true" : "false"
);
status.className = `batch-status ${item.status}`;
status.textContent =
item.status === "running"
? "Processing"
: item.status === "complete"
? "Complete"
: "Queued";
fill.style.width = `${item.progress * 100}%`;
run.textContent =
item.status === "complete"
? "Replay"
: item.status === "running"
? "Restart"
: "Run";
});
}
function updateScene(time) {
const batch = batches[selectedIndex];
const values = calculate(batch);
const oreRemainingCount = Math.ceil(
(values.oreRemaining / batch.ore) * orePile.children.length
);
const fuelRemainingCount = Math.ceil(
(values.fuelRemaining / batch.fuel) * fuelPile.children.length
);
const ironCount = Math.round(
(values.iron / batch.iron) * ironPile.children.length
);
const wasteCount = Math.round(
(values.waste / values.finalWaste) * wastePile.children.length
);
setVisibleCount(orePile, oreRemainingCount);
setVisibleCount(fuelPile, fuelRemainingCount);
setVisibleCount(ironPile, ironCount);
setVisibleCount(wastePile, wasteCount);
const isRunning = batch.status === "running";
const fireStrength = isRunning
? 0.65 + Math.sin(time * 7.5) * 0.15
: 0;
fireGroup.visible = isRunning && batch.progress > 0.08;
flameCubes.forEach((mesh, index) => {
const base = mesh.userData.baseScale;
const pulse =
0.82 +
Math.sin(time * 9 + mesh.userData.phase) * 0.18 +
Math.sin(time * 13 + index) * 0.08;
mesh.scale.set(
base.x * pulse,
base.y * (0.9 + pulse * 0.25),
base.z * pulse
);
mesh.position.y =
mesh.userData.baseY +
Math.sin(time * 6 + mesh.userData.phase) * 0.08;
mesh.material.emissiveIntensity = 1.7 + fireStrength * 1.4;
mesh.material.opacity = 0.72 + fireStrength * 0.2;
});
fireLight.intensity = isRunning
? 18 + Math.sin(time * 11) * 5 + batch.progress * 7
: 0;
smokeCubes.forEach((mesh, index) => {
mesh.visible = isRunning && batch.progress > 0.17;
if (!mesh.visible) return;
const cycle = (time * 0.17 + mesh.userData.phase) % 1;
mesh.position.set(
mesh.userData.offsetX + Math.sin(cycle * 7 + index) * 0.22,
2.8 + cycle * 4.7,
-1.15 + mesh.userData.offsetZ + cycle * 0.55
);
const size = 0.22 + cycle * 0.5;
mesh.scale.set(size, size, size);
mesh.material.opacity = Math.sin(cycle * Math.PI) * 0.23;
});
sparkCubes.forEach((mesh, index) => {
mesh.visible = isRunning && batch.progress > 0.25;
if (!mesh.visible) return;
const cycle = (time * 0.8 + mesh.userData.phase) % 1;
mesh.position.set(
mesh.userData.offset + Math.sin(cycle * 9 + index) * 0.4,
0.6 + cycle * 2.2,
-0.85 + Math.cos(cycle * 8 + index) * 0.25
);
mesh.material.opacity = (1 - cycle) * 0.9;
});
const hammerAngle = isRunning
? -0.95 + Math.sin(time * 8.5) * 0.75
: -0.95;
workerA.hammerArm.rotation.z = hammerAngle;
workerB.hammerArm.rotation.z = -hammerAngle * 0.65;
}
let previousTime = performance.now();
function animate(now) {
requestAnimationFrame(animate);
const dt = Math.min((now - previousTime) / 1000, 0.05);
previousTime = now;
updateSimulation(dt);
updateScene(now / 1000);
updateCamera();
updateUI();
renderer.render(scene, camera);
}
updateUI();
requestAnimationFrame(animate);
</script>
</body>
</html>
```