Prompt specification
Build or customize the Three.js 3D scene "Workshop Recipe Chain" 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: Workshop Recipe Chain
Category: Games & Play · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/workshop-recipe-chain-x3566
Scene Description Prompt:
Animate a low-poly workshop recipe converting counted materials into components and one finished object, stopping when inputs run out. One HTML file, Three.js from cdnjs.
Working Three.js Starter (workshop-recipe-chain-x3566):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Workshop Recipe — The Tin Robot</title>
<style>
:root {
--ink: #263238;
--muted: #68777a;
--paper: rgba(250, 247, 238, 0.91);
--line: rgba(38, 50, 56, 0.13);
--teal: #4f8f89;
--orange: #e9824a;
--gold: #dda83e;
--blue: #668fa3;
--wood: #b97842;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e9e4d8;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active { cursor: grabbing; }
#hud {
position: fixed;
inset: 0;
z-index: 5;
pointer-events: none;
}
.brand {
position: absolute;
top: 24px;
left: 28px;
width: min(360px, calc(100vw - 56px));
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 9px;
color: var(--teal);
font-size: 11px;
font-weight: 850;
letter-spacing: 0.19em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 25px;
height: 3px;
background: var(--teal);
border-radius: 2px;
}
h1 {
margin: 0;
font-size: clamp(30px, 4vw, 52px);
line-height: 0.95;
letter-spacing: -0.055em;
font-weight: 900;
text-transform: uppercase;
}
.subtitle {
margin-top: 10px;
color: var(--muted);
font-size: 13px;
line-height: 1.45;
max-width: 310px;
}
.inventory {
position: absolute;
top: 24px;
right: 28px;
width: 286px;
padding: 17px 18px 15px;
border: 1px solid var(--line);
border-radius: 18px;
background: var(--paper);
box-shadow: 0 14px 40px rgba(55, 46, 32, 0.11);
backdrop-filter: blur(12px);
}
.inventory-title {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 12px;
font-size: 10px;
font-weight: 850;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.remaining {
padding: 4px 7px;
border-radius: 7px;
background: #e6eee9;
color: #39736c;
letter-spacing: 0.06em;
}
.material {
display: grid;
grid-template-columns: 10px 1fr auto;
align-items: center;
gap: 9px;
padding: 10px 0;
border-top: 1px solid var(--line);
transition: opacity 0.25s, transform 0.25s;
}
.material.consumed {
opacity: 0.48;
transform: translateX(3px);
}
.swatch {
width: 9px;
height: 25px;
border-radius: 4px;
background: var(--blue);
}
.material-name {
font-size: 11px;
font-weight: 780;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.material-kind {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 10px;
font-weight: 500;
letter-spacing: 0;
text-transform: none;
}
.material b {
min-width: 22px;
font-size: 21px;
text-align: right;
font-variant-numeric: tabular-nums;
}
.pips {
grid-column: 2 / 4;
display: flex;
gap: 4px;
margin-top: -2px;
}
.pip {
height: 3px;
flex: 1;
border-radius: 3px;
background: #d8ddd8;
transition: background 0.25s;
}
.pip.on { background: var(--teal); }
.status-wrap {
position: absolute;
left: 28px;
right: 28px;
bottom: 24px;
display: grid;
grid-template-columns: minmax(260px, 470px) auto;
align-items: end;
gap: 18px;
}
.status-card {
padding: 15px 18px 16px;
border: 1px solid var(--line);
border-radius: 17px;
background: var(--paper);
box-shadow: 0 12px 35px rgba(55, 46, 32, 0.1);
backdrop-filter: blur(12px);
}
.status-line {
display: flex;
justify-content: space-between;
align-items: center;
gap: 20px;
margin-bottom: 10px;
}
#status {
font-size: 11px;
font-weight: 850;
letter-spacing: 0.09em;
text-transform: uppercase;
}
#clock {
color: var(--muted);
font-size: 10px;
font-variant-numeric: tabular-nums;
white-space: nowrap;
}
.progress {
height: 5px;
overflow: hidden;
border-radius: 5px;
background: #dde0db;
}
#progress-fill {
width: 0;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, var(--orange), var(--gold), var(--teal));
transition: width 0.08s linear;
}
.controls {
display: flex;
gap: 8px;
pointer-events: auto;
}
button {
border: 0;
border-radius: 13px;
padding: 13px 16px;
color: var(--ink);
background: var(--paper);
box-shadow: 0 10px 25px rgba(55, 46, 32, 0.11);
font: inherit;
font-size: 11px;
font-weight: 850;
letter-spacing: 0.09em;
text-transform: uppercase;
cursor: pointer;
backdrop-filter: blur(12px);
transition: transform 0.18s, background 0.18s;
}
button:hover { transform: translateY(-2px); }
button:active { transform: translateY(0); }
#replay {
color: white;
background: var(--ink);
}
#hint {
position: absolute;
right: 29px;
bottom: 91px;
color: rgba(38, 50, 56, 0.55);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
transition: opacity 0.5s;
}
#complete {
position: absolute;
right: 28px;
bottom: 104px;
width: 260px;
padding: 17px 18px;
border: 1px solid rgba(79, 143, 137, 0.25);
border-radius: 17px;
background: rgba(239, 247, 240, 0.94);
box-shadow: 0 15px 40px rgba(55, 46, 32, 0.12);
opacity: 0;
transform: translateY(12px);
transition: opacity 0.45s, transform 0.45s;
}
#complete.show {
opacity: 1;
transform: translateY(0);
}
#complete strong {
display: block;
color: #39736c;
font-size: 12px;
letter-spacing: 0.11em;
text-transform: uppercase;
}
#complete span {
display: block;
margin-top: 5px;
color: var(--muted);
font-size: 11px;
line-height: 1.4;
}
#boot {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
color: var(--teal);
background: #e9e4d8;
font-size: 11px;
font-weight: 850;
letter-spacing: 0.18em;
text-transform: uppercase;
transition: opacity 0.4s;
pointer-events: none;
}
#boot.hide { opacity: 0; }
@media (max-width: 720px) {
.brand { top: 16px; left: 17px; }
h1 { font-size: 31px; }
.subtitle { display: none; }
.inventory {
top: 105px;
right: 15px;
width: 205px;
padding: 12px 13px;
}
.material { padding: 7px 0; }
.material-kind { display: none; }
.material b { font-size: 17px; }
.status-wrap {
left: 15px;
right: 15px;
bottom: 15px;
grid-template-columns: 1fr;
gap: 8px;
}
.status-card { padding: 12px 14px; }
.controls { justify-content: flex-end; }
button { padding: 10px 13px; }
#hint { display: none; }
#complete {
right: 15px;
bottom: 120px;
width: 220px;
}
}
</style>
</head>
<body>
<div id="boot">Warming the workshop…</div>
<div id="hud">
<header class="brand">
<div class="eyebrow">Workshop recipe / 07</div>
<h1>The Tin<br>Robot</h1>
<div class="subtitle">
A counted build recipe. Seven raw pieces become six components,
then one finished companion.
</div>
</header>
<aside class="inventory">
<div class="inventory-title">
<span>Raw ingredients</span>
<span class="remaining"><span id="remaining">7</span> left</span>
</div>
<div class="material" id="row-alloy">
<span class="swatch" style="background:var(--blue)"></span>
<span>
<span class="material-name">Alloy panels</span>
<span class="material-kind">Cold-rolled body stock</span>
</span>
<b id="count-alloy">2</b>
<span class="pips" id="pips-alloy"></span>
</div>
<div class="material" id="row-maple">
<span class="swatch" style="background:var(--wood)"></span>
<span>
<span class="material-name">Maple dowels</span>
<span class="material-kind">Turned limb stock</span>
</span>
<b id="count-maple">4</b>
<span class="pips" id="pips-maple"></span>
</div>
<div class="material" id="row-brass">
<span class="swatch" style="background:var(--gold)"></span>
<span>
<span class="material-name">Brass core</span>
<span class="material-kind">Precision signal heart</span>
</span>
<b id="count-brass">1</b>
<span class="pips" id="pips-brass"></span>
</div>
</aside>
<div id="complete">
<strong>✓ One robot complete</strong>
<span>Every counted ingredient has been consumed. The workshop is ready for the next recipe.</span>
</div>
<div id="hint">Drag to orbit · Scroll to zoom</div>
<div class="status-wrap">
<div class="status-card">
<div class="status-line">
<span id="status">Queueing recipe</span>
<span id="clock">00:00 / 00:15</span>
</div>
<div class="progress"><div id="progress-fill"></div></div>
</div>
<div class="controls">
<button id="pause" type="button">Pause</button>
<button id="replay" type="button">Replay</button>
</div>
</div>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe9e4d8);
scene.fog = new THREE.Fog(0xe9e4d8, 24, 43);
const camera = new THREE.PerspectiveCamera(38, innerWidth / innerHeight, 0.1, 80);
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
document.body.prepend(renderer.domElement);
const clock = new THREE.Clock();
const state = {
elapsed: 0,
paused: false,
complete: false,
duration: 15,
status: ""
};
const palette = {
ink: 0x263238,
cream: 0xf4efe2,
wall: 0xd9d3c5,
floor: 0xc99761,
floorDark: 0xb9804d,
teal: 0x4f8f89,
tealDark: 0x376d69,
orange: 0xe9824a,
orangeDark: 0xb85f38,
gold: 0xe6b54a,
blue: 0x668fa3,
blueDark: 0x416979,
wood: 0xb97842,
woodDark: 0x87552f,
white: 0xfffaf0,
red: 0xc95f4a
};
function standard(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.78,
metalness: 0.04,
flatShading: true,
...options
});
}
const mat = {
ink: standard(palette.ink),
cream: standard(palette.cream),
wall: standard(palette.wall),
floor: standard(palette.floor),
floorDark: standard(palette.floorDark),
teal: standard(palette.teal),
tealDark: standard(palette.tealDark),
orange: standard(palette.orange),
orangeDark: standard(palette.orangeDark),
gold: standard(palette.gold, { metalness: 0.46, roughness: 0.38 }),
blue: standard(palette.blue, { metalness: 0.42, roughness: 0.48 }),
blueDark: standard(palette.blueDark, { metalness: 0.36, roughness: 0.52 }),
wood: standard(palette.wood),
woodDark: standard(palette.woodDark),
white: standard(palette.white),
red: standard(palette.red),
eye: standard(0x9ff4e5, { emissive: 0x54d6c6, emissiveIntensity: 1.7, roughness: 0.25 }),
darkGlass: standard(0x33484d, { roughness: 0.3, metalness: 0.2 })
};
function box(w, h, d, material, x = 0, y = 0, z = 0, parent = scene) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(w, h, d), material);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinder(rt, rb, h, segments, material, x = 0, y = 0, z = 0, parent = scene) {
const mesh = new THREE.Mesh(new THREE.CylinderGeometry(rt, rb, h, segments), material);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function roundedRect(ctx, x, y, w, h, r) {
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 labelTexture(title, subtitle, color = "#4f8f89") {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 160;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, 512, 160);
roundedRect(ctx, 6, 8, 500, 138, 24);
ctx.fillStyle = "rgba(250,247,238,0.96)";
ctx.fill();
ctx.strokeStyle = "rgba(38,50,56,0.15)";
ctx.lineWidth = 3;
ctx.stroke();
ctx.fillStyle = color;
ctx.fillRect(23, 30, 8, 96);
ctx.fillStyle = "#263238";
ctx.font = "800 42px system-ui, sans-serif";
ctx.textBaseline = "middle";
ctx.fillText(title, 50, 58);
ctx.fillStyle = "#68777a";
ctx.font = "700 27px system-ui, sans-serif";
ctx.fillText(subtitle, 51, 105);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.needsUpdate = true;
return texture;
}
function makeLabel(title, subtitle, color = "#4f8f89", width = 1.6) {
const sprite = new THREE.Sprite(new THREE.SpriteMaterial({
map: labelTexture(title, subtitle, color),
transparent: true,
depthTest: false,
depthWrite: false
}));
sprite.scale.set(width, width * 0.3125, 1);
sprite.renderOrder = 20;
return sprite;
}
function updateLabel(sprite, title, subtitle, color = "#4f8f89") {
sprite.material.map.dispose();
sprite.material.map = labelTexture(title, subtitle, color);
sprite.material.needsUpdate = true;
}
// Lighting
scene.add(new THREE.HemisphereLight(0xfff8e8, 0x8f7257, 2.0));
const key = new THREE.DirectionalLight(0xfff2d9, 3.3);
key.position.set(-7, 13, 8);
key.castShadow = true;
key.shadow.mapSize.set(2048, 2048);
key.shadow.camera.left = -13;
key.shadow.camera.right = 13;
key.shadow.camera.top = 10;
key.shadow.camera.bottom = -10;
key.shadow.camera.near = 1;
key.shadow.camera.far = 32;
key.shadow.bias = -0.00035;
scene.add(key);
const rim = new THREE.DirectionalLight(0xa7d7d0, 1.4);
rim.position.set(8, 6, -7);
scene.add(rim);
// Workshop shell
box(17.6, 0.36, 10.4, mat.floor, 0, -0.2, 0);
box(17.6, 3.8, 0.24, mat.wall, 0, 1.72, -4.82);
box(0.22, 3.8, 10.4, mat.wall, -8.7, 1.72, 0);
for (let i = 0; i < 12; i++) {
box(17.35, 0.012, 0.035, i % 3 === 0 ? mat.floorDark : mat.woodDark, 0, -0.012, -4.55 + i * 0.84);
}
box(17.8, 0.18, 0.32, mat.cream, 0, 0.05, -4.65);
box(0.32, 0.18, 10.1, mat.cream, -8.55, 0.05, 0);
// Back-wall pegboard and tools
box(3.25, 1.8, 0.11, mat.woodDark, -4.75, 2.25, -4.62);
for (let row = 0; row < 5; row++) {
for (let col = 0; col < 7; col++) {
cylinder(0.025, 0.025, 0.018, 6, mat.ink,
-6.08 + col * 0.44, 1.63 + row * 0.3, -4.54).rotation.x = Math.PI / 2;
}
}
box(0.11, 0.85, 0.11, mat.blueDark, -5.65, 2.35, -4.45);
box(0.38, 0.16, 0.12, mat.blue, -5.65, 2.78, -4.45);
box(0.11, 0.68, 0.11, mat.orange, -5.02, 2.33, -4.45);
box(0.42, 0.13, 0.12, mat.orange, -5.02, 2.69, -4.45);
box(0.12, 0.74, 0.12, mat.gold, -4.38, 2.37, -4.45);
box(0.34, 0.12, 0.12, mat.gold, -4.38, 2.74, -4.45);
// Window
box(3.0, 1.75, 0.12, mat.cream, 2.4, 2.55, -4.59);
box(2.72, 1.47, 0.08, mat.darkGlass, 2.4, 2.55, -4.5);
box(0.09, 1.5, 0.11, mat.cream, 2.4, 2.55, -4.43);
box(2.75, 0.09, 0.11, mat.cream, 2.4, 2.55, -4.43);
box(3.25, 0.15, 0.5, mat.woodDark, 2.4, 1.6, -4.48);
// Input rack
box(3.55, 0.18, 1.35, mat.tealDark, -5.28, 1.05, -2.58);
box(3.7, 0.12, 0.14, mat.teal, -5.28, 1.58, -3.2);
for (const x of [-6.78, -3.78]) {
for (const z of [-3.08, -2.08]) {
box(0.16, 1.0, 0.16, mat.tealDark, x, 0.48, z);
}
}
for (const x of [-6.25, -5.25, -4.25]) {
box(0.9, 0.05, 1.05, mat.woodDark, x, 1.17, -2.58);
}
// Cutting station
const cutX = -2.65;
box(1.85, 0.18, 1.35, mat.orangeDark, cutX, 1.03, -1.22);
for (const dx of [-0.72, 0.72]) {
for (const dz of [-0.48, 0.48]) {
box(0.13, 1.0, 0.13, mat.ink, cutX + dx, 0.48, -1.22 + dz);
}
}
box(1.16, 0.18, 0.75, mat.blueDark, cutX, 1.19, -1.29);
box(0.12, 0.88, 0.14, mat.ink, cutX - 0.46, 1.65, -1.28);
box(0.12, 0.88, 0.14, mat.ink, cutX + 0.46, 1.65, -1.28);
const sawBlade = new THREE.Group();
sawBlade.position.set(cutX, 1.72, -1.25);
scene.add(sawBlade);
const sawDisk = cylinder(0.47, 0.47, 0.07, 16, mat.blue, 0, 0, 0, sawBlade);
sawDisk.rotation.x = Math.PI / 2;
const sawHub = cylinder(0.12, 0.12, 0.1, 10, mat.gold, 0, 0, 0, sawBlade);
sawHub.rotation.x = Math.PI / 2;
for (let i = 0; i < 8; i++) {
const a = i * Math.PI / 4;
const tooth = box(0.09, 0.19, 0.075, mat.cream,
Math.cos(a) * 0.43, Math.sin(a) * 0.43, 0, sawBlade);
tooth.rotation.z = a - Math.PI / 2;
}
box(0.92, 0.28, 0.12, mat.orange, cutX, 2.18, -1.27);
// Lathe station
const latheX = -0.18;
box(1.85, 0.18, 1.35, mat.tealDark, latheX, 1.03, -1.22);
for (const dx of [-0.72, 0.72]) {
for (const dz of [-0.48, 0.48]) {
box(0.13, 1.0, 0.13, mat.ink, latheX + dx, 0.48, -1.22 + dz);
}
}
box(1.42, 0.25, 0.65, mat.cream, latheX, 1.24, -1.35);
const motor = cylinder(0.32, 0.32, 0.58, 10, mat.orange, latheX - 0.48, 1.64, -1.36);
motor.rotation.z = Math.PI / 2;
const spindle = cylinder(0.07, 0.07, 1.45, 8, mat.blueDark, latheX + 0.05, 1.64, -1.36);
spindle.rotation.z = Math.PI / 2;
box(0.24, 0.48, 0.34, mat.ink, latheX + 0.72, 1.52, -1.36);
// Press station
const pressX = 1.92;
box(1.75, 0.18, 1.32, mat.gold, pressX, 1.03, -1.22);
for (const dx of [-0.67, 0.67]) {
for (const dz of [-0.46, 0.46]) {
box(0.14, 1.0, 0.14, mat.ink, pressX + dx, 0.48, -1.22 + dz);
}
box(0.16, 1.65, 0.17, mat.orangeDark, pressX + dx, 1.87, -1.22);
}
box(1.62, 0.27, 0.48, mat.orange, pressX, 2.68, -1.22);
const piston = cylinder(0.13, 0.13, 0.65, 8, mat.blueDark, pressX, 2.15, -1.22);
box(0.58, 0.18, 0.58, mat.cream, pressX, 1.22, -1.22);
box(0.72, 0.12, 0.72, mat.gold, pressX, 1.34, -1.22);
// Assembly table
const assemblyX = 4.45;
box(2.75, 0.2, 2.05, mat.teal, assemblyX, 1.0, 0.65);
for (const dx of [-1.15, 1.15]) {
for (const dz of [-0.78, 0.78]) {
box(0.18, 0.96, 0.18, mat.tealDark, assemblyX + dx, 0.45, 0.65 + dz);
}
}
box(2.3, 0.12, 0.28, mat.woodDark, assemblyX, 0.43, 0.65);
const robotShadow = new THREE.Mesh(
new THREE.CircleGeometry(0.92, 24),
new THREE.MeshBasicMaterial({ color: 0x263238, transparent: true, opacity: 0.13, depthWrite: false })
);
robotShadow.rotation.x = -Math.PI / 2;
robotShadow.position.set(assemblyX, 1.115, 0.65);
robotShadow.visible = false;
scene.add(robotShadow);
// Floor route markers
for (let i = 0; i < 10; i++) {
const marker = box(0.38, 0.018, 0.12, i % 2 ? mat.cream : mat.gold,
-3.2 + i * 0.78, 0.005, -3.45);
marker.rotation.y = -0.35;
}
// Station signs
const cutSign = makeLabel("01 CUT", "ALLOY SHEAR", "#668fa3", 1.65);
cutSign.position.set(cutX, 2.62, -1.25);
scene.add(cutSign);
const latheSign = makeLabel("02 TURN", "MAPLE LATHE", "#e9824a", 1.65);
latheSign.position.set(latheX, 2.55, -1.28);
scene.add(latheSign);
const pressSign = makeLabel("03 PRESS", "BRASS CORE", "#dda83e", 1.65);
pressSign.position.set(pressX, 3.05, -1.22);
scene.add(pressSign);
const assemblySign = makeLabel("04 FIT", "ONE FINISHED OBJECT", "#4f8f89", 2.15);
assemblySign.position.set(assemblyX, 3.86, 0.65);
scene.add(assemblySign);
const alloyLabel = makeLabel("ALLOY", "× 02", "#668fa3", 1.02);
alloyLabel.position.set(-6.25, 2.28, -2.58);
scene.add(alloyLabel);
const mapleLabel = makeLabel("MAPLE", "× 04", "#e9824a", 1.02);
mapleLabel.position.set(-5.25, 2.28, -2.58);
scene.add(mapleLabel);
const brassLabel = makeLabel("BRASS", "× 01", "#dda83e", 1.02);
brassLabel.position.set(-4.25, 2.28, -2.58);
scene.add(brassLabel);
// Component factories
function makePanel(isHead) {
const group = new THREE.Group();
box(1.04, 1.05, 0.78, isHead ? mat.blue : mat.blueDark, 0, 0, 0, group);
box(0.91, 0.12, 0.81, mat.blue, 0, 0.48, 0, group);
box(0.78, 0.1, 0.81, mat.blue, 0, -0.48, 0, group);
for (const x of [-0.4, 0.4]) {
for (const y of [-0.39, 0.39]) {
const rivet = new THREE.Mesh(new THREE.SphereGeometry(0.035, 6, 4), mat.cream);
rivet.position.set(x, y, 0.405);
group.add(rivet);
}
}
if (isHead) {
box(0.71, 0.37, 0.045, mat.ink, 0, 0.06, 0.405, group);
box(0.12, 0.13, 0.06, mat.eye, -0.18, 0.08, 0.445, group);
box(0.12, 0.13, 0.06, mat.eye, 0.18, 0.08, 0.445, group);
box(0.23, 0.035, 0.05, mat.cream, 0, -0.08, 0.445, group);
cylinder(0.035, 0.035, 0.31, 6, mat.ink, 0, 0.66, 0, group);
const antenna = new THREE.Mesh(new THREE.SphereGeometry(0.105, 8, 6), mat.orange);
antenna.position.set(0, 0.85, 0);
group.add(antenna);
} else {
box(0.66, 0.16, 0.06, mat.cream, 0, -0.35, 0.42, group);
for (const x of [-0.38, 0.38]) {
box(0.11, 0.58, 0.82, mat.tealDark, x, 0, 0, group);
}
}
group.userData.baseScale = isHead ? 0.68 : 1;
return group;
}
function makeLimb() {
const group = new THREE.Group();
cylinder(0.115, 0.135, 0.8, 6, mat.wood, 0, 0, 0, group);
const topJoint = new THREE.Mesh(new THREE.SphereGeometry(0.15, 8, 6), mat.woodDark);
topJoint.position.y = 0.4;
group.add(topJoint);
const bottomJoint = new THREE.Mesh(new THREE.SphereGeometry(0.15, 8, 6), mat.woodDark);
bottomJoint.position.y = -0.4;
group.add(bottomJoint);
group.userData.baseScale = 1;
return group;
}
function makeCore() {
const group = new THREE.Group();
const heart = new THREE.Mesh(new THREE.IcosahedronGeometry(0.26, 1), mat.gold);
group.add(heart);
const ring = new THREE.Mesh(new THREE.TorusGeometry(0.35, 0.055, 5, 12), mat.cream);
ring.position.z = 0.04;
group.add(ring);
group.userData.baseScale = 1;
return group;
}
const bodyPanel = makePanel(false);
const headPanel = makePanel(true);
const limbs = [makeLimb(), makeLimb(), makeLimb(), makeLimb()];
const core = makeCore();
const components = [bodyPanel, headPanel, ...limbs, core];
components.forEach(component => {
component.visible = false;
scene.add(component);
});
const robotRoot = new THREE.Group();
scene.add(robotRoot);
// Raw ingredient geometry
function makeRawPlate() {
const group = new THREE.Group();
box(1.02, 0.13, 0.75, mat.blue, 0, 0, 0, group);
box(0.84, 0.025, 0.57, mat.blueDark, 0, 0.075, 0, group);
return group;
}
function makeRawRod() {
const group = new THREE.Group();
cylinder(0.115, 0.115, 0.92, 6, mat.wood, 0, 0, 0, group);
cylinder(0.14, 0.14, 0.11, 6, mat.woodDark, 0.4, 0, 0, group);
cylinder(0.14, 0.14, 0.11, 6, mat.woodDark, -0.4, 0, 0, group);
group.rotation.z = Math.PI / 2;
return group;
}
function makeRawCore() {
const group = new THREE.Group();
const piece = new THREE.Mesh(new THREE.DodecahedronGeometry(0.32, 0), mat.gold);
group.add(piece);
const stripe = new THREE.Mesh(new THREE.TorusGeometry(0.27, 0.035, 4, 10), mat.cream);
stripe.rotation.x = Math.PI / 2;
group.add(stripe);
return group;
}
const rawRecords = [];
function addRaw(type, index, x, y, z, component, output) {
const raw = type === "alloy" ? makeRawPlate() :
type === "maple" ? makeRawRod() : makeRawCore();
raw.position.set(x, y, z);
scene.add(raw);
rawRecords.push({
type,
index,
raw,
component,
output,
start: raw.position.clone(),
startQuaternion: raw.quaternion.clone(),
consumed: false
});
}
addRaw("alloy", 0, -6.25, 1.29, -2.58, bodyPanel, new THREE.Vector3(-2.88, 1.68, -0.26));
addRaw("alloy", 1, -6.25, 1.47, -2.58, headPanel, new THREE.Vector3(-2.42, 1.68, -0.26));
for (let i = 0; i < 4; i++) {
addRaw("maple", i, -5.25, 1.32, -2.96 + i * 0.25, limbs[i],
new THREE.Vector3(-0.62 + i * 0.29, 1.52, -0.19));
}
addRaw("brass", 0, -4.25, 1.42, -2.58, core, new THREE.Vector3(1.92, 1.48, -0.22));
// UI data
const counts = { alloy: 2, maple: 4, brass: 1 };
const maximums = { alloy: 2, maple: 4, brass: 1 };
const colors = { alloy: "#668fa3", maple: "#e9824a", brass: "#dda83e" };
const names = { alloy: "ALLOY", maple: "MAPLE", brass: "BRASS" };
const labelSprites = { alloy: alloyLabel, maple: mapleLabel, brass: brassLabel };
for (const key of Object.keys(maximums)) {
const pips = document.getElementById(`pips-${key}`);
for (let i = 0; i < maximums[key]; i++) {
const pip = document.createElement("i");
pip.className = "pip on";
pips.appendChild(pip);
}
}
function updateInventory() {
for (const key of Object.keys(counts)) {
document.getElementById(`count-${key}`).textContent = counts[key];
document.getElementById(`row-${key}`).classList.toggle("consumed", counts[key] === 0);
const pips = document.querySelectorAll(`#pips-${key} .pip`);
pips.forEach((pip, i) => pip.classList.toggle("on", i < counts[key]));
updateLabel(labelSprites[key], names[key], `× ${String(counts[key]).padStart(2, "0")}`, colors[key]);
}
const remaining = counts.alloy + counts.maple + counts.brass;
document.getElementById("remaining").textContent = remaining;
}
function consume(type) {
counts[type] = Math.max(0, counts[type] - 1);
updateInventory();
}
// Timeline helpers
const animations = [];
const stationPower = { cut: 0, lathe: 0, press: 0 };
function easeInOut(t) {
return t < 0.5 ? 4 * t * t * t : 1 - Math.pow(-2 * t + 2, 3) / 2;
}
function smooth(t) {
return t * t * (3 - 2 * t);
}
function addAnimation(start, duration, update) {
animations.push({ start, duration, update, started: false });
}
function processRaw(record, startTime, processPosition, stationName) {
const processingQuaternion = record.type === "maple"
? new THREE.Quaternion().setFromEuler(new THREE.Euler(0, 0, Math.PI / 2))
: record.startQuaternion.clone();
addAnimation(startTime, 1.72, (p, dt) => {
const raw = record.raw;
const component = record.component;
if (p < 0.36) {
const travel = easeInOut(p / 0.36);
raw.position.lerpVectors(record.start, processPosition, travel);
raw.position.y += Math.sin(travel * Math.PI) * 0.65;
raw.quaternion.slerpQuaternions(record.startQuaternion, processingQuaternion, travel);
} else {
raw.position.copy(processPosition);
raw.quaternion.slerpQuaternions(record.startQuaternion, processingQuaternion, smooth((p - 0.36) / 0.64));
if (record.type === "brass") {
raw.rotation.y += dt * 3.4;
raw.rotation.x += dt * 1.8;
}
if (record.type === "alloy") {
raw.position.x += Math.sin(p * 42) * 0.025;
}
}
if (!record.consumed && p >= 0.36) {
record.consumed = true;
consume(record.type);
}
if (p >= 0.66) {
component.visible = true;
component.position.copy(record.output);
const grow = smooth(Math.min(1, (p - 0.66) / 0.34));
component.scale.setScalar(component.userData.baseScale * grow);
raw.scale.setScalar(Math.max(0.08, 1 - grow * 0.92));
} else {
component.visible = false;
raw.scale.setScalar(1);
}
if (p > 0.36 && p < 0.72) {
stationPower[stationName] = Math.max(stationPower[stationName], 1);
}
if (p >= 1) {
raw.visible = false;
component.visible = true;
component.position.copy(record.output);
component.scale.setScalar(component.userData.baseScale);
}
});
}
processRaw(rawRecords[0], 0.55, new THREE.Vector3(-2.65, 1.72, -1.25), "cut");
processRaw(rawRecords[1], 1.62, new THREE.Vector3(-2.65, 1.72, -1.25), "cut");
for (let i = 0; i < 4; i++) {
processRaw(rawRecords[2 + i], 3.82 + i * 0.62,
new THREE.Vector3(-0.18, 1.64, -1.35), "lathe");
}
processRaw(rawRecords[6], 7.65, new THREE.Vector3(1.92, 1.56, -1.22), "press");
const targets = [
new THREE.Vector3(assemblyX, 2.05, 0.65), // body
new THREE.Vector3(assemblyX, 2.96, 0.65), // head
new THREE.Vector3(3.50, 2.04, 0.65), // left arm
new THREE.Vector3(5.40, 2.04, 0.65), // right arm
new THREE.Vector3(4.05, 1.48, 0.65), // left leg
new THREE.Vector3(4.85, 1.48, 0.65), // right leg
new THREE.Vector3(assemblyX, 2.05, 1.10) // chest core
];
const targetQuaternions = [
new THREE.Quaternion(),
new THREE.Quaternion(),
new THREE.Quaternion().setFromEuler(new THREE.Euler(0, 0, 0.28)),
new THREE.Quaternion().setFromEuler(new THREE.Euler(0, 0, -0.28)),
new THREE.Quaternion().setFromEuler(new THREE.Euler(0, 0, 0.05)),
new THREE.Quaternion().setFromEuler(new THREE.Euler(0, 0, -0.05)),
new THREE.Quaternion()
];
const assemblyStart = 9.72;
components.forEach((component, index) => {
const task = {
from: new THREE.Vector3(),
fromQ: new THREE.Quaternion(),
started: false
};
addAnimation(assemblyStart + index * 0.52, 0.9, p => {
if (!task.started) {
task.from.copy(component.position);
task.fromQ.copy(component.quaternion);
task.started = true;
}
const e = easeInOut(p);
component.position.lerpVectors(task.from, targets[index], e);
component.position.y += Math.sin(e * Math.PI) * 0.5;
component.quaternion.slerpQuaternions(task.fromQ, targetQuaternions[index], e);
const pop = 1 + Math.sin(e * Math.PI) * 0.075;
component.scale.setScalar(component.userData.baseScale * pop);
if (p >= 1) {
component.position.copy(targets[index]);
component.quaternion.copy(targetQuaternions[index]);
component.scale.setScalar(component.userData.baseScale);
}
});
task.reset = () => { task.started = false; };
component.userData.assemblyTask = task;
});
addAnimation(13.94, 0.8, p => {
const e = easeInOut(p);
robotRoot.rotation.y = -0.16 * e;
robotRoot.position.y = Math.sin(e * Math.PI) * 0.1;
});
// Camera controls implemented directly, without addons.
const controls = {
theta: 0.68,
phi: 1.03,
radiusFactor: 1,
target: new THREE.Vector3(0, 1.15, 0),
dragging: false,
lastX: 0,
lastY: 0,
pointers: new Map(),
pinchDistance: 0,
interacted: false
};
function fitRadius() {
const aspect = innerWidth / innerHeight;
if (aspect < 0.8) return 30;
if (aspect < 1.2) return 24;
return 18.5;
}
function updateCamera() {
const radius = fitRadius() * controls.radiusFactor;
const sinPhi = Math.sin(controls.phi);
camera.position.set(
controls.target.x + radius * sinPhi * Math.sin(controls.theta),
controls.target.y + radius * Math.cos(controls.phi),
controls.target.z + radius * sinPhi * Math.cos(controls.theta)
);
camera.lookAt(controls.target);
}
renderer.domElement.addEventListener("pointerdown", event => {
controls.pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
controls.dragging = true;
controls.lastX = event.clientX;
controls.lastY = event.clientY;
controls.interacted = true;
renderer.domElement.setPointerCapture(event.pointerId);
document.getElementById("hint").style.opacity = "0";
});
renderer.domElement.addEventListener("pointermove", event => {
if (!controls.pointers.has(event.pointerId)) return;
controls.pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (controls.pointers.size >= 2) {
const points = [...controls.pointers.values()];
const distance = Math.hypot(points[0].x - points[1].x, points[0].y - points[1].y);
if (controls.pinchDistance) {
controls.radiusFactor *= controls.pinchDistance / distance;
controls.radiusFactor = THREE.MathUtils.clamp(controls.radiusFactor, 0.65, 1.65);
}
controls.pinchDistance = distance;
return;
}
const dx = event.clientX - controls.lastX;
const dy = event.clientY - controls.lastY;
controls.theta -= dx * 0.006;
controls.phi = THREE.MathUtils.clamp(controls.phi + dy * 0.005, 0.55, 1.35);
controls.lastX = event.clientX;
controls.lastY = event.clientY;
});
function releasePointer(event) {
controls.pointers.delete(event.pointerId);
if (controls.pointers.size < 2) controls.pinchDistance = 0;
if (controls.pointers.size === 0) controls.dragging = false;
}
renderer.domElement.addEventListener("pointerup", releasePointer);
renderer.domElement.addEventListener("pointercancel", releasePointer);
renderer.domElement.addEventListener("pointerleave", event => {
if (!controls.dragging) releasePointer(event);
});
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
controls.radiusFactor *= Math.exp(event.deltaY * 0.001);
controls.radiusFactor = THREE.MathUtils.clamp(controls.radiusFactor, 0.65, 1.65);
controls.interacted = true;
document.getElementById("hint").style.opacity = "0";
}, { passive: false });
addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.fov = camera.aspect < 0.8 ? 50 : 38;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
});
// Status and controls
function statusFor(t) {
if (t < 0.5) return "Queueing recipe";
if (t < 3.55) return "01 / Shearing alloy panels";
if (t < 7.55) return "02 / Turning maple limbs";
if (t < 9.65) return "03 / Pressing the brass core";
if (t < 13.94) return "04 / Joining seven components";
if (t < 14.75) return "Finishing the tin robot";
return "Complete / One object made";
}
function formatTime(seconds) {
const s = Math.floor(seconds);
return `00:${String(s).padStart(2, "0")}`;
}
function updateStatus() {
const status = statusFor(state.elapsed);
if (status !== state.status) {
state.status = status;
document.getElementById("status").textContent = status;
}
document.getElementById("clock").textContent =
`${formatTime(state.elapsed)} / ${formatTime(state.duration)}`;
document.getElementById("progress-fill").style.width =
`${Math.min(100, state.elapsed / state.duration * 100)}%`;
}
document.getElementById("pause").addEventListener("click", () => {
state.paused = !state.paused;
document.getElementById("pause").textContent = state.paused ? "Resume" : "Pause";
});
document.getElementById("replay").addEventListener("click", resetRecipe);
function resetRecipe() {
state.elapsed = 0;
state.paused = false;
state.complete = false;
state.status = "";
document.getElementById("pause").textContent = "Pause";
document.getElementById("complete").classList.remove("show");
robotShadow.visible = false;
for (const record of rawRecords) {
record.consumed = false;
record.raw.visible = true;
record.raw.position.copy(record.start);
record.raw.quaternion.copy(record.startQuaternion);
record.raw.scale.setScalar(1);
record.component.visible = false;
record.component.position.copy(record.output);
record.component.quaternion.identity();
record.component.scale.setScalar(record.component.userData.baseScale);
record.component.userData.assemblyTask.reset();
scene.attach(record.component);
}
for (const animation of animations) animation.started = false;
robotRoot.rotation.set(0, 0, 0);
robotRoot.position.set(0, 0, 0);
counts.alloy = 2;
counts.maple = 4;
counts.brass = 1;
updateInventory();
updateStatus();
}
// Render loop
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
if (!state.paused && state.elapsed < state.duration) {
state.elapsed = Math.min(state.duration, state.elapsed + dt);
}
stationPower.cut = 0;
stationPower.lathe = 0;
stationPower.press = 0;
for (const animation of animations) {
const p = THREE.MathUtils.clamp(
(state.elapsed - animation.start) / animation.duration,
0,
1
);
if (p > 0 || animation.start <= state.elapsed) {
animation.update(p, dt);
}
}
sawBlade.rotation.z += dt * (2 + stationPower.cut * 19);
spindle.rotation.x += dt * stationPower.lathe * 13;
piston.position.y = 2.15 - Math.sin(clock.elapsedTime * 28) * 0.23 * stationPower.press;
if (state.elapsed >= 13.94 && !robotShadow.visible) {
robotShadow.visible = true;
}
if (state.elapsed >= 14.7 && !state.complete) {
state.complete = true;
document.getElementById("complete").classList.add("show");
document.getElementById("status").textContent = "Complete / One object made";
}
updateStatus();
updateCamera();
renderer.render(scene, camera);
}
updateInventory();
updateStatus();
updateCamera();
animate();
setTimeout(() => {
document.getElementById("boot").classList.add("hide");
setTimeout(() => document.getElementById("boot").remove(), 500);
}, 350);
</script>
</body>
</html>
```