Prompt specification
Build or customize the Three.js 3D scene "Dough expansion bowl" 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: Dough expansion bowl
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/dough-expansion-bowl-x0086
Scene Description Prompt:
Show a dough mound expanding inside a transparent bowl as symbolic gas pockets enlarge; retain a marked starting volume so the visible change is easy to compare. Build this with Three.js from cdnjs as a low-poly scene in one self-contained HTML file.
Working Three.js Starter (dough-expansion-bowl-x0086):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Dough Expansion — Gas Pocket Study</title>
<style>
:root {
--ink: #25353a;
--muted: #64747a;
--paper: rgba(250, 248, 242, 0.92);
--line: rgba(45, 65, 70, 0.16);
--accent: #cf7137;
--reference: #496971;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #eeeae2;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.hud {
position: fixed;
inset: 0;
pointer-events: none;
}
.intro {
position: absolute;
top: 24px;
left: 24px;
width: min(355px, calc(100vw - 48px));
padding: 18px 19px 17px;
border: 1px solid var(--line);
border-radius: 16px;
background: var(--paper);
box-shadow: 0 12px 35px rgba(45, 55, 52, 0.09);
backdrop-filter: blur(12px);
}
.eyebrow {
margin-bottom: 7px;
color: var(--accent);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(23px, 3vw, 31px);
font-weight: 750;
letter-spacing: -0.045em;
line-height: 1.05;
}
.description {
margin: 10px 0 15px;
color: var(--muted);
font-size: 13px;
line-height: 1.48;
}
.readout {
display: flex;
align-items: flex-end;
justify-content: space-between;
padding-top: 13px;
border-top: 1px solid var(--line);
}
.volume {
color: var(--ink);
font-size: 31px;
font-weight: 760;
line-height: 1;
letter-spacing: -0.04em;
font-variant-numeric: tabular-nums;
}
.status {
padding-bottom: 3px;
color: var(--muted);
font-size: 11px;
font-weight: 700;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 8px 15px;
margin-top: 14px;
color: var(--muted);
font-size: 10px;
font-weight: 650;
letter-spacing: 0.025em;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 6px;
}
.swatch {
width: 21px;
height: 0;
border-top: 2px solid var(--accent);
}
.swatch.dashed {
border-top-style: dashed;
border-color: var(--reference);
}
.controls {
position: absolute;
right: 24px;
bottom: 24px;
display: flex;
align-items: center;
gap: 10px;
width: min(430px, calc(100vw - 48px));
padding: 12px;
border: 1px solid var(--line);
border-radius: 15px;
background: var(--paper);
box-shadow: 0 12px 35px rgba(45, 55, 52, 0.09);
backdrop-filter: blur(12px);
pointer-events: auto;
}
button {
flex: 0 0 auto;
min-width: 72px;
height: 37px;
padding: 0 13px;
border: 1px solid rgba(37, 53, 58, 0.16);
border-radius: 9px;
background: #fffefa;
color: var(--ink);
font: inherit;
font-size: 12px;
font-weight: 750;
cursor: pointer;
transition:
background 150ms ease,
transform 150ms ease;
}
button:hover {
background: #f1ede4;
transform: translateY(-1px);
}
button.primary {
border-color: var(--ink);
background: var(--ink);
color: #fffdf8;
}
button.primary:hover {
background: #34474c;
}
input[type="range"] {
width: 100%;
height: 24px;
margin: 0;
accent-color: var(--accent);
cursor: pointer;
}
.hint {
position: absolute;
left: 24px;
bottom: 27px;
color: rgba(37, 53, 58, 0.64);
font-size: 11px;
font-weight: 650;
letter-spacing: 0.025em;
}
@media (max-width: 650px) {
.intro {
top: 14px;
left: 14px;
width: calc(100vw - 28px);
padding: 14px 15px;
}
.description {
margin-bottom: 10px;
}
.legend {
display: none;
}
.controls {
right: 14px;
bottom: 14px;
width: calc(100vw - 28px);
}
.hint {
display: none;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Low-poly dough expansion animation"></canvas>
<div class="hud">
<section class="intro">
<div class="eyebrow">Low-poly material study</div>
<h1>Dough under pressure</h1>
<p class="description">
Symbolic gas pockets inflate the mound. The dashed cage and base ring
preserve the original 1.0× starting volume for direct comparison.
</p>
<div class="readout">
<div id="volume" class="volume">1.00×</div>
<div id="status" class="status">marked start</div>
</div>
<div class="legend">
<span><i class="swatch dashed"></i> Starting volume</span>
<span><i class="swatch"></i> Current volume</span>
</div>
</section>
<div class="controls">
<button id="play" class="primary" type="button" aria-pressed="true">
Pause
</button>
<input
id="timeline"
type="range"
min="0"
max="1000"
value="0"
step="1"
aria-label="Expansion timeline"
/>
<button id="replay" type="button">Replay</button>
</div>
<div class="hint">Drag to orbit · Scroll to zoom · Double-click to reset view</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.querySelector("#scene");
const volumeElement = document.querySelector("#volume");
const statusElement = document.querySelector("#status");
const playButton = document.querySelector("#play");
const replayButton = document.querySelector("#replay");
const timeline = document.querySelector("#timeline");
// ---------------------------------------------------------------------
// Renderer and scene
// ---------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance",
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xeeeae2);
scene.fog = new THREE.Fog(0xeeeae2, 13, 28);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
100
);
const hemisphere = new THREE.HemisphereLight(0xfff8e9, 0x8b9a9d, 2.15);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff0d7, 3.15);
keyLight.position.set(4.5, 7.5, 5.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -5;
keyLight.shadow.camera.right = 5;
keyLight.shadow.camera.top = 5;
keyLight.shadow.camera.bottom = -5;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 20;
keyLight.shadow.bias = -0.0005;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xc8e5ea, 1.05);
fillLight.position.set(-5, 3, -4);
scene.add(fillLight);
// ---------------------------------------------------------------------
// Ground
// ---------------------------------------------------------------------
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(30, 30),
new THREE.MeshStandardMaterial({
color: 0xe8e3d9,
roughness: 0.94,
metalness: 0,
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.012;
ground.receiveShadow = true;
scene.add(ground);
const contactShadow = new THREE.Mesh(
new THREE.CircleGeometry(3.05, 48),
new THREE.MeshBasicMaterial({
color: 0x526064,
transparent: true,
opacity: 0.075,
depthWrite: false,
})
);
contactShadow.rotation.x = -Math.PI / 2;
contactShadow.position.y = 0.002;
scene.add(contactShadow);
// ---------------------------------------------------------------------
// Transparent, faceted glass bowl
// ---------------------------------------------------------------------
const bowlProfile = [
new THREE.Vector2(0.0, 0.03),
new THREE.Vector2(1.32, 0.03),
new THREE.Vector2(2.0, 0.08),
new THREE.Vector2(2.34, 0.3),
new THREE.Vector2(2.62, 0.72),
new THREE.Vector2(2.8, 1.32),
new THREE.Vector2(2.9, 2.05),
new THREE.Vector2(2.91, 2.25),
];
const bowlGeometry = new THREE.LatheGeometry(bowlProfile, 24);
const bowl = new THREE.Mesh(
bowlGeometry,
new THREE.MeshPhongMaterial({
color: 0xa9d4d7,
transparent: true,
opacity: 0.17,
side: THREE.DoubleSide,
shininess: 110,
specular: 0xdaf8ff,
depthWrite: false,
flatShading: true,
})
);
bowl.position.y = 0.015;
bowl.renderOrder = 3;
scene.add(bowl);
const bowlFacets = new THREE.Mesh(
bowlGeometry,
new THREE.MeshBasicMaterial({
color: 0x71989d,
wireframe: true,
transparent: true,
opacity: 0.065,
depthWrite: false,
})
);
bowlFacets.position.copy(bowl.position);
bowlFacets.renderOrder = 4;
scene.add(bowlFacets);
const bowlRim = new THREE.Mesh(
new THREE.TorusGeometry(2.91, 0.027, 6, 48),
new THREE.MeshStandardMaterial({
color: 0xaacfd1,
transparent: true,
opacity: 0.68,
roughness: 0.25,
metalness: 0.05,
depthWrite: false,
})
);
bowlRim.rotation.x = Math.PI / 2;
bowlRim.position.y = 2.265;
bowlRim.renderOrder = 4;
scene.add(bowlRim);
// ---------------------------------------------------------------------
// Low-poly dough mound
// ---------------------------------------------------------------------
const DOUGH_RADIUS = 1.5;
const DOUGH_HEIGHT = 1.35;
const DOUGH_BASE_Y = 0.095;
function createMoundGeometry(radius, height, rings = 9, segments = 14) {
const positions = [];
const indices = [];
// Top point.
positions.push(0, height, 0);
// Concentric rings from near the top to the base.
for (let ring = 1; ring <= rings; ring++) {
const t = ring / rings;
const phi = t * Math.PI * 0.5;
const ringRadius =
radius * Math.pow(Math.sin(phi), 0.78);
const ringHeight =
height * Math.pow(Math.cos(phi), 1.18);
for (let segment = 0; segment < segments; segment++) {
const angle = (segment / segments) * Math.PI * 2;
positions.push(
Math.cos(angle) * ringRadius,
ringHeight,
Math.sin(angle) * ringRadius
);
}
}
// Top fan.
for (let segment = 0; segment < segments; segment++) {
const next = (segment + 1) % segments;
indices.push(0, 1 + segment, 1 + next);
}
// Faces between rings.
for (let ring = 0; ring < rings - 1; ring++) {
const currentStart = 1 + ring * segments;
const nextStart = currentStart + segments;
for (let segment = 0; segment < segments; segment++) {
const next = (segment + 1) % segments;
const a = currentStart + segment;
const b = currentStart + next;
const c = nextStart + next;
const d = nextStart + segment;
indices.push(a, b, c, a, c, d);
}
}
// Bottom cap.
const bottomCenter = positions.length / 3;
positions.push(0, 0, 0);
const lastRingStart = 1 + (rings - 1) * segments;
for (let segment = 0; segment < segments; segment++) {
const next = (segment + 1) % segments;
indices.push(
bottomCenter,
lastRingStart + next,
lastRingStart + segment
);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
return geometry;
}
const mound = new THREE.Mesh(
createMoundGeometry(DOUGH_RADIUS, DOUGH_HEIGHT),
new THREE.MeshStandardMaterial({
color: 0xd6a65f,
roughness: 0.88,
metalness: 0,
flatShading: true,
transparent: true,
opacity: 0.9,
side: THREE.DoubleSide,
})
);
mound.position.y = DOUGH_BASE_Y;
mound.castShadow = true;
mound.receiveShadow = true;
mound.renderOrder = 1;
scene.add(mound);
// ---------------------------------------------------------------------
// Symbolic gas pockets
// ---------------------------------------------------------------------
const pocketRoot = new THREE.Group();
pocketRoot.position.y = DOUGH_BASE_Y;
scene.add(pocketRoot);
const pocketSpecifications = [
{ position: [-0.42, 0.3, 0.18], size: 0.25, delay: 0.03 },
{ position: [0.35, 0.38, 0.34], size: 0.28, delay: 0.1 },
{ position: [-0.78, 0.55, -0.12], size: 0.31, delay: 0.17 },
{ position: [0.12, 0.62, 0.62], size: 0.27, delay: 0.24 },
{ position: [0.75, 0.7, 0.05], size: 0.3, delay: 0.31 },
{ position: [-0.28, 0.88, -0.35], size: 0.32, delay: 0.39 },
{ position: [0.34, 1.02, -0.18], size: 0.27, delay: 0.48 },
{ position: [-0.7, 0.95, 0.3], size: 0.3, delay: 0.56 },
{ position: [0.05, 1.18, 0.16], size: 0.24, delay: 0.65 },
];
const pocketGeometry = new THREE.IcosahedronGeometry(1, 1);
const pocketEdges = new THREE.EdgesGeometry(pocketGeometry, 12);
const pockets = [];
pocketSpecifications.forEach((specification, index) => {
const group = new THREE.Group();
group.position.fromArray(specification.position);
const material = new THREE.MeshStandardMaterial({
color: index % 3 === 0 ? 0xffedb0 : 0xe9f2d7,
emissive: 0x9a8150,
emissiveIntensity: 0.13,
roughness: 0.32,
metalness: 0,
transparent: true,
opacity: 0.42,
depthWrite: false,
depthTest: false,
flatShading: true,
});
const bubble = new THREE.Mesh(pocketGeometry, material);
bubble.renderOrder = 6;
group.add(bubble);
const edgeMaterial = new THREE.LineBasicMaterial({
color: 0xfff9d9,
transparent: true,
opacity: 0.64,
depthWrite: false,
depthTest: false,
});
const edges = new THREE.LineSegments(pocketEdges, edgeMaterial);
edges.renderOrder = 7;
group.add(edges);
pocketRoot.add(group);
pockets.push({
group,
material,
edgeMaterial,
size: specification.size,
delay: specification.delay,
});
});
// ---------------------------------------------------------------------
// Persistent starting-volume cage
// ---------------------------------------------------------------------
function profileRadius(t) {
const phi = t * Math.PI * 0.5;
return DOUGH_RADIUS * Math.pow(Math.sin(phi), 0.78);
}
function profileHeight(t) {
const phi = t * Math.PI * 0.5;
return DOUGH_HEIGHT * Math.pow(Math.cos(phi), 1.18);
}
function createDashedLoop(radius, y, material, segments = 36) {
const points = [];
for (let index = 0; index < segments; index++) {
const angle = (index / segments) * Math.PI * 2;
points.push(
new THREE.Vector3(
Math.cos(angle) * radius,
y,
Math.sin(angle) * radius
)
);
}
const geometry = new THREE.BufferGeometry().setFromPoints(points);
const loop = new THREE.LineLoop(geometry, material);
loop.computeLineDistances();
return loop;
}
const referenceMaterial = new THREE.LineDashedMaterial({
color: 0x496971,
transparent: true,
opacity: 0.48,
dashSize: 0.1,
gapSize: 0.065,
depthWrite: false,
depthTest: false,
});
const startRing = createDashedLoop(
DOUGH_RADIUS,
DOUGH_BASE_Y + 0.015,
referenceMaterial
);
startRing.renderOrder = 5;
scene.add(startRing);
// Horizontal contour rings preserve the original mound silhouette.
[0.24, 0.48, 0.72, 0.91].forEach((t) => {
const contour = createDashedLoop(
profileRadius(t),
DOUGH_BASE_Y + profileHeight(t),
referenceMaterial,
28
);
contour.renderOrder = 5;
scene.add(contour);
});
// A few dashed meridians make the starting volume read as a 3D cage.
for (let index = 0; index < 6; index++) {
const angle = (index / 6) * Math.PI * 2;
const points = [];
for (let step = 0; step <= 18; step++) {
const t = 0.06 + (step / 18) * 0.92;
const radius = profileRadius(t);
points.push(
new THREE.Vector3(
Math.cos(angle) * radius,
DOUGH_BASE_Y + profileHeight(t),
Math.sin(angle) * radius
)
);
}
const geometry = new THREE.BufferGeometry().setFromPoints(points);
const meridian = new THREE.Line(geometry, referenceMaterial);
meridian.computeLineDistances();
meridian.renderOrder = 5;
scene.add(meridian);
}
// Height post and top tick for the starting measurement.
const markerAngle = 2.3;
const markerX = Math.cos(markerAngle) * DOUGH_RADIUS;
const markerZ = Math.sin(markerAngle) * DOUGH_RADIUS;
const heightPostGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(markerX, DOUGH_BASE_Y, markerZ),
new THREE.Vector3(
markerX,
DOUGH_BASE_Y + DOUGH_HEIGHT,
markerZ
),
]);
const heightPost = new THREE.Line(heightPostGeometry, referenceMaterial);
heightPost.computeLineDistances();
heightPost.renderOrder = 5;
scene.add(heightPost);
const heightTickGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(markerX - 0.2, DOUGH_BASE_Y + DOUGH_HEIGHT, markerZ),
new THREE.Vector3(markerX + 0.2, DOUGH_BASE_Y + DOUGH_HEIGHT, markerZ),
]);
const heightTick = new THREE.Line(
heightTickGeometry,
new THREE.LineBasicMaterial({
color: 0x496971,
transparent: true,
opacity: 0.62,
depthTest: false,
depthWrite: false,
})
);
heightTick.renderOrder = 5;
scene.add(heightTick);
// Current-volume outline.
const currentRingPoints = [];
for (let index = 0; index < 48; index++) {
const angle = (index / 48) * Math.PI * 2;
currentRingPoints.push(
new THREE.Vector3(
Math.cos(angle) * DOUGH_RADIUS,
DOUGH_BASE_Y + 0.025,
Math.sin(angle) * DOUGH_RADIUS
)
);
}
const currentRingGeometry = new THREE.BufferGeometry().setFromPoints(
currentRingPoints
);
const currentRing = new THREE.LineLoop(
currentRingGeometry,
new THREE.LineBasicMaterial({
color: 0xcf7137,
transparent: true,
opacity: 0.85,
depthWrite: false,
depthTest: false,
})
);
currentRing.renderOrder = 6;
scene.add(currentRing);
// ---------------------------------------------------------------------
// World-space labels drawn with canvas textures
// ---------------------------------------------------------------------
function roundedRectangle(context, x, y, width, height, radius) {
context.beginPath();
context.moveTo(x + radius, y);
context.lineTo(x + width - radius, y);
context.quadraticCurveTo(x + width, y, x + width, y + radius);
context.lineTo(x + width, y + height - radius);
context.quadraticCurveTo(
x + width,
y + height,
x + width - radius,
y + height
);
context.lineTo(x + radius, y + height);
context.quadraticCurveTo(x, y + height, x, y + height - radius);
context.lineTo(x, y + radius);
context.quadraticCurveTo(x, y, x + radius, y);
context.closePath();
}
function createLabel(kicker, value, accent) {
const labelCanvas = document.createElement("canvas");
labelCanvas.width = 512;
labelCanvas.height = 176;
const context = labelCanvas.getContext("2d");
const texture = new THREE.CanvasTexture(labelCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false,
depthTest: false,
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(1.65, 0.57, 1);
sprite.renderOrder = 10;
const label = {
sprite,
canvas: labelCanvas,
context,
texture,
kicker,
value,
accent,
};
paintLabel(label);
return label;
}
function paintLabel(label) {
const context = label.context;
const width = label.canvas.width;
const height = label.canvas.height;
context.clearRect(0, 0, width, height);
roundedRectangle(context, 4, 4, width - 8, height - 8, 24);
context.fillStyle = "rgba(250, 248, 241, 0.94)";
context.fill();
context.lineWidth = 3;
context.strokeStyle = "rgba(45, 65, 70, 0.16)";
context.stroke();
context.fillStyle = label.accent;
roundedRectangle(context, 22, 28, 12, 120, 6);
context.fill();
context.fillStyle = "#64747a";
context.font = "800 25px system-ui, sans-serif";
context.textBaseline = "top";
context.fillText(label.kicker.toUpperCase(), 55, 31);
context.fillStyle = "#25353a";
context.font = "760 60px system-ui, sans-serif";
context.fillText(label.value, 53, 76);
label.texture.needsUpdate = true;
}
const startLabel = createLabel("Start volume", "1.0×", "#496971");
startLabel.sprite.position.set(-1.66, 0.72, 0.95);
scene.add(startLabel.sprite);
const currentLabel = createLabel("Current volume", "1.00×", "#cf7137");
currentLabel.sprite.position.set(1.55, 0.78, 0.72);
scene.add(currentLabel.sprite);
// ---------------------------------------------------------------------
// Animation state
// ---------------------------------------------------------------------
const animationDuration = 6.5;
let progress = 0;
let playing = true;
let previousTime = performance.now();
function clamp(value, minimum, maximum) {
return Math.min(maximum, Math.max(minimum, value));
}
function smoothstep(edge0, edge1, value) {
const amount = clamp((value - edge0) / (edge1 - edge0), 0, 1);
return amount * amount * (3 - 2 * amount);
}
function updateScene(time) {
const expansion = smoothstep(0, 1, progress);
const scaleXZ = 1 + expansion * 0.42;
const scaleY = 1 + expansion * 0.58;
mound.scale.set(scaleXZ, scaleY, scaleXZ);
pocketRoot.scale.set(scaleXZ, scaleY, scaleXZ);
// Current base outline follows the expanding footprint.
const currentPositions = currentRingGeometry.attributes.position;
for (let index = 0; index < currentPositions.count; index++) {
const angle = (index / currentPositions.count) * Math.PI * 2;
currentPositions.setXYZ(
index,
Math.cos(angle) * DOUGH_RADIUS * scaleXZ,
DOUGH_BASE_Y + 0.025,
Math.sin(angle) * DOUGH_RADIUS * scaleXZ
);
}
currentPositions.needsUpdate = true;
// Each gas pocket inflates at a slightly different time.
pockets.forEach((pocket, index) => {
const growth = smoothstep(pocket.delay, 1, progress);
const pulse = 1 + Math.sin(time * 0.0022 + index * 1.7) * 0.025;
const size = pocket.size * (0.1 + growth * 0.9) * pulse;
pocket.group.scale.set(size * 1.08, size * 0.86, size * 0.97);
pocket.material.opacity = 0.28 + growth * 0.5;
pocket.edgeMaterial.opacity = 0.25 + growth * 0.48;
});
// Uniform non-uniform scaling gives the exact symbolic volume factor.
const volume = scaleXZ * scaleXZ * scaleY;
const displayedVolume = volume.toFixed(2) + "×";
volumeElement.textContent = displayedVolume;
if (Math.abs(currentLabel.value !== displayedVolume)) {
currentLabel.value = displayedVolume;
paintLabel(currentLabel);
}
currentLabel.sprite.position.set(
1.55 * scaleXZ,
DOUGH_BASE_Y + DOUGH_HEIGHT * scaleY * 0.67,
0.72 * scaleXZ
);
if (progress < 0.01) {
statusElement.textContent = "marked start";
} else if (progress < 0.995) {
statusElement.textContent = "expanding";
} else {
statusElement.textContent = "fully risen";
}
timeline.value = Math.round(progress * 1000);
}
function syncPlayButton() {
playButton.textContent = playing ? "Pause" : "Play";
playButton.setAttribute("aria-pressed", String(playing));
}
playButton.addEventListener("click", () => {
if (progress >= 1) {
progress = 0;
playing = true;
} else {
playing = !playing;
}
syncPlayButton();
});
replayButton.addEventListener("click", () => {
progress = 0;
playing = true;
syncPlayButton();
});
timeline.addEventListener("input", () => {
progress = Number(timeline.value) / 1000;
playing = false;
syncPlayButton();
});
window.addEventListener("keydown", (event) => {
if (event.code === "Space" && event.target === document.body) {
event.preventDefault();
playButton.click();
}
});
// ---------------------------------------------------------------------
// Custom camera controls: orbit, zoom and reset
// ---------------------------------------------------------------------
const cameraTarget = new THREE.Vector3(0, 0.9, 0);
let cameraRadius = 7.65;
let cameraTheta = 0.72;
let cameraPhi = 1.02;
function updateCamera() {
const horizontalRadius = Math.sin(cameraPhi) * cameraRadius;
camera.position.set(
cameraTarget.x + horizontalRadius * Math.sin(cameraTheta),
cameraTarget.y + Math.cos(cameraPhi) * cameraRadius,
cameraTarget.z + horizontalRadius * Math.cos(cameraTheta)
);
camera.lookAt(cameraTarget);
}
function resetCamera() {
cameraRadius = 7.65;
cameraTheta = 0.72;
cameraPhi = 1.02;
updateCamera();
}
let dragging = false;
let previousPointerX = 0;
let previousPointerY = 0;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - previousPointerX;
const deltaY = event.clientY - previousPointerY;
cameraTheta -= deltaX * 0.006;
cameraPhi = clamp(cameraPhi + deltaY * 0.005, 0.48, 1.38);
previousPointerX = event.clientX;
previousPointerY = event.clientY;
updateCamera();
});
function endDrag(event) {
dragging = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraRadius = clamp(cameraRadius + event.deltaY * 0.006, 5.1, 11.5);
updateCamera();
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetCamera);
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
resetCamera();
syncPlayButton();
// ---------------------------------------------------------------------
// Render loop
// ---------------------------------------------------------------------
function animate(time) {
const delta = Math.min((time - previousTime) / 1000, 0.05);
previousTime = time;
if (playing) {
progress = Math.min(1, progress + delta / animationDuration);
if (progress >= 1) {
playing = false;
syncPlayButton();
}
}
updateScene(time);
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
requestAnimationFrame(animate);
</script>
</body>
</html>
```