Prompt specification
Build or customize the Three.js 3D scene "Kitchen coordination dependency game" 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: Kitchen coordination dependency game
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/kitchen-coordination-dependency-game-x3908
Scene Description Prompt:
I'd like to see this as a low-poly Three.js scene: kitchen coordination dependency game. Create a fictional meal workflow with explicit preparation dependencies and shared tools; users schedule tasks to avoid simultaneous use of one tool while completing every serving. Use cdnjs and return one self-contained HTML file.
Working Three.js Starter (kitchen-coordination-dependency-game-x3908):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Kitchen Relay — Coordination Game</title>
<style>
:root {
--ink: #18312f;
--panel: rgba(20, 43, 42, 0.94);
--panel-2: rgba(29, 57, 54, 0.96);
--line: rgba(255, 255, 255, 0.12);
--muted: #9fb8b2;
--cream: #fff7e7;
--mint: #75e0bd;
--coral: #ff8e72;
--yellow: #ffd166;
--blue: #78bdf2;
--danger: #ff6b6b;
--service: #ffd166;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dce8e5;
color: var(--cream);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button { font: inherit; }
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
}
#scene:active { cursor: grabbing; }
.glass {
background: var(--panel);
border: 1px solid var(--line);
box-shadow: 0 18px 55px rgba(19, 39, 37, 0.22);
backdrop-filter: blur(16px);
}
.topbar {
position: fixed;
z-index: 20;
top: 12px;
left: 12px;
right: 12px;
min-height: 58px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 18px;
padding: 10px 14px;
border-radius: 16px;
pointer-events: auto;
}
.brand {
display: flex;
align-items: center;
gap: 11px;
min-width: 270px;
}
.brand-mark {
width: 37px;
height: 37px;
display: grid;
place-items: center;
border-radius: 11px;
color: #163d35;
background: linear-gradient(135deg, var(--mint), var(--yellow));
box-shadow: inset 0 -3px 0 rgba(0,0,0,.12);
font-size: 21px;
}
.brand h1 {
margin: 0;
font-size: 17px;
line-height: 1.1;
letter-spacing: .01em;
}
.brand p {
margin: 3px 0 0;
color: var(--muted);
font-size: 11px;
}
.stats {
display: flex;
align-items: center;
justify-content: center;
gap: 9px;
flex: 1;
}
.stat {
min-width: 102px;
padding: 7px 12px;
border-radius: 11px;
background: rgba(255,255,255,.055);
border: 1px solid rgba(255,255,255,.07);
}
.stat span {
display: block;
color: var(--muted);
font-size: 9px;
font-weight: 800;
text-transform: uppercase;
letter-spacing: .12em;
}
.stat strong {
display: block;
margin-top: 2px;
font-size: 15px;
font-variant-numeric: tabular-nums;
}
#phaseStat { color: var(--mint); }
.top-actions {
display: flex;
gap: 7px;
}
.icon-btn, .small-btn {
border: 1px solid rgba(255,255,255,.14);
color: var(--cream);
background: rgba(255,255,255,.07);
border-radius: 10px;
padding: 9px 12px;
cursor: pointer;
transition: .16s ease;
}
.icon-btn:hover, .small-btn:hover {
background: rgba(255,255,255,.13);
transform: translateY(-1px);
}
.recipe-panel {
position: fixed;
z-index: 15;
top: 82px;
left: 12px;
bottom: 344px;
width: 316px;
border-radius: 18px;
overflow: hidden;
display: flex;
flex-direction: column;
}
.recipe-head {
padding: 18px 18px 13px;
border-bottom: 1px solid var(--line);
}
.eyebrow {
color: var(--mint);
font-size: 10px;
font-weight: 900;
letter-spacing: .14em;
text-transform: uppercase;
}
.recipe-head h2 {
margin: 7px 0 5px;
font-family: Georgia, serif;
font-size: 23px;
font-weight: 700;
line-height: 1.05;
}
.recipe-head p {
margin: 0;
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
.recipe-progress {
margin-top: 13px;
height: 6px;
overflow: hidden;
border-radius: 9px;
background: rgba(255,255,255,.09);
}
#recipeProgressFill {
height: 100%;
width: 0;
border-radius: inherit;
background: linear-gradient(90deg, var(--mint), var(--yellow));
transition: width .25s ease;
}
.recipe-progress-label {
display: flex;
justify-content: space-between;
margin-top: 6px;
color: var(--muted);
font-size: 10px;
}
.list-label {
padding: 11px 16px 7px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: .1em;
text-transform: uppercase;
}
#taskList {
flex: 1;
overflow-y: auto;
padding: 0 9px 14px;
scrollbar-width: thin;
scrollbar-color: rgba(255,255,255,.18) transparent;
}
.task-card {
position: relative;
display: grid;
grid-template-columns: 8px 1fr auto;
gap: 10px;
align-items: start;
margin: 7px 0;
padding: 11px 10px 10px 8px;
border: 1px solid rgba(255,255,255,.07);
border-radius: 12px;
background: rgba(255,255,255,.035);
cursor: grab;
transition: .15s ease;
}
.task-card:hover {
background: rgba(255,255,255,.07);
transform: translateX(2px);
}
.task-card.selected {
border-color: var(--mint);
background: rgba(117,224,189,.10);
box-shadow: 0 0 0 1px rgba(117,224,189,.12);
}
.task-card.conflict {
border-color: rgba(255,107,107,.7);
background: rgba(255,107,107,.08);
}
.task-card.complete {
border-color: rgba(117,224,189,.42);
}
.task-stripe {
width: 8px;
height: 100%;
min-height: 49px;
border-radius: 8px;
background: var(--task-color);
}
.task-copy { min-width: 0; }
.task-topline {
display: flex;
align-items: center;
gap: 6px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: .06em;
text-transform: uppercase;
}
.task-name {
margin-top: 3px;
font-size: 12.5px;
font-weight: 760;
line-height: 1.25;
}
.task-deps {
margin-top: 4px;
color: #afc3be;
font-size: 10px;
line-height: 1.35;
}
.task-deps b { color: var(--yellow); }
.task-side {
min-width: 58px;
text-align: right;
}
.task-time {
color: var(--cream);
font-size: 10px;
font-weight: 800;
white-space: nowrap;
}
.task-status {
margin-top: 5px;
color: var(--muted);
font-size: 9px;
line-height: 1.2;
}
.task-status.bad { color: #ff9c9c; }
.task-status.good { color: var(--mint); }
.task-status.late { color: var(--yellow); }
.remove-task {
position: absolute;
right: 6px;
top: 6px;
width: 20px;
height: 20px;
display: none;
place-items: center;
padding: 0;
border: 0;
border-radius: 6px;
color: #ffd4d4;
background: rgba(255,107,107,.2);
cursor: pointer;
font-size: 13px;
line-height: 1;
}
.task-card.scheduled .remove-task { display: grid; }
.timeline-panel {
position: fixed;
z-index: 16;
left: 12px;
right: 12px;
bottom: 12px;
height: 320px;
border-radius: 18px;
display: flex;
flex-direction: column;
overflow: hidden;
}
.timeline-toolbar {
min-height: 52px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
padding: 9px 14px;
border-bottom: 1px solid var(--line);
}
.timeline-title h3 {
margin: 0;
font-size: 14px;
}
.timeline-title p {
margin: 3px 0 0;
color: var(--muted);
font-size: 10px;
}
.timeline-actions {
display: flex;
align-items: center;
gap: 7px;
flex-wrap: wrap;
justify-content: flex-end;
}
.primary-btn {
border: 0;
color: #163d35;
background: linear-gradient(135deg, var(--mint), #b9efbd);
border-radius: 10px;
padding: 10px 16px;
font-weight: 900;
cursor: pointer;
box-shadow: inset 0 -2px 0 rgba(0,0,0,.12);
transition: .16s ease;
}
.primary-btn:hover { transform: translateY(-1px); filter: brightness(1.04); }
.primary-btn.running { background: linear-gradient(135deg, var(--yellow), #ffb67b); }
.timeline-scroll {
flex: 1;
min-height: 0;
overflow: auto;
scrollbar-width: thin;
scrollbar-color: rgba(255,255,255,.18) transparent;
}
.ruler-row, .lane-row {
display: grid;
grid-template-columns: 120px minmax(860px, 1fr);
min-width: 980px;
}
.ruler-row {
position: sticky;
top: 0;
z-index: 8;
height: 27px;
background: rgba(18, 40, 38, .97);
border-bottom: 1px solid var(--line);
}
.lane-label {
position: sticky;
left: 0;
z-index: 6;
display: flex;
align-items: center;
gap: 8px;
padding: 0 12px;
border-right: 1px solid var(--line);
background: rgba(24, 51, 48, .98);
}
.ruler-label {
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: .1em;
text-transform: uppercase;
}
.ruler-track, .lane-track {
position: relative;
min-width: 0;
}
.ruler-track {
background:
linear-gradient(90deg, transparent calc(100% - 2px), rgba(255,107,107,.7) calc(100% - 2px)),
repeating-linear-gradient(to right, rgba(255,255,255,.13) 0 1px, transparent 1px calc(11.111%));
}
.ruler-tick {
position: absolute;
bottom: 2px;
transform: translateX(-50%);
color: #b6cbc6;
font-size: 9px;
font-variant-numeric: tabular-nums;
}
.lane-row {
height: 31px;
border-bottom: 1px solid rgba(255,255,255,.055);
}
.lane-row.focused .lane-label {
background: rgba(117,224,189,.16);
box-shadow: inset 3px 0 0 var(--mint);
}
.lane-dot {
width: 8px;
height: 8px;
flex: 0 0 auto;
border-radius: 50%;
background: var(--tool-color);
box-shadow: 0 0 0 3px color-mix(in srgb, var(--tool-color), transparent 78%);
}
.lane-name {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
font-size: 10px;
font-weight: 750;
}
.lane-count {
margin-left: auto;
color: var(--muted);
font-size: 9px;
}
.lane-track {
cursor: crosshair;
background:
linear-gradient(90deg, transparent calc(66.666% - 1px), rgba(255,209,102,.34) calc(66.666% - 1px), rgba(255,209,102,.34) calc(66.666% + 1px), transparent calc(66.666% + 1px)),
repeating-linear-gradient(to right, transparent 0 calc(11.111% - 1px), rgba(255,255,255,.07) calc(11.111% - 1px) calc(11.111%));
}
.now-line {
position: absolute;
z-index: 5;
top: 0;
bottom: 0;
left: 0;
width: 2px;
background: var(--coral);
box-shadow: 0 0 12px rgba(255,142,114,.8);
pointer-events: none;
display: none;
}
.timeline-footer {
min-height: 44px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 15px;
padding: 8px 14px;
border-top: 1px solid var(--line);
background: rgba(14, 34, 32, .7);
}
#selectionHint {
color: #c6d7d3;
font-size: 11px;
line-height: 1.3;
}
#selectionHint b { color: var(--mint); }
.legend {
display: flex;
gap: 11px;
color: var(--muted);
font-size: 9px;
white-space: nowrap;
}
.legend span::before {
content: "";
display: inline-block;
width: 7px;
height: 7px;
margin-right: 5px;
border-radius: 50%;
background: var(--dot);
}
.task-block {
position: absolute;
z-index: 4;
top: 4px;
height: 23px;
min-width: 25px;
overflow: hidden;
padding: 0 7px;
display: flex;
align-items: center;
border: 1px solid color-mix(in srgb, var(--block-color), white 20%);
border-radius: 7px;
color: #18312f;
background: var(--block-color);
box-shadow: 0 3px 8px rgba(0,0,0,.18);
cursor: grab;
font-size: 9px;
font-weight: 900;
white-space: nowrap;
user-select: none;
}
.task-block.selected {
outline: 2px solid white;
outline-offset: 1px;
z-index: 5;
}
.task-block.conflict {
color: white;
background: var(--danger);
border-color: #ffb0b0;
}
.task-block.late {
box-shadow: inset 0 -3px 0 rgba(255,209,102,.8), 0 3px 8px rgba(0,0,0,.18);
}
.task-block.complete {
filter: saturate(.65);
opacity: .72;
}
.block-progress {
position: absolute;
inset: auto 0 0;
height: 3px;
background: rgba(255,255,255,.55);
width: 0;
}
#toast {
position: fixed;
z-index: 60;
top: 82px;
left: 50%;
max-width: min(520px, 90vw);
padding: 11px 16px;
border: 1px solid rgba(255,255,255,.15);
border-radius: 12px;
color: var(--cream);
background: rgba(19, 45, 42, .96);
box-shadow: 0 15px 40px rgba(0,0,0,.24);
transform: translate(-50%, -20px);
opacity: 0;
pointer-events: none;
transition: .22s ease;
font-size: 12px;
text-align: center;
}
#toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
#toast.bad { border-color: rgba(255,107,107,.65); }
#toast.good { border-color: rgba(117,224,189,.65); }
.modal {
position: fixed;
z-index: 80;
inset: 0;
display: grid;
place-items: center;
padding: 20px;
background: rgba(10, 25, 23, .62);
backdrop-filter: blur(8px);
}
.modal[hidden] { display: none; }
.modal-card {
width: min(570px, 95vw);
max-height: 86vh;
overflow-y: auto;
padding: 24px;
border: 1px solid rgba(255,255,255,.16);
border-radius: 20px;
color: var(--cream);
background: linear-gradient(145deg, #21443f, #142e2c);
box-shadow: 0 30px 90px rgba(0,0,0,.42);
}
.modal-card h2 {
margin: 0 0 13px;
font-family: Georgia, serif;
font-size: 28px;
}
.modal-card p, .modal-card li {
color: #c5d8d3;
font-size: 13px;
line-height: 1.6;
}
.modal-card ol { padding-left: 20px; }
.modal-card strong { color: var(--cream); }
.modal-actions {
display: flex;
justify-content: flex-end;
gap: 9px;
margin-top: 20px;
}
.result-grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 9px;
margin: 18px 0;
}
.result-cell {
padding: 12px;
border-radius: 11px;
background: rgba(255,255,255,.07);
text-align: center;
}
.result-cell strong {
display: block;
font-size: 21px;
color: var(--mint);
}
.result-cell span {
color: var(--muted);
font-size: 10px;
}
@media (max-width: 980px) {
.recipe-panel { width: 274px; }
.stat { min-width: 84px; padding-inline: 9px; }
.brand { min-width: 220px; }
.brand p { display: none; }
}
@media (max-width: 720px) {
.topbar { left: 7px; right: 7px; top: 7px; }
.brand { min-width: 0; }
.brand h1 { font-size: 14px; }
.brand-mark { width: 32px; height: 32px; }
.stats { justify-content: flex-end; }
.stat { min-width: 66px; padding: 6px 7px; }
.stat span { font-size: 7px; }
.stat strong { font-size: 12px; }
.top-actions .icon-btn { padding: 8px; }
.recipe-panel {
top: 73px;
left: 7px;
right: 7px;
width: auto;
bottom: auto;
height: 180px;
}
.recipe-head { padding: 11px 13px; }
.recipe-head h2 { font-size: 18px; }
.recipe-head p, .recipe-progress, .recipe-progress-label { display: none; }
.list-label { padding-top: 7px; }
.timeline-panel {
left: 7px;
right: 7px;
bottom: 7px;
height: 318px;
}
.timeline-title p, .legend { display: none; }
.timeline-toolbar { align-items: flex-start; }
.timeline-actions { gap: 5px; }
.small-btn { padding: 8px; font-size: 11px; }
.primary-btn { padding: 9px 11px; font-size: 11px; }
#toast { top: 262px; }
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive low-poly kitchen"></canvas>
<header class="topbar glass">
<div class="brand">
<div class="brand-mark">⌁</div>
<div>
<h1>Kitchen Relay</h1>
<p>Coordinate tools, dependencies, and four dinner plates.</p>
</div>
</div>
<div class="stats">
<div class="stat">
<span>Plan</span>
<strong id="plannedStat">2 / 12</strong>
</div>
<div class="stat">
<span>Served</span>
<strong id="servedStat">0 / 4</strong>
</div>
<div class="stat">
<span>Shift clock</span>
<strong id="clockStat">00:00</strong>
</div>
<div class="stat">
<span>Status</span>
<strong id="phaseStat">Planning</strong>
</div>
</div>
<div class="top-actions">
<button class="icon-btn" id="helpBtn" title="How to play">Help</button>
<button class="icon-btn" id="resetBtn" title="Reset the schedule">Reset</button>
</div>
</header>
<aside class="recipe-panel glass">
<div class="recipe-head">
<div class="eyebrow">Fictional workflow · 4 servings</div>
<h2>Chanterelle Risotto & Herb Flatbread</h2>
<p>Every station has one job at a time. Every job has a prerequisite. Build a safe 60-minute service plan.</p>
<div class="recipe-progress"><div id="recipeProgressFill"></div></div>
<div class="recipe-progress-label">
<span id="progressLabel">2 tasks planned</span>
<span>Service target: 60m</span>
</div>
</div>
<div class="list-label">Preparation workflow</div>
<div id="taskList"></div>
</aside>
<section class="timeline-panel glass">
<div class="timeline-toolbar">
<div class="timeline-title">
<h3>Tool & station timeline</h3>
<p>Drag cards into their matching lane, or select a card and click a start time.</p>
</div>
<div class="timeline-actions">
<button class="small-btn" id="hintBtn" title="Place the next dependency-ready task at its earliest safe time">Hint</button>
<button class="small-btn" id="clearBtn">Clear</button>
<button class="small-btn" id="speedBtn" title="Simulation speed">1×</button>
<button class="primary-btn" id="playBtn">Start shift</button>
</div>
</div>
<div class="timeline-scroll" id="timelineScroll">
<div class="ruler-row">
<div class="lane-label ruler-label">Minutes</div>
<div class="ruler-track" id="rulerTrack"></div>
</div>
<div id="laneList"></div>
</div>
<div class="timeline-footer">
<div id="selectionHint"><b>Tip:</b> shared lanes reveal the bottleneck. Move a block to change its start.</div>
<div class="legend">
<span style="--dot:#75e0bd">Ready</span>
<span style="--dot:#ff6b6b">Conflict</span>
<span style="--dot:#ffd166">After service</span>
</div>
</div>
</section>
<div id="toast" role="status" aria-live="polite"></div>
<div class="modal" id="modal" hidden>
<div class="modal-card" role="dialog" aria-modal="true" aria-labelledby="modalTitle">
<h2 id="modalTitle"></h2>
<div id="modalBody"></div>
<div class="modal-actions">
<button class="small-btn" id="modalClose">Close</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";
// ---------------------------------------------------------------------
// Workflow data
// ---------------------------------------------------------------------
const TIMELINE_END = 90;
const SERVICE_WINDOW = 60;
const TOOL_COLORS = {
prep: "#75e0bd",
knife: "#78bdf2",
saucepan: "#ff9b73",
stockpot: "#b69cff",
oven: "#ffd166",
rest: "#83d6d1",
plating: "#f58fba"
};
const TOOLS = [
{ id: "prep", label: "Prep board" },
{ id: "knife", label: "Knife block" },
{ id: "saucepan", label: "Saucepan" },
{ id: "stockpot", label: "Stockpot" },
{ id: "oven", label: "Oven" },
{ id: "rest", label: "Resting rack" },
{ id: "plating", label: "Plating counter" }
];
const TASKS = [
{
id: "wash",
name: "Wash chanterelles",
stage: "Prep",
tool: "prep",
duration: 5,
deps: [],
detail: "Rinse and dry the mushrooms."
},
{
id: "slice",
name: "Slice shallots",
stage: "Prep",
tool: "knife",
duration: 6,
deps: ["wash"],
detail: "Slice the washed produce for the aromatic base."
},
{
id: "chop",
name: "Chop garden herbs",
stage: "Prep",
tool: "knife",
duration: 5,
deps: ["slice"],
detail: "Chop herbs for the flatbread and garnish."
},
{
id: "toast",
name: "Toast arborio rice",
stage: "Stove",
tool: "saucepan",
duration: 5,
deps: [],
detail: "Toast the dry rice in the shared saucepan."
},
{
id: "bloom",
name: "Bloom shallot & saffron",
stage: "Stove",
tool: "saucepan",
duration: 6,
deps: ["slice"],
detail: "Return to the saucepan and bloom the sliced aromatics."
},
{
id: "stock",
name: "Simmer mushroom broth",
stage: "Stove",
tool: "stockpot",
duration: 12,
deps: [],
detail: "Prepare the broth in the large stockpot."
},
{
id: "roast",
name: "Roast chanterelles",
stage: "Oven",
tool: "oven",
duration: 10,
deps: ["wash"],
detail: "Roast washed mushrooms until deeply browned."
},
{
id: "flatbread",
name: "Bake herb flatbread",
stage: "Oven",
tool: "oven",
duration: 8,
deps: ["chop"],
detail: "Bake the herb flatbread after the herbs are chopped."
},
{
id: "risotto",
name: "Cook saffron risotto",
stage: "Stove",
tool: "saucepan",
duration: 14,
deps: ["toast", "bloom", "stock"],
detail: "Return to the saucepan for the final risotto cook."
},
{
id: "rest",
name: "Rest & loosen risotto",
stage: "Finish",
tool: "rest",
duration: 4,
deps: ["risotto"],
detail: "Rest the risotto on the rack before portioning."
},
{
id: "portion",
name: "Portion four bowls",
stage: "Plate",
tool: "plating",
duration: 6,
deps: ["flatbread", "rest"],
detail: "Portion risotto and flatbread into four bowls."
},
{
id: "garnish",
name: "Garnish & send to service",
stage: "Plate",
tool: "plating",
duration: 4,
deps: ["roast", "portion"],
detail: "Finish all four bowls and send them to service."
}
];
const TASK_BY_ID = Object.fromEntries(TASKS.map(task => [task.id, task]));
const schedule = Object.fromEntries(TASKS.map(task => [task.id, null]));
const state = {
selected: null,
running: false,
started: false,
finished: false,
success: false,
current: 0,
speed: 1,
focusedTool: null
};
const taskList = document.querySelector("#taskList");
const laneList = document.querySelector("#laneList");
const rulerTrack = document.querySelector("#rulerTrack");
const playBtn = document.querySelector("#playBtn");
const selectionHint = document.querySelector("#selectionHint");
const toast = document.querySelector("#toast");
// Seed two independent tasks so the interaction is immediately visible.
schedule.wash = { start: 0, tool: "prep" };
schedule.toast = { start: 0, tool: "saucepan" };
function taskEnd(taskId) {
const task = TASK_BY_ID[taskId];
const placement = schedule[taskId];
return placement ? placement.start + task.duration : null;
}
function issuesFor(taskId) {
const task = TASK_BY_ID[taskId];
const placement = schedule[taskId];
if (!placement) return [];
const issues = [];
for (const depId of task.deps) {
const depTask = TASK_BY_ID[depId];
const depPlacement = schedule[depId];
if (!depPlacement) {
issues.push(`Dependency not planned: ${depTask.name}`);
} else if (placement.start < taskEnd(depId)) {
issues.push(`Must follow ${depTask.name}`);
}
}
for (const other of TASKS) {
if (other.id === taskId || other.tool !== task.tool) continue;
const otherPlacement = schedule[other.id];
if (!otherPlacement) continue;
const overlaps =
placement.start < otherPlacement.start + other.duration &&
otherPlacement.start < placement.start + task.duration;
if (overlaps) issues.push(`Tool conflict with ${other.name}`);
}
return issues;
}
function conflictTaskCount() {
return TASKS.filter(task => schedule[task.id] && issuesFor(task.id).length > 0).length;
}
function plannedCount() {
return TASKS.filter(task => schedule[task.id]).length;
}
function isComplete(taskId) {
const placement = schedule[taskId];
return Boolean(state.started && placement && state.current >= placement.start + TASK_BY_ID[taskId].duration);
}
function isLate(taskId) {
const placement = schedule[taskId];
return Boolean(placement && placement.start + TASK_BY_ID[taskId].duration > SERVICE_WINDOW);
}
function formatClock(minutes) {
const totalSeconds = Math.max(0, Math.floor(minutes * 60));
const mins = String(Math.floor(totalSeconds / 60)).padStart(2, "0");
const secs = String(totalSeconds % 60).padStart(2, "0");
return `${mins}:${secs}`;
}
let toastTimer;
function showToast(message, kind = "") {
toast.textContent = message;
toast.className = `show ${kind}`;
clearTimeout(toastTimer);
toastTimer = setTimeout(() => {
toast.className = kind;
}, 3200);
}
// ---------------------------------------------------------------------
// Timeline construction
// ---------------------------------------------------------------------
for (let minute = 0; minute <= TIMELINE_END; minute += 5) {
const tick = document.createElement("span");
tick.className = "ruler-tick";
tick.style.left = `${(minute / TIMELINE_END) * 100}%`;
tick.textContent = minute === 60 ? "60 service" : `${minute}`;
rulerTrack.appendChild(tick);
}
for (const tool of TOOLS) {
const row = document.createElement("div");
row.className = "lane-row";
row.dataset.tool = tool.id;
row.style.setProperty("--tool-color", TOOL_COLORS[tool.id]);
row.innerHTML = `
<div class="lane-label">
<span class="lane-dot"></span>
<span class="lane-name">${tool.label}</span>
<span class="lane-count"></span>
</div>
<div class="lane-track">
<div class="now-line"></div>
</div>
`;
laneList.appendChild(row);
const track = row.querySelector(".lane-track");
track.addEventListener("click", event => {
if (event.target.classList.contains("task-block")) return;
if (!state.selected) {
showToast("Select a task card first, then click its tool lane.");
return;
}
const task = TASK_BY_ID[state.selected];
if (task.tool !== tool.id) {
showToast(`${task.name} belongs in the ${TOOLS.find(t => t.id === task.tool).label} lane.`, "bad");
return;
}
const rect = track.getBoundingClientRect();
const ratio = Math.max(0, Math.min(1, (event.clientX - rect.left) / rect.width));
const start = Math.max(0, Math.min(TIMELINE_END - task.duration, Math.round(ratio * TIMELINE_END)));
placeTask(task.id, start, tool.id);
});
track.addEventListener("dragover", event => {
event.preventDefault();
event.dataTransfer.dropEffect = "move";
});
track.addEventListener("drop", event => {
event.preventDefault();
const taskId = event.dataTransfer.getData("text/plain");
const task = TASK_BY_ID[taskId];
if (!task) return;
if (task.tool !== tool.id) {
showToast(`${task.name} cannot use ${tool.label}. Use the ${TOOLS.find(t => t.id === task.tool).label} lane.`, "bad");
return;
}
const rect = track.getBoundingClientRect();
const ratio = Math.max(0, Math.min(1, (event.clientX - rect.left) / rect.width));
const start = Math.max(0, Math.min(TIMELINE_END - task.duration, Math.round(ratio * TIMELINE_END)));
placeTask(task.id, start, tool.id);
});
}
function placeTask(taskId, start, tool) {
const task = TASK_BY_ID[taskId];
if (!task) return;
schedule[taskId] = { start: Number(start), tool };
state.selected = taskId;
state.started = false;
state.running = false;
state.finished = false;
state.current = 0;
renderAll();
const issues = issuesFor(taskId);
if (issues.length) {
showToast(`${task.name}: ${issues[0]}.`, "bad");
} else {
showToast(`${task.name} scheduled at ${start}m.`, "good");
}
}
function removeTask(taskId) {
schedule[taskId] = null;
if (state.selected === taskId) state.selected = null;
state.started = false;
state.running = false;
state.finished = false;
state.current = 0;
renderAll();
}
// ---------------------------------------------------------------------
// Task list rendering
// ---------------------------------------------------------------------
function dependencyText(task) {
if (!task.deps.length) return "<b>No prerequisite</b> · can begin immediately";
const names = task.deps.map(id => TASK_BY_ID[id].name);
return `<b>After:</b> ${names.join(" + ")}`;
}
function renderTaskList() {
taskList.innerHTML = "";
for (const task of TASKS) {
const placement = schedule[task.id];
const issues = placement ? issuesFor(task.id) : [];
const complete = isComplete(task.id);
const late = isLate(task.id);
const card = document.createElement("article");
card.className = "task-card";
card.draggable = true;
card.dataset.task = task.id;
card.style.setProperty("--task-color", TOOL_COLORS[task.tool]);
if (state.selected === task.id) card.classList.add("selected");
if (issues.length) card.classList.add("conflict");
if (complete) card.classList.add("complete");
if (placement) card.classList.add("scheduled");
let status = "Not planned";
let statusClass = "";
if (placement) {
if (issues.length) {
status = `${issues.length} conflict${issues.length > 1 ? "s" : ""}`;
statusClass = "bad";
} else if (complete) {
status = "Complete";
statusClass = "good";
} else if (late) {
status = "After service";
statusClass = "late";
} else {
status = "Safe plan";
statusClass = "good";
}
}
const tool = TOOLS.find(item => item.id === task.tool);
card.innerHTML = `
<div class="task-stripe"></div>
<div class="task-copy">
<div class="task-topline">${task.stage} · ${tool.label}</div>
<div class="task-name">${task.name}</div>
<div class="task-deps">${dependencyText(task)}</div>
</div>
<div class="task-side">
<div class="task-time">${task.duration} min</div>
<div class="task-status ${statusClass}">${status}</div>
</div>
<button class="remove-task" aria-label="Remove ${task.name}">×</button>
`;
card.addEventListener("click", event => {
if (event.target.closest(".remove-task")) return;
state.selected = task.id;
state.focusedTool = task.tool;
renderAll();
const row = laneList.querySelector(`[data-tool="${task.tool}"]`);
row?.scrollIntoView({ behavior: "smooth", block: "nearest", inline: "nearest" });
});
card.querySelector(".remove-task").addEventListener("click", event => {
event.stopPropagation();
removeTask(task.id);
});
card.addEventListener("dragstart", event => {
event.dataTransfer.setData("text/plain", task.id);
event.dataTransfer.effectAllowed = "move";
state.selected = task.id;
renderAll();
});
taskList.appendChild(card);
}
}
function renderTimeline() {
for (const row of laneList.querySelectorAll(".lane-row")) {
const tool = row.dataset.tool;
const track = row.querySelector(".lane-track");
track.querySelectorAll(".task-block").forEach(block => block.remove());
const count = TASKS.filter(task => task.tool === tool && schedule[task.id]).length;
row.querySelector(".lane-count").textContent = count ? `${count} task${count > 1 ? "s" : ""}` : "";
for (const task of TASKS.filter(task => task.tool === tool && schedule[task.id])) {
const placement = schedule[task.id];
const block = document.createElement("div");
block.className = "task-block";
block.draggable = true;
block.dataset.task = task.id;
block.style.setProperty("--block-color", TOOL_COLORS[task.tool]);
block.style.left = `${(placement.start / TIMELINE_END) * 100}%`;
block.style.width = `${(task.duration / TIMELINE_END) * 100}%`;
block.title = `${task.name}: ${placement.start}–${placement.start + task.duration}m`;
const issues = issuesFor(task.id);
if (issues.length) block.classList.add("conflict");
if (state.selected === task.id) block.classList.add("selected");
if (isLate(task.id)) block.classList.add("late");
if (isComplete(task.id)) block.classList.add("complete");
const progress = state.started
? Math.max(0, Math.min(100, ((state.current - placement.start) / task.duration) * 100))
: 0;
block.innerHTML = `
${task.name}
<span class="block-progress" style="width:${progress}%"></span>
`;
block.addEventListener("click", event => {
event.stopPropagation();
state.selected = task.id;
state.focusedTool = task.tool;
renderAll();
});
block.addEventListener("dragstart", event => {
event.stopPropagation();
event.dataTransfer.setData("text/plain", task.id);
event.dataTransfer.effectAllowed = "move";
state.selected = task.id;
renderAll();
});
track.appendChild(block);
}
}
const nowPosition = `${(state.current / TIMELINE_END) * 100}%`;
laneList.querySelectorAll(".now-line").forEach(line => {
line.style.left = nowPosition;
line.style.display = state.started ? "block" : "none";
});
}
function renderHeader() {
const planned = plannedCount();
const conflicts = conflictTaskCount();
const served = isComplete("garnish") ? 4 : 0;
document.querySelector("#plannedStat").textContent = `${planned} / ${TASKS.length}`;
document.querySelector("#servedStat").textContent = `${served} / 4`;
document.querySelector("#clockStat").textContent = formatClock(state.current);
document.querySelector("#recipeProgressFill").style.width = `${(planned / TASKS.length) * 100}%`;
document.querySelector("#progressLabel").textContent = `${planned} task${planned === 1 ? "" : "s"} planned`;
const phase = document.querySelector("#phaseStat");
if (state.finished && state.success) {
phase.textContent = "Service complete";
phase.style.color = "var(--mint)";
} else if (state.running) {
phase.textContent = "Shift running";
phase.style.color = "var(--yellow)";
} else if (conflicts) {
phase.textContent = `${conflicts} conflict${conflicts > 1 ? "s" : ""}`;
phase.style.color = "var(--danger)";
} else {
phase.textContent = "Planning";
phase.style.color = "var(--mint)";
}
if (state.running) {
playBtn.textContent = "Pause shift";
playBtn.classList.add("running");
} else {
playBtn.classList.remove("running");
if (state.finished) playBtn.textContent = "Run again";
else if (planned < TASKS.length) playBtn.textContent = `Plan ${TASKS.length - planned} more`;
else if (conflicts) playBtn.textContent = `Fix ${conflicts} conflict${conflicts > 1 ? "s" : ""}`;
else playBtn.textContent = "Start shift";
}
}
function renderSelectionHint() {
if (!state.selected) {
selectionHint.innerHTML = "<b>Tip:</b> shared lanes reveal the bottleneck. Move a block to change its start.";
return;
}
const task = TASK_BY_ID[state.selected];
const tool = TOOLS.find(item => item.id === task.tool);
const placement = schedule[task.id];
selectionHint.innerHTML = placement
? `<b>${task.name}</b> · ${placement.start}–${placement.start + task.duration}m · drag its block to move it.`
: `<b>${task.name}</b> · click a start time in the ${tool.label} lane.`;
}
function renderAll() {
renderTaskList();
renderTimeline();
renderHeader();
renderSelectionHint();
laneList.querySelectorAll(".lane-row").forEach(row => {
row.classList.toggle("focused", row.dataset.tool === state.focusedTool);
});
}
// ---------------------------------------------------------------------
// Hint, simulation, help, and reset
// ---------------------------------------------------------------------
function findEarliestSafeStart(task) {
const maxStart = SERVICE_WINDOW - task.duration;
for (let start = 0; start <= maxStart; start++) {
const dependencySafe = task.deps.every(depId => {
const dep = schedule[depId];
return dep && start >= dep.start + TASK_BY_ID[depId].duration;
});
if (!dependencySafe) continue;
const resourceSafe = TASKS.every(other => {
if (other.id === task.id || other.tool !== task.tool) return true;
const placement = schedule[other.id];
if (!placement) return true;
return start >= placement.start + other.duration || placement.start >= start + task.duration;
});
if (resourceSafe) return start;
}
return null;
}
document.querySelector("#hintBtn").addEventListener("click", () => {
const next = TASKS.find(task => !schedule[task.id] && task.deps.every(dep => schedule[dep]));
if (!next) {
showToast("Every dependency-ready task is already placed.");
return;
}
const start = findEarliestSafeStart(next);
if (start === null) {
showToast(`No safe slot remains for ${next.name} before service.`, "bad");
return;
}
placeTask(next.id, start, next.tool);
});
document.querySelector("#clearBtn").addEventListener("click", () => {
for (const task of TASKS) schedule[task.id] = null;
state.selected = null;
state.started = false;
state.running = false;
state.finished = false;
state.current = 0;
renderAll();
showToast("Timeline cleared. Build a new service plan.");
});
document.querySelector("#resetBtn").addEventListener("click", () => {
for (const task of TASKS) schedule[task.id] = null;
schedule.wash = { start: 0, tool: "prep" };
schedule.toast = { start: 0, tool: "saucepan" };
state.selected = null;
state.started = false;
state.running = false;
state.finished = false;
state.success = false;
state.current = 0;
renderAll();
showToast("Plan reset to the two starter tasks.", "good");
});
document.querySelector("#speedBtn").addEventListener("click", () => {
state.speed = state.speed === 1 ? 2 : state.speed === 2 ? 4 : 1;
document.querySelector("#speedBtn").textContent = `${state.speed}×`;
});
playBtn.addEventListener("click", () => {
if (state.running) {
state.running = false;
renderAll();
showToast("Shift paused.");
return;
}
if (state.finished) {
state.current = 0;
state.started = true;
state.finished = false;
state.success = false;
state.running = true;
renderAll();
return;
}
const planned = plannedCount();
if (planned < TASKS.length) {
showToast(`Plan all ${TASKS.length} tasks before starting the shift. ${TASKS.length - planned} remain.`, "bad");
return;
}
const conflicts = conflictTaskCount();
if (conflicts) {
const first = TASKS.find(task => issuesFor(task.id).length);
showToast(`${first.name}: ${issuesFor(first.id)[0]}.`, "bad");
return;
}
state.started = true;
state.running = true;
state.current = 0;
renderAll();
showToast("Service has started. Watch the shared stations.", "good");
});
const modal = document.querySelector("#modal");
const modalTitle = document.querySelector("#modalTitle");
const modalBody = document.querySelector("#modalBody");
function openModal(title, html) {
modalTitle.textContent = title;
modalBody.innerHTML = html;
modal.hidden = false;
}
document.querySelector("#helpBtn").addEventListener("click", () => {
openModal("How to run the kitchen", `
<p>This fictional meal contains <strong>12 preparation tasks</strong> for <strong>four servings</strong>. Each task has a duration, a required tool, and explicit preparation dependencies.</p>
<ol>
<li><strong>Plan the workflow.</strong> Drag a task card into its matching tool lane. You can also select a card and click a time in its lane.</li>
<li><strong>Respect dependencies.</strong> A task cannot begin until every listed prerequisite has finished.</li>
<li><strong>Protect shared tools.</strong> The saucepan, oven, knife block, and plating counter can only handle one task at a time. Overlaps turn red.</li>
<li><strong>Move or remove tasks.</strong> Drag scheduled blocks to change their start. Use the small × on a task card to unschedule it.</li>
<li><strong>Start service.</strong> Run the 60-minute shift and finish all four bowls before service closes.</li>
</ol>
<p><strong>3D controls:</strong> drag the kitchen to orbit, use the mouse wheel to zoom, and click a station to focus its timeline lane.</p>
<p>The <strong>Hint</strong> button places the next dependency-ready task at its earliest conflict-free time. It never ignores dependencies or shared-tool occupancy.</p>
`);
});
document.querySelector("#modalClose").addEventListener("click", () => {
modal.hidden = true;
});
modal.addEventListener("click", event => {
if (event.target === modal) modal.hidden = true;
});
function finishShift(success) {
state.running = false;
state.finished = true;
state.success = success;
renderAll();
const totalDuration = Math.max(...TASKS.map(task => {
const placement = schedule[task.id];
return placement.start + task.duration;
}));
openModal(success ? "Four bowls, right on time" : "Service window closed", `
<p>${success
? "The final garnish is complete. All dependencies were respected, shared tools never overlapped, and four servings reached the pass."
: "The kitchen reached the 60-minute service window before the final garnish was complete."}</p>
<div class="result-grid">
<div class="result-cell"><strong>${success ? "4" : "0"}</strong><span>bowls served</span></div>
<div class="result-cell"><strong>${totalDuration}m</strong><span>planned finish</span></div>
<div class="result-cell"><strong>${conflictTaskCount()}</strong><span>conflicts</span></div>
</div>
<p>${success
? "Try clearing the plan and finding a shorter schedule, or watch the same plan again at a higher speed."
: "Look for a shared bottleneck, especially the saucepan and plating counter. Moving independent prep earlier can preserve capacity."}</p>
`);
}
// ---------------------------------------------------------------------
// Three.js low-poly kitchen
// ---------------------------------------------------------------------
const canvas = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({ canvas, antialias: true, alpha: false });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight, false);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdce8e5);
scene.fog = new THREE.Fog(0xdce8e5, 19, 34);
const camera = new THREE.PerspectiveCamera(42, window.innerWidth / window.innerHeight, 0.1, 80);
const cameraTarget = new THREE.Vector3(0, 1.0, -1.4);
const cameraState = {
radius: 18.5,
theta: 0.68,
phi: 0.88
};
function updateCamera() {
const { radius, theta, phi } = cameraState;
camera.position.set(
cameraTarget.x + radius * Math.sin(theta) * Math.sin(phi),
cameraTarget.y + radius * Math.cos(phi),
cameraTarget.z + radius * Math.cos(theta) * Math.sin(phi)
);
camera.lookAt(cameraTarget);
}
updateCamera();
const hemi = new THREE.HemisphereLight(0xf6fff9, 0x60756d, 2.0);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff1d2, 3.0);
sun.position.set(-7, 13, 9);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -13;
sun.shadow.camera.right = 13;
sun.shadow.camera.top = 11;
sun.shadow.camera.bottom = -9;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 35;
sun.shadow.bias = -0.0006;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb8e8ff, 1.1);
fill.position.set(10, 7, 4);
scene.add(fill);
const materials = new Map();
function material(color, options = {}) {
const key = `${color}-${JSON.stringify(options)}`;
if (!materials.has(key)) {
materials.set(key, new THREE.MeshStandardMaterial({
color,
roughness: 0.78,
metalness: 0,
flatShading: true,
...options
}));
}
return materials.get(key);
}
function mesh(geometry, color, parent, x = 0, y = 0, z = 0, options = {}) {
const object = new THREE.Mesh(geometry, typeof color === "string" || typeof color === "number" ? material(color, options) : color);
object.position.set(x, y, z);
object.castShadow = true;
object.receiveShadow = true;
parent.add(object);
return object;
}
function box(w, h, d, color, parent, x = 0, y = 0, z = 0, options = {}) {
return mesh(new THREE.BoxGeometry(w, h, d), color, parent, x, y, z, options);
}
function cylinder(rt, rb, h, color, parent, x = 0, y = 0, z = 0, segments = 12, options = {}) {
return mesh(new THREE.CylinderGeometry(rt, rb, h, segments), color, parent, x, y, z, options);
}
function makeLabel(text, color = "#23453f") {
const labelCanvas = document.createElement("canvas");
labelCanvas.width = 512;
labelCanvas.height = 96;
const ctx = labelCanvas.getContext("2d");
ctx.fillStyle = "rgba(255,248,226,0.94)";
ctx.fillRect(0, 0, 512, 96);
ctx.fillStyle = color;
ctx.font = "800 34px system-ui";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text.toUpperCase(), 256, 50);
const texture = new THREE.CanvasTexture(labelCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(new THREE.SpriteMaterial({ map: texture, transparent: true }));
sprite.scale.set(1.9, 0.36, 1);
return sprite;
}
const room = new THREE.Group();
scene.add(room);
box(18.4, 0.18, 13.4, 0xb8cac2, room, 0, -0.12, 0);
for (let x = -8; x <= 8; x += 2) box(0.025, 0.012, 13, 0xa6b9b1, room, x, -0.018, 0);
for (let z = -6; z <= 6; z += 2) box(18, 0.012, 0.025, 0xa6b9b1, room, 0, -0.017, z);
box(18.4, 6.2, 0.18, 0xe8eee6, room, 0, 3.0, -6.65);
box(0.18, 6.2, 13.2, 0xd8e4dc, room, -9.15, 3.0, 0);
box(18.5, 0.15, 0.2, 0x315d56, room, 0, 0.65, -6.52);
box(0.2, 0.15, 13.1, 0x315d56, room, -9.0, 0.65, 0);
// Background shelves and jars.
box(5.7, 0.12, 0.55, 0x8b6e50, room, -4.6, 3.15, -6.25);
box(4.5, 0.12, 0.5, 0x8b6e50, room, 4.2, 3.15, -6.25);
for (let i = 0; i < 8; i++) {
const x = -6.8 + i * 0.62;
cylinder(0.16, 0.18, 0.42, i % 2 ? 0xd99a62 : 0x7ea88d, room, x, 3.42, -6.17, 8);
cylinder(0.17, 0.17, 0.06, 0xefe1bd, room, x, 3.67, -6.17, 8);
}
for (let i = 0; i < 6; i++) {
cylinder(0.14, 0.16, 0.38, i % 2 ? 0xe2a878 : 0x8db79c, room, 2.6 + i * 0.56, 3.4, -6.18, 8);
}
const stationPositions = {
prep: new THREE.Vector3(-6.8, 0, -4.85),
knife: new THREE.Vector3(-4.55, 0, -4.85),
saucepan: new THREE.Vector3(-2.3, 0, -4.85),
stockpot: new THREE.Vector3(0.0, 0, -4.85),
oven: new THREE.Vector3(2.65, 0, -4.85),
rest: new THREE.Vector3(5.05, 0, -4.85),
plating: new THREE.Vector3(7.35, 0, -4.85)
};
const stationRoots = {};
const beacons = {};
function cabinetFor(tool, cabinetColor = 0x78988d) {
const group = new THREE.Group();
group.position.copy(stationPositions[tool]);
group.userData.tool = tool;
room.add(group);
stationRoots[tool] = group;
box(2.05, 0.92, 0.86, cabinetColor, group, 0, 0.52, 0);
box(2.18, 0.12, 1.0, 0xf1e6cf, group, 0, 1.04, 0);
box(0.87, 0.68, 0.035, 0x66867c, group, -0.52, 0.50, 0.45);
box(0.87, 0.68, 0.035, 0x66867c, group, 0.52, 0.50, 0.45);
box(0.28, 0.04, 0.05, 0xf4d78c, group, -0.15, 0.61, 0.48);
box(0.28, 0.04, 0.05, 0xf4d78c, group, 0.15, 0.61, 0.48);
const label = makeLabel(TOOLS.find(item => item.id === tool).label);
label.position.set(0, 2.18, 0.1);
group.add(label);
const beaconMaterial = new THREE.MeshStandardMaterial({
color: 0x75e0bd,
emissive: 0x2d8e68,
emissiveIntensity: 1.4,
roughness: 0.45
});
const beacon = mesh(new THREE.IcosahedronGeometry(0.13, 1), beaconMaterial, group, 0, 2.48, 0.1);
beacon.visible = false;
beacons[tool] = beacon;
return group;
}
const prep = cabinetFor("prep", 0x719889);
box(1.2, 0.055, 0.62, 0xc89458, prep, -0.1, 1.14, 0.05);
for (let i = 0; i < 4; i++) {
const mushroom = new THREE.Group();
mushroom.position.set(-0.45 + i * 0.25, 1.2, 0.07 + (i % 2) * 0.16);
mushroom.rotation.y = i * 0.7;
cylinder(0.07, 0.10, 0.15, 0xd8c8a7, mushroom, 0, 0.07, 0, 8);
mesh(new THREE.SphereGeometry(0.13, 8, 5), 0x9b6742, mushroom, 0, 0.15, 0);
prep.add(mushroom);
}
const knife = cabinetFor("knife", 0x6e958d);
box(1.05, 0.055, 0.58, 0xc89458, knife, -0.1, 1.14, 0.02);
box(0.52, 0.025, 0.12, 0xd9e2df, knife, 0.22, 1.19, 0.02, { metalness: 0.65, roughness: 0.25 });
box(0.23, 0.05, 0.08, 0x533d32, knife, -0.14, 1.18, 0.02);
for (let i = 0; i < 5; i++) {
const herb = box(0.05, 0.09, 0.15, 0x4c9b67, knife, -0.48 + i * 0.12, 1.22, 0.12);
herb.rotation.y = i * 0.55;
}
const saucepanStation = cabinetFor("saucepan", 0x6d8f86);
box(1.65, 0.08, 0.78, 0x394542, saucepanStation, 0, 1.14, 0);
for (const burnerX of [-0.42, 0.42]) {
cylinder(0.29, 0.29, 0.035, 0x202724, saucepanStation, burnerX, 1.20, 0, 16);
cylinder(0.16, 0.16, 0.045, 0x59635d, saucepanStation, burnerX, 1.23, 0, 12);
}
cylinder(0.29, 0.23, 0.34, 0xaebbb8, saucepanStation, -0.38, 1.40, 0, 12, { metalness: 0.65, roughness: 0.28 });
cylinder(0.255, 0.255, 0.025, 0xd7a74f, saucepanStation, -0.38, 1.58, 0, 12);
box(0.62, 0.055, 0.075, 0x313d39, saucepanStation, 0.08, 1.47, 0);
cylinder(0.25, 0.22, 0.30, 0xb8c4c1, saucepanStation, 0.46, 1.40, 0, 12, { metalness: 0.65, roughness: 0.28 });
cylinder(0.21, 0.21, 0.02, 0x8b5a32, saucepanStation, 0.46, 1.56, 0, 12);
const stock = cabinetFor("stockpot", 0x718d84);
cylinder(0.41, 0.34, 0.62, 0xb8c3bf, stock, 0, 1.44, 0, 14, { metalness: 0.72, roughness: 0.25 });
cylinder(0.37, 0.37, 0.025, 0x8c6337, stock, 0, 1.76, 0, 14);
box(0.12, 0.07, 0.70, 0x35403c, stock, 0, 1.62, 0);
for (const side of [-1, 1]) {
const handle = mesh(new THREE.TorusGeometry(0.16, 0.035, 6, 12, Math.PI), 0x46514d, stock, side * 0.43, 1.48, 0);
handle.rotation.z = side === 1 ? -Math.PI / 2 : Math.PI / 2;
}
const oven = cabinetFor("oven", 0x6b837d);
box(1.65, 0.83, 0.05, 0x293432, oven, 0, 0.55, 0.46);
box(1.30, 0.44, 0.035, 0x17211f, oven, 0, 0.49, 0.50);
const ovenGlow = box(1.12, 0.25, 0.025, 0xe6783e, oven, 0, 0.45, 0.53, {
emissive: 0xb94620,
emissiveIntensity: 0.65,
roughness: 0.45
});
box(1.46, 0.055, 0.08, 0xb9c4bf, oven, 0, 0.83, 0.54);
for (let i = 0; i < 3; i++) {
const knob = cylinder(0.06, 0.06, 0.05, 0xd7c88e, oven, -0.45 + i * 0.45, 0.94, 0.51, 10);
knob.rotation.x = Math.PI / 2;
}
const rest = cabinetFor("rest", 0x76968b);
for (let i = 0; i < 7; i++) {
box(0.055, 0.22, 0.72, 0x87938e, rest, -0.6 + i * 0.2, 1.27, 0);
}
box(1.42, 0.06, 0.07, 0x65736e, rest, 0, 1.15, -0.36);
box(1.42, 0.06, 0.07, 0x65736e, rest, 0, 1.15, 0.36);
cylinder(0.31, 0.25, 0.16, 0xe4d9bd, rest, 0, 1.36, 0, 12);
const plating = cabinetFor("plating", 0x789389);
for (let i = 0; i < 5; i++) {
cylinder(0.32, 0.32, 0.035, 0xf3ead5, plating, -0.45 + i * 0.23, 1.13 + i * 0.035, 0.08, 14);
}
cylinder(0.28, 0.19, 0.19, 0xf7edda, plating, 0.52, 1.22, 0.1, 12);
cylinder(0.24, 0.24, 0.02, 0xc6a467, plating, 0.52, 1.325, 0.1, 12);
// Central island with four place settings.
const island = new THREE.Group();
island.position.set(0, 0, 0.7);
room.add(island);
box(5.25, 0.88, 2.25, 0x64877c, island, 0, 0.50, 0);
box(5.5, 0.14, 2.45, 0xeadbc0, island, 0, 1.01, 0);
box(1.55, 0.76, 0.04, 0x58776e, island, -1.25, 0.49, 1.14);
box(1.55, 0.76, 0.04, 0x58776e, island, 1.25, 0.49, 1.14);
const dishGroups = [];
for (let i = 0; i < 4; i++) {
const dish = new THREE.Group();
dish.position.set(-1.65 + i * 1.1, 1.10, 0.12);
island.add(dish);
cylinder(0.38, 0.38, 0.035, 0xf5edda, dish, 0, 0.02, 0, 14);
cylinder(0.31, 0.22, 0.18, 0xe9dfca, dish, 0, 0.12, 0, 14);
const rice = mesh(new THREE.ConeGeometry(0.27, 0.22, 10), 0xe8bd55, dish, 0, 0.29, 0);
const garnish = new THREE.Group();
garnish.position.set(0, 0.41, 0);
dish.add(garnish);
for (let j = 0; j < 4; j++) {
const mushroom = mesh(new THREE.SphereGeometry(0.075, 7, 5), 0x9a5f35, garnish, (j - 1.5) * 0.10, j % 2 * 0.02, (j % 2 - .5) * 0.12);
mushroom.scale.y = 0.45;
}
const herb = box(0.11, 0.025, 0.045, 0x4c9d62, garnish, 0.05, 0.06, 0.02);
herb.rotation.y = 0.5;
rice.visible = false;
garnish.visible = false;
dishGroups.push({ rice, garnish });
}
// Low-poly chefs.
function makeChef(color, idlePosition) {
const chef = new THREE.Group();
chef.position.copy(idlePosition);
const skin = 0xdba77f;
cylinder(0.22, 0.28, 0.67, color, chef, 0, 0.88, 0, 8);
mesh(new THREE.IcosahedronGeometry(0.245, 1), skin, chef, 0, 1.40, 0);
cylinder(0.24, 0.22, 0.17, 0xf8f4e8, chef, 0, 1.67, 0, 8);
mesh(new THREE.SphereGeometry(0.24, 8, 5), 0xfffaf0, chef, 0, 1.80, 0);
box(0.13, 0.34, 0.15, 0x3e4b49, chef, -0.12, 0.34, 0);
box(0.13, 0.34, 0.15, 0x3e4b49, chef, 0.12, 0.34, 0);
const leftArm = new THREE.Group();
leftArm.position.set(-0.29, 1.08, 0);
cylinder(0.065, 0.075, 0.46, color, leftArm, 0, -0.20, 0, 7);
mesh(new THREE.IcosahedronGeometry(0.08, 0), skin, leftArm, 0, -0.44, 0);
chef.add(leftArm);
const rightArm = new THREE.Group();
rightArm.position.set(0.29, 1.08, 0);
cylinder(0.065, 0.075, 0.46, color, rightArm, 0, -0.20, 0, 7);
mesh(new THREE.IcosahedronGeometry(0.08, 0), skin, rightArm, 0, -0.44, 0);
chef.add(rightArm);
room.add(chef);
return { group: chef, leftArm, rightArm, idlePosition: idlePosition.clone(), target: idlePosition.clone() };
}
const chefs = [
makeChef(0xef8f73, new THREE.Vector3(-2.6, 0, 2.6)),
makeChef(0x5fb9aa, new THREE.Vector3(-0.9, 0, 3.2)),
makeChef(0xe2b64f, new THREE.Vector3(0.9, 0, 3.1)),
makeChef(0x6d9fd1, new THREE.Vector3(2.7, 0, 2.5))
];
// Decorative plants and hanging lamps.
function makePlant(x, z) {
const plant = new THREE.Group();
plant.position.set(x, 0, z);
cylinder(0.34, 0.27, 0.48, 0xc87854, plant, 0, 0.24, 0, 8);
for (let i = 0; i < 7; i++) {
const leaf = mesh(new THREE.IcosahedronGeometry(0.24, 0), i % 2 ? 0x4f9164 : 0x6ba376, plant,
(i - 3) * 0.12, 0.72 + (i % 2) * 0.15, (i % 3 - 1) * 0.13);
leaf.scale.set(1.2, 0.55, 0.65);
leaf.rotation.z = (i - 3) * 0.18;
}
room.add(plant);
}
makePlant(-8.0, 3.7);
makePlant(8.0, 3.6);
for (const x of [-5.2, 0, 5.2]) {
cylinder(0.02, 0.02, 1.3, 0x344b46, room, x, 4.55, -1.8, 6);
cylinder(0.48, 0.25, 0.34, 0x324a45, room, x, 3.86, -1.8, 10);
cylinder(0.36, 0.36, 0.035, 0xffedb0, room, x, 3.68, -1.8, 12, {
emissive: 0xffcf70,
emissiveIntensity: 0.8
});
}
// ---------------------------------------------------------------------
// Direct camera controls and station picking
// ---------------------------------------------------------------------
let dragging = false;
let pointerMoved = false;
let lastPointer = { x: 0, y: 0 };
canvas.addEventListener("pointerdown", event => {
if (event.button !== 0) return;
dragging = true;
pointerMoved = false;
lastPointer = { x: event.clientX, y: event.clientY };
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", event => {
if (!dragging) return;
const dx = event.clientX - lastPointer.x;
const dy = event.clientY - lastPointer.y;
if (Math.abs(dx) + Math.abs(dy) > 2) pointerMoved = true;
cameraState.theta -= dx * 0.006;
cameraState.phi = Math.max(0.48, Math.min(1.32, cameraState.phi - dy * 0.005));
lastPointer = { x: event.clientX, y: event.clientY };
updateCamera();
});
canvas.addEventListener("pointerup", event => {
dragging = false;
if (!pointerMoved) pickStation(event);
});
canvas.addEventListener("pointercancel", () => { dragging = false; });
canvas.addEventListener("wheel", event => {
event.preventDefault();
cameraState.radius = Math.max(10, Math.min(25, cameraState.radius * Math.exp(event.deltaY * 0.001)));
updateCamera();
}, { passive: false });
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
function pickStation(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(stationRoots), true);
if (!hits.length) return;
let object = hits[0].object;
while (object && !object.userData.tool) object = object.parent;
const tool = object?.userData.tool;
if (!tool) return;
state.focusedTool = tool;
renderAll();
const row = laneList.querySelector(`[data-tool="${tool}"]`);
row?.scrollIntoView({ behavior: "smooth", block: "nearest", inline: "nearest" });
showToast(`${TOOLS.find(item => item.id === tool).label} lane focused.`);
}
function updateScene(dt, elapsed) {
const activeTasks = state.started
? TASKS.filter(task => {
const placement = schedule[task.id];
return placement && state.current >= placement.start && state.current < placement.start + task.duration;
})
: [];
for (const tool of Object.keys(beacons)) {
beacons[tool].visible = activeTasks.some(task => task.tool === tool);
if (beacons[tool].visible) {
beacons[tool].rotation.y += dt * 2;
beacons[tool].position.y = 2.48 + Math.sin(elapsed * 3.2) * 0.05;
}
}
chefs.forEach((chef, index) => {
const activeTask = activeTasks[index];
if (activeTask) {
const station = stationPositions[activeTask.tool];
chef.target.set(station.x + (index - 1.5) * 0.18, 0, station.z + 1.12);
chef.group.rotation.y = Math.PI;
const chop = Math.sin(elapsed * 8 + index) * 0.25;
chef.leftArm.rotation.x = -0.85 + chop;
chef.rightArm.rotation.x = -0.85 - chop;
} else {
chef.target.copy(chef.idlePosition);
chef.group.rotation.y = Math.sin(elapsed * 0.45 + index) * 0.25;
chef.leftArm.rotation.x = Math.sin(elapsed * 1.2 + index) * 0.08;
chef.rightArm.rotation.x = -Math.sin(elapsed * 1.2 + index) * 0.08;
}
chef.group.position.lerp(chef.target, 1 - Math.pow(0.001, dt));
chef.group.position.y = activeTask ? Math.abs(Math.sin(elapsed * 7 + index)) * 0.018 : 0;
});
const portionDone = isComplete("portion");
const garnishDone = isComplete("garnish");
dishGroups.forEach((dish, index) => {
dish.rice.visible = portionDone;
dish.garnish.visible = garnishDone;
dish.garnish.rotation.y = elapsed * 0.35 + index;
});
ovenGlow.material.emissiveIntensity = activeTasks.some(task => task.tool === "oven")
? 1.35 + Math.sin(elapsed * 7) * 0.25
: 0.55;
}
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight, false);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
// ---------------------------------------------------------------------
// Main loop
// ---------------------------------------------------------------------
const clock = new THREE.Clock();
let uiAccumulator = 0;
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
if (state.running) {
state.current += dt * 4 * state.speed;
if (state.current >= SERVICE_WINDOW) {
state.current = SERVICE_WINDOW;
const allComplete = TASKS.every(task => isComplete(task.id));
finishShift(allComplete);
}
}
uiAccumulator += dt;
if (uiAccumulator > 0.10) {
uiAccumulator = 0;
if (state.started) {
renderTimeline();
renderHeader();
renderTaskList();
}
}
updateScene(dt, elapsed);
renderer.render(scene, camera);
}
renderAll();
animate();
showToast("Welcome! Two starter tasks are planned. Build the rest of the service.", "good");
</script>
</body>
</html>
```