Prompt specification
Build or customize the Three.js 3D scene "Community Kitchen Capacity Limits" 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: Community Kitchen Capacity Limits
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/community-kitchen-capacity-limits-x3195
Scene Description Prompt:
A voxel community kitchen where batching helps preparation but limited oven capacity creates queues. Three.js from cdnjs, one HTML file.
Working Three.js Starter (community-kitchen-capacity-limits-x3195):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Community Kitchen — Batch Lab</title>
<style>
:root {
--ink: #263431;
--muted: #6f7c76;
--paper: #fffaf0;
--line: #ded8c8;
--teal: #286c64;
--teal-dark: #1d514c;
--orange: #e66d42;
--gold: #e8b34f;
--sage: #7e9f83;
--shadow: 0 18px 50px rgba(42, 55, 48, .16);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dbe4d8;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button { font: inherit; }
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene canvas:active { cursor: grabbing; }
#hud {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 5;
}
.panel {
pointer-events: auto;
background: rgba(255, 250, 240, .93);
border: 1px solid rgba(255, 255, 255, .8);
box-shadow: var(--shadow);
backdrop-filter: blur(15px);
-webkit-backdrop-filter: blur(15px);
}
.brand {
position: absolute;
top: 20px;
left: 22px;
display: flex;
align-items: center;
gap: 12px;
padding: 12px 16px 12px 12px;
border-radius: 17px;
}
.brand-mark {
width: 42px;
height: 42px;
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 3px;
transform: rotate(-2deg);
}
.brand-mark i {
display: block;
background: var(--teal);
border-radius: 3px;
}
.brand-mark i:nth-child(2),
.brand-mark i:nth-child(6) { background: var(--orange); }
.brand-mark i:nth-child(4) { background: var(--gold); }
.brand h1 {
margin: 0;
font-size: 15px;
line-height: 1.1;
letter-spacing: .11em;
font-weight: 850;
}
.brand p {
margin: 5px 0 0;
color: var(--muted);
font: 600 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: .08em;
text-transform: uppercase;
}
.stats {
position: absolute;
top: 20px;
left: 50%;
transform: translateX(-50%);
display: flex;
align-items: stretch;
padding: 9px;
border-radius: 17px;
}
.stat {
min-width: 92px;
padding: 4px 16px;
border-right: 1px solid var(--line);
}
.stat:last-child { border-right: 0; }
.stat small {
display: block;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: .13em;
text-transform: uppercase;
}
.stat strong {
display: block;
margin-top: 4px;
font: 800 20px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.stat strong.accent { color: var(--orange); }
.transport {
position: absolute;
top: 20px;
right: 22px;
display: flex;
gap: 8px;
pointer-events: auto;
}
.icon-btn {
min-width: 43px;
height: 43px;
padding: 0 12px;
border: 1px solid rgba(255,255,255,.75);
border-radius: 13px;
background: rgba(255,250,240,.94);
color: var(--ink);
box-shadow: 0 8px 25px rgba(42,55,48,.12);
font: 800 11px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
cursor: pointer;
transition: transform .15s, background .15s;
}
.icon-btn:hover { transform: translateY(-2px); background: white; }
.icon-btn.active { background: var(--teal); color: white; }
.controls {
position: absolute;
left: 22px;
bottom: 20px;
width: 340px;
padding: 18px;
border-radius: 21px;
}
.eyebrow {
color: var(--teal);
font-size: 10px;
font-weight: 850;
letter-spacing: .16em;
text-transform: uppercase;
}
h2 {
margin: 5px 0 14px;
font-size: 21px;
letter-spacing: -.025em;
}
.recipe-list {
display: grid;
gap: 7px;
}
.recipe {
width: 100%;
padding: 9px 10px;
display: flex;
align-items: center;
gap: 10px;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(255,255,255,.55);
color: var(--ink);
text-align: left;
cursor: pointer;
transition: border-color .15s, background .15s, transform .15s;
}
.recipe:hover { transform: translateX(2px); }
.recipe.selected {
border-color: var(--teal);
background: #f0f7ee;
box-shadow: inset 3px 0 0 var(--teal);
}
.recipe-dot {
width: 13px;
height: 13px;
flex: 0 0 auto;
border-radius: 4px;
background: var(--food);
box-shadow: 0 0 0 3px color-mix(in srgb, var(--food) 18%, transparent);
}
.recipe-copy { flex: 1; }
.recipe-copy strong { display: block; font-size: 13px; }
.recipe-copy small {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 10px;
}
.recipe-key {
color: #a2aaa5;
font: 700 10px/1 ui-monospace, monospace;
}
.field-label {
margin: 15px 0 7px;
display: flex;
justify-content: space-between;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: .09em;
text-transform: uppercase;
}
.batch-sizes {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 7px;
}
.size-btn {
padding: 9px 5px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(255,255,255,.58);
color: var(--muted);
cursor: pointer;
font: 750 11px/1.2 ui-monospace, monospace;
}
.size-btn strong { display: block; color: var(--ink); font-size: 15px; }
.size-btn.selected { background: var(--teal); border-color: var(--teal); color: white; }
.size-btn.selected strong { color: white; }
.estimate {
margin: 12px 0 10px;
padding: 10px 11px;
border-radius: 11px;
background: #edf1e7;
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px;
}
.estimate div + div {
border-left: 1px solid #d4dbce;
padding-left: 10px;
}
.estimate small {
display: block;
color: var(--muted);
font-size: 9px;
font-weight: 750;
text-transform: uppercase;
letter-spacing: .07em;
}
.estimate strong {
display: block;
margin-top: 4px;
font: 800 12px/1.2 ui-monospace, monospace;
}
.primary {
width: 100%;
padding: 12px 14px;
border: 0;
border-radius: 12px;
background: var(--orange);
color: white;
box-shadow: 0 8px 18px rgba(230,109,66,.24);
font-size: 12px;
font-weight: 850;
letter-spacing: .02em;
cursor: pointer;
transition: transform .15s, background .15s;
}
.primary:hover { transform: translateY(-2px); background: #d95d34; }
.note {
margin: 10px 0 0;
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
.activity {
position: absolute;
top: 82px;
right: 22px;
width: 285px;
padding: 17px;
border-radius: 19px;
}
.activity-head {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 12px;
}
.live {
display: flex;
align-items: center;
gap: 6px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: .1em;
text-transform: uppercase;
}
.live::before {
content: "";
width: 7px;
height: 7px;
border-radius: 50%;
background: #54a86a;
box-shadow: 0 0 0 4px rgba(84,168,106,.12);
}
.oven-row { margin: 9px 0; }
.oven-title {
display: flex;
justify-content: space-between;
margin-bottom: 5px;
font: 800 10px/1 ui-monospace, monospace;
text-transform: uppercase;
letter-spacing: .06em;
}
.oven-title span:last-child { color: var(--muted); }
.bar {
height: 7px;
overflow: hidden;
border-radius: 5px;
background: #e4e5dc;
}
.bar i {
display: block;
height: 100%;
width: 0;
border-radius: inherit;
background: var(--orange);
transition: width .15s linear;
}
.bar.ready i { background: #55a769; }
.subhead {
margin: 15px 0 8px;
color: var(--muted);
font-size: 9px;
font-weight: 850;
letter-spacing: .12em;
text-transform: uppercase;
}
.queue-item {
display: flex;
align-items: center;
gap: 9px;
padding: 8px 0;
border-bottom: 1px solid #e8e2d5;
}
.queue-item:last-child { border-bottom: 0; }
.queue-number {
width: 23px;
height: 23px;
display: grid;
place-items: center;
border-radius: 7px;
background: #f3e3cf;
color: #a65b34;
font: 800 10px/1 ui-monospace, monospace;
}
.queue-item strong {
display: block;
font-size: 11px;
}
.queue-item small {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 9px;
}
.empty {
padding: 11px;
border: 1px dashed #d7d3c6;
border-radius: 10px;
color: var(--muted);
text-align: center;
font-size: 10px;
}
.prep-line {
margin-top: 13px;
padding: 10px;
border-radius: 11px;
background: #edf1e7;
display: flex;
justify-content: space-between;
font-size: 10px;
}
.prep-line strong { font-family: ui-monospace, monospace; }
.toast {
position: absolute;
left: 50%;
top: 91px;
transform: translate(-50%, -14px);
max-width: min(430px, calc(100vw - 30px));
padding: 10px 16px;
border-radius: 100px;
background: rgba(38,52,49,.92);
color: white;
box-shadow: 0 10px 30px rgba(0,0,0,.16);
font-size: 11px;
font-weight: 650;
text-align: center;
opacity: 0;
transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.camera-hint {
position: absolute;
left: 50%;
bottom: 21px;
transform: translateX(-50%);
padding: 8px 13px;
border-radius: 100px;
background: rgba(255,250,240,.78);
color: #67746e;
font: 700 9px/1 ui-monospace, monospace;
letter-spacing: .05em;
text-transform: uppercase;
backdrop-filter: blur(8px);
}
@media (max-width: 1050px) {
.stat { min-width: 76px; padding-inline: 11px; }
.activity { display: none; }
}
@media (max-width: 760px) {
.brand { top: 10px; left: 10px; padding: 9px 11px 9px 9px; }
.brand h1 { font-size: 12px; }
.brand p { display: none; }
.brand-mark { width: 34px; height: 34px; }
.transport { top: 10px; right: 10px; }
.icon-btn { height: 39px; min-width: 39px; padding-inline: 9px; }
.stats {
top: 62px;
left: 10px;
right: 10px;
transform: none;
justify-content: space-between;
padding: 6px;
}
.stat { min-width: 0; flex: 1; padding: 4px 8px; }
.stat strong { font-size: 16px; }
.stat small { font-size: 8px; }
.controls {
left: 10px;
right: 10px;
bottom: 10px;
width: auto;
padding: 13px;
max-height: 49vh;
overflow-y: auto;
border-radius: 16px;
}
.controls h2 { margin-bottom: 9px; font-size: 18px; }
.recipe-list { grid-template-columns: repeat(3, 1fr); gap: 5px; }
.recipe { padding: 8px 6px; display: block; }
.recipe-dot { display: inline-block; margin-bottom: 5px; }
.recipe-copy strong { font-size: 10px; }
.recipe-copy small, .recipe-key { display: none; }
.field-label { margin-top: 10px; }
.camera-hint { display: none; }
.toast { top: 117px; }
}
@media (max-height: 670px) {
.controls { max-height: 58vh; overflow-y: auto; }
.activity { display: none; }
}
</style>
</head>
<body>
<div id="scene"></div>
<div id="hud">
<header class="brand panel">
<div class="brand-mark" aria-hidden="true">
<i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i>
</div>
<div>
<h1>COMMUNITY KITCHEN</h1>
<p>Batch Lab · Service Flow</p>
</div>
</header>
<section class="stats panel" aria-label="Kitchen statistics">
<div class="stat"><small>Plates served</small><strong id="platesStat">0</strong></div>
<div class="stat"><small>Batches</small><strong id="batchesStat">0</strong></div>
<div class="stat"><small>Oven queue</small><strong id="queueStat" class="accent">0</strong></div>
<div class="stat"><small>Load</small><strong id="loadStat">0/2</strong></div>
</section>
<div class="transport">
<button class="icon-btn" id="pauseBtn" title="Pause simulation">Ⅱ</button>
<button class="icon-btn" id="speedBtn" title="Change simulation speed">1×</button>
<button class="icon-btn" id="resetBtn" title="Reset kitchen">↺</button>
</div>
<section class="controls panel">
<div class="eyebrow">Batch workflow</div>
<h2>Prepare a community batch</h2>
<div class="recipe-list">
<button class="recipe selected" data-recipe="stew" style="--food:#e66d42">
<span class="recipe-dot"></span>
<span class="recipe-copy">
<strong>Garden stew</strong>
<small>Bright vegetables · oven finish</small>
</span>
<span class="recipe-key">1</span>
</button>
<button class="recipe" data-recipe="bread" style="--food:#d99a4e">
<span class="recipe-dot"></span>
<span class="recipe-copy">
<strong>Rosemary loaf</strong>
<small>Shared bread · quick bake</small>
</span>
<span class="recipe-key">2</span>
</button>
<button class="recipe" data-recipe="roast" style="--food:#88a957">
<span class="recipe-dot"></span>
<span class="recipe-copy">
<strong>Root roast</strong>
<small>Seasonal roots · hearty finish</small>
</span>
<span class="recipe-key">3</span>
</button>
</div>
<div class="field-label">
<span>Batch size</span>
<span>One prep task</span>
</div>
<div class="batch-sizes">
<button class="size-btn" data-size="4"><strong>4</strong>plates</button>
<button class="size-btn selected" data-size="6"><strong>6</strong>plates</button>
<button class="size-btn" data-size="8"><strong>8</strong>plates</button>
</div>
<div class="estimate">
<div>
<small>Shared prep</small>
<strong id="prepEstimate">3.7s total</strong>
</div>
<div>
<small>Prep per plate</small>
<strong id="plateEstimate">0.62s / plate</strong>
</div>
</div>
<button class="primary" id="queueBtn">Queue 6-plate garden stew</button>
<p class="note">
Larger batches share setup work, but every tray still needs one of two ovens.
Queue three batches to see the oven line form.
</p>
</section>
<section class="activity panel">
<div class="activity-head">
<strong style="font-size:14px">Live service</strong>
<span class="live">Running</span>
</div>
<div class="oven-row">
<div class="oven-title"><span>Oven 01</span><span id="oven1Status">Empty</span></div>
<div class="bar" id="oven1Bar"><i></i></div>
</div>
<div class="oven-row">
<div class="oven-title"><span>Oven 02</span><span id="oven2Status">Empty</span></div>
<div class="bar" id="oven2Bar"><i></i></div>
</div>
<div class="subhead">Oven queue</div>
<div id="queueList">
<div class="empty">No trays waiting</div>
</div>
<div class="prep-line">
<span>Shared prep station</span>
<strong id="prepLineStatus">Ready</strong>
</div>
</section>
<div class="toast" id="toast"></div>
<div class="camera-hint">Drag to orbit · Shift-drag to pan · Scroll to zoom</div>
</div>
<script type="module">
import * as THREE from 'https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js';
/* --------------------------------------------------------------------------
Scene
--------------------------------------------------------------------------- */
const sceneHost = document.getElementById('scene');
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
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.12;
sceneHost.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdbe4d8);
scene.fog = new THREE.Fog(0xdbe4d8, 34, 62);
const camera = new THREE.OrthographicCamera(-16, 16, 10, -10, 0.1, 100);
const cameraTarget = new THREE.Vector3(0, 1.2, 0);
let cameraYaw = 0.72;
let cameraPitch = 0.68;
let cameraDistance = 28;
const hemi = new THREE.HemisphereLight(0xfff8e8, 0x718879, 2.0);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xffefd2, 3.1);
sun.position.set(-9, 17, 11);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -18;
sun.shadow.camera.right = 18;
sun.shadow.camera.top = 18;
sun.shadow.camera.bottom = -18;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 45;
sun.shadow.bias = -0.00025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xbcd7e6, 1.1);
fill.position.set(13, 8, -8);
scene.add(fill);
const materialCache = new Map();
function material(color, options = {}) {
const key = color + '|' + JSON.stringify(options);
if (!materialCache.has(key)) {
materialCache.set(key, new THREE.MeshStandardMaterial({
color,
roughness: 0.78,
metalness: 0,
...options
}));
}
return materialCache.get(key);
}
function box(parent, w, h, d, color, x = 0, y = 0, z = 0, options = {}) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(w, h, d),
color?.isMaterial ? color : material(color, options)
);
mesh.position.set(x, y, z);
mesh.castShadow = h > 0.22;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinder(parent, radiusTop, radiusBottom, height, color, x, y, z, segments = 8) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radiusTop, radiusBottom, height, segments),
material(color)
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function labelSprite(text, x, y, z, width = 3.4, accent = '#286c64') {
const canvas = document.createElement('canvas');
canvas.width = 512;
canvas.height = 96;
const ctx = canvas.getContext('2d');
ctx.fillStyle = 'rgba(255,250,240,.96)';
ctx.fillRect(3, 3, 506, 90);
ctx.fillStyle = accent;
ctx.fillRect(3, 3, 12, 90);
ctx.strokeStyle = '#ded8c8';
ctx.lineWidth = 4;
ctx.strokeRect(3, 3, 506, 90);
ctx.fillStyle = '#263431';
ctx.font = '800 39px monospace';
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
ctx.fillText(text, 263, 49);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const sprite = new THREE.Sprite(new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
}));
sprite.position.set(x, y, z);
sprite.scale.set(width, width * 96 / 512, 1);
sprite.renderOrder = 20;
scene.add(sprite);
return sprite;
}
const dynamicGroup = new THREE.Group();
scene.add(dynamicGroup);
const ovenPickTargets = [];
function makeCounter(x, z, w, d, bodyColor, topColor, topY = 1.42) {
const group = new THREE.Group();
group.position.set(x, 0, z);
scene.add(group);
box(group, w, 1.28, d, bodyColor, 0, 0.64, 0);
box(group, w + 0.22, 0.18, d + 0.18, topColor, 0, topY, 0);
box(group, 0.08, 0.95, 0.06, '#344b46', 0, 0.66, d / 2 + 0.025);
box(group, 0.42, 0.07, 0.09, '#e6ddc7', -0.18, 0.98, d / 2 + 0.06);
return group;
}
function buildKitchen() {
// Foundation and voxel checker floor.
box(scene, 22.4, 0.35, 16.4, '#b5c4b5', 0, -0.30, 0);
const floorA = '#e8dfc9';
const floorB = '#c5d0bc';
for (let ix = 0; ix < 11; ix++) {
for (let iz = 0; iz < 8; iz++) {
const tile = box(
scene, 1.93, 0.13, 1.93,
(ix + iz) % 2 ? floorA : floorB,
-10 + ix * 2, -0.065, -7 + iz * 2
);
tile.castShadow = false;
}
}
// Two open walls keep the dollhouse view readable.
const backWall = box(scene, 22.2, 5.2, 0.25, '#f1ead9', 0, 2.55, -8.1);
const leftWall = box(scene, 0.25, 5.2, 16.2, '#e9e4d5', -11.1, 2.55, 0);
backWall.castShadow = false;
leftWall.castShadow = false;
box(scene, 22.0, 0.18, 0.12, '#729887', 0, 0.28, -7.93);
box(scene, 0.12, 0.18, 16.0, '#729887', -10.93, 0.28, 0);
box(scene, 22.0, 0.13, 0.12, '#d1c6ae', 0, 4.95, -7.92);
box(scene, 0.12, 0.13, 16.0, '#d1c6ae', -10.92, 4.95, 0);
// Backsplash tiles.
for (let x = -10; x <= 10; x += 2) {
box(scene, 1.84, 0.64, 0.06, '#a9c3b4', x, 1.72, -7.93);
box(scene, 1.84, 0.64, 0.06, '#c3d5c7', x, 2.43, -7.93);
}
// Window on the left wall.
for (const z of [-3.5, 2.4]) {
box(scene, 0.12, 2.35, 3.0, '#a9d1d5', -10.91, 3.05, z);
box(scene, 0.16, 2.65, 0.16, '#f7f1e4', -10.80, 3.05, z - 1.56);
box(scene, 0.16, 2.65, 0.16, '#f7f1e4', -10.80, 3.05, z + 1.56);
box(scene, 0.16, 0.16, 3.28, '#f7f1e4', -10.80, 4.38, z);
box(scene, 0.16, 0.16, 3.28, '#f7f1e4', -10.80, 1.72, z);
box(scene, 0.17, 2.3, 0.12, '#f7f1e4', -10.77, 3.05, z);
}
// Wall shelf and jars.
box(scene, 4.8, 0.14, 0.65, '#a96f43', -3.9, 3.45, -7.52);
const jarColors = ['#d9924a', '#8baa63', '#c05d48', '#e3c263', '#739e8e'];
for (let i = 0; i < 10; i++) {
const x = -5.9 + i * 0.44;
box(scene, 0.28, 0.52 + (i % 2) * 0.12, 0.28, jarColors[i % jarColors.length], x, 3.79, -7.49);
box(scene, 0.31, 0.08, 0.31, '#f2e8d3', x, 4.09, -7.49);
}
// Noticeboard.
box(scene, 2.25, 1.55, 0.12, '#b88752', -8.55, 3.4, -7.84);
box(scene, 2.02, 1.32, 0.08, '#dfcf9e', -8.55, 3.4, -7.74);
box(scene, 0.70, 0.82, 0.04, '#f8f1df', -8.95, 3.52, -7.67);
box(scene, 0.50, 0.68, 0.04, '#dfeee3', -8.35, 3.35, -7.66);
box(scene, 0.56, 0.09, 0.06, '#d06b4b', -8.95, 3.84, -7.62);
// Fridge.
box(scene, 2.15, 3.45, 1.75, '#e8e4d6', -8.85, 1.72, -6.15);
box(scene, 1.98, 2.02, 0.10, '#f8f2e5', -8.85, 2.29, -5.24);
box(scene, 1.98, 1.08, 0.10, '#f1e9d8', -8.85, 0.87, -5.24);
box(scene, 0.10, 0.67, 0.13, '#517b72', -8.05, 2.22, -5.12);
box(scene, 0.10, 0.48, 0.13, '#517b72', -8.05, 0.95, -5.12);
// Sink counter.
const sink = makeCounter(-8.1, -1.35, 3.35, 2.0, '#709486', '#e4ddca');
box(sink, 1.35, 0.09, 1.05, '#556b68', -0.38, 1.53, 0.05);
box(sink, 0.10, 0.78, 0.10, '#aab4ae', 0.25, 1.88, -0.58);
box(sink, 0.10, 0.10, 0.72, '#aab4ae', 0.25, 2.24, -0.27);
box(sink, 0.10, 0.22, 0.10, '#aab4ae', 0.25, 2.13, 0.04);
// Prep island.
const prep = makeCounter(-3.0, 0.72, 4.35, 2.15, '#3b756d', '#c78e59');
box(prep, 1.45, 0.10, 0.95, '#e5bd79', -0.75, 1.57, 0.04);
box(prep, 0.62, 0.05, 0.10, '#68746f', -0.34, 1.65, 0.20);
box(prep, 0.15, 0.07, 0.34, '#38413f', -0.58, 1.66, 0.27);
for (let i = 0; i < 3; i++) {
box(prep, 0.62, 0.42, 0.62, i % 2 ? '#bf7750' : '#73905c', 1.15, 1.72, -0.55 + i * 0.56);
for (let j = 0; j < 3; j++) {
box(prep, 0.13, 0.15, 0.13, i === 0 ? '#e5b548' : i === 1 ? '#d96a45' : '#81a15f',
1.0 + j * 0.16, 2.00, -0.55 + i * 0.56);
}
}
// Small trolley for batches waiting at the prep station.
box(scene, 2.3, 0.12, 1.55, '#a87950', -6.05, 1.10, 2.35);
for (const x of [-7.0, -5.1]) {
for (const z of [1.78, 2.92]) {
box(scene, 0.11, 0.85, 0.11, '#60746d', x, 0.56, z);
}
}
// Oven queue counter.
makeCounter(0.65, -3.15, 4.6, 1.35, '#c28755', '#ead9b9');
box(scene, 0.16, 0.28, 0.16, '#d6a03f', 2.35, 1.66, -3.32);
box(scene, 0.48, 0.08, 0.34, '#f5efdf', 1.55, 1.55, -3.15);
box(scene, 0.35, 0.035, 0.23, '#d9704e', 1.55, 1.60, -3.15);
// Serving/pass counter.
makeCounter(8.85, -0.95, 3.25, 1.55, '#4e7d70', '#d6bf94');
for (let i = 0; i < 4; i++) {
cylinder(scene, 0.26, 0.18, 0.12, '#f8f1df', 8.05 + i * 0.58, 1.59, -0.90);
}
// Small community dining area.
const table = new THREE.Group();
table.position.set(8.5, 0, 4.55);
scene.add(table);
box(table, 2.45, 0.16, 1.55, '#c9915b', 0, 1.30, 0);
for (const x of [-0.9, 0.9]) {
for (const z of [-0.48, 0.48]) {
box(table, 0.16, 1.18, 0.16, '#5d776e', x, 0.60, z);
}
}
box(table, 0.75, 0.34, 0.56, '#dfb651', 0.35, 1.55, 0);
cylinder(table, 0.25, 0.25, 0.08, '#f5eddb', -0.55, 1.43, 0);
for (const x of [7.1, 9.9]) {
box(scene, 0.70, 0.14, 0.70, '#8eaa8c', x, 0.72, 4.55);
box(scene, 0.18, 0.65, 0.18, '#64766e', x, 0.34, 4.55);
}
// Voxel plant.
box(scene, 0.55, 0.55, 0.55, '#b96e45', 5.8, 0.28, 2.0);
box(scene, 0.18, 1.25, 0.18, '#567b4f', 5.8, 1.0, 2.0);
box(scene, 0.72, 0.42, 0.48, '#719557', 5.58, 1.35, 2.0);
box(scene, 0.52, 0.52, 0.65, '#86a961', 6.05, 1.60, 2.0);
box(scene, 0.45, 0.32, 0.45, '#628b4f', 5.8, 1.95, 2.0);
// Pendant lights.
for (const x of [-4.5, 2.0, 7.8]) {
box(scene, 0.06, 1.25, 0.06, '#52645d', x, 4.70, -0.8);
box(scene, 0.72, 0.28, 0.72, '#315e58', x, 3.98, -0.8);
box(scene, 0.55, 0.08, 0.55, '#ffe6a4', x, 3.80, -0.8);
}
labelSprite('PREP', -3.0, 2.70, 0.25, 2.8);
labelSprite('OVEN QUEUE', 0.65, 2.62, -3.13, 3.8, '#e66d42');
labelSprite('PASS', 8.85, 2.48, -0.90, 2.6);
labelSprite('COMMUNITY KITCHEN', -2.9, 4.56, -7.72, 5.2);
}
function buildOven(x, index) {
const group = new THREE.Group();
group.position.set(x, 0, -6.30);
scene.add(group);
box(group, 2.05, 2.72, 1.55, '#e9e3d4', 0, 1.36, 0);
box(group, 2.18, 0.18, 1.66, '#63756e', 0, 2.80, 0);
box(group, 1.74, 1.48, 0.12, '#283331', 0, 1.32, 0.82);
const glowMaterial = material('#412e24', {
emissive: '#ff7b2f',
emissiveIntensity: 0
});
const glow = box(group, 1.48, 1.20, 0.05, glowMaterial, 0, 1.30, 0.89);
glow.castShadow = false;
const glassMaterial = material('#ffb15c', {
transparent: true,
opacity: 0.18,
roughness: 0.15,
metalness: 0.05,
depthWrite: false
});
const glass = box(group, 1.53, 1.03, 0.06, glassMaterial, 0, 1.30, 0.96);
glass.castShadow = false;
glass.renderOrder = 3;
glass.userData.ovenIndex = index;
ovenPickTargets.push(glass);
box(group, 1.68, 0.10, 0.13, '#3b4a46', 0, 1.95, 0.96);
box(group, 1.35, 0.11, 0.16, '#d8c9a7', 0, 0.75, 0.98);
for (const knobX of [-0.48, 0, 0.48]) {
box(group, 0.18, 0.18, 0.12, '#43534e', knobX, 2.42, 0.84);
}
const statusMaterial = material('#5b9a68', {
emissive: '#4ac16d',
emissiveIntensity: 0.55
});
const status = box(group, 0.18, 0.18, 0.13, statusMaterial, 0.75, 2.42, 0.86);
status.castShadow = false;
labelSprite(`OVEN 0${index + 1}`, x, 3.28, -5.48, 2.65, '#e66d42');
const steam = [];
for (let i = 0; i < 6; i++) {
const steamMaterial = new THREE.MeshBasicMaterial({
color: 0xfff4dd,
transparent: true,
opacity: 0,
depthWrite: false
});
const puff = new THREE.Mesh(new THREE.BoxGeometry(0.10, 0.10, 0.10), steamMaterial);
puff.visible = false;
scene.add(puff);
steam.push(puff);
}
return { x, index, group, glowMaterial, statusMaterial, steam, batch: null, elapsed: 0, readyAge: 0 };
}
function makeVoxelPerson(apronColor, skinColor = '#d9a27b') {
const group = new THREE.Group();
box(group, 0.38, 0.62, 0.34, '#354b4c', -0.21, 0.34, 0);
box(group, 0.38, 0.62, 0.34, '#354b4c', 0.21, 0.34, 0);
box(group, 0.87, 0.88, 0.50, apronColor, 0, 1.08, 0);
box(group, 0.63, 0.62, 0.08, '#f5edda', 0, 1.02, 0.29);
box(group, 0.58, 0.55, 0.53, skinColor, 0, 1.82, 0);
box(group, 0.60, 0.18, 0.55, '#55453d', 0, 2.08, -0.01);
const leftArm = new THREE.Group();
const rightArm = new THREE.Group();
leftArm.position.set(-0.53, 1.43, 0);
rightArm.position.set(0.53, 1.43, 0);
group.add(leftArm, rightArm);
box(leftArm, 0.27, 0.68, 0.29, apronColor, 0, -0.29, 0);
box(rightArm, 0.27, 0.68, 0.29, apronColor, 0, -0.29, 0);
box(leftArm, 0.25, 0.22, 0.27, skinColor, 0, -0.68, 0);
box(rightArm, 0.25, 0.22, 0.27, skinColor, 0, -0.68, 0);
const eyesMaterial = material('#303432');
box(group, 0.075, 0.075, 0.035, eyesMaterial, -0.15, 1.88, 0.285);
box(group, 0.075, 0.075, 0.035, eyesMaterial, 0.15, 1.88, 0.285);
return { group, leftArm, rightArm };
}
function addChefHat(group) {
box(group, 0.74, 0.23, 0.62, '#fbf6e9', 0, 2.31, 0);
box(group, 0.56, 0.38, 0.48, '#fffaf0', -0.17, 2.57, 0);
box(group, 0.56, 0.38, 0.48, '#fffaf0', 0.17, 2.57, 0);
box(group, 0.55, 0.35, 0.47, '#fffaf0', 0, 2.61, 0);
}
buildKitchen();
const oven1 = buildOven(4.00, 0);
const oven2 = buildOven(6.65, 1);
const chef = makeVoxelPerson('#34776f');
addChefHat(chef.group);
chef.group.position.set(-1.5, 0.08, 3.4);
scene.add(chef.group);
const resident = makeVoxelPerson('#b76f5b', '#bd825f');
box(resident.group, 0.62, 0.16, 0.62, '#f5e6c5', 0, 1.38, 0.72);
resident.group.position.set(5.1, 0.08, 3.25);
resident.group.rotation.y = -0.55;
scene.add(resident.group);
/* --------------------------------------------------------------------------
Simulation
--------------------------------------------------------------------------- */
const recipes = {
stew: {
name: 'Garden stew',
short: 'Stew',
color: '#e66d42',
foods: ['#e7673f', '#efb64e', '#719b55', '#f3d7a1'],
prepFixed: 1.8,
prepEach: 0.32,
bakeFixed: 4.0,
bakeEach: 0.35
},
bread: {
name: 'Rosemary loaf',
short: 'Bread',
color: '#d99a4e',
foods: ['#c98742', '#e5bd76', '#a87539', '#78905a'],
prepFixed: 2.1,
prepEach: 0.24,
bakeFixed: 3.8,
bakeEach: 0.25
},
roast: {
name: 'Root roast',
short: 'Roast',
color: '#88a957',
foods: ['#91aa5c', '#c76c4a', '#d9ae56', '#728f49'],
prepFixed: 2.0,
prepEach: 0.38,
bakeFixed: 4.4,
bakeEach: 0.40
}
};
const state = {
batches: [],
prepQueue: [],
prepActive: null,
ovenQueue: [],
ovens: [oven1, oven2],
completedBatches: 0,
servedPortions: 0,
nextId: 1,
paused: false,
speed: 1
};
let selectedRecipe = 'stew';
let selectedSize = 6;
function makeTray(recipeId, quantity, batchId) {
const recipe = recipes[recipeId];
const group = new THREE.Group();
box(group, 1.50, 0.12, 0.94, '#425651', 0, 0, 0);
box(group, 1.34, 0.06, 0.78, '#75847b', 0, 0.08, 0);
const foodCount = Math.min(8, Math.max(4, quantity));
for (let i = 0; i < foodCount; i++) {
const col = i % 3;
const row = Math.floor(i / 3);
const x = -0.44 + col * 0.44;
const z = -0.23 + row * 0.23;
const variation = (batchId + i) % recipe.foods.length;
box(group, 0.30, 0.18 + (i % 2) * 0.04, 0.18, recipe.foods[variation], x, 0.20, z);
}
if (recipeId === 'bread') {
box(group, 0.22, 0.10, 0.12, '#60824d', 0.30, 0.36, -0.20);
box(group, 0.19, 0.10, 0.12, '#60824d', -0.15, 0.36, 0.20);
}
return group;
}
function createBatch(recipeId, quantity) {
const recipe = recipes[recipeId];
const prepTotal = recipe.prepFixed + recipe.prepEach * quantity;
const bakeTotal = recipe.bakeFixed + recipe.bakeEach * quantity;
const batch = {
id: state.nextId++,
recipeId,
quantity,
phase: 'prepQueue',
prepElapsed: 0,
prepTotal,
bakeElapsed: 0,
bakeTotal,
outputAge: 0,
visual: null
};
batch.visual = makeTray(recipeId, quantity, batch.id);
batch.visual.position.set(-6.0, 1.22, 2.25);
dynamicGroup.add(batch.visual);
state.batches.push(batch);
state.prepQueue.push(batch);
return batch;
}
function unloadOven(index, manual = false) {
const oven = state.ovens[index];
if (!oven.batch) return;
if (oven.batch.phase === 'ready') {
const batch = oven.batch;
batch.phase = 'output';
batch.outputAge = 0;
oven.batch = null;
oven.elapsed = 0;
oven.readyAge = 0;
state.completedBatches++;
state.servedPortions += batch.quantity;
toast(
manual
? `Oven ${index + 1} unloaded · ${batch.quantity} plates sent to the pass`
: `${recipes[batch.recipeId].short} sent to the pass · ${batch.quantity} plates`
);
}
}
function updateSimulation(dt) {
if (state.paused) return;
const simDt = dt * state.speed;
// One shared prep station.
if (!state.prepActive && state.prepQueue.length) {
state.prepActive = state.prepQueue.shift();
state.prepActive.phase = 'prepping';
}
if (state.prepActive) {
state.prepActive.prepElapsed += simDt;
if (state.prepActive.prepElapsed >= state.prepActive.prepTotal) {
const batch = state.prepActive;
batch.phase = 'ovenQueue';
state.ovenQueue.push(batch);
state.prepActive = null;
toast(`${recipes[batch.recipeId].short} prepped · tray sent to oven queue`);
}
}
// Two ovens pull from the shared queue.
for (const oven of state.ovens) {
if (!oven.batch && state.ovenQueue.length) {
oven.batch = state.ovenQueue.shift();
oven.batch.phase = 'baking';
oven.batch.bakeElapsed = 0;
oven.elapsed = 0;
oven.readyAge = 0;
}
if (!oven.batch) continue;
if (oven.batch.phase === 'baking') {
oven.batch.bakeElapsed += simDt;
oven.elapsed = oven.batch.bakeElapsed;
if (oven.batch.bakeElapsed >= oven.batch.bakeTotal) {
oven.batch.phase = 'ready';
oven.readyAge = 0;
toast(`Oven ${oven.index + 1} ready · click the oven to unload early`);
}
} else if (oven.batch.phase === 'ready') {
oven.readyAge += simDt;
if (oven.readyAge >= 1.25) unloadOven(oven.index);
}
}
// Output remains visible on the pass briefly.
for (let i = state.batches.length - 1; i >= 0; i--) {
const batch = state.batches[i];
if (batch.phase !== 'output') continue;
batch.outputAge += simDt;
if (batch.outputAge >= 5) {
dynamicGroup.remove(batch.visual);
state.batches.splice(i, 1);
}
}
}
/* --------------------------------------------------------------------------
Visual state updates
--------------------------------------------------------------------------- */
const targetPosition = new THREE.Vector3();
function updateBatchVisuals(dt) {
const outputBatches = state.batches.filter(batch => batch.phase === 'output');
const smooth = 1 - Math.exp(-dt * 10);
for (const batch of state.batches) {
let scale = 1;
if (batch.phase === 'prepQueue') {
const index = state.prepQueue.indexOf(batch);
targetPosition.set(-6.75 + (index % 2) * 1.12, 1.23, 1.92 + Math.floor(index / 2) * 0.75);
} else if (batch.phase === 'prepping') {
targetPosition.set(-2.35, 1.69, 0.74);
} else if (batch.phase === 'ovenQueue') {
const index = state.ovenQueue.indexOf(batch);
targetPosition.set(-1.02 + index * 1.31, 1.60, -3.16);
} else if (batch.phase === 'baking' || batch.phase === 'ready') {
const oven = state.ovens.find(item => item.batch === batch);
if (oven) targetPosition.set(oven.x, 0.98, -5.72);
} else if (batch.phase === 'output') {
const index = outputBatches.indexOf(batch);
targetPosition.set(8.10 + index * 0.65, 1.58, -0.93);
if (batch.outputAge > 4.1) scale = Math.max(0.05, 1 - (batch.outputAge - 4.1));
}
batch.visual.position.lerp(targetPosition, smooth);
batch.visual.scale.lerp(new THREE.Vector3(scale, scale, scale), smooth);
batch.visual.rotation.y = Math.sin(performance.now() * 0.001 + batch.id) * 0.015;
}
}
function updateOvenVisuals() {
for (const oven of state.ovens) {
const batch = oven.batch;
const active = batch?.phase === 'baking';
const ready = batch?.phase === 'ready';
const progress = batch ? Math.min(1, oven.elapsed / batch.bakeTotal) : 0;
oven.glowMaterial.emissiveIntensity = active ? 0.65 + progress * 1.25 : ready ? 0.85 : 0;
oven.statusMaterial.color.set(ready ? '#e5a440' : active ? '#e87842' : '#5b9a68');
oven.statusMaterial.emissive.set(ready ? '#ffb23c' : active ? '#ff6d32' : '#4ac16d');
oven.statusMaterial.emissiveIntensity = active || ready ? 0.75 : 0.35;
for (let i = 0; i < oven.steam.length; i++) {
const puff = oven.steam[i];
puff.visible = active;
if (active) {
const t = (progress * 1.3 + i * 0.16) % 1;
puff.position.set(
oven.x + Math.sin(i * 2.4 + t * 5) * 0.18,
2.95 + t * 1.35,
-6.05 + Math.cos(i + t * 4) * 0.11
);
puff.rotation.y = t * 2;
const size = 0.08 + t * 0.13;
puff.scale.setScalar(size);
puff.material.opacity = (1 - t) * 0.42;
}
}
}
}
function updateChef(dt) {
let targetX = -1.4;
let targetZ = 3.35;
if (state.prepActive) {
targetX = -2.8;
targetZ = 2.35;
} else if (state.ovens.some(oven => oven.batch)) {
targetX = 5.2;
targetZ = -3.75;
}
const dx = targetX - chef.group.position.x;
const dz = targetZ - chef.group.position.z;
const moving = Math.abs(dx) + Math.abs(dz) > 0.15;
if (moving) {
chef.group.position.x += dx * Math.min(1, dt * 3.5);
chef.group.position.z += dz * Math.min(1, dt * 3.5);
chef.group.rotation.y = Math.atan2(dx, dz);
}
const stride = moving ? Math.sin(performance.now() * 0.011) * 0.45 : 0;
chef.leftArm.rotation.x = stride;
chef.rightArm.rotation.x = -stride;
chef.group.position.y = 0.08 + (moving ? Math.abs(Math.sin(performance.now() * 0.011)) * 0.045 : 0);
resident.group.position.y = 0.08 + Math.sin(performance.now() * 0.002) * 0.015;
}
/* --------------------------------------------------------------------------
UI
--------------------------------------------------------------------------- */
const $ = id => document.getElementById(id);
const toastElement = $('toast');
let toastTimer = 0;
function toast(message) {
toastElement.textContent = message;
toastElement.classList.add('show');
clearTimeout(toastTimer);
toastTimer = setTimeout(() => toastElement.classList.remove('show'), 2600);
}
function updateEstimate() {
const recipe = recipes[selectedRecipe];
const prepTotal = recipe.prepFixed + recipe.prepEach * selectedSize;
const perPlate = prepTotal / selectedSize;
$('prepEstimate').textContent = `${prepTotal.toFixed(1)}s total`;
$('plateEstimate').textContent = `${perPlate.toFixed(2)}s / plate`;
$('queueBtn').textContent = `Queue ${selectedSize}-plate ${recipe.short.toLowerCase()}`;
}
function updateUI() {
$('platesStat').textContent = state.servedPortions;
$('batchesStat').textContent = state.completedBatches;
$('queueStat').textContent = state.ovenQueue.length;
const occupied = state.ovens.filter(oven => oven.batch).length;
$('loadStat').textContent = `${occupied}/2`;
state.ovens.forEach((oven, index) => {
const status = $(`oven${index + 1}Status`);
const bar = $(`oven${index + 1}Bar`);
const fill = bar.querySelector('i');
const batch = oven.batch;
if (!batch) {
status.textContent = 'Empty';
fill.style.width = '0%';
bar.classList.remove('ready');
} else if (batch.phase === 'ready') {
status.textContent = 'Ready';
fill.style.width = '100%';
bar.classList.add('ready');
} else {
const percent = Math.min(100, (oven.elapsed / batch.bakeTotal) * 100);
status.textContent = `${Math.floor(percent)}%`;
fill.style.width = `${percent}%`;
bar.classList.remove('ready');
}
});
const queueList = $('queueList');
if (!state.ovenQueue.length) {
queueList.innerHTML = '<div class="empty">No trays waiting</div>';
} else {
queueList.innerHTML = state.ovenQueue.map((batch, index) => `
<div class="queue-item">
<span class="queue-number">${index + 1}</span>
<span>
<strong>${recipes[batch.recipeId].name}</strong>
<small>${batch.quantity} plates · waiting for an oven</small>
</span>
</div>
`).join('');
}
if (state.prepActive) {
const percent = Math.floor((state.prepActive.prepElapsed / state.prepActive.prepTotal) * 100);
$('prepLineStatus').textContent = `${recipes[state.prepActive.recipeId].short} ${percent}%`;
} else if (state.prepQueue.length) {
$('prepLineStatus').textContent = `${state.prepQueue.length} waiting`;
} else {
$('prepLineStatus').textContent = 'Ready';
}
}
document.querySelectorAll('.recipe').forEach(button => {
button.addEventListener('click', () => {
document.querySelectorAll('.recipe').forEach(item => item.classList.remove('selected'));
button.classList.add('selected');
selectedRecipe = button.dataset.recipe;
updateEstimate();
});
});
document.querySelectorAll('.size-btn').forEach(button => {
button.addEventListener('click', () => {
document.querySelectorAll('.size-btn').forEach(item => item.classList.remove('selected'));
button.classList.add('selected');
selectedSize = Number(button.dataset.size);
updateEstimate();
});
});
$('queueBtn').addEventListener('click', () => {
const batch = createBatch(selectedRecipe, selectedSize);
toast(`Batch #${batch.id} queued · ${batch.quantity} ${recipes[selectedRecipe].short.toLowerCase()} plates`);
updateUI();
});
$('pauseBtn').addEventListener('click', () => {
state.paused = !state.paused;
$('pauseBtn').textContent = state.paused ? '▶' : 'Ⅱ';
$('pauseBtn').classList.toggle('active', state.paused);
toast(state.paused ? 'Kitchen simulation paused' : 'Kitchen simulation running');
});
$('speedBtn').addEventListener('click', () => {
state.speed = state.speed === 1 ? 2 : state.speed === 2 ? 4 : 1;
$('speedBtn').textContent = `${state.speed}×`;
toast(`Simulation speed: ${state.speed}×`);
});
$('resetBtn').addEventListener('click', () => {
for (const batch of state.batches) dynamicGroup.remove(batch.visual);
state.batches.length = 0;
state.prepQueue.length = 0;
state.ovenQueue.length = 0;
state.prepActive = null;
state.completedBatches = 0;
state.servedPortions = 0;
state.nextId = 1;
for (const oven of state.ovens) {
oven.batch = null;
oven.elapsed = 0;
oven.readyAge = 0;
}
toast('Kitchen reset');
updateUI();
});
window.addEventListener('keydown', event => {
if (event.target instanceof HTMLInputElement || event.target instanceof HTMLTextAreaElement) return;
if (event.code === 'Space') {
event.preventDefault();
$('pauseBtn').click();
}
const recipeKeys = { '1': 'stew', '2': 'bread', '3': 'roast' };
if (recipeKeys[event.key]) {
document.querySelector(`[data-recipe="${recipeKeys[event.key]}"]`).click();
}
});
updateEstimate();
/* --------------------------------------------------------------------------
Camera controls, implemented without external controls
--------------------------------------------------------------------------- */
function updateCamera() {
const horizontal = Math.cos(cameraPitch) * cameraDistance;
camera.position.set(
cameraTarget.x + Math.sin(cameraYaw) * horizontal,
cameraTarget.y + Math.sin(cameraPitch) * cameraDistance,
cameraTarget.z + Math.cos(cameraYaw) * horizontal
);
camera.lookAt(cameraTarget);
}
function updateProjection() {
const aspect = window.innerWidth / window.innerHeight;
const viewHeight = aspect < 1 ? Math.max(18, 24 / aspect) : 18;
camera.left = -viewHeight * aspect / 2;
camera.right = viewHeight * aspect / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.updateProjectionMatrix();
}
let pointerDown = false;
let pointerMoved = false;
let lastPointerX = 0;
let lastPointerY = 0;
let downX = 0;
let downY = 0;
renderer.domElement.addEventListener('pointerdown', event => {
pointerDown = true;
pointerMoved = false;
lastPointerX = downX = event.clientX;
lastPointerY = downY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener('pointermove', event => {
if (!pointerDown) return;
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
if (Math.abs(event.clientX - downX) + Math.abs(event.clientY - downY) > 5) {
pointerMoved = true;
}
if (event.shiftKey) {
const panScale = cameraDistance * 0.00125;
cameraTarget.x -= dx * panScale * Math.cos(cameraYaw);
cameraTarget.z += dx * panScale * Math.sin(cameraYaw);
cameraTarget.z -= dy * panScale * Math.cos(cameraYaw);
cameraTarget.x -= dy * panScale * Math.sin(cameraYaw);
} else {
cameraYaw -= dx * 0.006;
cameraPitch = THREE.MathUtils.clamp(cameraPitch + dy * 0.005, 0.32, 1.16);
}
lastPointerX = event.clientX;
lastPointerY = event.clientY;
updateCamera();
});
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
renderer.domElement.addEventListener('pointerup', event => {
pointerDown = false;
if (!pointerMoved) {
const rect = renderer.domElement.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(ovenPickTargets, false);
if (hits.length) {
const ovenIndex = hits[0].object.userData.ovenIndex;
const oven = state.ovens[ovenIndex];
if (oven.batch?.phase === 'ready') {
unloadOven(ovenIndex, true);
} else if (oven.batch) {
toast(`Oven ${ovenIndex + 1} is still baking`);
} else {
toast(`Oven ${ovenIndex + 1} is available`);
}
}
}
});
renderer.domElement.addEventListener('pointercancel', () => {
pointerDown = false;
});
renderer.domElement.addEventListener('wheel', event => {
event.preventDefault();
cameraDistance = THREE.MathUtils.clamp(
cameraDistance + event.deltaY * 0.012,
17,
40
);
updateCamera();
}, { passive: false });
renderer.domElement.addEventListener('contextmenu', event => event.preventDefault());
renderer.domElement.addEventListener('dblclick', () => {
cameraYaw = 0.72;
cameraPitch = 0.68;
cameraDistance = 28;
cameraTarget.set(0, 1.2, 0);
updateCamera();
});
window.addEventListener('resize', () => {
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
updateProjection();
updateCamera();
});
updateProjection();
updateCamera();
/* --------------------------------------------------------------------------
Main loop
--------------------------------------------------------------------------- */
const clock = new THREE.Clock();
let uiAccumulator = 0;
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
updateSimulation(dt);
updateBatchVisuals(dt);
updateOvenVisuals();
updateChef(dt);
uiAccumulator += dt;
if (uiAccumulator >= 0.1) {
updateUI();
uiAccumulator = 0;
}
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```