Prompt specification
Build or customize the Three.js 3D scene "Street festival cup-return stall" 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: Street festival cup-return stall
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/street-festival-cup-return-stall-x0495
Scene Description Prompt:
Using Three.js from cdnjs in standalone HTML, animate reusable cups circulating between stylized festival booths, a return station, and a washing area.
Working Three.js Starter (street-festival-cup-return-stall-x0495):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Cup Loop — Festival Reuse Network</title>
<style>
:root {
color-scheme: dark;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #18152a;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
#hud {
position: fixed;
inset: 0;
pointer-events: none;
color: #fff;
text-shadow: 0 2px 12px rgba(0, 0, 0, 0.45);
}
.topbar {
position: absolute;
top: 22px;
left: 24px;
right: 24px;
display: flex;
justify-content: space-between;
align-items: flex-start;
gap: 18px;
}
.brand {
display: flex;
flex-direction: column;
gap: 4px;
}
.brand strong {
font-size: clamp(25px, 4vw, 44px);
line-height: 1;
letter-spacing: -0.05em;
font-weight: 850;
}
.brand span {
color: #f5c86b;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.22em;
text-transform: uppercase;
}
.status {
display: flex;
align-items: center;
gap: 10px;
padding: 10px 13px;
border: 1px solid rgba(255, 255, 255, 0.17);
border-radius: 999px;
background: rgba(21, 18, 39, 0.64);
backdrop-filter: blur(12px);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.13em;
white-space: nowrap;
}
.status-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: #6df0b6;
box-shadow: 0 0 14px #6df0b6;
animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse {
50% {
opacity: 0.45;
transform: scale(0.75);
}
}
.panel {
position: absolute;
left: 24px;
bottom: 24px;
width: min(310px, calc(100vw - 48px));
padding: 16px;
border: 1px solid rgba(255, 255, 255, 0.13);
border-radius: 18px;
background: rgba(22, 19, 42, 0.76);
backdrop-filter: blur(14px);
}
.panel-title {
margin-bottom: 12px;
font-size: 10px;
font-weight: 850;
letter-spacing: 0.18em;
color: #b9b6cf;
text-transform: uppercase;
}
.legend {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px 14px;
margin-bottom: 14px;
font-size: 11px;
font-weight: 700;
}
.legend-item {
display: flex;
align-items: center;
gap: 8px;
}
.swatch {
width: 9px;
height: 9px;
border-radius: 3px;
box-shadow: 0 0 9px currentColor;
}
.button-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
}
button {
pointer-events: auto;
border: 0;
border-radius: 10px;
padding: 10px 13px;
color: #17142a;
background: #f5c86b;
font: inherit;
font-size: 10px;
font-weight: 900;
letter-spacing: 0.1em;
cursor: pointer;
transition: transform 150ms ease, filter 150ms ease;
}
button:hover {
filter: brightness(1.08);
transform: translateY(-1px);
}
.help {
color: #aaa7bd;
font-size: 10px;
line-height: 1.5;
}
#toast {
position: absolute;
right: 24px;
bottom: 24px;
max-width: 260px;
padding: 12px 15px;
border: 1px solid rgba(255, 255, 255, 0.12);
border-radius: 14px;
background: rgba(22, 19, 42, 0.68);
backdrop-filter: blur(12px);
color: #d6d3e4;
font-size: 11px;
line-height: 1.5;
text-align: right;
}
@media (max-width: 700px) {
.topbar {
top: 15px;
left: 16px;
right: 16px;
}
.status {
padding: 8px 10px;
font-size: 8px;
}
.panel {
left: 16px;
bottom: 16px;
}
#toast {
display: none;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Animated festival cup reuse loop"></canvas>
<div id="hud">
<div class="topbar">
<div class="brand">
<span>Festival reuse network</span>
<strong>CUP LOOP</strong>
</div>
<div class="status">
<i class="status-dot"></i>
<span id="statusText">12 CUPS IN CIRCULATION</span>
</div>
</div>
<div class="panel">
<div class="panel-title">Reuse network</div>
<div class="legend">
<div class="legend-item">
<i class="swatch" style="color:#f4b94f;background:#f4b94f"></i>
Food booths
</div>
<div class="legend-item">
<i class="swatch" style="color:#55e5c1;background:#55e5c1"></i>
Return station
</div>
<div class="legend-item">
<i class="swatch" style="color:#62b9ff;background:#62b9ff"></i>
Washing area
</div>
<div class="legend-item">
<i class="swatch" style="color:#e8e1f7;background:#e8e1f7"></i>
Cup route
</div>
</div>
<div class="button-row">
<button id="pauseButton">PAUSE LOOP</button>
<div class="help">Drag to orbit<br />Scroll to zoom</div>
</div>
</div>
<div id="toast">
Every cup follows one shared loop:<br />
booth → booth → return → wash → booth
</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 pauseButton = document.querySelector("#pauseButton");
const statusText = document.querySelector("#statusText");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x18152a);
scene.fog = new THREE.Fog(0x18152a, 23, 43);
const camera = new THREE.PerspectiveCamera(
44,
innerWidth / innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.15;
const clock = new THREE.Clock();
const animatedLights = [];
const bubbles = [];
const animatedCups = [];
let elapsed = 0;
let paused = false;
const standard = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.72,
metalness: 0.03,
...options
});
const materials = {
ground: standard(0x242037, { roughness: 1 }),
plaza: standard(0x393148, { roughness: 0.95 }),
cream: standard(0xffefd2),
dark: standard(0x211d31),
metal: standard(0x8d91a5, { metalness: 0.55, roughness: 0.36 }),
black: standard(0x11101a),
white: standard(0xf7f2e9),
return: standard(0x38d9ad),
water: standard(0x42bdf4, {
transparent: true,
opacity: 0.72,
roughness: 0.18,
metalness: 0.05,
depthWrite: false
})
};
function addBox(
width,
height,
depth,
material,
x,
y,
z,
parent = scene
) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addCylinderBetween(
start,
end,
radius,
material,
parent = scene,
radialSegments = 12
) {
const direction = new THREE.Vector3().subVectors(end, start);
const length = direction.length();
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(
radius,
radius,
length,
radialSegments
),
material
);
mesh.position.copy(start).add(end).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function createLabel(title, subtitle, accent) {
const labelCanvas = document.createElement("canvas");
labelCanvas.width = 768;
labelCanvas.height = 192;
const context = labelCanvas.getContext("2d");
context.fillStyle = "rgba(25, 21, 43, 0.94)";
context.fillRect(0, 0, 768, 192);
context.fillStyle = accent;
context.fillRect(0, 0, 18, 192);
context.strokeStyle = "rgba(255,255,255,0.20)";
context.lineWidth = 5;
context.strokeRect(3, 3, 762, 186);
context.fillStyle = "#ffffff";
context.font = "800 64px system-ui, sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(title.toUpperCase(), 394, 72);
context.fillStyle = accent;
context.font = "700 25px system-ui, sans-serif";
context.fillText(subtitle.toUpperCase(), 394, 132);
const texture = new THREE.CanvasTexture(labelCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.scale.set(3.15, 0.79, 1);
sprite.renderOrder = 10;
return sprite;
}
function createCup(accent) {
const group = new THREE.Group();
const body = new THREE.Mesh(
new THREE.CylinderGeometry(0.165, 0.125, 0.42, 18),
materials.white
);
body.position.y = 0.21;
body.castShadow = true;
body.receiveShadow = true;
group.add(body);
const band = new THREE.Mesh(
new THREE.CylinderGeometry(0.158, 0.145, 0.11, 18),
standard(accent, { roughness: 0.5 })
);
band.position.y = 0.12;
band.castShadow = true;
group.add(band);
const rim = new THREE.Mesh(
new THREE.TorusGeometry(0.163, 0.025, 8, 20),
standard(accent, { roughness: 0.45 })
);
rim.rotation.x = Math.PI / 2;
rim.position.y = 0.42;
rim.castShadow = true;
group.add(rim);
return group;
}
function faceCenter(group, x, z) {
// Local +Z points toward the plaza center.
group.rotation.y = Math.atan2(-x, -z);
}
function createBooth(title, subtitle, accent, x, z) {
const group = new THREE.Group();
group.position.set(x, 0, z);
faceCenter(group, x, z);
scene.add(group);
const accentMaterial = standard(accent, { roughness: 0.58 });
const paleAccent = standard(accent, {
emissive: accent,
emissiveIntensity: 0.08
});
addBox(3.55, 0.22, 2.15, materials.dark, 0, 0.12, 0, group);
addBox(3.1, 1.45, 0.18, accentMaterial, 0, 1.1, -0.72, group);
addBox(3.0, 0.85, 1.15, materials.cream, 0, 0.73, 0, group);
addBox(3.22, 0.13, 1.36, paleAccent, 0, 1.22, 0, group);
for (const postX of [-1.46, 1.46]) {
addBox(0.13, 2.35, 0.13, materials.cream, postX, 1.2, 0.68, group);
}
addBox(3.55, 0.22, 1.85, accentMaterial, 0, 2.42, 0, group);
for (let i = 0; i < 7; i++) {
const stripeMaterial = i % 2 === 0 ? materials.cream : accentMaterial;
addBox(
0.47,
0.15,
1.94,
stripeMaterial,
-1.53 + i * 0.51,
2.25,
0.06,
group
);
}
addBox(0.75, 0.9, 0.09, materials.dark, 1.03, 1.72, -0.61, group);
for (let i = 0; i < 3; i++) {
addBox(
0.48,
0.055,
0.025,
standard(i === 1 ? 0xffdd75 : 0xffffff),
1.03,
1.47 + i * 0.19,
-0.545,
group
);
}
for (let i = 0; i < 3; i++) {
const cup = createCup(accent);
cup.position.set(-0.9 + i * 0.55, 1.3, 0.25);
cup.scale.setScalar(0.76);
group.add(cup);
}
const label = createLabel(title, subtitle, accent);
label.position.set(0, 3.05, 0);
group.add(label);
return group;
}
function createReturnStation(x, z) {
const group = new THREE.Group();
group.position.set(x, 0, z);
faceCenter(group, x, z);
scene.add(group);
const mint = standard(0x42dfb3, {
emissive: 0x20a985,
emissiveIntensity: 0.12
});
addBox(2.8, 0.2, 2.1, materials.dark, 0, 0.12, 0, group);
addBox(1.55, 2.25, 1.35, mint, -0.38, 1.25, 0, group);
addBox(0.9, 0.18, 0.08, materials.black, -0.38, 1.52, 0.72, group);
addBox(0.68, 0.09, 0.05, standard(0xb9fff0), -0.38, 1.52, 0.78, group);
addBox(0.72, 0.72, 1.15, standard(0x237e72), 1.03, 0.53, 0, group);
for (let i = 0; i < 4; i++) {
const cup = createCup(0x7df5d4);
cup.position.set(1.03, 0.83 + i * 0.08, 0.04);
cup.scale.setScalar(0.8);
group.add(cup);
}
const label = createLabel("RETURN", "Drop · sort · recirculate", "#55e5c1");
label.position.set(0, 2.85, 0);
group.add(label);
return group;
}
function createWashingArea(x, z) {
const group = new THREE.Group();
group.position.set(x, 0, z);
faceCenter(group, x, z);
scene.add(group);
addBox(3.25, 0.2, 2.25, materials.dark, 0, 0.12, 0, group);
addBox(2.65, 0.12, 1.75, materials.metal, 0, 0.29, 0, group);
addBox(2.65, 0.62, 0.14, standard(0x70c8f5), 0, 0.55, -0.82, group);
addBox(2.65, 0.62, 0.14, standard(0x70c8f5), 0, 0.55, 0.82, group);
addBox(0.14, 0.62, 1.7, standard(0x70c8f5), -1.3, 0.55, 0, group);
addBox(0.14, 0.62, 1.7, standard(0x70c8f5), 1.3, 0.55, 0, group);
const water = new THREE.Mesh(
new THREE.PlaneGeometry(2.45, 1.55),
materials.water
);
water.rotation.x = -Math.PI / 2;
water.position.y = 0.61;
group.add(water);
addCylinderBetween(
new THREE.Vector3(-0.9, 0.65, -0.4),
new THREE.Vector3(-0.9, 1.65, -0.4),
0.065,
materials.metal,
group
);
addCylinderBetween(
new THREE.Vector3(-0.9, 1.65, -0.4),
new THREE.Vector3(0.05, 1.65, -0.4),
0.065,
materials.metal,
group
);
addCylinderBetween(
new THREE.Vector3(0.05, 1.65, -0.4),
new THREE.Vector3(0.05, 1.32, -0.4),
0.065,
materials.metal,
group
);
for (let i = 0; i < 10; i++) {
const bubble = new THREE.Mesh(
new THREE.SphereGeometry(0.06 + Math.random() * 0.07, 10, 10),
new THREE.MeshStandardMaterial({
color: 0xd8f6ff,
transparent: true,
opacity: 0.38,
roughness: 0.1,
metalness: 0,
depthWrite: false
})
);
bubble.position.set(
-1 + Math.random() * 2,
0.68,
-0.65 + Math.random() * 1.3
);
bubble.userData.baseY = bubble.position.y;
bubble.userData.speed = 0.25 + Math.random() * 0.35;
bubble.userData.phase = Math.random() * Math.PI * 2;
bubbles.push(bubble);
group.add(bubble);
}
const label = createLabel("WASHING", "Clean · inspect · reuse", "#62b9ff");
label.position.set(0, 2.75, 0);
group.add(label);
return group;
}
// Festival plaza.
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(48, 48),
materials.ground
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.08;
ground.receiveShadow = true;
scene.add(ground);
const plaza = new THREE.Mesh(
new THREE.CylinderGeometry(10.4, 10.4, 0.1, 96),
materials.plaza
);
plaza.position.y = -0.015;
plaza.receiveShadow = true;
scene.add(plaza);
const plazaRing = new THREE.Mesh(
new THREE.TorusGeometry(10.15, 0.035, 8, 96),
new THREE.MeshBasicMaterial({
color: 0x9a82c9,
transparent: true,
opacity: 0.38
})
);
plazaRing.rotation.x = Math.PI / 2;
plazaRing.position.y = 0.055;
scene.add(plazaRing);
// Booths and service points.
createBooth("Tea", "Fresh brews", 0xf2b84b, -5.2, -3.5);
createBooth("Lemonade", "Cold + bright", 0xf3d44e, -1.4, -5.25);
createBooth("Tacos", "Street favorites", 0xf47e68, 3.85, -4.05);
createBooth("Grill", "Smoke + spice", 0xa883e8, -4.55, 3.15);
createReturnStation(5.85, 1.5);
createWashingArea(0.35, 4.85);
// The circulation route passes in front of each service point.
const routePoints = [
new THREE.Vector3(-5.05, 0.075, -1.65),
new THREE.Vector3(-2.05, 0.075, -3.85),
new THREE.Vector3(3.55, 0.075, -2.85),
new THREE.Vector3(5.15, 0.075, -1.15),
new THREE.Vector3(4.65, 0.075, 1.55),
new THREE.Vector3(2.55, 0.075, 3.65),
new THREE.Vector3(-1.55, 0.075, 3.75),
new THREE.Vector3(-4.75, 0.075, 1.35)
];
const routeCurve = new THREE.CatmullRomCurve3(
routePoints,
true,
"catmullrom",
0.5
);
const routeGeometry = new THREE.BufferGeometry().setFromPoints(
routeCurve.getPoints(280)
);
const routeLine = new THREE.Line(
routeGeometry,
new THREE.LineDashedMaterial({
color: 0xdce7ff,
dashSize: 0.22,
gapSize: 0.15,
transparent: true,
opacity: 0.82
})
);
routeLine.computeLineDistances();
scene.add(routeLine);
const routeGlow = new THREE.Mesh(
new THREE.TubeGeometry(routeCurve, 280, 0.055, 8, true),
new THREE.MeshBasicMaterial({
color: 0x8adfff,
transparent: true,
opacity: 0.19,
depthWrite: false
})
);
scene.add(routeGlow);
const markerColors = [
0xf2b84b,
0xf3d44e,
0xf47e68,
0x55e5c1,
0x55e5c1,
0x62b9ff,
0x62b9ff,
0xa883e8
];
routePoints.forEach((point, index) => {
const marker = new THREE.Mesh(
new THREE.TorusGeometry(0.18, 0.027, 8, 24),
new THREE.MeshBasicMaterial({ color: markerColors[index] })
);
marker.rotation.x = Math.PI / 2;
marker.position.copy(point);
marker.position.y = 0.11;
scene.add(marker);
});
// Reusable cups circulating around the route.
const cupColors = [
0xffbd5c,
0x62dfff,
0xff7b8e,
0x78efb9,
0xb991ff,
0xffd95c
];
for (let i = 0; i < 12; i++) {
const holder = new THREE.Group();
const cup = createCup(cupColors[i % cupColors.length]);
cup.scale.setScalar(0.88);
holder.add(cup);
scene.add(holder);
animatedCups.push({
holder,
cup,
offset: i / 12,
speed: 0.0125 + (i % 4) * 0.00115,
bobPhase: Math.random() * Math.PI * 2
});
}
// Overhead festival string lights.
function createStringLights(points, colorOffset = 0) {
const curve = new THREE.CatmullRomCurve3(points);
const wire = new THREE.Mesh(
new THREE.TubeGeometry(curve, 60, 0.018, 6, false),
materials.dark
);
scene.add(wire);
const colors = [0xffd66c, 0xff7c92, 0x67e8f9, 0x9bf58a];
for (let i = 0; i < 14; i++) {
const t = (i + 0.5) / 14;
const point = curve.getPoint(t);
const bulbMaterial = standard(colors[(i + colorOffset) % colors.length], {
emissive: colors[(i + colorOffset) % colors.length],
emissiveIntensity: 1.8,
roughness: 0.25
});
const bulb = new THREE.Mesh(
new THREE.SphereGeometry(0.095, 12, 12),
bulbMaterial
);
bulb.position.copy(point);
bulb.position.y -= 0.1;
bulb.userData.phase = i * 0.55 + colorOffset;
scene.add(bulb);
animatedLights.push(bulb);
}
}
function createPole(x, z, height = 4.6) {
const pole = new THREE.Mesh(
new THREE.CylinderGeometry(0.055, 0.075, height, 10),
materials.metal
);
pole.position.set(x, height / 2, z);
pole.castShadow = true;
scene.add(pole);
}
createPole(-9.4, -6.6, 5);
createPole(0, -8.3, 5);
createPole(9.4, -6.6, 5);
createStringLights([
new THREE.Vector3(-9.4, 4.75, -6.6),
new THREE.Vector3(-4.6, 3.75, -7.5),
new THREE.Vector3(0, 3.35, -8.3),
new THREE.Vector3(4.6, 3.75, -7.5),
new THREE.Vector3(9.4, 4.75, -6.6)
]);
// Lighting.
scene.add(
new THREE.HemisphereLight(0xaeb9ff, 0x49364a, 1.7)
);
const keyLight = new THREE.DirectionalLight(0xffe3b3, 2.5);
keyLight.position.set(-7, 13, 9);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -15;
keyLight.shadow.camera.right = 15;
keyLight.shadow.camera.top = 15;
keyLight.shadow.camera.bottom = -15;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 40;
keyLight.shadow.bias = -0.0008;
scene.add(keyLight);
const coolRim = new THREE.DirectionalLight(0x7b8cff, 1.25);
coolRim.position.set(8, 7, -9);
scene.add(coolRim);
[
[-5, 3, -3, 0xffbf66],
[3, 3, -3, 0xff7890],
[5, 3, 2, 0x5cebc3],
[0, 3, 4.5, 0x62b9ff]
].forEach(([x, y, z, color]) => {
const light = new THREE.PointLight(color, 18, 8, 2);
light.position.set(x, y, z);
scene.add(light);
});
// Custom orbit camera controls — no addons or examples are used.
const orbit = {
target: new THREE.Vector3(0, 0.7, 0),
radius: 17.5,
theta: 0.72,
phi: 0.95
};
function updateCamera() {
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
orbit.target.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
orbit.target.y + orbit.radius * Math.cos(orbit.phi),
orbit.target.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(orbit.target);
}
let dragging = false;
let lastPointerX = 0;
let lastPointerY = 0;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - lastPointerX;
const deltaY = event.clientY - lastPointerY;
orbit.theta -= deltaX * 0.006;
orbit.phi = THREE.MathUtils.clamp(
orbit.phi + deltaY * 0.005,
0.35,
1.42
);
lastPointerX = event.clientX;
lastPointerY = event.clientY;
});
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();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius + event.deltaY * 0.012,
10,
26
);
},
{ passive: false }
);
canvas.addEventListener("dblclick", () => {
orbit.radius = 17.5;
orbit.theta = 0.72;
orbit.phi = 0.95;
});
pauseButton.addEventListener("click", () => {
paused = !paused;
pauseButton.textContent = paused ? "RESUME LOOP" : "PAUSE LOOP";
statusText.textContent = paused
? "CIRCULATION PAUSED"
: "12 CUPS IN CIRCULATION";
});
function resize() {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
}
addEventListener("resize", resize);
updateCamera();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
if (!paused) {
elapsed += delta;
}
for (const item of animatedCups) {
const t = (item.offset + elapsed * item.speed) % 1;
const position = routeCurve.getPointAt(t);
const tangent = routeCurve.getTangentAt(t);
item.holder.position.copy(position);
item.holder.rotation.y = Math.atan2(tangent.x, tangent.z);
item.cup.position.y =
0.035 + Math.sin(elapsed * 3.1 + item.bobPhase) * 0.018;
item.cup.rotation.y += delta * 0.8;
}
for (const light of animatedLights) {
light.material.emissiveIntensity =
1.45 + Math.sin(elapsed * 1.8 + light.userData.phase) * 0.45;
}
for (const bubble of bubbles) {
const rise = ((elapsed * bubble.userData.speed) % 0.55);
bubble.position.y = bubble.userData.baseY + rise;
bubble.position.x +=
Math.sin(elapsed * 1.7 + bubble.userData.phase) * delta * 0.045;
if (bubble.position.y > bubble.userData.baseY + 0.55) {
bubble.position.y = bubble.userData.baseY;
}
}
updateCamera();
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```