Prompt specification
Build or customize the Three.js 3D scene "Schedule From Partial-Order Clues" 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: Schedule From Partial-Order Clues
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/schedule-from-partial-order-clues-x3428
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts temporal order and overlapping events. Create a small scene-building puzzle with actions constrained by before, after, and during statements. Accept multiple valid schedules when the clues do not determine a unique order. Voxel style.
Working Three.js Starter (schedule-from-partial-order-clues-x3428):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Voxel Foundry — Temporal Schedule Puzzle</title>
<style>
:root {
--bg: #0a1020;
--panel: rgba(15, 24, 43, 0.92);
--panel-solid: #111b30;
--line: #31415f;
--muted: #8fa1bd;
--text: #edf5ff;
--cyan: #54e5d2;
--orange: #ff8a4c;
--purple: #bd83ff;
--green: #b6e36b;
--yellow: #ffd66b;
--red: #ff647c;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 52% 34%, #223252 0%, #111a2d 38%, #080d19 100%);
color: var(--text);
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
"Liberation Mono", monospace;
}
button {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
outline: none;
touch-action: none;
}
.vignette,
.scanlines {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 2;
}
.vignette {
background: radial-gradient(
ellipse at center,
transparent 48%,
rgba(3, 7, 16, 0.54) 100%
);
}
.scanlines {
opacity: 0.12;
background: repeating-linear-gradient(
to bottom,
transparent 0,
transparent 3px,
rgba(255, 255, 255, 0.025) 4px
);
}
.hud {
position: fixed;
inset: 0;
z-index: 5;
pointer-events: none;
}
.hud > * {
pointer-events: auto;
}
.topbar {
position: absolute;
top: 16px;
left: 18px;
right: 18px;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 18px;
}
.brand {
display: flex;
align-items: center;
gap: 12px;
padding: 10px 14px 10px 10px;
background: var(--panel);
border: 2px solid var(--line);
box-shadow: 5px 5px 0 rgba(3, 7, 16, 0.78);
backdrop-filter: blur(12px);
}
.brand-mark {
width: 38px;
height: 38px;
position: relative;
background: var(--cyan);
box-shadow:
inset -8px -8px 0 rgba(19, 91, 101, 0.35),
4px 4px 0 #07101d;
}
.brand-mark::before,
.brand-mark::after {
content: "";
position: absolute;
background: #10192d;
}
.brand-mark::before {
width: 8px;
height: 22px;
left: 8px;
top: 8px;
}
.brand-mark::after {
width: 8px;
height: 8px;
right: 7px;
top: 7px;
box-shadow: -12px 12px 0 #10192d;
}
.brand h1 {
margin: 0;
font-size: 16px;
line-height: 1.1;
letter-spacing: 0.11em;
}
.brand p {
margin: 5px 0 0;
color: var(--muted);
font-size: 10px;
letter-spacing: 0.08em;
}
.top-actions {
display: flex;
gap: 8px;
flex-wrap: wrap;
justify-content: flex-end;
}
.pixel-button {
min-height: 38px;
padding: 9px 12px;
color: var(--text);
background: #17243d;
border: 2px solid #3a4d70;
box-shadow: 3px 3px 0 #070d19;
cursor: pointer;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.06em;
text-transform: uppercase;
transition:
transform 80ms ease,
border-color 120ms ease,
background 120ms ease;
}
.pixel-button:hover {
border-color: var(--cyan);
background: #1d2d4b;
}
.pixel-button:active {
transform: translate(2px, 2px);
box-shadow: 1px 1px 0 #070d19;
}
.pixel-button.primary {
color: #07131a;
background: var(--cyan);
border-color: #9ff8eb;
}
.pixel-button.primary:hover {
background: #79f3e4;
}
.panel {
background: var(--panel);
border: 2px solid var(--line);
box-shadow: 5px 5px 0 rgba(3, 7, 16, 0.78);
backdrop-filter: blur(12px);
}
#clues {
position: absolute;
top: 94px;
left: 18px;
width: 296px;
padding: 14px;
}
.panel-title {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-bottom: 12px;
}
.panel-title strong {
font-size: 12px;
letter-spacing: 0.11em;
}
.panel-title span {
color: var(--muted);
font-size: 9px;
}
.intro {
margin: 0 0 13px;
color: #b8c6db;
font-size: 11px;
line-height: 1.55;
}
.clue {
position: relative;
display: grid;
grid-template-columns: 42px 1fr;
gap: 10px;
padding: 11px 10px;
margin-top: 8px;
background: rgba(6, 13, 27, 0.55);
border: 1px solid #2c3b58;
transition:
border-color 150ms ease,
background 150ms ease;
}
.clue.bad {
border-color: var(--red);
background: rgba(91, 26, 47, 0.42);
}
.clue.pulse {
animation: clue-pulse 700ms ease;
}
@keyframes clue-pulse {
0%,
100% {
transform: translateX(0);
}
30% {
transform: translateX(5px);
}
60% {
transform: translateX(-3px);
}
}
.relation {
display: grid;
place-items: center;
min-height: 39px;
color: #07121c;
font-size: 9px;
font-weight: 900;
letter-spacing: 0.04em;
}
.relation.before {
background: var(--cyan);
}
.relation.during {
background: var(--purple);
}
.relation.after {
background: var(--green);
}
.clue-text {
color: #dce8f8;
font-size: 10px;
line-height: 1.5;
}
.clue-text b {
color: white;
}
#status {
position: absolute;
top: 94px;
right: 18px;
width: 278px;
padding: 14px;
}
.verdict {
display: flex;
align-items: center;
gap: 8px;
padding: 10px;
margin-bottom: 10px;
color: var(--yellow);
background: rgba(98, 72, 23, 0.25);
border: 1px solid rgba(255, 214, 107, 0.45);
font-size: 11px;
font-weight: 900;
letter-spacing: 0.08em;
}
.verdict.good {
color: var(--green);
background: rgba(75, 107, 32, 0.24);
border-color: rgba(182, 227, 107, 0.5);
}
.verdict.flash {
animation: verdict-flash 450ms ease;
}
@keyframes verdict-flash {
50% {
transform: scale(1.025);
filter: brightness(1.4);
}
}
.status-dot {
width: 8px;
height: 8px;
background: currentColor;
box-shadow: 2px 2px 0 rgba(0, 0, 0, 0.45);
}
#violation-list {
color: #bdcbe0;
font-size: 10px;
line-height: 1.45;
}
#violation-list p {
margin: 5px 0;
}
#violation-list p::before {
content: "› ";
color: var(--red);
font-weight: 900;
}
.section-divider {
height: 1px;
margin: 13px 0;
background: #2b3a55;
}
.live-title {
display: flex;
justify-content: space-between;
color: var(--muted);
font-size: 9px;
letter-spacing: 0.08em;
}
#activity-label {
color: var(--yellow);
font-weight: 800;
}
#live-list {
margin-top: 8px;
}
.live-row {
display: grid;
grid-template-columns: 8px 1fr auto;
align-items: center;
gap: 8px;
padding: 5px 0;
color: #71839f;
font-size: 9px;
}
.live-row .dot {
width: 7px;
height: 7px;
background: #34445e;
}
.live-row.active {
color: white;
}
.live-row.active .dot {
background: var(--job-color);
box-shadow: 0 0 9px var(--job-color);
}
#dock {
position: absolute;
left: 50%;
bottom: 16px;
width: min(1020px, calc(100vw - 36px));
transform: translateX(-50%);
padding: 12px;
}
.dock-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 14px;
margin-bottom: 10px;
}
.dock-copy {
color: var(--muted);
font-size: 9px;
line-height: 1.4;
}
.dock-copy strong {
display: block;
color: white;
font-size: 11px;
letter-spacing: 0.08em;
margin-bottom: 2px;
}
.dock-buttons {
display: flex;
gap: 7px;
flex-wrap: wrap;
justify-content: flex-end;
}
.actions-grid {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 8px;
}
.action-card {
min-width: 0;
display: grid;
grid-template-columns: 36px minmax(0, 1fr) auto;
align-items: center;
gap: 8px;
padding: 8px;
background: #0c1528;
border: 2px solid #293b5b;
cursor: pointer;
user-select: none;
transition:
border-color 120ms ease,
transform 120ms ease,
background 120ms ease;
}
.action-card:hover {
background: #111d34;
border-color: #4a6088;
}
.action-card.selected {
border-color: var(--job-color);
background: color-mix(in srgb, var(--job-color) 9%, #0c1528);
transform: translateY(-2px);
}
.action-code {
display: grid;
place-items: center;
width: 34px;
height: 34px;
color: #07131d;
background: var(--job-color);
box-shadow: 3px 3px 0 #050a14;
font-size: 10px;
font-weight: 900;
}
.action-info {
min-width: 0;
}
.action-info strong {
display: block;
overflow: hidden;
color: white;
font-size: 9px;
letter-spacing: 0.05em;
text-overflow: ellipsis;
white-space: nowrap;
}
.action-info small {
display: block;
margin-top: 4px;
color: var(--muted);
font-size: 8px;
}
.stepper {
display: flex;
gap: 3px;
}
.stepper button {
width: 25px;
height: 27px;
padding: 0;
color: white;
background: #1b2a46;
border: 1px solid #405574;
cursor: pointer;
font-size: 15px;
line-height: 1;
}
.stepper button:hover:not(:disabled) {
color: #08121f;
background: var(--job-color);
}
.stepper button:disabled {
opacity: 0.25;
cursor: default;
}
#toast {
position: fixed;
z-index: 10;
left: 50%;
top: 82px;
max-width: min(480px, calc(100vw - 30px));
transform: translate(-50%, -14px);
padding: 10px 14px;
color: white;
background: #182741;
border: 2px solid var(--cyan);
box-shadow: 4px 4px 0 #050a13;
opacity: 0;
pointer-events: none;
font-size: 10px;
line-height: 1.5;
transition:
opacity 150ms ease,
transform 150ms ease;
}
#toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
@media (max-width: 850px) {
#clues {
width: 246px;
}
#status {
width: 238px;
}
.actions-grid {
grid-template-columns: repeat(2, 1fr);
}
#dock {
max-height: 42vh;
overflow: auto;
}
}
@media (max-width: 620px) {
.topbar {
top: 9px;
left: 9px;
right: 9px;
}
.brand {
padding: 8px;
}
.brand p,
.top-actions .secondary {
display: none;
}
#clues {
top: 76px;
left: 9px;
width: 210px;
max-height: 34vh;
overflow: auto;
padding: 10px;
}
#status {
display: none;
}
#dock {
left: 8px;
right: 8px;
bottom: 8px;
width: auto;
transform: none;
padding: 9px;
}
.dock-head {
align-items: flex-start;
}
.dock-copy {
display: none;
}
.dock-buttons {
width: 100%;
justify-content: flex-start;
}
.pixel-button {
min-height: 34px;
padding: 7px 9px;
font-size: 9px;
}
.actions-grid {
gap: 5px;
}
.action-card {
grid-template-columns: 29px minmax(0, 1fr) auto;
gap: 5px;
padding: 6px;
}
.action-code {
width: 28px;
height: 28px;
font-size: 8px;
}
.action-info strong {
font-size: 8px;
}
.stepper button {
width: 22px;
}
}
</style>
</head>
<body>
<canvas id="scene" tabindex="0" aria-label="Interactive voxel timeline puzzle"></canvas>
<div class="vignette"></div>
<div class="scanlines"></div>
<main class="hud">
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true"></div>
<div>
<h1>VOXEL FOUNDRY</h1>
<p>TEMPORAL ORDER / BUILD-ORDER PUZZLE</p>
</div>
</div>
<div class="top-actions">
<button class="pixel-button secondary" id="reset-btn">Reset</button>
<button class="pixel-button secondary" id="hint-btn">Hint</button>
<button class="pixel-button primary" id="check-btn">Check schedule</button>
</div>
</header>
<aside class="panel" id="clues">
<div class="panel-title">
<strong>CLUE BOARD</strong>
<span>3 RELATIONS</span>
</div>
<p class="intro">
Drag the colored job blocks along their lanes. The clues constrain
relationships, not one exact answer.
</p>
<div class="clue" data-clue="before">
<div class="relation before">BEFORE</div>
<div class="clue-text">
<b>Mix Clay</b> must finish before <b>Fire Kiln</b> begins.
</div>
</div>
<div class="clue" data-clue="during">
<div class="relation during">DURING</div>
<div class="clue-text">
<b>Glaze Tiles</b> must run entirely while the <b>kiln is firing</b>.
</div>
</div>
<div class="clue" data-clue="after">
<div class="relation after">AFTER</div>
<div class="clue-text">
<b>Pack Tiles</b> must begin after <b>Fire Kiln</b> is complete.
</div>
</div>
</aside>
<aside class="panel" id="status">
<div class="panel-title">
<strong>SCHEDULE STATUS</strong>
<span id="solution-count">20 POSSIBLE</span>
</div>
<div class="verdict" id="verdict">
<span class="status-dot"></span>
<span id="verdict-text">UNSTABLE TIMELINE</span>
</div>
<div id="violation-list" aria-live="polite"></div>
<div class="section-divider"></div>
<div class="live-title">
<span>LIVE FOUNDRY</span>
<span id="activity-label">T2</span>
</div>
<div id="live-list"></div>
</aside>
<section class="panel" id="dock">
<div class="dock-head">
<div class="dock-copy">
<strong>BUILD-ORDER CONSOLE</strong>
Drag blocks in 3D, use the arrows, or click the timeline to scrub.
</div>
<div class="dock-buttons">
<button class="pixel-button primary" id="play-btn">▶ Play timeline</button>
<button class="pixel-button" id="next-btn">Next valid · 20</button>
</div>
</div>
<div class="actions-grid" id="actions-grid"></div>
</section>
</main>
<div id="toast" role="status" aria-live="polite"></div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Puzzle definition
// -------------------------------------------------------------------------
const TOTAL_SLOTS = 9;
const actions = [
{
id: "mix",
code: "MX",
name: "Mix Clay",
duration: 2,
color: "#54e5d2",
initial: 2,
start: 2
},
{
id: "fire",
code: "FK",
name: "Fire Kiln",
duration: 3,
color: "#ff8a4c",
initial: 3,
start: 3
},
{
id: "glaze",
code: "GL",
name: "Glaze Tiles",
duration: 2,
color: "#bd83ff",
initial: 4,
start: 4
},
{
id: "pack",
code: "PK",
name: "Pack Tiles",
duration: 2,
color: "#b6e36b",
initial: 7,
start: 7
}
];
const actionById = new Map(actions.map((action) => [action.id, action]));
const selectedId = "mix";
const events = new Map();
const eventMeshes = [];
const workers = [];
const beacons = [];
const effects = {};
const canvas = document.querySelector("#scene");
const actionsGrid = document.querySelector("#actions-grid");
const verdict = document.querySelector("#verdict");
const verdictText = document.querySelector("#verdict-text");
const violationList = document.querySelector("#violation-list");
const solutionCount = document.querySelector("#solution-count");
const activityLabel = document.querySelector("#activity-label");
const liveList = document.querySelector("#live-list");
const toast = document.querySelector("#toast");
const clueElements = new Map(
[...document.querySelectorAll(".clue")].map((element) => [
element.dataset.clue,
element
])
);
// -------------------------------------------------------------------------
// Renderer, scene, and camera
// -------------------------------------------------------------------------
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);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.15;
const scene = new THREE.Scene();
scene.background = new THREE.Color("#0d1628");
scene.fog = new THREE.Fog("#0d1628", 24, 42);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
80
);
const cameraTarget = new THREE.Vector3(0, 1.1, -0.15);
const orbit = {
theta: 0.43,
phi: 1.03,
radius: 23
};
function updateCamera() {
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
cameraTarget.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
cameraTarget.y + orbit.radius * Math.cos(orbit.phi),
cameraTarget.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(cameraTarget);
}
updateCamera();
const hemisphere = new THREE.HemisphereLight("#b8d8ff", "#182036", 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight("#fff0d5", 3.25);
sun.position.set(-7, 13, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -12;
sun.shadow.camera.right = 12;
sun.shadow.camera.top = 12;
sun.shadow.camera.bottom = -12;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 35;
sun.shadow.bias = -0.00035;
scene.add(sun);
const rimLight = new THREE.DirectionalLight("#65a8ff", 1.45);
rimLight.position.set(10, 6, -8);
scene.add(rimLight);
const kilnLight = new THREE.PointLight("#ff7a38", 2.2, 8, 2);
kilnLight.position.set(-1.6, 1.8, -2.8);
scene.add(kilnLight);
// -------------------------------------------------------------------------
// Voxel helpers
// -------------------------------------------------------------------------
const materialCache = new Map();
function standardMaterial(color) {
if (!materialCache.has(color)) {
materialCache.set(
color,
new THREE.MeshStandardMaterial({
color,
roughness: 0.78,
metalness: 0.06
})
);
}
return materialCache.get(color);
}
function voxel(
width,
height,
depth,
color,
x = 0,
y = 0,
z = 0,
parent = scene,
options = {}
) {
const material = options.material || standardMaterial(color);
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = options.castShadow !== false;
mesh.receiveShadow = options.receiveShadow !== false;
parent.add(mesh);
return mesh;
}
function addEdges(mesh, color = "#ffffff", opacity = 0.6) {
const material = new THREE.LineBasicMaterial({
color,
transparent: true,
opacity
});
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(mesh.geometry),
material
);
mesh.add(edges);
return edges;
}
function makeTextSprite(
text,
{
width = 2.4,
background = "#10192d",
accent = "#54e5d2",
foreground = "#eef6ff"
} = {}
) {
const image = document.createElement("canvas");
image.width = 512;
image.height = 112;
const context = image.getContext("2d");
context.clearRect(0, 0, image.width, image.height);
context.fillStyle = background;
context.fillRect(4, 4, 504, 104);
context.fillStyle = accent;
context.fillRect(4, 4, 13, 104);
context.fillRect(4, 4, 504, 5);
let fontSize = 43;
context.font = `800 ${fontSize}px ui-monospace, monospace`;
while (
context.measureText(text).width > 460 &&
fontSize > 20
) {
fontSize -= 2;
context.font = `800 ${fontSize}px ui-monospace, monospace`;
}
context.textAlign = "center";
context.textBaseline = "middle";
context.fillStyle = foreground;
context.fillText(text, 260, 59);
const texture = new THREE.CanvasTexture(image);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
texture.magFilter = THREE.LinearFilter;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(width, width * (112 / 512), 1);
sprite.renderOrder = 20;
return sprite;
}
// -------------------------------------------------------------------------
// Factory diorama
// -------------------------------------------------------------------------
voxel(17.2, 0.72, 11.2, "#0a1222", 0, -0.36, 0);
voxel(16.7, 0.2, 10.7, "#293650", 0, 0.08, 0);
// Floor tile seams.
for (let x = -7.5; x <= 7.5; x += 1.5) {
voxel(0.035, 0.025, 10.35, "#1d2b43", x, 0.195, 0);
}
for (let z = -4.5; z <= 4.5; z += 1.5) {
voxel(16.35, 0.025, 0.035, "#1d2b43", 0, 0.195, z);
}
// Rear wall.
voxel(16.5, 4.7, 0.28, "#17243b", 0, 2.48, -5.02);
let seed = 92817;
function random() {
seed = (seed * 16807) % 2147483647;
return (seed - 1) / 2147483646;
}
const brickColors = ["#22324e", "#1d2c47", "#293b58", "#20304a"];
for (let row = 0; row < 10; row++) {
for (let column = 0; column < 18; column++) {
const color = brickColors[Math.floor(random() * brickColors.length)];
voxel(
0.84,
0.36,
0.12,
color,
-7.55 + column * 0.89 + (row % 2) * 0.08,
0.47 + row * 0.42,
-4.82
);
}
}
// Cyan factory windows.
for (const x of [-6.6, -4.9, 4.9, 6.6]) {
voxel(1.15, 1.05, 0.12, "#0c1b2d", x, 3.35, -4.72);
voxel(0.83, 0.73, 0.13, "#2d9fac", x, 3.35, -4.61);
voxel(0.09, 0.78, 0.15, "#17283a", x, 3.35, -4.53);
voxel(0.88, 0.08, 0.15, "#17283a", x, 3.35, -4.53);
}
const foundrySign = makeTextSprite("VOXEL FOUNDRY", {
width: 5.8,
background: "#14233a",
accent: "#54e5d2",
foreground: "#e8f8ff"
});
foundrySign.position.set(0, 3.75, -4.55);
scene.add(foundrySign);
// Decorative wall clock.
voxel(1.25, 1.25, 0.18, "#0c1628", 7.1, 2.3, -4.56);
voxel(0.95, 0.95, 0.2, "#e7eef7", 7.1, 2.3, -4.42);
voxel(0.09, 0.34, 0.06, "#162238", 7.1, 2.43, -4.28);
voxel(0.31, 0.09, 0.06, "#162238", 7.2, 2.28, -4.27);
voxel(0.11, 0.11, 0.08, "#ff647c", 7.1, 2.3, -4.22);
// Crates and pipes around the workshop.
voxel(0.75, 0.75, 0.75, "#6e4a34", -7.25, 0.59, -3.65);
voxel(0.79, 0.13, 0.79, "#9a6743", -7.25, 0.96, -3.65);
voxel(0.7, 0.7, 0.7, "#765137", 7.3, 0.56, -3.45);
for (let y = 0.55; y <= 2.15; y += 0.42) {
voxel(0.25, 0.25, 0.25, "#38516b", 7.25, y, -4.25);
}
// -------------------------------------------------------------------------
// Factory stations and workers
// -------------------------------------------------------------------------
const stationXs = [-4.8, -1.6, 1.6, 4.8];
const stationZ = -3.45;
function makeBeacon(x, color) {
const material = new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 0.18,
roughness: 0.4
});
const beacon = voxel(0.2, 0.2, 0.2, color, x, 2.08, -4.45, scene, {
material
});
beacons.push({ id: actionById.get(color === "#54e5d2" ? "mix" :
color === "#ff8a4c" ? "fire" :
color === "#bd83ff" ? "glaze" : "pack"), material });
return beacon;
}
function makeWorker(x, z, color, id) {
const root = new THREE.Group();
root.position.set(x, 0.23, z);
scene.add(root);
voxel(0.42, 0.5, 0.32, color, 0, 0.55, 0, root);
voxel(0.4, 0.35, 0.36, "#e7edf4", 0, 1.02, 0, root);
voxel(0.31, 0.13, 0.03, "#162238", 0, 1.05, 0.2, root);
voxel(0.16, 0.35, 0.18, "#29374f", -0.12, 0.15, 0, root);
voxel(0.16, 0.35, 0.18, "#29374f", 0.12, 0.15, 0, root);
voxel(0.2, 0.12, 0.3, "#101a2c", -0.12, -0.06, 0.04, root);
voxel(0.2, 0.12, 0.3, "#101a2c", 0.12, -0.06, 0.04, root);
const leftArm = new THREE.Group();
const rightArm = new THREE.Group();
leftArm.position.set(-0.28, 0.76, 0);
rightArm.position.set(0.28, 0.76, 0);
root.add(leftArm, rightArm);
voxel(0.13, 0.38, 0.15, color, 0, -0.16, 0, leftArm);
voxel(0.13, 0.38, 0.15, color, 0, -0.16, 0, rightArm);
voxel(0.17, 0.17, 0.17, "#e7edf4", 0, -0.39, 0, leftArm);
voxel(0.17, 0.17, 0.17, "#e7edf4", 0, -0.39, 0, rightArm);
workers.push({ id, root, leftArm, rightArm, baseY: root.position.y });
return root;
}
// Mix station.
{
const x = stationXs[0];
voxel(2.25, 0.18, 1.75, "#364862", x, 0.29, stationZ);
voxel(0.24, 0.85, 0.24, "#65758d", x - 0.72, 0.69, stationZ);
voxel(0.24, 0.85, 0.24, "#65758d", x + 0.72, 0.69, stationZ);
voxel(1.45, 0.65, 1.05, "#6c7d95", x, 1.05, stationZ);
voxel(1.55, 0.18, 1.15, "#26374e", x, 1.45, stationZ);
voxel(0.28, 1.25, 0.28, "#8ea0b4", x + 0.63, 1.7, stationZ - 0.18);
voxel(0.65, 0.18, 0.65, "#4c6078", x + 0.63, 2.25, stationZ - 0.18);
const rotor = new THREE.Group();
rotor.position.set(x, 1.62, stationZ);
scene.add(rotor);
voxel(0.12, 0.75, 0.12, "#d2dce7", 0, -0.25, 0, rotor);
voxel(0.95, 0.12, 0.16, "#d2dce7", 0, -0.55, 0, rotor);
voxel(0.16, 0.12, 0.95, "#d2dce7", 0, -0.55, 0, rotor);
effects.mix = { rotor };
const label = makeTextSprite("MIX CLAY", {
width: 2.55,
accent: "#54e5d2"
});
label.position.set(x, 2.62, -4.53);
scene.add(label);
makeBeacon(x, "#54e5d2");
makeWorker(x, -2.08, "#54e5d2", "mix");
}
// Fire station.
{
const x = stationXs[1];
voxel(2.35, 0.18, 1.8, "#56383c", x, 0.29, stationZ);
voxel(0.4, 1.55, 1.35, "#9a5141", x - 0.78, 1.05, stationZ);
voxel(0.4, 1.55, 1.35, "#9a5141", x + 0.78, 1.05, stationZ);
voxel(1.95, 0.38, 1.35, "#b35e48", x, 1.8, stationZ);
voxel(1.2, 1.18, 0.18, "#241923", x, 1.02, stationZ + 0.58);
const flameMaterial = new THREE.MeshStandardMaterial({
color: "#ff8a4c",
emissive: "#ff5a18",
emissiveIntensity: 1.2,
roughness: 0.5
});
const flames = [];
for (let i = 0; i < 4; i++) {
const flame = voxel(
0.24,
0.55 + (i % 2) * 0.15,
0.22,
"#ff8a4c",
x - 0.4 + i * 0.26,
0.85,
stationZ + 0.7,
scene,
{ material: flameMaterial }
);
flames.push(flame);
}
voxel(0.48, 1.45, 0.48, "#704044", x + 0.72, 2.65, stationZ - 0.3);
voxel(0.68, 0.18, 0.68, "#26364b", x + 0.72, 3.43, stationZ - 0.3);
effects.fire = { flames, flameMaterial };
const label = makeTextSprite("FIRE KILN", {
width: 2.55,
accent: "#ff8a4c"
});
label.position.set(x, 2.62, -4.53);
scene.add(label);
makeBeacon(x, "#ff8a4c");
makeWorker(x, -2.08, "#ff8a4c", "fire");
}
// Glaze station.
{
const x = stationXs[2];
voxel(2.35, 0.18, 1.8, "#463b62", x, 0.29, stationZ);
voxel(0.25, 1.6, 0.25, "#74658e", x - 0.8, 1.1, stationZ);
voxel(0.25, 1.6, 0.25, "#74658e", x + 0.8, 1.1, stationZ);
voxel(1.85, 0.28, 0.8, "#5f527c", x, 1.87, stationZ);
voxel(1.3, 0.18, 0.85, "#a87ee0", x, 0.68, stationZ);
const brush = new THREE.Group();
brush.position.set(x, 1.4, stationZ + 0.25);
scene.add(brush);
voxel(0.12, 0.8, 0.12, "#dce5ef", 0, 0, 0, brush);
voxel(0.65, 0.18, 0.28, "#bd83ff", 0, -0.38, 0, brush);
effects.glaze = { brush, baseX: x };
const label = makeTextSprite("GLAZE TILES", {
width: 2.8,
accent: "#bd83ff"
});
label.position.set(x, 2.62, -4.53);
scene.add(label);
makeBeacon(x, "#bd83ff");
makeWorker(x, -2.08, "#bd83ff", "glaze");
}
// Pack station.
{
const x = stationXs[3];
voxel(2.4, 0.18, 1.85, "#3c5145", x, 0.29, stationZ);
voxel(1.75, 0.38, 0.85, "#53695c", x, 0.62, stationZ);
voxel(1.65, 0.12, 0.72, "#1c2a2b", x, 0.86, stationZ);
for (let i = 0; i < 5; i++) {
voxel(0.12, 0.1, 0.78, "#839186", x - 0.68 + i * 0.34, 0.96, stationZ);
}
const crate = new THREE.Group();
crate.position.set(x - 0.35, 1.13, stationZ);
scene.add(crate);
voxel(0.65, 0.58, 0.65, "#b68a57", 0, 0, 0, crate);
voxel(0.69, 0.1, 0.69, "#d1a56f", 0, 0.3, 0, crate);
voxel(0.1, 0.62, 0.69, "#7d5a3b", 0, 0, 0, crate);
effects.pack = { crate, baseX: x - 0.35 };
const label = makeTextSprite("PACK TILES", {
width: 2.65,
accent: "#b6e36b"
});
label.position.set(x, 2.62, -4.53);
scene.add(label);
makeBeacon(x, "#b6e36b");
makeWorker(x, -2.08, "#b6e36b", "pack");
}
// -------------------------------------------------------------------------
// 3D timeline
// -------------------------------------------------------------------------
const slotWidth = 1.05;
const timelineWidth = TOTAL_SLOTS * slotWidth;
const timelineLeft = -timelineWidth / 2;
const laneZs = [3.72, 2.57, 1.42, 0.27];
const timelineBoard = voxel(
11.25,
0.22,
4.85,
"#111d32",
-0.2,
0.36,
2.02
);
const laneColors = ["#193c43", "#3f2b32", "#302849", "#263d2d"];
actions.forEach((action, index) => {
voxel(
timelineWidth,
0.055,
0.82,
laneColors[index],
0,
0.505,
laneZs[index]
);
const laneLabel = makeTextSprite(action.code, {
width: 0.68,
background: "#10192d",
accent: action.color,
foreground: action.color
});
laneLabel.position.set(-5.22, 0.78, laneZs[index]);
scene.add(laneLabel);
});
for (let slot = 0; slot <= TOTAL_SLOTS; slot++) {
const x = timelineLeft + slot * slotWidth;
voxel(0.035, 0.04, 4.2, "#34445f", x, 0.54, 2.02);
if (slot < TOTAL_SLOTS) {
const label = makeTextSprite(`T${slot}`, {
width: 0.56,
background: "#111b30",
accent: "#647895",
foreground: "#b8c7dc"
});
label.position.set(
timelineLeft + (slot + 0.5) * slotWidth,
0.75,
4.18
);
scene.add(label);
}
}
const playhead = new THREE.Group();
const playheadMaterial = new THREE.MeshStandardMaterial({
color: "#ffd66b",
emissive: "#ffb52e",
emissiveIntensity: 1.1,
roughness: 0.35
});
voxel(
0.055,
1.18,
4.38,
"#ffd66b",
0,
1.02,
2.02,
playhead,
{ material: playheadMaterial }
);
const nowLabel = makeTextSprite("NOW", {
width: 0.72,
background: "#33280d",
accent: "#ffd66b",
foreground: "#fff0b2"
});
nowLabel.position.set(0, 0.94, 0);
playhead.add(nowLabel);
scene.add(playhead);
function createEvent(action, laneIndex) {
const group = new THREE.Group();
group.position.y = 0.76;
group.position.z = laneZs[laneIndex];
scene.add(group);
const material = new THREE.MeshStandardMaterial({
color: action.color,
emissive: new THREE.Color(action.color),
emissiveIntensity: 0.07,
roughness: 0.6,
metalness: 0.05
});
const borders = [];
for (let segment = 0; segment < action.duration; segment++) {
const block = voxel(
slotWidth - 0.08,
0.43,
0.7,
action.color,
(segment - (action.duration - 1) / 2) * slotWidth,
0,
0,
group,
{ material }
);
block.userData.actionId = action.id;
eventMeshes.push(block);
const border = addEdges(block, "#ffffff", 0.45);
borders.push(border);
}
const label = makeTextSprite(action.name.toUpperCase(), {
width: action.duration === 3 ? 2.7 : 2.25,
background: "#10192d",
accent: action.color,
foreground: "#f4f8ff"
});
label.position.set(0, 0.58, 0);
group.add(label);
const event = {
action,
group,
material,
borders,
label
};
events.set(action.id, event);
updateEventPosition(event);
}
actions.forEach((action, index) => createEvent(action, index));
function updateEventPosition(event) {
const action = event.action;
event.group.position.x =
timelineLeft + (action.start + action.duration / 2) * slotWidth;
}
// -------------------------------------------------------------------------
// Timeline controls
// -------------------------------------------------------------------------
let playing = false;
let simSlot = 2;
let simulationAccumulator = 0;
const slotDuration = 0.85;
const activeIds = new Set();
function setActionStart(id, start) {
const action = actionById.get(id);
const maximum = TOTAL_SLOTS - action.duration;
action.start = THREE.MathUtils.clamp(
Math.round(start),
0,
maximum
);
updateEventPosition(events.get(id));
renderValidation();
updateActivity();
updateActionRows();
}
function selectAction(id) {
actionsGrid.querySelectorAll(".action-card").forEach((card) => {
card.classList.toggle("selected", card.dataset.action === id);
});
renderValidation();
}
function updateActionRows() {
for (const card of actionsGrid.querySelectorAll(".action-card")) {
const action = actionById.get(card.dataset.action);
const previous = card.querySelector(".move-previous");
const next = card.querySelector(".move-next");
previous.disabled = action.start === 0;
next.disabled = action.start === TOTAL_SLOTS - action.duration;
card.querySelector(".action-start").textContent =
`T${action.start} · ${action.duration} slots`;
}
}
for (const action of actions) {
const card = document.createElement("div");
card.className = "action-card";
card.dataset.action = action.id;
card.style.setProperty("--job-color", action.color);
card.innerHTML = `
<div class="action-code">${action.code}</div>
<div class="action-info">
<strong>${action.name.toUpperCase()}</strong>
<small class="action-start"></small>
</div>
<div class="stepper">
<button class="move-previous" aria-label="Move ${action.name} earlier">−</button>
<button class="move-next" aria-label="Move ${action.name} later">+</button>
</div>
`;
card.addEventListener("click", () => selectAction(action.id));
card.querySelector(".move-previous").addEventListener("click", (event) => {
event.stopPropagation();
playing = false;
setActionStart(action.id, action.start - 1);
});
card.querySelector(".move-next").addEventListener("click", (event) => {
event.stopPropagation();
playing = false;
setActionStart(action.id, action.start + 1);
});
actionsGrid.appendChild(card);
}
// -------------------------------------------------------------------------
// Constraint validation
// -------------------------------------------------------------------------
function getViolations() {
const mix = actionById.get("mix");
const fire = actionById.get("fire");
const glaze = actionById.get("glaze");
const pack = actionById.get("pack");
const violations = [];
if (mix.start + mix.duration > fire.start) {
violations.push({
clue: "before",
ids: ["mix", "fire"],
message: "Mix Clay finishes after Fire Kiln starts."
});
}
if (
glaze.start < fire.start ||
glaze.start + glaze.duration > fire.start + fire.duration
) {
violations.push({
clue: "during",
ids: ["fire", "glaze"],
message: "Glaze Tiles is not fully contained by Fire Kiln."
});
}
if (pack.start < fire.start + fire.duration) {
violations.push({
clue: "after",
ids: ["fire", "pack"],
message: "Pack Tiles begins before firing is complete."
});
}
return violations;
}
function renderValidation() {
const violations = getViolations();
const invalidIds = new Set(violations.flatMap((violation) => violation.ids));
if (violations.length === 0) {
verdict.classList.add("good");
verdictText.textContent = "VALID TIMELINE";
violationList.innerHTML = `
<p>All three temporal relations hold.</p>
<p>This puzzle has many valid answers; exact placement is not fixed.</p>
`;
} else {
verdict.classList.remove("good");
verdictText.textContent = "UNSTABLE TIMELINE";
violationList.innerHTML = violations
.map((violation) => `<p>${violation.message}</p>`)
.join("");
}
for (const [clue, element] of clueElements) {
element.classList.toggle(
"bad",
violations.some((violation) => violation.clue === clue)
);
}
for (const action of actions) {
const event = events.get(action.id);
const selected = action.id === selectedId;
const invalid = invalidIds.has(action.id);
const borderColor = selected
? "#ffd66b"
: invalid
? "#ff647c"
: "#d8e8ff";
for (const border of event.borders) {
border.material.color.set(borderColor);
border.material.opacity = selected || invalid ? 0.95 : 0.4;
}
}
}
function enumerateValidSchedules() {
const schedules = [];
const mix = actionById.get("mix");
const fire = actionById.get("fire");
const glaze = actionById.get("glaze");
const pack = actionById.get("pack");
for (
let fireStart = 0;
fireStart <= TOTAL_SLOTS - fire.duration;
fireStart++
) {
for (
let mixStart = 0;
mixStart <= TOTAL_SLOTS - mix.duration;
mixStart++
) {
if (mixStart + mix.duration > fireStart) continue;
for (
let glazeStart = 0;
glazeStart <= TOTAL_SLOTS - glaze.duration;
glazeStart++
) {
if (
glazeStart < fireStart ||
glazeStart + glaze.duration > fireStart + fire.duration
) {
continue;
}
for (
let packStart = 0;
packStart <= TOTAL_SLOTS - pack.duration;
packStart++
) {
if (packStart < fireStart + fire.duration) continue;
schedules.push({
mix: mixStart,
fire: fireStart,
glaze: glazeStart,
pack: packStart
});
}
}
}
}
return schedules;
}
const validSchedules = enumerateValidSchedules();
solutionCount.textContent = `${validSchedules.length} POSSIBLE`;
document.querySelector("#next-btn").textContent =
`Next valid · ${validSchedules.length}`;
let solutionCursor = -1;
function loadNextValidSchedule() {
const current = Object.fromEntries(
actions.map((action) => [action.id, action.start])
);
const currentIndex = validSchedules.findIndex(
(schedule) =>
actions.every(
(action) => schedule[action.id] === current[action.id]
)
);
solutionCursor =
currentIndex >= 0
? (currentIndex + 1) % validSchedules.length
: 0;
const schedule = validSchedules[solutionCursor];
for (const action of actions) {
action.start = schedule[action.id];
updateEventPosition(events.get(action.id));
}
playing = false;
updatePlayButton();
renderValidation();
updateActivity();
updateActionRows();
showToast(
`Loaded valid schedule ${solutionCursor + 1} of ${validSchedules.length}. ` +
"The clues deliberately allow multiple answers."
);
}
function checkSchedule() {
const valid = getViolations().length === 0;
verdict.classList.remove("flash");
void verdict.offsetWidth;
verdict.classList.add("flash");
showToast(
valid
? "Valid schedule. More than one schedule satisfies these clues."
: "Not valid yet. Check the highlighted relation on the clue board."
);
}
// -------------------------------------------------------------------------
// Activity playback
// -------------------------------------------------------------------------
function setSimulationSlot(slot) {
simSlot = THREE.MathUtils.clamp(slot, 0, TOTAL_SLOTS);
activeIds.clear();
for (const action of actions) {
const active =
simSlot >= action.start &&
simSlot < action.start + action.duration;
if (active) activeIds.add(action.id);
const event = events.get(action.id);
event.material.emissiveIntensity = active ? 0.58 : 0.07;
}
playhead.position.x = timelineLeft + simSlot * slotWidth;
updateActivity();
}
function updateActivity() {
activityLabel.textContent = `T${simSlot}`;
const activeActions = actions.filter((action) =>
activeIds.has(action.id)
);
let summary = "No jobs active";
if (activeActions.length === 1) {
summary = `${activeActions[0].name} is active`;
} else if (activeActions.length > 1) {
summary =
`${activeActions.map((action) => action.name).join(" + ")} ` +
"overlap in this slot";
}
liveList.innerHTML = actions
.map((action) => {
const active = activeIds.has(action.id);
return `
<div class="live-row ${active ? "active" : ""}"
style="--job-color:${action.color}">
<span class="dot"></span>
<span>${action.name}</span>
<span>${active ? "ACTIVE" : "WAIT"}</span>
</div>
`;
})
.join("");
liveList.title = summary;
}
function updatePlayButton() {
const button = document.querySelector("#play-btn");
button.textContent = playing ? "Ⅱ Pause" : "▶ Play timeline";
button.classList.toggle("primary", !playing);
}
function togglePlayback() {
if (!playing && simSlot >= TOTAL_SLOTS) {
setSimulationSlot(0);
}
playing = !playing;
simulationAccumulator = 0;
updatePlayButton();
}
// -------------------------------------------------------------------------
// Hints and toast
// -------------------------------------------------------------------------
let toastTimer;
function showToast(message) {
clearTimeout(toastTimer);
toast.textContent = message;
toast.classList.add("show");
toastTimer = setTimeout(() => {
toast.classList.remove("show");
}, 3300);
}
function showHint() {
const fire = actionById.get("fire");
const hints = {
mix: {
clue: "before",
text:
"Mix Clay must finish before firing starts. " +
"With the current kiln time, move the mixer toward the left."
},
fire: {
clue: "during",
text:
"The glaze job must fit inside the three firing slots, " +
"and packing must begin after the kiln finishes."
},
glaze: {
clue: "during",
text:
"A two-slot glaze can occupy the first two or last two " +
"slots of the three-slot firing."
},
pack: {
clue: "after",
text:
`Packing begins at or after T${fire.start + fire.duration}, ` +
"once firing is complete."
}
};
const hint = hints[selectedId];
const clue = clueElements.get(hint.clue);
clue.classList.remove("pulse");
void clue.offsetWidth;
clue.classList.add("pulse");
showToast(hint.text);
}
function resetPuzzle() {
for (const action of actions) {
action.start = action.initial;
updateEventPosition(events.get(action.id));
}
playing = false;
simulationAccumulator = 0;
setSimulationSlot(2);
updatePlayButton();
renderValidation();
updateActionRows();
showToast("Timeline reset. The mixer currently overlaps the kiln.");
}
document.querySelector("#check-btn").addEventListener("click", checkSchedule);
document.querySelector("#next-btn").addEventListener(
"click",
loadNextValidSchedule
);
document.querySelector("#play-btn").addEventListener("click", togglePlayback);
document.querySelector("#reset-btn").addEventListener("click", resetPuzzle);
document.querySelector("#hint-btn").addEventListener("click", showHint);
// -------------------------------------------------------------------------
// Direct camera and timeline controls
// -------------------------------------------------------------------------
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const dragPlane = new THREE.Plane(new THREE.Vector3(0, 1, 0), -0.76);
const planeIntersection = new THREE.Vector3();
let drag = null;
let cameraDrag = null;
function setPointer(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;
}
function pickEvent(event) {
setPointer(event);
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(eventMeshes, false);
return hits.length ? hits[0] : null;
}
function pickTimeline(event) {
setPointer(event);
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObject(timelineBoard, false);
return hits.length ? hits[0] : null;
}
canvas.addEventListener("pointerdown", (event) => {
canvas.focus();
canvas.setPointerCapture(event.pointerId);
const hit = pickEvent(event);
if (hit) {
const action = actionById.get(hit.object.userData.actionId);
selectAction(action.id);
raycaster.ray.intersectPlane(dragPlane, planeIntersection);
drag = {
id: action.id,
offset: planeIntersection.x - events.get(action.id).group.position.x,
pointerId: event.pointerId,
moved: false
};
playing = false;
updatePlayButton();
canvas.style.cursor = "grabbing";
return;
}
cameraDrag = {
pointerId: event.pointerId,
x: event.clientX,
y: event.clientY,
moved: false
};
canvas.style.cursor = "grabbing";
});
canvas.addEventListener("pointermove", (event) => {
if (drag && event.pointerId === drag.pointerId) {
setPointer(event);
raycaster.setFromCamera(pointer, camera);
if (raycaster.ray.intersectPlane(dragPlane, planeIntersection)) {
const action = actionById.get(drag.id);
const eventObject = events.get(action.id);
const center = planeIntersection.x - drag.offset;
const start = Math.round(
(center - timelineLeft) / slotWidth - action.duration / 2
);
setActionStart(action.id, start);
drag.moved = true;
}
return;
}
if (cameraDrag && event.pointerId === cameraDrag.pointerId) {
const deltaX = event.clientX - cameraDrag.x;
const deltaY = event.clientY - cameraDrag.y;
if (Math.abs(deltaX) + Math.abs(deltaY) > 3) {
cameraDrag.moved = true;
}
orbit.theta -= deltaX * 0.0055;
orbit.phi = THREE.MathUtils.clamp(
orbit.phi + deltaY * 0.0045,
0.48,
1.36
);
cameraDrag.x = event.clientX;
cameraDrag.y = event.clientY;
updateCamera();
return;
}
const hover = pickEvent(event);
canvas.style.cursor = hover ? "grab" : "default";
});
function finishPointer(event) {
if (drag && event.pointerId === drag.pointerId) {
drag = null;
canvas.style.cursor = "grab";
} else if (
cameraDrag &&
event.pointerId === cameraDrag.pointerId &&
!cameraDrag.moved
) {
const hit = pickTimeline(event);
if (hit) {
const slot = Math.floor(
(hit.point.x - timelineLeft) / slotWidth
);
setSimulationSlot(slot);
}
}
cameraDrag = null;
canvas.style.cursor = "default";
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", finishPointer);
canvas.addEventListener("pointercancel", finishPointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius + event.deltaY * 0.012,
14,
30
);
updateCamera();
},
{ passive: false }
);
window.addEventListener("keydown", (event) => {
if (event.target instanceof HTMLButtonElement) return;
if (event.key === "ArrowLeft") {
const action = actionById.get(selectedId);
setActionStart(selectedId, action.start - 1);
} else if (event.key === "ArrowRight") {
const action = actionById.get(selectedId);
setActionStart(selectedId, action.start + 1);
} else if (event.code === "Space") {
event.preventDefault();
togglePlayback();
} else if (event.key.toLowerCase() === "r") {
resetPuzzle();
} else if (event.key.toLowerCase() === "h") {
showHint();
}
});
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
const time = clock.elapsedTime;
if (playing) {
simulationAccumulator += delta;
while (simulationAccumulator >= slotDuration) {
simulationAccumulator -= slotDuration;
if (simSlot >= TOTAL_SLOTS) {
playing = false;
updatePlayButton();
break;
}
setSimulationSlot(simSlot + 1);
}
}
const mixActive = activeIds.has("mix");
const fireActive = activeIds.has("fire");
const glazeActive = activeIds.has("glaze");
const packActive = activeIds.has("pack");
if (mixActive) {
effects.mix.rotor.rotation.y += delta * 8;
} else {
effects.mix.rotor.rotation.y += delta * 0.15;
}
effects.fire.flameMaterial.emissiveIntensity =
fireActive ? 2.25 + Math.sin(time * 13) * 0.5 : 0.25;
effects.fire.flames.forEach((flame, index) => {
const pulse = fireActive
? 0.82 + Math.sin(time * 11 + index * 1.8) * 0.28
: 0.55;
flame.scale.y = pulse;
flame.scale.x = 0.9 + pulse * 0.12;
});
effects.glaze.brush.position.x =
effects.glaze.baseX +
(glazeActive ? Math.sin(time * 4.8) * 0.48 : 0);
effects.pack.crate.position.x =
effects.pack.baseX +
(packActive ? (Math.sin(time * 3.2) + 1) * 0.28 : 0);
for (const worker of workers) {
const active = activeIds.has(worker.id);
worker.root.position.y =
worker.baseY + (active ? Math.abs(Math.sin(time * 5.5)) * 0.055 : 0);
worker.leftArm.rotation.z =
active ? -0.45 + Math.sin(time * 6) * 0.35 : -0.08;
worker.rightArm.rotation.z =
active ? 0.45 - Math.sin(time * 6) * 0.35 : 0.08;
}
for (const beacon of beacons) {
const active = activeIds.has(beacon.id);
beacon.material.emissiveIntensity = active
? 1.6 + Math.sin(time * 8) * 0.45
: 0.15;
}
kilnLight.intensity = fireActive
? 2.8 + Math.sin(time * 12) * 0.7
: 0.8;
renderer.render(scene, camera);
}
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
// Initial state.
selectAction(selectedId);
setSimulationSlot(2);
renderValidation();
updateActionRows();
updatePlayButton();
animate();
</script>
</body>
</html>
```