Prompt specification
Build or customize the Three.js 3D scene "Helpers complete separate preparations" 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: Helpers complete separate preparations
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/helpers-complete-separate-preparations-x3846
Scene Description Prompt:
Please use Three.js from cdnjs for a low-poly scene based on this idea: helpers complete separate preparations. Animate one helper placing cups while another hangs a banner; both tasks finish before the cake arrives, with distinct movement paths avoiding collisions. Return one self-contained HTML file.
Working Three.js Starter (helpers-complete-separate-preparations-x3846):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Party Preparations — Three.js Low-Poly Scene</title>
<style>
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dcecef;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: #263238;
}
canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
canvas:active { cursor: grabbing; }
.hud {
position: fixed;
inset: 0;
pointer-events: none;
}
.header {
position: absolute;
top: 22px;
left: 24px;
max-width: 470px;
padding: 17px 20px 16px;
border: 1px solid rgba(255, 255, 255, 0.72);
border-radius: 18px;
background: rgba(255, 255, 255, 0.84);
box-shadow: 0 12px 35px rgba(47, 72, 77, 0.14);
backdrop-filter: blur(12px);
}
.eyebrow {
margin-bottom: 4px;
color: #60777b;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
h1 {
margin: 0;
color: #1f3438;
font-size: clamp(23px, 3vw, 34px);
line-height: 1.05;
letter-spacing: -0.04em;
}
.subtitle {
margin: 8px 0 0;
color: #5d7276;
font-size: 13px;
line-height: 1.45;
}
.tasks {
position: absolute;
top: 22px;
right: 24px;
display: grid;
gap: 9px;
width: min(290px, calc(100vw - 48px));
}
.task {
display: grid;
grid-template-columns: 12px 1fr auto;
align-items: center;
gap: 10px;
min-height: 56px;
padding: 10px 12px;
border: 1px solid rgba(255, 255, 255, 0.75);
border-radius: 14px;
background: rgba(255, 255, 255, 0.84);
box-shadow: 0 8px 24px rgba(47, 72, 77, 0.11);
backdrop-filter: blur(10px);
}
.task .dot {
width: 10px;
height: 10px;
border-radius: 50%;
background: #90a4a8;
box-shadow: 0 0 0 4px rgba(144, 164, 168, 0.13);
}
.task[data-task="cups"] .dot { background: #2a9d8f; }
.task[data-task="banner"] .dot { background: #e76f51; }
.task[data-task="cake"] .dot { background: #e9c46a; }
.task strong {
display: block;
font-size: 13px;
line-height: 1.2;
}
.task .state {
justify-self: end;
padding: 5px 8px;
border-radius: 999px;
background: #edf1f1;
color: #607174;
font-size: 10px;
font-weight: 800;
white-space: nowrap;
}
.task[data-state="active"] .state {
background: #fff2cc;
color: #8a6414;
}
.task[data-state="done"] .state {
background: #dff3eb;
color: #237565;
}
.bottom {
position: absolute;
right: 24px;
bottom: 22px;
left: 24px;
display: grid;
grid-template-columns: auto minmax(160px, 1fr) auto;
align-items: center;
gap: 14px;
max-width: 940px;
margin: 0 auto;
padding: 12px 14px;
border: 1px solid rgba(255, 255, 255, 0.75);
border-radius: 17px;
background: rgba(255, 255, 255, 0.84);
box-shadow: 0 12px 35px rgba(47, 72, 77, 0.13);
backdrop-filter: blur(12px);
pointer-events: auto;
}
.buttons {
display: flex;
gap: 7px;
}
button {
border: 0;
border-radius: 10px;
padding: 9px 12px;
background: #29484d;
color: white;
font: inherit;
font-size: 12px;
font-weight: 750;
cursor: pointer;
transition: transform 0.15s ease, background 0.15s ease;
}
button:hover { background: #1e393d; }
button:active { transform: translateY(1px); }
.timeline {
position: relative;
height: 9px;
overflow: hidden;
border-radius: 999px;
background: #dce5e6;
}
.timeline-fill {
width: 0;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, #2a9d8f, #e76f51 52%, #e9c46a);
transition: width 0.05s linear;
}
.hint {
color: #6b7c7f;
font-size: 11px;
white-space: nowrap;
}
@media (max-width: 760px) {
.header {
top: 12px;
left: 12px;
right: 12px;
max-width: none;
padding: 13px 15px;
}
.subtitle { display: none; }
.tasks {
top: 103px;
right: 12px;
width: 220px;
}
.task {
min-height: 44px;
padding: 7px 9px;
}
.task strong { font-size: 11px; }
.task .state { font-size: 9px; padding: 4px 6px; }
.bottom {
right: 12px;
bottom: 12px;
left: 12px;
grid-template-columns: auto 1fr;
}
.hint { display: none; }
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Animated low-poly party preparation scene"></canvas>
<div class="hud">
<section class="header">
<div class="eyebrow">Low-poly event timeline</div>
<h1>Party Preparations</h1>
<p class="subtitle">
Two helpers work on separate routes. Cups and banner are finished before the cake arrives.
</p>
</section>
<section class="tasks" aria-live="polite">
<div class="task" data-task="cups" data-state="active">
<span class="dot"></span>
<strong>Cup station</strong>
<span class="state">Gathering cups</span>
</div>
<div class="task" data-task="banner" data-state="active">
<span class="dot"></span>
<strong>Banner frame</strong>
<span class="state">Taking banner</span>
</div>
<div class="task" data-task="cake" data-state="waiting">
<span class="dot"></span>
<strong>Cake delivery</strong>
<span class="state">Waiting backstage</span>
</div>
</section>
<section class="bottom">
<div class="buttons">
<button id="play" type="button">Pause</button>
<button id="replay" type="button">Replay</button>
</div>
<div class="timeline" aria-label="Animation progress">
<div class="timeline-fill" id="progress"></div>
</div>
<div class="hint">Drag to orbit · Scroll to zoom</div>
</section>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ---------------------------------------------------------------------
// Renderer and scene
// ---------------------------------------------------------------------
const canvas = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false
});
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.08;
const scene = new THREE.Scene();
scene.background = new THREE.Color("#dcecef");
scene.fog = new THREE.Fog("#dcecef", 25, 42);
const camera = new THREE.OrthographicCamera(-10, 10, 6, -6, 0.1, 100);
const cameraTarget = new THREE.Vector3(0, 1.05, -0.25);
let cameraYaw = 0.58;
let cameraPitch = 0.68;
let cameraZoom = 1;
function updateCamera() {
const radius = 19;
camera.position.set(
cameraTarget.x + Math.sin(cameraYaw) * Math.cos(cameraPitch) * radius,
cameraTarget.y + Math.sin(cameraPitch) * radius,
cameraTarget.z + Math.cos(cameraYaw) * Math.cos(cameraPitch) * radius
);
camera.lookAt(cameraTarget);
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const viewHeight = Math.max(11.8, 17 / aspect) / cameraZoom;
camera.left = (-viewHeight * aspect) / 2;
camera.right = (viewHeight * aspect) / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.updateProjectionMatrix();
renderer.setSize(width, height, false);
updateCamera();
}
window.addEventListener("resize", resize);
resize();
const hemisphere = new THREE.HemisphereLight("#fff9e8", "#78969a", 2.25);
scene.add(hemisphere);
const sunlight = new THREE.DirectionalLight("#fff2d7", 3.25);
sunlight.position.set(-4, 11, 8);
sunlight.castShadow = true;
sunlight.shadow.mapSize.set(2048, 2048);
sunlight.shadow.camera.left = -10;
sunlight.shadow.camera.right = 10;
sunlight.shadow.camera.top = 10;
sunlight.shadow.camera.bottom = -10;
sunlight.shadow.camera.near = 1;
sunlight.shadow.camera.far = 30;
sunlight.shadow.bias = -0.0005;
scene.add(sunlight);
const fillLight = new THREE.DirectionalLight("#b8dfe5", 1.15);
fillLight.position.set(8, 5, -5);
scene.add(fillLight);
// ---------------------------------------------------------------------
// Small geometry/material helpers
// ---------------------------------------------------------------------
function material(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.78,
metalness: 0,
flatShading: true,
...options
});
}
const M = {
floor: material("#eadbc2"),
floorEdge: material("#cbb998"),
wall: material("#f5e6d2"),
sideWall: material("#cbdedb"),
trim: material("#fff7e8"),
wood: material("#b98554"),
darkWood: material("#765038"),
teal: material("#2a9d8f"),
tealDark: material("#20766c"),
coral: material("#e76f51"),
cream: material("#fff3dd"),
yellow: material("#e9c46a"),
pink: material("#ef8fa3"),
frosting: material("#fff4e2"),
dark: material("#263238"),
green: material("#52796f"),
leaf: material("#6a994e")
};
function box(w, h, d, mat, x, y, z, parent = scene) {
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(rt, rb, h, segments, mat, x, y, z, parent = scene) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(rt, rb, h, segments),
mat
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function sphere(radius, width, height, mat, x, y, z, parent = scene) {
const mesh = new THREE.Mesh(
new THREE.SphereGeometry(radius, width, height),
mat
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
parent.add(mesh);
return mesh;
}
function torus(radius, tube, radial, tubular, mat, x, y, z, parent = scene) {
const mesh = new THREE.Mesh(
new THREE.TorusGeometry(radius, tube, radial, tubular),
mat
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
parent.add(mesh);
return mesh;
}
const clamp = (value, min = 0, max = 1) =>
Math.max(min, Math.min(max, value));
const smooth = value => {
const x = clamp(value);
return x * x * (3 - 2 * x);
};
const lerp = (a, b, amount) => a + (b - a) * amount;
function angleLerp(a, b, amount) {
let difference = (b - a + Math.PI) % (Math.PI * 2) - Math.PI;
if (difference < -Math.PI) difference += Math.PI * 2;
return a + difference * amount;
}
// ---------------------------------------------------------------------
// Room
// ---------------------------------------------------------------------
box(14, 0.25, 9, M.floorEdge, 0, -0.15, 0);
box(13.85, 0.06, 8.85, M.floor, 0, -0.015, 0);
// Back wall with a central delivery opening.
box(5.8, 4.2, 0.18, M.wall, -4.1, 2.1, -4.35);
box(5.8, 4.2, 0.18, M.wall, 4.1, 2.1, -4.35);
box(0.18, 4.2, 9, M.sideWall, -7, 2.1, 0);
box(5.8, 0.13, 0.08, M.trim, -4.1, 0.08, -4.22);
box(5.8, 0.13, 0.08, M.trim, 4.1, 0.08, -4.22);
box(0.08, 0.13, 9, M.trim, -6.86, 0.08, 0);
// Doorway trim.
box(0.16, 3.7, 0.2, M.tealDark, -1.25, 1.85, -4.25);
box(0.16, 3.7, 0.2, M.tealDark, 1.25, 1.85, -4.25);
box(2.65, 0.16, 0.2, M.tealDark, 0, 3.68, -4.25);
// A short backstage aisle.
box(2.45, 0.09, 2.7, M.floorEdge, 0, -0.02, -5.45);
// Quiet floor tile seams.
const seamMat = material("#d7c5aa");
for (let x = -6; x <= 6; x += 1.5) {
box(0.018, 0.008, 8.65, seamMat, x, 0.018, 0);
}
for (let z = -3.8; z <= 3.8; z += 1.5) {
box(13.65, 0.008, 0.018, seamMat, 0, 0.018, z);
}
// Window on the left rear wall.
box(1.9, 1.28, 0.07, M.tealDark, -4.45, 2.7, -4.20);
box(1.68, 1.06, 0.08, material("#9bd3dc", { roughness: 0.42 }), -4.45, 2.7, -4.14);
box(0.07, 1.12, 0.09, M.cream, -4.45, 2.7, -4.08);
box(1.72, 0.07, 0.09, M.cream, -4.45, 2.7, -4.08);
// ---------------------------------------------------------------------
// Furniture
// ---------------------------------------------------------------------
function makeTable(x, z, width, depth, topY, topMaterial = M.wood) {
const top = box(width, 0.16, depth, topMaterial, x, topY, z);
const legHeight = topY - 0.08;
for (const sx of [-1, 1]) {
for (const sz of [-1, 1]) {
box(
0.13,
legHeight,
0.13,
M.darkWood,
x + sx * (width / 2 - 0.18),
legHeight / 2,
z + sz * (depth / 2 - 0.16)
);
}
}
return top;
}
// Cup preparation table.
makeTable(-5.2, 2.7, 1.8, 1.2, 0.92, M.wood);
// Party table and cloth.
makeTable(-1.35, 0.75, 2.7, 1.5, 1.04, M.wood);
box(2.55, 0.035, 1.34, M.cream, -1.35, 1.142, 0.75);
// Small supply table for the banner.
makeTable(5.3, 3.2, 1.25, 0.75, 0.72, M.darkWood);
// Banner frame.
cylinder(0.06, 0.06, 3.65, 8, M.tealDark, 1.65, 1.825, -4.19);
cylinder(0.06, 0.06, 3.65, 8, M.tealDark, 4.35, 1.825, -4.19);
box(2.84, 0.11, 0.11, M.tealDark, 3, 3.63, -4.19);
sphere(0.09, 8, 6, M.yellow, 1.65, 3.69, -4.19);
sphere(0.09, 8, 6, M.yellow, 4.35, 3.69, -4.19);
// A low-poly plant.
cylinder(0.28, 0.22, 0.42, 8, M.coral, -6.25, 0.21, -3.45);
cylinder(0.035, 0.045, 1.05, 6, M.darkWood, -6.25, 0.85, -3.45);
const leafGeo = new THREE.ConeGeometry(0.28, 0.9, 5);
[
[-0.25, 1.12, 0.05, 0.45],
[0.22, 1.28, -0.08, -0.45],
[0.02, 1.45, 0.12, 0.15]
].forEach(([x, y, z, rz]) => {
const leaf = new THREE.Mesh(leafGeo, M.leaf);
leaf.position.set(-6.25 + x, y, -3.45 + z);
leaf.rotation.z = rz;
leaf.castShadow = true;
scene.add(leaf);
});
// ---------------------------------------------------------------------
// Visible, spatially separate routes
// ---------------------------------------------------------------------
const cupRoute = new THREE.CatmullRomCurve3([
new THREE.Vector3(-5.2, 0, 3.45),
new THREE.Vector3(-4.7, 0, 2.95),
new THREE.Vector3(-3.8, 0, 2.45),
new THREE.Vector3(-2.8, 0, 2.12),
new THREE.Vector3(-2.25, 0, 2.05)
], false, "centripetal");
const bannerRoute = new THREE.CatmullRomCurve3([
new THREE.Vector3(5.3, 0, 3.45),
new THREE.Vector3(5.45, 0, 2.2),
new THREE.Vector3(5.1, 0, 0.4),
new THREE.Vector3(4.4, 0, -1.6),
new THREE.Vector3(3.0, 0, -3.05)
], false, "centripetal");
const cakeRoute = new THREE.CatmullRomCurve3([
new THREE.Vector3(0, 0, -6.45),
new THREE.Vector3(0, 0, -4.1),
new THREE.Vector3(0, 0, -2.45),
new THREE.Vector3(0.42, 0, -1.5),
new THREE.Vector3(0.8, 0, -0.75)
], false, "centripetal");
function addRoute(curve, color) {
const points = curve.getPoints(90).map(point =>
new THREE.Vector3(point.x, 0.035, point.z)
);
const geometry = new THREE.BufferGeometry().setFromPoints(points);
const lineMaterial = new THREE.LineDashedMaterial({
color,
dashSize: 0.18,
gapSize: 0.11,
transparent: true,
opacity: 0.56,
linewidth: 1
});
const line = new THREE.Line(geometry, lineMaterial);
line.computeLineDistances();
scene.add(line);
}
addRoute(cupRoute, "#2a9d8f");
addRoute(bannerRoute, "#e76f51");
addRoute(cakeRoute, "#d7a936");
// ---------------------------------------------------------------------
// Helper characters
// ---------------------------------------------------------------------
function createHelper(shirtColor, accentColor, skinColor) {
const root = new THREE.Group();
scene.add(root);
const shirt = material(shirtColor);
const accent = material(accentColor);
const skin = material(skinColor);
cylinder(0.28, 0.34, 0.74, 7, shirt, 0, 0.94, 0, root);
box(0.42, 0.48, 0.08, accent, 0, 0.92, 0.285, root);
sphere(0.255, 8, 6, skin, 0, 1.53, 0, root);
cylinder(0.25, 0.25, 0.08, 8, accent, 0, 1.73, 0, root);
cylinder(0.16, 0.2, 0.17, 8, accent, 0, 1.84, 0, root);
const eyeMat = material("#263238");
sphere(0.026, 6, 5, eyeMat, -0.085, 1.57, 0.225, root);
sphere(0.026, 6, 5, eyeMat, 0.085, 1.57, 0.225, root);
sphere(0.028, 6, 5, eyeMat, 0, 1.46, 0.235, root);
const arms = [];
const legs = [];
for (const side of [-1, 1]) {
const arm = new THREE.Group();
arm.position.set(side * 0.36, 1.19, 0);
root.add(arm);
cylinder(0.075, 0.085, 0.43, 6, shirt, 0, -0.205, 0, arm);
sphere(0.09, 7, 5, skin, 0, -0.45, 0, arm);
arms.push(arm);
const leg = new THREE.Group();
leg.position.set(side * 0.14, 0.57, 0);
root.add(leg);
cylinder(0.095, 0.105, 0.45, 6, M.dark, 0, -0.22, 0, leg);
box(0.18, 0.11, 0.3, M.dark, 0, -0.48, 0.07, leg);
legs.push(leg);
}
root.userData.arms = arms;
root.userData.legs = legs;
return root;
}
const cupHelper = createHelper("#2a9d8f", "#f4a261", "#c9825b");
const bannerHelper = createHelper("#e76f51", "#f4a261", "#e0aa78");
// Cup helper tray.
const tray = new THREE.Group();
tray.position.set(0, 1.0, 0.56);
cupHelper.add(tray);
box(0.82, 0.055, 0.48, M.darkWood, 0, 0, 0, tray);
box(0.82, 0.12, 0.035, M.wood, 0, 0.04, 0.225, tray);
box(0.82, 0.12, 0.035, M.wood, 0, 0.04, -0.225, tray);
function animateLimbs(helper, moving, phase, armPose = -1.02) {
const [legA, legB] = helper.userData.legs;
const [armA, armB] = helper.userData.arms;
if (moving) {
legA.rotation.x = Math.sin(phase) * 0.52;
legB.rotation.x = -Math.sin(phase) * 0.52;
armA.rotation.x = armPose;
armB.rotation.x = armPose;
armA.rotation.z = 0.08;
armB.rotation.z = -0.08;
} else {
legA.rotation.x = lerp(legA.rotation.x, 0, 0.18);
legB.rotation.x = lerp(legB.rotation.x, 0, 0.18);
armA.rotation.x = lerp(armA.rotation.x, armPose, 0.18);
armB.rotation.x = lerp(armB.rotation.x, armPose, 0.18);
}
}
// ---------------------------------------------------------------------
// Cups
// ---------------------------------------------------------------------
function createCup(color) {
const group = new THREE.Group();
const cupMaterial = material(color);
const body = new THREE.Mesh(
new THREE.CylinderGeometry(0.12, 0.105, 0.23, 10, 1, true),
cupMaterial
);
body.position.y = 0.115;
body.castShadow = true;
group.add(body);
const bottom = new THREE.Mesh(
new THREE.CylinderGeometry(0.106, 0.106, 0.025, 10),
cupMaterial
);
bottom.position.y = 0.012;
group.add(bottom);
const rim = torus(0.115, 0.018, 5, 10, cupMaterial, 0, 0.23, 0, group);
rim.rotation.x = Math.PI / 2;
const handle = torus(0.075, 0.024, 5, 9, cupMaterial, 0.13, 0.12, 0, group);
handle.scale.set(0.78, 1.12, 1);
scene.add(group);
return group;
}
const cups = [
createCup("#f2c14e"),
createCup("#5ab1a2"),
createCup("#f28f8f")
];
const stationCupPositions = [
new THREE.Vector3(-5.55, 1.015, 2.53),
new THREE.Vector3(-5.22, 1.015, 2.53),
new THREE.Vector3(-4.89, 1.015, 2.53)
];
const trayLocalPositions = [
new THREE.Vector3(-0.21, 1.06, 0.58),
new THREE.Vector3(0.21, 1.06, 0.58),
new THREE.Vector3(0, 1.305, 0.58)
];
const tableCupPositions = [
new THREE.Vector3(-1.95, 1.165, 0.76),
new THREE.Vector3(-1.35, 1.165, 0.76),
new THREE.Vector3(-0.75, 1.165, 0.76)
];
const cupPlaceStarts = [4.95, 5.67, 6.39];
const cupPlaceEnd = 7.11;
// ---------------------------------------------------------------------
// Banner
// ---------------------------------------------------------------------
function createBannerTexture() {
const bannerCanvas = document.createElement("canvas");
bannerCanvas.width = 768;
bannerCanvas.height = 288;
const context = bannerCanvas.getContext("2d");
context.fillStyle = "#e76f51";
context.fillRect(0, 0, 768, 288);
context.strokeStyle = "#fff3dd";
context.lineWidth = 14;
context.strokeRect(18, 18, 732, 252);
context.fillStyle = "#fff3dd";
context.textAlign = "center";
context.textBaseline = "middle";
context.font = "900 105px sans-serif";
context.fillText("HAPPY DAY!", 384, 143);
const texture = new THREE.CanvasTexture(bannerCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(renderer.capabilities.getMaxAnisotropy(), 8);
return texture;
}
const bannerGeometry = new THREE.PlaneGeometry(2.4, 0.9, 8, 3);
const bannerMaterial = new THREE.MeshStandardMaterial({
map: createBannerTexture(),
side: THREE.DoubleSide,
roughness: 0.88,
flatShading: true
});
const banner = new THREE.Mesh(bannerGeometry, bannerMaterial);
banner.castShadow = true;
banner.receiveShadow = true;
scene.add(banner);
const ropeMaterial = new THREE.MeshStandardMaterial({
color: "#fff3dd",
roughness: 1,
transparent: true,
opacity: 0
});
const leftRope = cylinder(
0.018, 0.018, 1, 5, ropeMaterial, 0, 0, 0
);
const rightRope = cylinder(
0.018, 0.018, 1, 5, ropeMaterial, 0, 0, 0
);
leftRope.castShadow = true;
rightRope.castShadow = true;
const ropeUp = new THREE.Vector3(0, 1, 0);
function setRopeBetween(mesh, start, end) {
const direction = new THREE.Vector3().subVectors(end, start);
const length = direction.length();
mesh.position.copy(start).add(end).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(ropeUp, direction.normalize());
mesh.scale.set(1, length, 1);
}
const leftHook = new THREE.Vector3(1.8, 3.6, -4.16);
const rightHook = new THREE.Vector3(4.2, 3.6, -4.16);
// ---------------------------------------------------------------------
// Cake and delivery trolley
// ---------------------------------------------------------------------
const cakeDelivery = new THREE.Group();
scene.add(cakeDelivery);
cakeDelivery.visible = false;
const wheelPivots = [];
for (const sx of [-1, 1]) {
for (const sz of [-1, 1]) {
const pivot = new THREE.Group();
pivot.position.set(sx * 0.72, 0.25, sz * 0.45);
cakeDelivery.add(pivot);
const wheel = cylinder(
0.23, 0.23, 0.13, 10, M.dark, 0, 0, 0, pivot
);
wheel.rotation.z = Math.PI / 2;
const hub = cylinder(
0.09, 0.09, 0.15, 8, M.yellow, 0, 0, 0, pivot
);
hub.rotation.z = Math.PI / 2;
wheelPivots.push(pivot);
}
}
box(1.65, 0.12, 1.22, M.yellow, 0, 0.48, 0, cakeDelivery);
box(1.75, 0.09, 1.32, M.cream, 0, 0.67, 0, cakeDelivery);
box(1.45, 0.08, 0.08, M.yellow, 0, 0.57, 0.61, cakeDelivery);
const cake = new THREE.Group();
cakeDelivery.add(cake);
cylinder(0.73, 0.77, 0.53, 12, M.pink, 0, 0.985, 0, cake);
cylinder(0.56, 0.6, 0.43, 12, M.frosting, 0, 1.465, 0, cake);
cylinder(0.39, 0.43, 0.36, 12, M.pink, 0, 1.855, 0, cake);
cylinder(0.34, 0.35, 0.09, 12, M.frosting, 0, 2.075, 0, cake);
const frostingRingA = torus(
0.735, 0.055, 5, 12, M.frosting, 0, 1.23, 0, cake
);
frostingRingA.rotation.x = Math.PI / 2;
const frostingRingB = torus(
0.565, 0.048, 5, 12, M.frosting, 0, 1.65, 0, cake
);
frostingRingB.rotation.x = Math.PI / 2;
const sprinkleColors = ["#f2c14e", "#5ab1a2", "#fff3dd", "#805ad5"];
for (let i = 0; i < 24; i++) {
const angle = (i / 24) * Math.PI * 2;
const radius = i % 2 === 0 ? 0.735 : 0.565;
const height = i % 2 === 0 ? 1.08 : 1.55;
const sprinkle = box(
0.055,
0.025,
0.12,
material(sprinkleColors[i % sprinkleColors.length]),
Math.cos(angle) * radius,
height,
Math.sin(angle) * radius,
cake
);
sprinkle.rotation.y = -angle;
sprinkle.rotation.z = Math.sin(i * 3.7) * 0.6;
}
const flameMaterial = material("#ffb347", {
emissive: "#ff7a18",
emissiveIntensity: 1.8,
roughness: 0.35
});
const flames = [];
for (let i = 0; i < 5; i++) {
const angle = (i / 5) * Math.PI * 2;
const x = Math.cos(angle) * 0.21;
const z = Math.sin(angle) * 0.21;
cylinder(0.035, 0.04, 0.22, 7, M.teal, x, 2.235, z, cake);
const flame = new THREE.Mesh(
new THREE.ConeGeometry(0.055, 0.16, 6),
flameMaterial
);
flame.position.set(x, 2.41, z);
cake.add(flame);
flames.push(flame);
}
// Celebration confetti, only released after delivery.
const confetti = [];
const confettiColors = ["#e76f51", "#2a9d8f", "#e9c46a", "#805ad5"];
for (let i = 0; i < 24; i++) {
const piece = new THREE.Mesh(
new THREE.TetrahedronGeometry(0.065),
material(confettiColors[i % confettiColors.length])
);
piece.visible = false;
piece.castShadow = true;
scene.add(piece);
confetti.push(piece);
}
// ---------------------------------------------------------------------
// Choreography
// ---------------------------------------------------------------------
const CUP_PICKUP_START = 0.25;
const CUP_PICKUP_END = 0.9;
const CUP_WALK_END = 4.8;
const CUP_DONE = 7.11;
const BANNER_PICKUP_START = 0.3;
const BANNER_PICKUP_END = 1.0;
const BANNER_WALK_END = 5.1;
const BANNER_DONE = 6.6;
const CAKE_START = 7.4;
const CAKE_END = 10.5;
const DURATION = 13.5;
const cupFinal = new THREE.Vector3(-2.25, 0, 2.05);
const cupAside = new THREE.Vector3(-3.05, 0, 2.82);
const cupTable = new THREE.Vector3(-1.35, 0, 0.75);
function updateCupHelper(t) {
const routeProgress = clamp((t - CUP_PICKUP_END) /
(CUP_WALK_END - CUP_PICKUP_END));
let position;
let yaw;
let moving = false;
if (t < CUP_PICKUP_END) {
position = cupRoute.getPointAt(0);
yaw = Math.PI;
} else if (t < CUP_WALK_END) {
position = cupRoute.getPointAt(routeProgress);
const tangent = cupRoute.getTangentAt(routeProgress);
yaw = Math.atan2(tangent.x, tangent.z);
moving = true;
} else {
position = cupFinal.clone();
const targetYaw = Math.atan2(
cupTable.x - cupFinal.x,
cupTable.z - cupFinal.z
);
yaw = angleLerp(yaw, targetYaw, smooth((t - 4.55) / 0.3));
}
if (t > CUP_DONE + 0.04) {
const asideProgress = smooth((t - (CUP_DONE + 0.04)) / 0.8);
position.lerp(cupAside, asideProgress);
moving = asideProgress > 0 && asideProgress < 1;
yaw = angleLerp(yaw, 2.45, asideProgress);
}
const bob = moving ? Math.abs(Math.sin(t * 8.5)) * 0.045 : 0;
cupHelper.position.set(position.x, bob, position.z);
cupHelper.rotation.y = yaw;
let armPose = -1.0;
if (t < CUP_PICKUP_START) armPose = -0.65;
for (let i = 0; i < cupPlaceStarts.length; i++) {
const start = cupPlaceStarts[i];
if (t >= start && t < start + 0.72) {
const reach = Math.sin((t - start) / 0.72 * Math.PI);
armPose = -1.35 - reach * 0.3;
break;
}
}
animateLimbs(cupHelper, moving, t * 8.8, armPose);
tray.visible = t < CUP_DONE;
cupHelper.updateMatrixWorld(true);
}
function updateCups(t) {
cups.forEach((cup, index) => {
const station = stationCupPositions[index];
const trayPosition = cupHelper.localToWorld(
trayLocalPositions[index].clone()
);
const target = tableCupPositions[index];
const placeStart = cupPlaceStarts[index];
const placeEnd = placeStart + 0.72;
let position;
let rotation = cupHelper.rotation.y;
if (t < CUP_PICKUP_START) {
position = station.clone();
rotation = 0;
} else if (t < CUP_PICKUP_END) {
const pickup = smooth((t - CUP_PICKUP_START) /
(CUP_PICKUP_END - CUP_PICKUP_START));
position = station.clone().lerp(trayPosition, pickup);
rotation = angleLerp(0, cupHelper.rotation.y, pickup);
} else if (t < placeStart) {
position = trayPosition;
} else if (t < placeEnd) {
const placing = smooth((t - placeStart) / (placeEnd - placeStart));
position = trayPosition.clone().lerp(target, placing);
rotation = angleLerp(cupHelper.rotation.y, 0, placing);
} else {
position = target.clone();
rotation = 0;
}
cup.position.copy(position);
cup.rotation.y = rotation;
cup.visible = true;
});
}
const bannerFinalPosition = new THREE.Vector3(3, 2.65, -4.18);
const bannerStationPosition = new THREE.Vector3(5.3, 1.0, 3.2);
function updateBannerHelper(t) {
const routeProgress = clamp((t - BANNER_PICKUP_END) /
(BANNER_WALK_END - BANNER_PICKUP_END));
let position;
let yaw;
let moving = false;
if (t < BANNER_PICKUP_END) {
position = bannerRoute.getPointAt(0);
yaw = Math.PI;
} else if (t < BANNER_WALK_END) {
position = bannerRoute.getPointAt(routeProgress);
const tangent = bannerRoute.getTangentAt(routeProgress);
yaw = Math.atan2(tangent.x, tangent.z);
moving = true;
} else {
position = bannerRoute.getPointAt(1);
yaw = Math.PI;
}
if (t > BANNER_DONE + 0.08) {
const asideProgress = smooth((t - (BANNER_DONE + 0.08)) / 0.7);
position.lerp(new THREE.Vector3(4.78, 0, -2.65), asideProgress);
yaw = angleLerp(yaw, 1.35, asideProgress);
moving = asideProgress > 0 && asideProgress < 1;
}
const bob = moving ? Math.abs(Math.sin(t * 8.1)) * 0.045 : 0;
bannerHelper.position.set(position.x, bob, position.z);
bannerHelper.rotation.y = yaw;
let armPose = -1.08;
if (t >= BANNER_WALK_END && t < BANNER_DONE) {
const lifting = smooth((t - BANNER_WALK_END) /
(BANNER_DONE - BANNER_WALK_END));
armPose = lerp(-1.08, -2.25, lifting);
}
animateLimbs(bannerHelper, moving, t * 8.4, armPose);
bannerHelper.updateMatrixWorld(true);
}
function updateBanner(t) {
const forward = new THREE.Vector3(
Math.sin(bannerHelper.rotation.y),
0,
Math.cos(bannerHelper.rotation.y)
);
const carryPosition = bannerHelper.position.clone().addScaledVector(forward, 0.46);
carryPosition.y = 1.5;
let position;
let scaleX;
if (t < BANNER_PICKUP_START) {
position = bannerStationPosition.clone();
scaleX = 0.24;
} else if (t < BANNER_PICKUP_END) {
const pickup = smooth((t - BANNER_PICKUP_START) /
(BANNER_PICKUP_END - BANNER_PICKUP_START));
position = bannerStationPosition.clone().lerp(carryPosition, pickup);
scaleX = lerp(0.24, 0.72, pickup);
} else if (t < BANNER_WALK_END) {
position = carryPosition;
scaleX = 0.72;
} else if (t < BANNER_DONE) {
const hanging = smooth((t - BANNER_WALK_END) /
(BANNER_DONE - BANNER_WALK_END));
position = carryPosition.clone().lerp(bannerFinalPosition, hanging);
scaleX = lerp(0.72, 1, hanging);
} else {
position = bannerFinalPosition.clone();
scaleX = 1;
}
banner.position.copy(position);
banner.scale.x = scaleX;
// Gentle cloth motion.
const positions = bannerGeometry.attributes.position;
for (let i = 0; i < positions.count; i++) {
const x = positions.getX(i);
const y = positions.getY(i);
const wave = Math.sin(x * 3.1 + t * 2.2) *
0.025 * (0.45 + y + 0.45);
positions.setZ(i, wave);
}
positions.needsUpdate = true;
banner.updateMatrixWorld(true);
const visible = t >= BANNER_WALK_END - 0.04;
leftRope.visible = visible;
rightRope.visible = visible;
ropeMaterial.opacity = visible
? clamp((t - BANNER_WALK_END) / 0.28)
: 0;
if (visible) {
const leftTop = banner.localToWorld(new THREE.Vector3(-1.2, 0.45, 0));
const rightTop = banner.localToWorld(new THREE.Vector3(1.2, 0.45, 0));
setRopeBetween(leftRope, leftTop, leftHook);
setRopeBetween(rightRope, rightTop, rightHook);
}
}
function updateCake(t) {
cakeDelivery.visible = t >= CAKE_START - 0.18;
if (!cakeDelivery.visible) return;
const progress = clamp((t - CAKE_START) / (CAKE_END - CAKE_START));
const position = cakeRoute.getPointAt(smooth(progress));
cakeDelivery.position.copy(position);
const travel = position.z + 6.45;
wheelPivots.forEach(wheel => {
wheel.rotation.x = travel * 2.4;
});
flames.forEach((flame, index) => {
const flicker = 0.88 + Math.sin(t * 12 + index * 1.7) * 0.12;
flame.scale.set(flicker, flicker, flicker);
});
}
function updateConfetti(t) {
const released = t >= 10.25;
confetti.forEach((piece, index) => {
piece.visible = released;
if (!released) return;
const age = t - 10.25;
const fall = (age * 1.12 + index * 0.19) % 4.35;
piece.position.set(
0.8 + Math.sin(index * 2.31) * 2.1 + Math.sin(age * 2 + index) * 0.2,
4.55 - fall,
-0.5 + Math.cos(index * 1.73) * 1.75
);
piece.rotation.x = age * 2.7 + index;
piece.rotation.y = age * 1.9 + index * 0.4;
});
}
// ---------------------------------------------------------------------
// HUD
// ---------------------------------------------------------------------
const cupsTask = document.querySelector('[data-task="cups"]');
const bannerTask = document.querySelector('[data-task="banner"]');
const cakeTask = document.querySelector('[data-task="cake"]');
const progress = document.querySelector("#progress");
const playButton = document.querySelector("#play");
const replayButton = document.querySelector("#replay");
function setTask(element, label, state) {
element.querySelector(".state").textContent = label;
element.dataset.state = state;
}
function updateHUD(t) {
progress.style.width = `${clamp(t / DURATION) * 100}%`;
if (t < CUP_PICKUP_END) {
setTask(cupsTask, "Gathering cups", "active");
} else if (t < cupPlaceStarts[0]) {
setTask(cupsTask, "Carrying 3 cups", "active");
} else if (t < CUP_DONE) {
setTask(cupsTask, "Placing cups", "active");
} else {
setTask(cupsTask, "3 cups ready", "done");
}
if (t < BANNER_PICKUP_END) {
setTask(bannerTask, "Taking banner", "active");
} else if (t < BANNER_WALK_END) {
setTask(bannerTask, "Carrying banner", "active");
} else if (t < BANNER_DONE) {
setTask(bannerTask, "Hanging banner", "active");
} else {
setTask(bannerTask, "Banner ready", "done");
}
if (t < CAKE_START) {
setTask(cakeTask, "Waiting backstage", "waiting");
} else if (t < CAKE_END) {
setTask(cakeTask, "Arriving", "active");
} else {
setTask(cakeTask, "Centerpiece ready", "done");
}
}
// ---------------------------------------------------------------------
// Direct camera controls — no external controls module
// ---------------------------------------------------------------------
let dragging = false;
let previousX = 0;
let previousY = 0;
canvas.addEventListener("pointerdown", event => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", event => {
if (!dragging) return;
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
cameraYaw -= deltaX * 0.006;
cameraPitch = clamp(cameraPitch + deltaY * 0.0045, 0.36, 1.12);
});
canvas.addEventListener("pointerup", event => {
dragging = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
});
canvas.addEventListener("pointercancel", () => {
dragging = false;
});
canvas.addEventListener("wheel", event => {
event.preventDefault();
cameraZoom = clamp(cameraZoom - event.deltaY * 0.001, 0.76, 1.42);
resize();
}, { passive: false });
// ---------------------------------------------------------------------
// Animation loop
// ---------------------------------------------------------------------
let time = 0;
let playing = true;
let lastTime = performance.now();
playButton.addEventListener("click", () => {
if (time >= DURATION) time = 0;
playing = !playing;
playButton.textContent = playing ? "Pause" : "Play";
});
replayButton.addEventListener("click", () => {
time = 0;
playing = true;
playButton.textContent = "Pause";
});
function animate(now) {
const delta = Math.min((now - lastTime) / 1000, 0.05);
lastTime = now;
if (playing) {
time = Math.min(time + delta, DURATION);
if (time >= DURATION) {
playing = false;
playButton.textContent = "Play";
}
}
updateCupHelper(time);
updateCups(time);
updateBannerHelper(time);
updateBanner(time);
updateCake(time);
updateConfetti(time);
updateHUD(time);
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
requestAnimationFrame(animate);
</script>
</body>
</html>
```