Prompt specification
Build or customize the Three.js 3D scene "Ore lump and slag fragment display" 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: Ore lump and slag fragment display
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/ore-lump-and-slag-fragment-display-x2281
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows Meroitic iron production in Kush. Place contrasting ore, charcoal, slag, and iron sample models on labeled supports. Make clear that these represent different process stages rather than interchangeable raw materials. Voxel style.
Working Three.js Starter (ore-lump-and-slag-fragment-display-x2281):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Meroitic Iron Production in Kush — Voxel Process Diagram</title>
<style>
:root {
--ink: #172125;
--paper: #eee9dc;
--panel: rgba(19, 27, 29, 0.94);
--ore: #c66c43;
--charcoal: #687078;
--slag: #559496;
--iron: #d6dfe2;
--fire: #f1a34b;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #c9c3b4;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
outline: none;
touch-action: none;
cursor: grab;
}
#scene:active {
cursor: grabbing;
}
.header {
position: fixed;
z-index: 5;
top: 22px;
left: 24px;
width: min(535px, calc(100vw - 48px));
pointer-events: none;
}
.eyebrow {
display: inline-flex;
align-items: center;
gap: 8px;
margin-bottom: 8px;
color: #5c3428;
font-size: 11px;
font-weight: 850;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 25px;
height: 4px;
background: var(--ore);
box-shadow: 8px 0 0 rgba(198, 108, 67, 0.35);
}
h1 {
margin: 0;
max-width: 520px;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(30px, 3.3vw, 52px);
line-height: 0.98;
letter-spacing: -0.035em;
text-wrap: balance;
}
.subtitle {
margin: 10px 0 0;
max-width: 510px;
color: #465054;
font-size: 13px;
line-height: 1.45;
}
.warning {
display: inline-grid;
grid-template-columns: auto 1fr;
gap: 10px;
align-items: start;
margin-top: 14px;
padding: 10px 12px;
max-width: 515px;
border-left: 4px solid var(--fire);
background: rgba(250, 246, 235, 0.88);
box-shadow: 0 6px 24px rgba(38, 32, 23, 0.1);
backdrop-filter: blur(8px);
}
.warning strong {
display: block;
margin-bottom: 2px;
font-size: 10px;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.warning span {
color: #4d514f;
font-size: 11px;
line-height: 1.35;
}
.controls {
position: fixed;
z-index: 7;
top: 20px;
right: 20px;
display: flex;
gap: 7px;
}
.control-button {
min-height: 38px;
padding: 0 12px;
border: 1px solid rgba(29, 37, 39, 0.2);
border-radius: 4px;
background: rgba(247, 243, 231, 0.9);
color: #263034;
box-shadow: 0 4px 16px rgba(30, 35, 34, 0.09);
font: 750 10px/1 ui-sans-serif, system-ui, sans-serif;
letter-spacing: 0.08em;
text-transform: uppercase;
cursor: pointer;
backdrop-filter: blur(8px);
}
.control-button:hover,
.control-button[aria-pressed="true"] {
background: #1b2528;
color: #fff8e9;
border-color: #1b2528;
}
.detail-panel {
position: fixed;
z-index: 6;
top: 70px;
right: 20px;
width: min(365px, calc(100vw - 40px));
padding: 17px 18px 16px;
border: 1px solid rgba(255, 255, 255, 0.12);
border-top: 4px solid var(--ore);
background: var(--panel);
color: #f5f0e4;
box-shadow: 0 16px 45px rgba(25, 27, 25, 0.2);
backdrop-filter: blur(12px);
}
.detail-meta {
display: flex;
justify-content: space-between;
gap: 10px;
color: #aab1ad;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
#detail-role {
color: var(--ore);
}
#detail-title {
margin: 7px 0 8px;
font-family: Georgia, "Times New Roman", serif;
font-size: 26px;
font-weight: 500;
letter-spacing: -0.02em;
}
#detail-body {
margin: 0;
color: #c9cec9;
font-size: 12px;
line-height: 1.55;
}
#detail-action {
margin-top: 12px;
padding-top: 11px;
border-top: 1px solid rgba(255, 255, 255, 0.11);
color: #fff5df;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.bottom-dock {
position: fixed;
z-index: 6;
right: 20px;
bottom: 18px;
left: 20px;
width: min(930px, calc(100vw - 40px));
margin: auto;
padding: 12px;
border: 1px solid rgba(28, 37, 39, 0.18);
background: rgba(245, 240, 227, 0.92);
box-shadow: 0 14px 40px rgba(31, 35, 33, 0.16);
backdrop-filter: blur(12px);
}
.flow {
display: flex;
align-items: center;
justify-content: center;
gap: 8px;
margin-bottom: 9px;
color: #3b4344;
font-size: 10px;
font-weight: 850;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.flow .token {
padding: 4px 8px;
border: 1px solid rgba(35, 42, 43, 0.14);
background: rgba(255, 255, 255, 0.45);
}
.flow .ore { border-left: 4px solid var(--ore); }
.flow .charcoal { border-left: 4px solid var(--charcoal); }
.flow .furnace { border-left: 4px solid var(--fire); }
.flow .iron { border-left: 4px solid var(--iron); }
.flow .slag { border-left: 4px solid var(--slag); }
.stage-grid {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 7px;
}
.stage-button {
position: relative;
min-height: 52px;
padding: 8px 9px 8px 14px;
border: 1px solid rgba(35, 42, 43, 0.15);
background: rgba(255, 255, 255, 0.42);
color: #273033;
text-align: left;
cursor: pointer;
}
.stage-button::before {
content: "";
position: absolute;
top: 7px;
bottom: 7px;
left: 5px;
width: 4px;
background: var(--stage-color);
}
.stage-button:hover,
.stage-button.active {
background: #1b2528;
color: #fff7e8;
border-color: #1b2528;
}
.stage-button strong {
display: block;
font-size: 10px;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.stage-button span {
display: block;
margin-top: 3px;
color: #707775;
font-size: 9px;
}
.stage-button:hover span,
.stage-button.active span {
color: #bfc6c1;
}
.help {
position: fixed;
z-index: 5;
bottom: 164px;
left: 22px;
color: rgba(28, 35, 36, 0.7);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
pointer-events: none;
}
.note {
position: fixed;
z-index: 5;
right: 22px;
bottom: 166px;
color: rgba(28, 35, 36, 0.65);
font-size: 9px;
font-style: italic;
pointer-events: none;
}
@media (max-width: 800px) {
.header {
top: 15px;
left: 15px;
width: calc(100vw - 30px);
}
h1 {
max-width: 440px;
font-size: 31px;
}
.subtitle {
max-width: 430px;
font-size: 11px;
}
.warning {
max-width: 440px;
padding: 8px 9px;
}
.controls {
top: auto;
right: 14px;
bottom: 144px;
}
.control-button {
min-height: 34px;
padding: 0 9px;
font-size: 9px;
}
.detail-panel {
top: auto;
right: 14px;
bottom: 190px;
width: min(340px, calc(100vw - 28px));
padding: 12px 14px;
}
#detail-title {
font-size: 21px;
}
#detail-body {
font-size: 11px;
}
.bottom-dock {
right: 10px;
bottom: 10px;
left: 10px;
width: auto;
padding: 8px;
}
.stage-grid {
gap: 4px;
}
.stage-button {
min-height: 49px;
padding: 7px 5px 7px 10px;
}
.stage-button strong {
font-size: 8px;
}
.stage-button span {
font-size: 7px;
}
.flow {
gap: 3px;
font-size: 7px;
}
.flow .token {
padding: 3px 4px;
}
.help,
.note {
display: none;
}
}
@media (max-width: 520px) {
.subtitle,
.warning {
display: none;
}
.detail-panel {
bottom: 177px;
}
.stage-button span {
display: none;
}
.flow .token {
font-size: 6px;
}
}
</style>
</head>
<body>
<canvas
id="scene"
tabindex="0"
aria-label="Interactive voxel diagram of iron ore and charcoal entering a furnace, producing metallic iron and slag."
></canvas>
<header class="header">
<div class="eyebrow">Meroitic Kush · material process</div>
<h1>Making iron in Kush</h1>
<p class="subtitle">
A voxel teaching model of the iron-smelting chain: mineral feedstock and fuel
enter the furnace, while metallic iron and slag leave it.
</p>
<div class="warning">
<strong>Not interchangeable materials</strong>
<span>
Ore and charcoal are different <em>inputs</em>. Slag and iron are different
<em>outputs</em>. Slag is residue—not fuel—and iron is the product—not ore.
</span>
</div>
</header>
<nav class="controls" aria-label="Camera controls">
<button class="control-button" id="rotateButton" aria-pressed="false">Auto orbit</button>
<button class="control-button" id="resetButton">Reset view</button>
</nav>
<aside class="detail-panel" id="detailPanel" aria-live="polite">
<div class="detail-meta">
<span id="detail-category">Feedstock</span>
<span id="detail-role">Input</span>
</div>
<h2 id="detail-title">Iron-bearing ore</h2>
<p id="detail-body"></p>
<div id="detail-action"></div>
</aside>
<div class="help">Drag to orbit · Scroll to zoom · Click a sample</div>
<div class="note">Schematic process model, not a reconstruction of one site.</div>
<section class="bottom-dock" aria-label="Process stages">
<div class="flow" aria-label="Ore and charcoal enter the furnace; iron and slag leave it">
<span class="token ore">Ore</span>
<b>+</b>
<span class="token charcoal">Charcoal</span>
<b>→</b>
<span class="token furnace">Smelting furnace</span>
<b>→</b>
<span class="token iron">Iron</span>
<b>+</b>
<span class="token slag">Slag</span>
</div>
<div class="stage-grid">
<button
class="stage-button active"
data-stage="ore"
style="--stage-color: var(--ore)"
aria-pressed="true"
>
<strong>Iron ore</strong>
<span>Feedstock</span>
</button>
<button
class="stage-button"
data-stage="charcoal"
style="--stage-color: var(--charcoal)"
aria-pressed="false"
>
<strong>Charcoal</strong>
<span>Fuel</span>
</button>
<button
class="stage-button"
data-stage="slag"
style="--stage-color: var(--slag)"
aria-pressed="false"
>
<strong>Slag</strong>
<span>Byproduct</span>
</button>
<button
class="stage-button"
data-stage="iron"
style="--stage-color: var(--iron)"
aria-pressed="false"
>
<strong>Iron</strong>
<span>Product</span>
</button>
</div>
</section>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight, false);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xc9c3b4);
scene.fog = new THREE.Fog(0xc9c3b4, 29, 52);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
const cameraState = {
theta: 0.34,
phi: 1.06,
radius: 21.5,
target: new THREE.Vector3(0, 1.45, 0),
autoRotate: false
};
function resetCamera() {
cameraState.theta = 0.34;
cameraState.phi = 1.06;
cameraState.radius = window.innerWidth < 700 ? 27 : 21.5;
cameraState.target.set(0, 1.45, 0);
}
function updateCamera() {
const sinPhi = Math.sin(cameraState.phi);
camera.position.set(
cameraState.target.x +
cameraState.radius * sinPhi * Math.sin(cameraState.theta),
cameraState.target.y + cameraState.radius * Math.cos(cameraState.phi),
cameraState.target.z +
cameraState.radius * sinPhi * Math.cos(cameraState.theta)
);
camera.lookAt(cameraState.target);
}
updateCamera();
const hemisphere = new THREE.HemisphereLight(0xfff4d9, 0x596568, 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffe8bc, 4.1);
sun.position.set(-9, 15, 9);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -19;
sun.shadow.camera.right = 19;
sun.shadow.camera.top = 15;
sun.shadow.camera.bottom = -15;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 45;
sun.shadow.bias = -0.0006;
scene.add(sun);
const rim = new THREE.DirectionalLight(0xb7d8dc, 1.15);
rim.position.set(11, 8, -11);
scene.add(rim);
const stageData = {
ore: {
category: "Feedstock",
role: "Input",
title: "Iron-bearing ore",
body:
"Mined rock containing iron minerals. It is the mineral feedstock from which metallic iron is sought. The reddish blocks represent iron-rich material within a rocky matrix, not charcoal or metal.",
action: "Crushed, sorted, and charged with charcoal",
color: "#c66c43",
labelTitle: "IRON-BEARING ORE",
labelSub: "MINERAL FEEDSTOCK"
},
charcoal: {
category: "Fuel",
role: "Input",
title: "Charcoal",
body:
"A carbon-rich fuel made by heating wood in limited air. In the furnace it supplies heat and carbon for reduction. Charcoal is a fuel, not ore, and it does not become the metallic product by simply being the same substance.",
action: "Burned as fuel inside the smelting furnace",
color: "#687078",
labelTitle: "CHARCOAL",
labelSub: "CARBON FUEL"
},
slag: {
category: "Byproduct",
role: "Output",
title: "Smelting slag",
body:
"The vitrified, non-metallic residue formed from much of the gangue and flux. Slag may retain traces of iron, but it is waste from the process—not the desired metal and not a replacement for charcoal.",
action: "Removed from the furnace as solid residue",
color: "#559496",
labelTitle: "SLAG",
labelSub: "NON-METALLIC RESIDUE"
},
iron: {
category: "Product",
role: "Output",
title: "Metallic iron",
body:
"The useful metallic output. In early bloomery production, the reduced iron forms a porous mass called a bloom that is consolidated and worked further. It is a finished metal product, not another form of ore.",
action: "Consolidated from a bloom and further worked",
color: "#d6dfe2",
labelTitle: "METALLIC IRON",
labelSub: "DESIRED PRODUCT"
}
};
const stagePositions = {
ore: -7.15,
charcoal: -3.75,
slag: 3.75,
iron: 7.15
};
const materialCache = new Map();
function material(color, roughness = 0.78, metalness = 0) {
const key = `${color}-${roughness}-${metalness}`;
if (!materialCache.has(key)) {
materialCache.set(
key,
new THREE.MeshStandardMaterial({
color,
roughness,
metalness
})
);
}
return materialCache.get(key);
}
function addBox(parent, size, position, colorOrMaterial, options = {}) {
const geometry = new THREE.BoxGeometry(
size[0],
size[1],
size[2]
);
const mat =
typeof colorOrMaterial === "string"
? material(
colorOrMaterial,
options.roughness ?? 0.78,
options.metalness ?? 0
)
: colorOrMaterial;
const mesh = new THREE.Mesh(geometry, mat);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = options.castShadow !== false;
mesh.receiveShadow = options.receiveShadow !== false;
parent.add(mesh);
return mesh;
}
function mulberry32(seed) {
return function () {
let t = (seed += 0x6d2b79f5);
t = Math.imul(t ^ (t >>> 15), t | 1);
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
const random = mulberry32(481516);
function roundedRect(ctx, x, y, w, h, radius) {
const r = Math.min(radius, w / 2, h / 2);
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.arcTo(x + w, y, x + w, y + h, r);
ctx.arcTo(x + w, y + h, x, y + h, r);
ctx.arcTo(x, y + h, x, y, r);
ctx.arcTo(x, y, x + w, y, r);
ctx.closePath();
}
function makeLabelSprite(title, subtitle, accent) {
const labelCanvas = document.createElement("canvas");
labelCanvas.width = 768;
labelCanvas.height = 192;
const ctx = labelCanvas.getContext("2d");
ctx.clearRect(0, 0, 768, 192);
roundedRect(ctx, 8, 8, 752, 176, 19);
ctx.fillStyle = "rgba(18, 25, 27, 0.94)";
ctx.fill();
ctx.strokeStyle = accent;
ctx.lineWidth = 5;
ctx.stroke();
ctx.fillStyle = accent;
roundedRect(ctx, 24, 27, 74, 74, 9);
ctx.fill();
ctx.fillStyle = "#172125";
ctx.font = "900 28px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText("◆", 61, 65);
ctx.textAlign = "left";
ctx.fillStyle = "#fff8e9";
ctx.font = "850 43px system-ui, sans-serif";
ctx.fillText(title, 120, 69);
ctx.fillStyle = accent;
ctx.font = "800 25px system-ui, sans-serif";
ctx.letterSpacing = "2px";
ctx.fillText(subtitle, 122, 126);
const texture = new THREE.CanvasTexture(labelCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
texture.magFilter = THREE.LinearFilter;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false,
toneMapped: false
})
);
sprite.scale.set(2.82, 0.705, 1);
return sprite;
}
// Stepped diorama base.
addBox(
scene,
[35, 0.55, 21],
[0, -0.32, 0],
"#8e8576",
{ castShadow: false }
);
const tileGeometry = new THREE.BoxGeometry(1.12, 0.075, 1.12);
const tileMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 1,
metalness: 0
});
const columns = 30;
const rows = 18;
const tiles = new THREE.InstancedMesh(
tileGeometry,
tileMaterial,
columns * rows
);
const tileMatrix = new THREE.Matrix4();
const tileColor = new THREE.Color();
const tilePalette = ["#b9ae98", "#c0b59f", "#afa58f", "#c7bca7", "#b4aa95"];
let tileIndex = 0;
for (let row = 0; row < rows; row++) {
for (let column = 0; column < columns; column++) {
const x = (column - (columns - 1) / 2) * 1.15;
const z = (row - (rows - 1) / 2) * 1.15;
tileMatrix.makeTranslation(x, 0.01, z);
tiles.setMatrixAt(tileIndex, tileMatrix);
tileColor.set(
tilePalette[Math.floor(random() * tilePalette.length)]
);
tileColor.offsetHSL(0, 0, (random() - 0.5) * 0.035);
tiles.setColorAt(tileIndex, tileColor);
tileIndex++;
}
}
tiles.instanceMatrix.needsUpdate = true;
if (tiles.instanceColor) tiles.instanceColor.needsUpdate = true;
tiles.receiveShadow = true;
scene.add(tiles);
// Central smelting furnace.
const furnace = new THREE.Group();
scene.add(furnace);
const stoneDark = material("#3f4545", 0.94);
const stoneMid = material("#59605d", 0.93);
const stoneWarm = material("#6c6254", 0.95);
addBox(furnace, [3.2, 0.48, 2.45], [0, 0.26, 0], stoneDark);
addBox(furnace, [2.8, 0.3, 2.15], [0, 0.61, 0], stoneWarm);
addBox(furnace, [2.4, 2.35, 0.52], [0, 1.72, -0.92], stoneMid);
addBox(furnace, [0.58, 2.65, 1.85], [-1.12, 1.7, 0], stoneDark);
addBox(furnace, [0.58, 2.65, 1.85], [1.12, 1.7, 0], stoneDark);
addBox(furnace, [0.78, 0.58, 1.9], [-0.72, 2.6, 0], stoneWarm);
addBox(furnace, [0.78, 0.58, 1.9], [0.72, 2.6, 0], stoneWarm);
addBox(furnace, [2.8, 0.48, 2.0], [0, 3.08, 0], stoneDark);
addBox(furnace, [1.05, 0.88, 1.1], [0, 3.68, -0.25], stoneMid);
addBox(furnace, [1.25, 0.18, 1.3], [0, 4.18, -0.25], stoneWarm);
addBox(
furnace,
[1.65, 1.55, 0.13],
[0, 1.52, 0.37],
"#151919"
);
const furnaceLabel = makeLabelSprite(
"SMELTING FURNACE",
"HEAT + REDUCTION",
"#f1a34b"
);
furnaceLabel.scale.set(2.55, 0.64, 1);
furnaceLabel.position.set(0, 4.75, 0.2);
furnace.add(furnaceLabel);
const fireMaterial = new THREE.MeshStandardMaterial({
color: 0xff8b2a,
emissive: 0xff4b08,
emissiveIntensity: 2.5,
roughness: 0.65
});
const fireBlocks = [];
for (let i = 0; i < 11; i++) {
const size = 0.18 + random() * 0.18;
const fire = addBox(
furnace,
[size, size * (0.65 + random()), size],
[
(random() - 0.5) * 1.25,
0.76 + random() * 0.75,
0.43 + random() * 0.35
],
fireMaterial
);
fireBlocks.push({
mesh: fire,
phase: random() * Math.PI * 2,
baseY: fire.position.y
});
}
const furnaceLight = new THREE.PointLight(0xff7b2d, 11, 7.5, 2);
furnaceLight.position.set(0, 1.5, 1.2);
furnace.add(furnaceLight);
// Floor arrows explain input and output directions.
function addFloorArrow(startX, endX, z, color) {
const direction = Math.sign(endX - startX);
const length = Math.abs(endX - startX);
const count = Math.max(2, Math.floor(length / 0.38));
const step = length / count;
for (let i = 0; i < count; i++) {
addBox(
scene,
[0.16, 0.075, 0.16],
[startX + direction * step * (i + 0.5), 0.095, z],
color,
{ castShadow: false }
);
}
const headX = endX - direction * 0.14;
addBox(
scene,
[0.18, 0.09, 0.16],
[headX, 0.105, z],
color,
{ castShadow: false }
);
addBox(
scene,
[0.18, 0.09, 0.16],
[headX - direction * 0.15, 0.105, z - 0.15],
color,
{ castShadow: false }
);
addBox(
scene,
[0.18, 0.09, 0.16],
[headX - direction * 0.15, 0.105, z + 0.15],
color,
{ castShadow: false }
);
}
addFloorArrow(-5.65, -1.9, 1.72, "#c66c43");
addFloorArrow(-2.38, -1.65, 0.38, "#596168");
addFloorArrow(1.7, 2.35, 0.38, "#559496");
addFloorArrow(1.9, 5.62, 1.72, "#d6dfe2");
const stageRoots = {};
const selectionFrames = {};
function createSupport(stage, x) {
const config = stageData[stage];
const group = new THREE.Group();
group.position.x = x;
group.userData.stage = stage;
scene.add(group);
stageRoots[stage] = group;
addBox(group, [2.85, 0.22, 2.35], [0, 0.12, 0], "#293235");
addBox(group, [2.42, 0.86, 1.92], [0, 0.64, 0], "#485052");
addBox(group, [2.86, 0.2, 2.38], [0, 1.16, 0], "#30393b");
addBox(group, [2.52, 0.08, 2.08], [0, 1.3, 0], config.color);
const label = makeLabelSprite(
config.labelTitle,
config.labelSub,
config.color
);
label.position.set(0, 0.7, 1.22);
group.add(label);
const frameMaterial = new THREE.MeshStandardMaterial({
color: config.color,
emissive: config.color,
emissiveIntensity: 1.2,
roughness: 0.45
});
const frame = new THREE.Group();
frame.visible = false;
group.add(frame);
addBox(frame, [3.08, 0.09, 0.09], [0, 0.08, 1.34], frameMaterial);
addBox(frame, [3.08, 0.09, 0.09], [0, 0.08, -1.34], frameMaterial);
addBox(frame, [0.09, 0.09, 2.68], [1.54, 0.08, 0], frameMaterial);
addBox(frame, [0.09, 0.09, 2.68], [-1.54, 0.08, 0], frameMaterial);
selectionFrames[stage] = frame;
return group;
}
function makeOreSample(parent) {
const colors = ["#7f402d", "#a95235", "#c47445", "#654038", "#8d4932"];
for (let i = 0; i < 9; i++) {
const cluster = new THREE.Group();
cluster.position.set(
-0.96 + (i % 3) * 0.55 + (random() - 0.5) * 0.18,
1.42,
-0.62 + Math.floor(i / 3) * 0.45 + (random() - 0.5) * 0.16
);
parent.add(cluster);
for (let j = 0; j < 5; j++) {
const size = 0.23 + random() * 0.22;
addBox(
cluster,
[size, size * (0.7 + random() * 0.5), size],
[
(random() - 0.5) * 0.48,
size * 0.48 + Math.floor(j / 3) * 0.18,
(random() - 0.5) * 0.42
],
colors[Math.floor(random() * colors.length)]
);
}
}
addBox(
parent,
[2.08, 0.08, 1.55],
[0, 1.37, 0],
"#594238"
);
}
function makeCharcoalSample(parent) {
const charColors = ["#202426", "#2d3031", "#3c3e3e", "#484a49"];
for (let row = 0; row < 3; row++) {
for (let column = 0; column < 3; column++) {
const x = -0.65 + column * 0.65 + (row % 2) * 0.12;
const z = -0.48 + row * 0.48;
const y = 1.47 + (row === 2 ? 0.28 : 0);
for (let piece = 0; piece < 3; piece++) {
addBox(
parent,
[0.31, 0.27, 0.31],
[x, y, z - 0.32 + piece * 0.32],
charColors[(row + column + piece) % charColors.length],
{ roughness: 1 }
);
}
}
}
for (let i = 0; i < 7; i++) {
const size = 0.15 + random() * 0.12;
addBox(
parent,
[size, size, size],
[
-0.95 + random() * 1.9,
1.44 + size * 0.5,
-0.72 + random() * 1.4
],
i % 2 ? "#292c2d" : "#454747",
{ roughness: 1 }
);
}
}
function makeSlagSample(parent) {
const slagColors = ["#355b5d", "#467779", "#2e4e52", "#5b8584"];
for (let i = 0; i < 7; i++) {
const group = new THREE.Group();
group.position.set(
-0.92 + random() * 1.84,
1.42,
-0.55 + random() * 1.1
);
parent.add(group);
for (let j = 0; j < 4; j++) {
const size = 0.26 + random() * 0.25;
addBox(
group,
[size, size * (0.45 + random() * 0.5), size],
[
(random() - 0.5) * 0.45,
size * 0.38 + (j > 1 ? 0.18 : 0),
(random() - 0.5) * 0.45
],
slagColors[Math.floor(random() * slagColors.length)],
{ roughness: 0.28, metalness: 0.18 }
);
}
}
}
function makeIronSample(parent) {
const silver = ["#aeb9bd", "#c7d0d2", "#8f9da2", "#dbe1e2"];
const ironMaterial = new THREE.MeshStandardMaterial({
color: 0xc4cdd0,
roughness: 0.27,
metalness: 0.68
});
// Rough bloom: a clustered, porous metallic mass.
for (let i = 0; i < 13; i++) {
const size = 0.22 + random() * 0.19;
addBox(
parent,
[size, size * 0.75, size],
[
-0.72 + random() * 1.45,
1.55 + size * 0.35 + (i > 8 ? 0.18 : 0),
-0.5 + random() * 1.05
],
silver[Math.floor(random() * silver.length)],
{ roughness: 0.34, metalness: 0.58 }
);
}
// Two consolidated bars distinguish the metal product from the bloom.
for (let bar = 0; bar < 2; bar++) {
const x = -0.46 + bar * 0.92;
for (let segment = 0; segment < 4; segment++) {
addBox(
parent,
[0.38, 0.24, 0.42],
[x, 1.5, 0.72 - segment * 0.43],
ironMaterial
);
}
}
}
const sampleBuilders = {
ore: makeOreSample,
charcoal: makeCharcoalSample,
slag: makeSlagSample,
iron: makeIronSample
};
for (const [stage, x] of Object.entries(stagePositions)) {
const support = createSupport(stage, x);
sampleBuilders[stage](support);
support.traverse((object) => {
object.userData.stage = stage;
});
}
// Selected material state.
let selectedStage = "ore";
function selectStage(stage) {
selectedStage = stage;
const config = stageData[stage];
document.querySelector("#detail-category").textContent = config.category;
document.querySelector("#detail-role").textContent = config.role;
document.querySelector("#detail-title").textContent = config.title;
document.querySelector("#detail-body").textContent = config.body;
document.querySelector("#detail-action").textContent = config.action;
document.querySelector("#detailPanel").style.borderTopColor = config.color;
document.querySelector("#detail-role").style.color = config.color;
for (const [id, frame] of Object.entries(selectionFrames)) {
frame.visible = id === stage;
}
document.querySelectorAll(".stage-button").forEach((button) => {
const active = button.dataset.stage === stage;
button.classList.toggle("active", active);
button.setAttribute("aria-pressed", String(active));
});
}
selectStage("ore");
document.querySelectorAll(".stage-button").forEach((button) => {
button.addEventListener("click", () => {
selectStage(button.dataset.stage);
});
});
// Direct camera controls: pointer orbit, wheel zoom, keyboard movement.
let pointerActive = false;
let pointerId = null;
let lastPointerX = 0;
let lastPointerY = 0;
let pointerTravel = 0;
canvas.addEventListener("pointerdown", (event) => {
pointerActive = true;
pointerId = event.pointerId;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
pointerTravel = 0;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!pointerActive || event.pointerId !== pointerId) return;
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
pointerTravel += Math.abs(dx) + Math.abs(dy);
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - dy * 0.005,
0.48,
1.43
);
});
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
function stageAtPointer(event) {
const rect = canvas.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(Object.values(stageRoots), true);
if (!hits.length) return null;
let object = hits[0].object;
while (object) {
if (object.userData.stage) return object.userData.stage;
object = object.parent;
}
return null;
}
canvas.addEventListener("pointerup", (event) => {
if (event.pointerId !== pointerId) return;
pointerActive = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
if (pointerTravel < 7) {
const stage = stageAtPointer(event);
if (stage) selectStage(stage);
}
});
canvas.addEventListener("pointercancel", () => {
pointerActive = false;
});
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
14,
31
);
},
{ passive: false }
);
canvas.addEventListener("keydown", (event) => {
const amount = 0.12;
if (event.key === "ArrowLeft") cameraState.theta -= amount;
if (event.key === "ArrowRight") cameraState.theta += amount;
if (event.key === "ArrowUp") {
cameraState.phi = Math.max(0.48, cameraState.phi - amount);
}
if (event.key === "ArrowDown") {
cameraState.phi = Math.min(1.43, cameraState.phi + amount);
}
if (event.key === "+" || event.key === "=") {
cameraState.radius = Math.max(14, cameraState.radius - 1);
}
if (event.key === "-" || event.key === "_") {
cameraState.radius = Math.min(31, cameraState.radius + 1);
}
});
const rotateButton = document.querySelector("#rotateButton");
rotateButton.addEventListener("click", () => {
cameraState.autoRotate = !cameraState.autoRotate;
rotateButton.setAttribute("aria-pressed", String(cameraState.autoRotate));
});
document.querySelector("#resetButton").addEventListener("click", () => {
resetCamera();
});
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height, false);
}
window.addEventListener("resize", resize);
const clock = new THREE.Clock();
renderer.setAnimationLoop(() => {
const delta = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
if (cameraState.autoRotate && !pointerActive) {
cameraState.theta += delta * 0.12;
}
for (const block of fireBlocks) {
const pulse = 0.82 + Math.sin(elapsed * 7 + block.phase) * 0.18;
block.mesh.scale.y = pulse;
block.mesh.position.y =
block.baseY + Math.sin(elapsed * 2.5 + block.phase) * 0.04;
}
fireMaterial.emissiveIntensity =
2.25 + Math.sin(elapsed * 8.5) * 0.38;
furnaceLight.intensity = 10 + Math.sin(elapsed * 9) * 2.1;
updateCamera();
renderer.render(scene, camera);
});
</script>
</body>
</html>
```