Prompt specification
Build or customize the Three.js 3D scene "Single Oven Two Recipes" 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: Single Oven Two Recipes
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/single-oven-two-recipes-x3174
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring opportunity costs of mutually exclusive choices. Show one oven and two dough trays with different baking durations. A timeline advances only the selected batch while the waiting batch remains visibly outside. Stylized solid forms.
Working Three.js Starter (single-oven-two-recipes-x3174):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>One Oven — The Cost of Choice</title>
<style>
:root {
--cream: #f3eee4;
--paper: #fbf8f1;
--ink: #17282e;
--muted: #6e7774;
--orange: #eb6238;
--orange-dark: #c84625;
--green: #2c8068;
--line: #ded8cc;
--shadow: 0 16px 40px rgba(28, 36, 34, 0.13);
}
* {
box-sizing: border-box;
}
html,
body {
margin: 0;
min-height: 100%;
background: var(--cream);
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
.app {
min-height: 100vh;
display: grid;
grid-template-rows: auto 1fr;
}
.topbar {
height: 70px;
padding: 0 28px;
display: flex;
align-items: center;
justify-content: space-between;
border-bottom: 1px solid var(--line);
background: rgba(251, 248, 241, 0.92);
backdrop-filter: blur(12px);
z-index: 20;
}
.brand {
display: flex;
align-items: center;
gap: 12px;
font-size: 13px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.brand-mark {
width: 32px;
height: 32px;
display: grid;
place-items: center;
border-radius: 9px;
background: var(--orange);
box-shadow: 0 6px 16px rgba(235, 98, 56, 0.25);
}
.brand-mark svg {
width: 19px;
height: 19px;
}
.edition {
color: var(--muted);
font-size: 11px;
font-weight: 700;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.workspace {
min-height: 0;
display: grid;
grid-template-columns: minmax(0, 1fr) 390px;
}
.scene-card {
position: relative;
min-width: 0;
min-height: 620px;
overflow: hidden;
background: #eee7da;
isolation: isolate;
}
#stage {
position: absolute;
inset: 0;
}
#stage canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
#stage canvas:active {
cursor: grabbing;
}
.scene-heading {
position: absolute;
top: 27px;
left: 30px;
z-index: 3;
max-width: 380px;
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
color: var(--orange-dark);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.live-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--orange);
box-shadow: 0 0 0 5px rgba(235, 98, 56, 0.12);
}
.scene-heading h2 {
margin: 10px 0 5px;
max-width: 340px;
font-size: clamp(25px, 3vw, 39px);
line-height: 1.02;
letter-spacing: -0.045em;
}
.scene-heading p {
margin: 0;
color: #69716e;
font-size: 13px;
line-height: 1.5;
}
.orbit-hint {
position: absolute;
right: 22px;
top: 28px;
z-index: 3;
padding: 8px 11px;
border: 1px solid rgba(23, 40, 46, 0.12);
border-radius: 999px;
color: #69716e;
background: rgba(251, 248, 241, 0.7);
backdrop-filter: blur(8px);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.04em;
pointer-events: none;
}
.world-label {
position: absolute;
z-index: 4;
min-width: 136px;
padding: 9px 12px;
border-radius: 11px;
box-shadow: var(--shadow);
transform: translate(-50%, -100%);
pointer-events: none;
white-space: nowrap;
transition: opacity 160ms ease;
}
.world-label.active {
color: white;
background: var(--ink);
}
.world-label.waiting {
color: var(--ink);
border: 1px solid rgba(44, 128, 104, 0.18);
background: rgba(251, 248, 241, 0.93);
}
.world-label strong {
display: flex;
align-items: center;
gap: 7px;
font-size: 10px;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.world-label strong::before {
content: "";
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--orange);
}
.world-label.waiting strong::before {
background: var(--green);
}
.world-label span {
display: block;
margin-top: 4px;
font-size: 12px;
font-variant-numeric: tabular-nums;
opacity: 0.76;
}
.transport {
position: absolute;
left: 24px;
right: 24px;
bottom: 22px;
z-index: 6;
display: flex;
align-items: center;
gap: 10px;
padding: 10px;
border: 1px solid rgba(23, 40, 46, 0.12);
border-radius: 16px;
background: rgba(251, 248, 241, 0.88);
box-shadow: var(--shadow);
backdrop-filter: blur(14px);
}
.play-button,
.reset-button,
.speed-button {
border: 0;
cursor: pointer;
transition:
transform 150ms ease,
background 150ms ease,
color 150ms ease;
}
.play-button:hover,
.reset-button:hover,
.speed-button:hover {
transform: translateY(-1px);
}
.play-button {
min-width: 116px;
height: 44px;
border-radius: 11px;
color: white;
background: var(--orange);
font-size: 12px;
font-weight: 800;
}
.play-button:hover {
background: var(--orange-dark);
}
.reset-button {
width: 44px;
height: 44px;
border-radius: 11px;
color: var(--ink);
background: #e9e4d9;
font-size: 21px;
}
.speed-control {
display: flex;
align-items: center;
gap: 5px;
margin-left: auto;
}
.speed-label {
margin-right: 7px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.speed-button {
width: 38px;
height: 34px;
border-radius: 9px;
color: var(--muted);
background: transparent;
font-size: 11px;
font-weight: 800;
}
.speed-button.selected {
color: var(--ink);
background: white;
box-shadow: 0 2px 8px rgba(23, 40, 46, 0.1);
}
.speed-note {
color: var(--muted);
font-size: 9px;
white-space: nowrap;
}
.scene-status {
position: absolute;
left: 27px;
bottom: 100px;
z-index: 5;
max-width: 470px;
padding: 9px 12px;
border-radius: 10px;
color: #4f5c58;
background: rgba(251, 248, 241, 0.77);
font-size: 11px;
font-weight: 650;
backdrop-filter: blur(8px);
pointer-events: none;
}
.panel {
min-height: 0;
padding: 29px 28px 24px;
overflow-y: auto;
border-left: 1px solid var(--line);
background: var(--paper);
}
.panel-topline {
display: flex;
align-items: center;
justify-content: space-between;
color: var(--muted);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.slot-badge {
padding: 6px 8px;
border: 1px solid #ded8cc;
border-radius: 999px;
color: var(--orange-dark);
}
.panel h1 {
margin: 15px 0 12px;
font-size: clamp(34px, 3.2vw, 47px);
line-height: 0.98;
letter-spacing: -0.055em;
}
.intro {
margin: 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.section-label {
margin: 23px 0 10px;
color: var(--muted);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.choices {
display: grid;
gap: 9px;
}
.choice {
width: 100%;
display: flex;
align-items: center;
justify-content: space-between;
gap: 14px;
padding: 14px;
border: 1px solid var(--line);
border-radius: 13px;
color: var(--ink);
background: transparent;
cursor: pointer;
text-align: left;
transition:
border 160ms ease,
background 160ms ease,
transform 160ms ease;
}
.choice:hover {
transform: translateY(-1px);
border-color: #c9c1b3;
}
.choice.selected {
border-color: var(--orange);
background: #fff4ed;
box-shadow: inset 3px 0 0 var(--orange);
}
.choice-name {
display: block;
margin-bottom: 4px;
font-size: 14px;
font-weight: 800;
}
.choice-meta {
display: block;
color: var(--muted);
font-size: 11px;
}
.choice-duration {
flex: 0 0 auto;
padding: 7px 9px;
border-radius: 9px;
color: var(--muted);
background: #eee9df;
font-size: 10px;
font-weight: 850;
letter-spacing: 0.04em;
}
.choice.selected .choice-duration {
color: white;
background: var(--orange);
}
.cost-card {
margin-top: 18px;
padding: 18px;
border-radius: 15px;
color: white;
background: var(--ink);
box-shadow: 0 13px 28px rgba(23, 40, 46, 0.18);
}
.cost-kicker {
color: #b7c1be;
font-size: 9px;
font-weight: 850;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.cost-main {
display: flex;
align-items: baseline;
gap: 9px;
margin: 7px 0 5px;
}
.cost-main strong {
color: #ff8a61;
font-size: 35px;
line-height: 1;
letter-spacing: -0.05em;
}
.cost-main span {
color: #c8d0cd;
font-size: 11px;
}
.cost-card p {
margin: 0;
color: #c2cbc8;
font-size: 11px;
line-height: 1.5;
}
.timeline {
display: grid;
gap: 15px;
}
.timeline-row {
display: grid;
gap: 7px;
}
.timeline-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
font-size: 11px;
font-weight: 750;
}
.timeline-state {
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.timeline-time {
color: var(--muted);
font-size: 10px;
font-variant-numeric: tabular-nums;
white-space: nowrap;
}
.progress-track {
position: relative;
height: 8px;
overflow: hidden;
border-radius: 999px;
background: #e7e1d6;
}
.progress-fill {
width: 0;
height: 100%;
border-radius: inherit;
background: var(--orange);
}
.progress-fill.waiting {
width: 0 !important;
background: repeating-linear-gradient(
135deg,
rgba(44, 128, 104, 0.22) 0,
rgba(44, 128, 104, 0.22) 5px,
rgba(44, 128, 104, 0.08) 5px,
rgba(44, 128, 104, 0.08) 10px
);
}
.footnote {
margin: 18px 0 0;
padding-top: 15px;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 10px;
line-height: 1.55;
}
.footnote strong {
color: var(--ink);
}
@media (max-width: 920px) {
.app {
display: block;
}
.topbar {
height: 62px;
}
.workspace {
display: block;
}
.scene-card {
height: 68vh;
min-height: 510px;
}
.panel {
overflow: visible;
border-top: 1px solid var(--line);
border-left: 0;
}
}
@media (max-width: 560px) {
.topbar {
padding: 0 18px;
}
.edition {
display: none;
}
.scene-card {
height: 72vh;
min-height: 520px;
}
.scene-heading {
top: 20px;
left: 19px;
right: 18px;
}
.scene-heading h2 {
max-width: 250px;
font-size: 28px;
}
.scene-heading p {
max-width: 250px;
}
.orbit-hint {
top: auto;
right: 17px;
bottom: 104px;
}
.transport {
left: 12px;
right: 12px;
bottom: 12px;
flex-wrap: wrap;
}
.speed-control {
width: 100%;
margin-left: 0;
padding-top: 3px;
}
.speed-note {
margin-left: auto;
}
.scene-status {
left: 15px;
right: 15px;
bottom: 114px;
}
.panel {
padding: 24px 19px;
}
}
</style>
</head>
<body>
<div class="app">
<header class="topbar">
<div class="brand">
<span class="brand-mark" aria-hidden="true">
<svg viewBox="0 0 24 24" fill="none">
<path d="M5 17.5h14M7 14h10M9 10.5h6M11 7h2"
stroke="white" stroke-width="2.2"
stroke-linecap="round" />
</svg>
</span>
Choice / Cost
</div>
<div class="edition">Interactive kitchen · Concept 01</div>
</header>
<main class="workspace">
<section class="scene-card" aria-label="Interactive 3D kitchen scene">
<div id="stage"></div>
<div class="scene-heading">
<div class="eyebrow">
<span class="live-dot"></span>
One oven · two trays
</div>
<h2>The oven only has room for one decision.</h2>
<p>Watch the chosen batch bake while the alternative waits outside.</p>
</div>
<div class="orbit-hint">Drag to orbit · Scroll to zoom</div>
<div id="activeLabel" class="world-label active">
<strong id="activeLabelName">Baking</strong>
<span id="activeLabelTime">00:00 / 18:00</span>
</div>
<div id="waitingLabel" class="world-label waiting">
<strong id="waitingLabelName">Waiting outside</strong>
<span id="waitingLabelTime">00:00 / 09:00</span>
</div>
<div id="sceneStatus" class="scene-status" aria-live="polite">
The sourdough occupies the oven. The cinnamon knot stays at 00:00.
</div>
<div class="transport" aria-label="Simulation controls">
<button id="playButton" class="play-button" type="button">Ⅱ Pause</button>
<button id="resetButton" class="reset-button" type="button"
aria-label="Reset timeline" title="Reset timeline">↺</button>
<div class="speed-control" aria-label="Simulation speed">
<span class="speed-label">Speed</span>
<button class="speed-button selected" type="button" data-speed="1">1×</button>
<button class="speed-button" type="button" data-speed="4">4×</button>
<button class="speed-button" type="button" data-speed="12">12×</button>
<span class="speed-note">1 sec = 1 min</span>
</div>
</div>
</section>
<aside class="panel">
<div class="panel-topline">
<span>Opportunity cost</span>
<span class="slot-badge">1 oven slot</span>
</div>
<h1>One oven.<br />Two good reasons to wait.</h1>
<p class="intro">
Choose the batch that enters the oven. The other stays visibly
outside, and its production clock never advances.
</p>
<div class="section-label">Choose the first batch</div>
<div class="choices">
<button class="choice selected" type="button"
data-batch="sourdough" aria-pressed="true">
<span>
<span class="choice-name">Sourdough boule</span>
<span class="choice-meta">230°C · slow, crisp bake</span>
</span>
<span class="choice-duration">18 min</span>
</button>
<button class="choice" type="button"
data-batch="knot" aria-pressed="false">
<span>
<span class="choice-name">Cinnamon knot</span>
<span class="choice-meta">190°C · quick breakfast bake</span>
</span>
<span class="choice-duration">9 min</span>
</button>
</div>
<div class="cost-card">
<div class="cost-kicker">What the other batch loses</div>
<div class="cost-main">
<strong id="costValue">18 min</strong>
<span>of oven access</span>
</div>
<p id="costCopy">
The cinnamon knot cannot bake while the sourdough occupies the oven.
</p>
</div>
<div class="section-label">Production timeline</div>
<div class="timeline">
<div class="timeline-row">
<div class="timeline-head">
<span id="activeTimelineName">Sourdough boule</span>
<span id="activeTimelineState" class="timeline-state">Baking</span>
<span id="activeTimelineTime" class="timeline-time">00:00 / 18:00</span>
</div>
<div class="progress-track">
<div id="activeFill" class="progress-fill"></div>
</div>
</div>
<div class="timeline-row">
<div class="timeline-head">
<span id="waitingTimelineName">Cinnamon knot</span>
<span class="timeline-state" style="color: var(--green)">Waiting</span>
<span id="waitingTimelineTime" class="timeline-time">00:00 / 09:00</span>
</div>
<div class="progress-track">
<div class="progress-fill waiting"></div>
</div>
</div>
</div>
<p class="footnote">
<strong>Try the trade-off:</strong> switch batches while the oven is
running. The experiment restarts so the two choices remain directly
comparable. Keyboard: Space to pause, 1 and 2 to switch.
</p>
</aside>
</main>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const stage = document.getElementById("stage");
const scene = new THREE.Scene();
scene.background = new THREE.Color("#eee7da");
scene.fog = new THREE.Fog("#eee7da", 15, 27);
const camera = new THREE.PerspectiveCamera(37, 1, 0.1, 100);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.15;
stage.appendChild(renderer.domElement);
renderer.domElement.setAttribute(
"aria-label",
"A 3D kitchen with one oven, one baking dough tray, and one waiting dough tray"
);
const hemi = new THREE.HemisphereLight(0xfff7e7, 0x718078, 2.25);
scene.add(hemi);
const keyLight = new THREE.DirectionalLight(0xffffff, 3.2);
keyLight.position.set(4, 8, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -7;
keyLight.shadow.camera.right = 7;
keyLight.shadow.camera.top = 7;
keyLight.shadow.camera.bottom = -7;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 25;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xb8d7d2, 1.1);
fillLight.position.set(-6, 4, 2);
scene.add(fillLight);
const material = (color, roughness = 0.8, metalness = 0) =>
new THREE.MeshStandardMaterial({ color, roughness, metalness });
const mats = {
ground: material("#d9d5ca", 0.96),
oven: material("#28383e", 0.68, 0.08),
ovenSide: material("#31444a", 0.62, 0.08),
ovenTop: material("#3c5055", 0.58, 0.12),
cavity: material("#11191b", 0.95),
door: material("#203036", 0.66, 0.12),
metal: material("#738185", 0.48, 0.45),
blackMetal: material("#263136", 0.5, 0.35),
wood: material("#bd8a58", 0.9),
woodEdge: material("#9d6e45", 0.92),
tray: material("#52656a", 0.66, 0.22),
trayRim: material("#34474c", 0.58, 0.25),
mat: material("#8fa79b", 0.96),
flour: material("#f5ecd9", 1),
score: material("#a77748", 0.95),
screen: material("#9ed5c4", 0.45),
indicator: new THREE.MeshStandardMaterial({
color: "#ff7549",
emissive: "#ff4b25",
emissiveIntensity: 1.5,
roughness: 0.45
})
};
function box(parent, w, h, d, mat, x = 0, y = 0, z = 0) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(w, h, d), mat);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinder(
parent,
radius,
depth,
mat,
x = 0,
y = 0,
z = 0,
rotationX = Math.PI / 2
) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, depth, 32),
mat
);
mesh.position.set(x, y, z);
mesh.rotation.x = rotationX;
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// Ground
const ground = new THREE.Mesh(new THREE.PlaneGeometry(40, 40), mats.ground);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.015;
ground.receiveShadow = true;
scene.add(ground);
// Oven
const oven = new THREE.Group();
oven.position.x = -1.55;
scene.add(oven);
box(oven, 2.42, 0.52, 2.0, mats.oven, 0, 0.29, 0);
box(oven, 0.2, 1.88, 2.0, mats.oven, -1.11, 1.48, 0);
box(oven, 0.2, 1.88, 2.0, mats.ovenSide, 1.11, 1.48, 0);
box(oven, 2.42, 0.2, 2.0, mats.ovenTop, 0, 2.46, 0);
box(oven, 2.22, 1.8, 0.14, mats.cavity, 0, 1.49, -0.91);
box(oven, 2.18, 0.14, 1.88, mats.blackMetal, 0, 0.59, 0);
// Front frame and controls
box(oven, 2.43, 0.28, 0.22, mats.ovenTop, 0, 2.27, 0.96);
box(oven, 0.17, 1.55, 0.2, mats.ovenTop, -1.08, 1.47, 0.96);
box(oven, 0.17, 1.55, 0.2, mats.ovenTop, 1.08, 1.47, 0.96);
box(oven, 1.85, 0.08, 0.1, mats.metal, 0, 2.14, 1.1);
cylinder(oven, 0.115, 0.11, mats.metal, 0.56, 2.49, 1.03);
cylinder(oven, 0.115, 0.11, mats.metal, 0.84, 2.49, 1.03);
cylinder(oven, 0.115, 0.11, mats.inkKnob || mats.blackMetal, 0.7, 2.49, 1.09);
box(oven, 0.43, 0.17, 0.05, mats.screen, -0.55, 2.49, 1.045);
box(oven, 0.12, 0.035, 0.025, mats.indicator, -0.55, 2.49, 1.08);
// Open oven door
const door = box(oven, 2.04, 0.13, 1.28, mats.door, 0, 0.43, 1.39);
door.rotation.x = -0.035;
box(oven, 1.77, 0.035, 0.95, mats.cavity, 0, 0.515, 1.37);
box(oven, 1.84, 0.09, 0.1, mats.metal, 0, 0.58, 1.95);
// Feet
for (const x of [-0.92, 0.92]) {
for (const z of [-0.72, 0.72]) {
box(oven, 0.2, 0.13, 0.2, mats.blackMetal, x, 0.04, z);
}
}
// Glowing rear heating element
const heatingCurve = new THREE.CatmullRomCurve3([
new THREE.Vector3(-0.7, 0.92, -0.79),
new THREE.Vector3(-0.7, 1.28, -0.79),
new THREE.Vector3(-0.3, 1.38, -0.79),
new THREE.Vector3(0.3, 1.38, -0.79),
new THREE.Vector3(0.7, 1.28, -0.79),
new THREE.Vector3(0.7, 0.92, -0.79)
]);
const heatingMaterial = new THREE.MeshStandardMaterial({
color: "#d85a32",
emissive: "#ff4d20",
emissiveIntensity: 1.2,
roughness: 0.45
});
const heatingElement = new THREE.Mesh(
new THREE.TubeGeometry(heatingCurve, 48, 0.035, 8, false),
heatingMaterial
);
oven.add(heatingElement);
const ovenLight = new THREE.PointLight("#ff884d", 7, 4.2, 2);
ovenLight.position.set(0, 1.25, -0.35);
oven.add(ovenLight);
// Counter where the waiting tray remains outside
const counter = new THREE.Group();
counter.position.x = 2.15;
scene.add(counter);
box(counter, 2.45, 0.16, 1.65, mats.wood, 0, 1.0, 0);
box(counter, 2.49, 0.08, 1.69, mats.woodEdge, 0, 0.89, 0);
box(counter, 2.12, 0.1, 1.28, mats.woodEdge, 0, 0.43, 0);
for (const x of [-1.03, 1.03]) {
for (const z of [-0.59, 0.59]) {
box(counter, 0.16, 0.86, 0.16, mats.woodEdge, x, 0.44, z);
}
}
box(counter, 1.76, 0.025, 1.16, mats.mat, 0, 1.093, 0.04);
// Dough and tray factories
function createTray() {
const tray = new THREE.Group();
box(tray, 1.5, 0.08, 0.95, mats.tray, 0, 0, 0);
box(tray, 1.5, 0.12, 0.055, mats.trayRim, 0, 0.075, -0.448);
box(tray, 1.5, 0.12, 0.055, mats.trayRim, 0, 0.075, 0.448);
box(tray, 0.055, 0.12, 0.84, mats.trayRim, -0.722, 0.075, 0);
box(tray, 0.055, 0.12, 0.84, mats.trayRim, 0.722, 0.075, 0);
return tray;
}
function createSourdough() {
const food = new THREE.Group();
const doughMaterial = new THREE.MeshStandardMaterial({
color: "#ead3a4",
roughness: 0.96
});
const body = new THREE.Mesh(
new THREE.SphereGeometry(0.5, 32, 20),
doughMaterial
);
body.scale.set(1.22, 0.56, 0.74);
body.position.y = 0.31;
body.castShadow = true;
body.receiveShadow = true;
food.add(body);
for (const [x, angle] of [[-0.3, -0.44], [0, -0.38], [0.3, -0.32]]) {
const score = box(
food,
0.026,
0.022,
0.48,
mats.score,
x,
0.535,
0
);
score.rotation.y = angle;
}
const flourPositions = [
[-0.42, 0.53, -0.15],
[-0.08, 0.57, 0.22],
[0.32, 0.53, -0.2],
[0.49, 0.46, 0.13]
];
for (const [x, y, z] of flourPositions) {
const flake = new THREE.Mesh(
new THREE.SphereGeometry(0.045, 10, 8),
mats.flour
);
flake.scale.set(1.3, 0.35, 1);
flake.position.set(x, y, z);
food.add(flake);
}
return {
food,
material: doughMaterial,
raw: new THREE.Color("#ead3a4"),
baked: new THREE.Color("#a95628")
};
}
function createKnot() {
const food = new THREE.Group();
const doughMaterial = new THREE.MeshStandardMaterial({
color: "#efd8a4",
roughness: 0.97
});
const points = [];
const turns = 3.7;
const count = 110;
for (let i = 0; i < count; i++) {
const t = i / (count - 1);
const angle = t * Math.PI * 2 * turns;
const radius = 0.35 * (1 - t * 0.72);
points.push(
new THREE.Vector3(
Math.cos(angle) * radius,
0.25 + Math.sin(t * Math.PI * 3) * 0.018,
Math.sin(angle) * radius * 0.78
)
);
}
const curve = new THREE.CatmullRomCurve3(points);
const knot = new THREE.Mesh(
new THREE.TubeGeometry(curve, 120, 0.115, 12, false),
doughMaterial
);
knot.castShadow = true;
knot.receiveShadow = true;
food.add(knot);
const center = new THREE.Mesh(
new THREE.SphereGeometry(0.17, 20, 14),
doughMaterial
);
center.scale.set(1, 0.62, 0.9);
center.position.y = 0.25;
center.castShadow = true;
food.add(center);
return {
food,
material: doughMaterial,
raw: new THREE.Color("#efd8a4"),
baked: new THREE.Color("#c77935")
};
}
const batches = {
sourdough: {
id: "sourdough",
name: "Sourdough boule",
duration: 18,
root: new THREE.Group(),
dough: createSourdough(),
target: new THREE.Vector3()
},
knot: {
id: "knot",
name: "Cinnamon knot",
duration: 9,
root: new THREE.Group(),
dough: createKnot(),
target: new THREE.Vector3()
}
};
for (const batch of Object.values(batches)) {
const tray = createTray();
tray.add(batch.dough.food);
batch.root.add(tray);
scene.add(batch.root);
}
const ovenPosition = new THREE.Vector3(-1.55, 0.7, 0.02);
const outsidePosition = new THREE.Vector3(2.15, 1.13, 0.06);
batches.sourdough.root.position.copy(ovenPosition);
batches.knot.root.position.copy(outsidePosition);
let selectedId = "sourdough";
let elapsed = 0;
let speed = 1;
let playing = true;
function updateBatchTargets() {
for (const batch of Object.values(batches)) {
batch.target.copy(
batch.id === selectedId ? ovenPosition : outsidePosition
);
}
}
updateBatchTargets();
// Direct camera controls: no examples/addons are used.
const cameraState = {
yaw: 0.34,
pitch: 0.48,
radius: 12.8,
target: new THREE.Vector3(0.25, 1.18, 0)
};
function updateCamera() {
const aspect = camera.aspect;
const fit = aspect < 0.9 ? 1.18 : 1;
camera.position.set(
cameraState.target.x +
cameraState.radius * fit *
Math.sin(cameraState.yaw) *
Math.cos(cameraState.pitch),
cameraState.target.y +
cameraState.radius * fit * Math.sin(cameraState.pitch),
cameraState.target.z +
cameraState.radius * fit *
Math.cos(cameraState.yaw) *
Math.cos(cameraState.pitch)
);
camera.lookAt(cameraState.target);
}
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
cameraState.yaw -= dx * 0.005;
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch + dy * 0.004,
0.24,
0.78
);
pointerX = event.clientX;
pointerY = event.clientY;
});
renderer.domElement.addEventListener("pointerup", (event) => {
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
});
renderer.domElement.addEventListener("pointercancel", () => {
dragging = false;
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.008,
8.4,
17
);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", () => {
cameraState.yaw = 0.34;
cameraState.pitch = 0.48;
cameraState.radius = 12.8;
});
// UI references
const playButton = document.getElementById("playButton");
const resetButton = document.getElementById("resetButton");
const sceneStatus = document.getElementById("sceneStatus");
const activeLabelName = document.getElementById("activeLabelName");
const activeLabelTime = document.getElementById("activeLabelTime");
const waitingLabelName = document.getElementById("waitingLabelName");
const waitingLabelTime = document.getElementById("waitingLabelTime");
const activeTimelineName = document.getElementById("activeTimelineName");
const activeTimelineState = document.getElementById("activeTimelineState");
const activeTimelineTime = document.getElementById("activeTimelineTime");
const waitingTimelineName = document.getElementById("waitingTimelineName");
const waitingTimelineTime = document.getElementById("waitingTimelineTime");
const activeFill = document.getElementById("activeFill");
const costValue = document.getElementById("costValue");
const costCopy = document.getElementById("costCopy");
const choiceButtons = [...document.querySelectorAll(".choice")];
const speedButtons = [...document.querySelectorAll(".speed-button")];
function formatTime(minutes) {
const totalSeconds = Math.floor(minutes * 60 + 0.0001);
const mins = Math.floor(totalSeconds / 60);
const secs = totalSeconds % 60;
return `${String(mins).padStart(2, "0")}:${String(secs).padStart(2, "0")}`;
}
function announce(message) {
sceneStatus.textContent = message;
}
function selectBatch(id) {
if (id === selectedId && elapsed < batches[id].duration) return;
selectedId = id;
elapsed = 0;
playing = true;
updateBatchTargets();
const selected = batches[id];
const waiting = Object.values(batches).find((batch) => batch.id !== id);
announce(
`The ${selected.name.toLowerCase()} enters the oven. ` +
`The ${waiting.name.toLowerCase()} stays outside at 00:00.`
);
updateUI();
}
choiceButtons.forEach((button) => {
button.addEventListener("click", () => {
selectBatch(button.dataset.batch);
});
});
speedButtons.forEach((button) => {
button.addEventListener("click", () => {
speed = Number(button.dataset.speed);
speedButtons.forEach((item) => {
item.classList.toggle("selected", item === button);
});
});
});
playButton.addEventListener("click", () => {
const selected = batches[selectedId];
if (elapsed >= selected.duration) {
elapsed = 0;
playing = true;
announce(
`A fresh ${selected.name.toLowerCase()} enters the oven. ` +
`The alternative remains unbaked.`
);
} else {
playing = !playing;
announce(
playing
? `The ${selected.name.toLowerCase()} resumes baking.`
: `The timeline is paused. The waiting tray remains at 00:00.`
);
}
updateUI();
});
resetButton.addEventListener("click", () => {
elapsed = 0;
playing = false;
announce("The timeline is reset. Both choices are ready to compare again.");
updateUI();
});
window.addEventListener("keydown", (event) => {
if (event.target instanceof HTMLButtonElement) return;
if (event.code === "Space") {
event.preventDefault();
playButton.click();
}
if (event.key === "1") selectBatch("sourdough");
if (event.key === "2") selectBatch("knot");
});
function updateUI() {
const selected = batches[selectedId];
const waiting = Object.values(batches).find((batch) => batch.id !== id(selected));
const progress = elapsed / selected.duration;
choiceButtons.forEach((button) => {
const active = button.dataset.batch === selectedId;
button.classList.toggle("selected", active);
button.setAttribute("aria-pressed", String(active));
});
activeLabelName.textContent = "Baking";
activeLabelTime.textContent =
`${formatTime(elapsed)} / ${formatTime(selected.duration)}`;
waitingLabelName.textContent = `${waiting.name} · waiting`;
waitingLabelTime.textContent =
`00:00 / ${formatTime(waiting.duration)}`;
activeTimelineName.textContent = selected.name;
activeTimelineState.textContent =
elapsed >= selected.duration ? "Ready" : playing ? "Baking" : "Paused";
activeTimelineTime.textContent =
`${formatTime(elapsed)} / ${formatTime(selected.duration)}`;
waitingTimelineName.textContent = waiting.name;
waitingTimelineTime.textContent =
`00:00 / ${formatTime(waiting.duration)}`;
activeFill.style.width = `${Math.min(progress * 100, 100)}%`;
costValue.textContent = `${selected.duration} min`;
costCopy.textContent =
`The ${waiting.name.toLowerCase()} cannot bake while the ` +
`${selected.name.toLowerCase()} occupies the oven.`;
playButton.textContent =
elapsed >= selected.duration
? "▶ Bake again"
: playing
? "Ⅱ Pause"
: "▶ Start bake";
}
// Keeps the reference to the selected batch clear without relying on IDs.
function id(batch) {
return batch.id;
}
function resize() {
const rect = stage.getBoundingClientRect();
renderer.setSize(rect.width, rect.height, false);
camera.aspect = rect.width / Math.max(rect.height, 1);
camera.updateProjectionMatrix();
updateCamera();
}
const resizeObserver = new ResizeObserver(resize);
resizeObserver.observe(stage);
resize();
const clock = new THREE.Clock();
const projected = new THREE.Vector3();
function placeWorldLabel(element, worldPosition) {
projected.copy(worldPosition);
projected.y += 0.92;
projected.project(camera);
const rect = stage.getBoundingClientRect();
const x = (projected.x * 0.5 + 0.5) * rect.width;
const y = (-projected.y * 0.5 + 0.5) * rect.height;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
element.style.opacity = projected.z > 1 ? "0" : "1";
}
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
const selected = batches[selectedId];
if (playing && elapsed < selected.duration) {
elapsed = Math.min(selected.duration, elapsed + dt * speed);
if (elapsed >= selected.duration) {
playing = false;
announce(
`The ${selected.name.toLowerCase()} is ready. ` +
`The alternative never entered the oven and stayed at 00:00.`
);
}
}
const progress = elapsed / selected.duration;
for (const batch of Object.values(batches)) {
const isActive = batch.id === selectedId;
const batchProgress = isActive ? progress : 0;
batch.root.position.lerp(
batch.target,
1 - Math.exp(-dt * 7)
);
batch.dough.material.color
.copy(batch.dough.raw)
.lerp(batch.dough.baked, batchProgress);
batch.dough.food.scale.set(
1 + batchProgress * 0.045,
1 + batchProgress * 0.11,
1 + batchProgress * 0.035
);
}
const heatPulse = playing ? Math.sin(clock.elapsedTime * 8) * 0.35 : 0;
heatingMaterial.emissiveIntensity =
0.7 + progress * 2.1 + Math.max(heatPulse, 0);
ovenLight.intensity = 3 + progress * 7 + Math.max(heatPulse, 0);
updateCamera();
renderer.render(scene, camera);
placeWorldLabel(
document.getElementById("activeLabel"),
batches[selectedId].root.position
);
const waitingId = selectedId === "sourdough" ? "knot" : "sourdough";
placeWorldLabel(
document.getElementById("waitingLabel"),
batches[waitingId].root.position
);
updateUI();
}
updateUI();
animate();
</script>
</body>
</html>
```