Prompt specification
Build or customize the Three.js 3D scene "Summer drink preparation bar" 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: Summer drink preparation bar
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/summer-drink-preparation-bar-x0123
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring ice cubes and melting. Arrange glasses, ice tray, fruit slices, jug, and reusable straws; show cubes entering drinks and liquid levels rising consistently around their submerged portions. Voxel style.
Working Three.js Starter (summer-drink-preparation-bar-x0123):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Meltday — Voxel Drink Station</title>
<style>
:root {
--ink: #26323a;
--muted: #64747c;
--paper: rgba(255, 252, 246, 0.88);
--line: rgba(56, 73, 82, 0.12);
--mint: #68c7b6;
--orange: #f49a62;
--blue: #79bfe5;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #eee9df;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.overlay {
position: fixed;
inset: 0;
pointer-events: none;
}
.card {
background: var(--paper);
border: 1px solid rgba(255, 255, 255, 0.78);
box-shadow:
0 16px 40px rgba(65, 77, 81, 0.10),
inset 0 0 0 1px var(--line);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
.title-card {
position: absolute;
top: 24px;
left: 24px;
width: min(360px, calc(100vw - 48px));
padding: 18px 20px 16px;
border-radius: 18px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 8px;
color: #5b7774;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 9px;
height: 9px;
border-radius: 2px;
background: var(--mint);
box-shadow: 13px 0 0 #b7ded7;
}
h1 {
margin: 0;
font-size: clamp(26px, 4vw, 40px);
line-height: 0.95;
letter-spacing: -0.055em;
}
.subtitle {
margin: 10px 0 0;
max-width: 290px;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.status-card {
position: absolute;
top: 24px;
right: 24px;
min-width: 205px;
padding: 14px 16px;
border-radius: 16px;
}
.status-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 16px;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.status-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--mint);
box-shadow: 0 0 0 5px rgba(104, 199, 182, 0.14);
animation: pulse 1.8s ease-in-out infinite;
}
@keyframes pulse {
50% {
box-shadow: 0 0 0 8px rgba(104, 199, 182, 0.04);
}
}
.meter {
height: 6px;
margin-top: 12px;
overflow: hidden;
border-radius: 4px;
background: rgba(64, 88, 92, 0.10);
}
.meter-fill {
width: 100%;
height: 100%;
transform: scaleX(0);
transform-origin: left;
border-radius: inherit;
background: linear-gradient(90deg, #78cdbf, #8bc6e8, #f5ad74);
transition: transform 300ms ease-out;
}
.meter-label {
margin-top: 8px;
color: var(--muted);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.legend-card {
position: absolute;
bottom: 24px;
left: 24px;
display: flex;
gap: 18px;
align-items: center;
padding: 12px 16px;
border-radius: 14px;
color: var(--muted);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
}
.swatch {
width: 10px;
height: 10px;
border-radius: 2px;
box-shadow: inset 0 0 0 1px rgba(25, 45, 55, 0.08);
}
.help-card {
position: absolute;
right: 24px;
bottom: 24px;
max-width: 270px;
padding: 11px 14px;
border-radius: 14px;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
text-align: right;
}
.help-card strong {
color: var(--ink);
font-weight: 800;
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #eee9df;
color: #61757b;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
transition: opacity 400ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 720px) {
.title-card {
top: 14px;
left: 14px;
padding: 14px 16px;
}
.status-card {
top: 14px;
right: 14px;
min-width: 150px;
padding: 11px 13px;
}
.status-row {
font-size: 8px;
}
.subtitle {
display: none;
}
.legend-card {
left: 14px;
bottom: 14px;
gap: 10px;
padding: 10px 12px;
font-size: 8px;
}
.help-card {
right: 14px;
bottom: 14px;
max-width: 160px;
font-size: 9px;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<div class="overlay">
<section class="title-card card">
<div class="eyebrow">Voxel refreshment lab</div>
<h1>Meltday.</h1>
<p class="subtitle">
Ice cubes fly from the tray, settle into colorful drinks, displace the
liquid, and slowly melt back into it.
</p>
</section>
<section class="status-card card">
<div class="status-row">
<span id="statusText">Ice in motion</span>
<span class="status-dot"></span>
</div>
<div class="meter"><div class="meter-fill" id="meltFill"></div></div>
<div class="meter-label" id="meltLabel">0 cubes submerged</div>
</section>
<section class="legend-card card">
<div class="legend-item">
<span class="swatch" style="background:#70cbbb"></span> Drinks
</div>
<div class="legend-item">
<span class="swatch" style="background:#c7efff"></span> Ice
</div>
<div class="legend-item">
<span class="swatch" style="background:#f3a16a"></span> Fruit
</div>
</section>
<section class="help-card card">
<strong>Drag</strong> to orbit · <strong>Scroll</strong> to zoom ·
<strong>Tap a glass</strong> for ice
</section>
</div>
<div id="loading">Building the drink station…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const sceneHost = document.getElementById("scene");
const loading = document.getElementById("loading");
const statusText = document.getElementById("statusText");
const meltFill = document.getElementById("meltFill");
const meltLabel = document.getElementById("meltLabel");
// -------------------------------------------------------------------------
// Renderer, scene, camera, and lighting
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xeee9df);
scene.fog = new THREE.Fog(0xeee9df, 14, 27);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
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.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
sceneHost.appendChild(renderer.domElement);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
60
);
const cameraTarget = new THREE.Vector3(-0.15, 0.72, 0.0);
let azimuth = 0.60;
let polar = 1.02;
let cameraRadius = 10.9;
function updateCamera() {
const sinPolar = Math.sin(polar);
camera.position.set(
cameraTarget.x + cameraRadius * sinPolar * Math.sin(azimuth),
cameraTarget.y + cameraRadius * Math.cos(polar),
cameraTarget.z + cameraRadius * sinPolar * Math.cos(azimuth)
);
camera.lookAt(cameraTarget);
}
updateCamera();
const hemisphere = new THREE.HemisphereLight(0xfff8e9, 0x8099a1, 2.2);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff3dc, 3.2);
keyLight.position.set(-4.5, 9, 6.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -8;
keyLight.shadow.camera.right = 8;
keyLight.shadow.camera.top = 8;
keyLight.shadow.camera.bottom = -8;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 25;
keyLight.shadow.bias = -0.0008;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0xaedfff, 1.4);
rimLight.position.set(5, 5, -5);
scene.add(rimLight);
// -------------------------------------------------------------------------
// Shared materials and geometry helpers
// -------------------------------------------------------------------------
const palette = {
ink: 0x314149,
cream: 0xfff8e8,
mint: 0x79cbbb,
aqua: 0x7bc4df,
peach: 0xf29b67,
lavender: 0x9aa9dc,
tray: 0x7598bc,
trayDark: 0x3e607f,
tileA: 0xf4efe6,
tileB: 0xeae3d7,
tableEdge: 0xb8ada0
};
function standard(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.78,
metalness: 0,
...options
});
}
const materials = {
cream: standard(palette.cream, { roughness: 0.88 }),
tray: standard(palette.tray, { roughness: 0.68 }),
trayDark: standard(palette.trayDark, { roughness: 0.82 }),
mint: standard(palette.mint, { roughness: 0.72 }),
peach: standard(palette.peach, { roughness: 0.72 }),
lavender: standard(palette.lavender, { roughness: 0.72 }),
ink: standard(palette.ink, { roughness: 0.8 }),
tableEdge: standard(palette.tableEdge, { roughness: 0.95 })
};
const glassMaterial = new THREE.MeshPhysicalMaterial({
color: 0xd5f7ff,
transparent: true,
opacity: 0.24,
roughness: 0.13,
metalness: 0.02,
depthWrite: false
});
const glassEdgeMaterial = new THREE.LineBasicMaterial({
color: 0x78b7c7,
transparent: true,
opacity: 0.58
});
function box(
parent,
width,
height,
depth,
material,
x = 0,
y = 0,
z = 0,
castShadow = true,
receiveShadow = true
) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = receiveShadow;
parent.add(mesh);
return mesh;
}
function addEdges(mesh, color = 0x78b7c7, opacity = 0.52) {
const edgeMaterial = glassEdgeMaterial.clone();
edgeMaterial.color.setHex(color);
edgeMaterial.opacity = opacity;
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(mesh.geometry, 24),
edgeMaterial
);
edges.renderOrder = 7;
mesh.add(edges);
return edges;
}
// -------------------------------------------------------------------------
// Voxel tiled table
// -------------------------------------------------------------------------
const tableBase = box(
scene,
14.6,
0.24,
10.9,
materials.tableEdge,
0,
-0.17,
0,
false,
true
);
const columns = 12;
const rows = 9;
const tileGeometry = new THREE.BoxGeometry(1.18, 0.08, 1.18);
const tileMaterial = standard(0xffffff, { roughness: 0.95 });
const tiles = new THREE.InstancedMesh(
tileGeometry,
tileMaterial,
columns * rows
);
const dummy = new THREE.Object3D();
const tileColor = new THREE.Color();
let tileIndex = 0;
for (let row = 0; row < rows; row++) {
for (let column = 0; column < columns; column++) {
dummy.position.set(
(column - (columns - 1) / 2) * 1.2,
-0.04,
(row - (rows - 1) / 2) * 1.2
);
dummy.updateMatrix();
tiles.setMatrixAt(tileIndex, dummy.matrix);
const alternate = (column + row) % 2 === 0;
tileColor.setHex(alternate ? palette.tileA : palette.tileB);
tiles.setColorAt(tileIndex, tileColor);
tileIndex++;
}
}
tiles.instanceMatrix.needsUpdate = true;
if (tiles.instanceColor) tiles.instanceColor.needsUpdate = true;
tiles.receiveShadow = true;
scene.add(tiles);
// -------------------------------------------------------------------------
// Pixel fruit slices
// -------------------------------------------------------------------------
function makeFruitSlice(pulpColor, rindColor, pithColor = 0xffe9b0) {
const group = new THREE.Group();
const cell = 0.115;
const pulp = standard(pulpColor, { roughness: 0.82 });
const rind = standard(rindColor, { roughness: 0.86 });
const pith = standard(pithColor, { roughness: 0.9 });
for (let x = -4; x <= 4; x++) {
for (let y = -4; y <= 4; y++) {
const radius = Math.hypot(x, y);
if (radius > 4.3) continue;
let material = pulp;
if (radius > 3.45) material = rind;
else if (radius > 2.8) material = pith;
else if (radius < 0.8) material = pith;
box(
group,
cell * 0.91,
cell * 0.91,
0.105,
material,
x * cell,
y * cell,
0
);
}
}
return group;
}
const orangeSlice = makeFruitSlice(0xf49a4f, 0xe87538);
orangeSlice.rotation.x = -Math.PI / 2;
orangeSlice.position.set(2.65, 0.13, 1.72);
orangeSlice.rotation.z = 0.18;
scene.add(orangeSlice);
const limeSlice = makeFruitSlice(0xa9d66d, 0x4f9b54, 0xe5f1bc);
limeSlice.rotation.x = -Math.PI / 2;
limeSlice.position.set(2.18, 0.13, 2.05);
limeSlice.rotation.z = -0.32;
scene.add(limeSlice);
const lemonSlice = makeFruitSlice(0xf1d968, 0xd5b846, 0xfff4bd);
lemonSlice.rotation.x = -Math.PI / 2;
lemonSlice.position.set(2.88, 0.14, 2.26);
lemonSlice.scale.setScalar(0.78);
scene.add(lemonSlice);
// -------------------------------------------------------------------------
// Reusable voxel straws
// -------------------------------------------------------------------------
function addStraw(parent, color, x, z, height = 2.08) {
const group = new THREE.Group();
group.position.set(x, 0, z);
parent.add(group);
const material = standard(color, { roughness: 0.6 });
const lower = 0.34;
const upper = height;
box(
group,
0.085,
upper - lower,
0.085,
material,
0,
(upper + lower) / 2,
0
);
box(group, 0.12, 0.12, 0.12, material, 0.04, upper, 0);
box(group, 0.31, 0.085, 0.085, material, 0.19, upper, 0);
box(group, 0.085, 0.19, 0.085, material, 0.34, upper - 0.08, 0);
for (let i = 0; i < 3; i++) {
box(
group,
0.115,
0.035,
0.115,
materials.cream,
0,
1.72 + i * 0.055,
0
);
}
return group;
}
function addTableStraw(x, z, color, rotation) {
const group = new THREE.Group();
group.position.set(x, 0.1, z);
group.rotation.y = rotation;
scene.add(group);
const material = standard(color, { roughness: 0.64 });
box(group, 0.78, 0.065, 0.065, material, 0, 0, 0);
box(group, 0.09, 0.09, 0.09, material, 0.38, 0, 0);
box(group, 0.065, 0.065, 0.28, material, 0.38, 0, 0.14);
box(group, 0.09, 0.09, 0.09, materials.cream, -0.28, 0, 0);
}
addTableStraw(1.15, 2.27, 0xf08f67, -0.18);
addTableStraw(1.65, 2.42, 0x68bcae, 0.08);
// -------------------------------------------------------------------------
// Square voxel glasses and their liquid volumes
// -------------------------------------------------------------------------
const glasses = [];
const pickMeshes = [];
const cubeOffsets = [
new THREE.Vector2(-0.22, -0.17),
new THREE.Vector2(0.22, -0.17),
new THREE.Vector2(0.0, 0.22)
];
function makeGlass(position, color, initialHeight, strawColor) {
const group = new THREE.Group();
group.position.copy(position);
scene.add(group);
const glass = {
group,
color,
baseY: 0.10,
innerWidth: 1.08,
area: 1.08 * 1.08,
level: initialHeight,
initialVolume: initialHeight * 1.08 * 1.08,
cubes: [],
cubeCount: 0,
foam: []
};
const outer = 1.26;
const wall = 0.09;
const wallHeight = 1.48;
const wallCenter = glass.baseY + wallHeight / 2;
const zCenter = outer / 2 - wall / 2;
const bottom = box(
group,
outer,
0.09,
outer,
glassMaterial,
0,
0.045,
0,
false,
false
);
bottom.renderOrder = 5;
addEdges(bottom, 0x8cc7d3, 0.48);
const front = box(
group,
outer,
wallHeight,
wall,
glassMaterial,
0,
wallCenter,
zCenter,
false,
false
);
const back = box(
group,
outer,
wallHeight,
wall,
glassMaterial,
0,
wallCenter,
-zCenter,
false,
false
);
const left = box(
group,
wall,
wallHeight,
glass.innerWidth,
glassMaterial,
-zCenter,
wallCenter,
0,
false,
false
);
const right = box(
group,
wall,
wallHeight,
glass.innerWidth,
glassMaterial,
zCenter,
wallCenter,
0,
false,
false
);
for (const wallMesh of [front, back, left, right]) {
wallMesh.renderOrder = 5;
wallMesh.userData.glass = glass;
pickMeshes.push(wallMesh);
addEdges(wallMesh, 0x84c3d0, 0.58);
}
const rimY = glass.baseY + wallHeight;
const rimFront = box(
group,
outer + 0.04,
0.055,
0.11,
glassMaterial,
0,
rimY,
zCenter,
false,
false
);
rimFront.renderOrder = 6;
const rimBack = rimFront.clone();
rimBack.position.z = -zCenter;
group.add(rimBack);
const rimSide = box(
group,
0.11,
0.055,
glass.innerWidth,
glassMaterial,
zCenter,
rimY,
0,
false,
false
);
rimSide.renderOrder = 6;
const rimSide2 = rimSide.clone();
rimSide2.position.x = -zCenter;
group.add(rimSide2);
const liquidMaterial = new THREE.MeshPhysicalMaterial({
color,
transparent: true,
opacity: 0.73,
roughness: 0.22,
metalness: 0,
depthWrite: false
});
const liquid = box(
group,
glass.innerWidth,
1,
glass.innerWidth,
liquidMaterial,
0,
glass.baseY + initialHeight / 2,
0,
false,
false
);
liquid.scale.y = initialHeight;
liquid.renderOrder = 2;
const surfaceColor = new THREE.Color(color).lerp(
new THREE.Color(0xffffff),
0.34
);
const surfaceMaterial = new THREE.MeshBasicMaterial({
color: surfaceColor,
transparent: true,
opacity: 0.86,
depthWrite: false
});
const surface = box(
group,
glass.innerWidth + 0.012,
0.025,
glass.innerWidth + 0.012,
surfaceMaterial,
0,
glass.baseY + initialHeight,
0,
false,
false
);
surface.renderOrder = 4;
glass.liquid = liquid;
glass.surface = surface;
glass.surfaceMaterial = surfaceMaterial;
// Small measurement marks.
for (let i = 0; i < 4; i++) {
box(
group,
i === 3 ? 0.18 : 0.12,
0.022,
0.025,
materials.cream,
0.48,
0.42 + i * 0.30,
0.648
);
}
// A small pixel badge on the front.
box(group, 0.24, 0.095, 0.028, materials.cream, 0, 0.25, 0.658);
box(
group,
0.12,
0.045,
0.03,
standard(color, { roughness: 0.7 }),
0,
0.25,
0.68
);
addStraw(group, strawColor, 0.30, -0.19);
const garnish = makeFruitSlice(
color,
new THREE.Color(color).multiplyScalar(0.72).getHex(),
0xffe8b4
);
garnish.scale.setScalar(0.50);
garnish.position.set(0.47, 1.48, 0.16);
group.add(garnish);
// A few floating voxel bubbles.
const foamMaterial = new THREE.MeshBasicMaterial({
color: 0xfff9e9,
transparent: true,
opacity: 0.72,
depthWrite: false
});
const foamOffsets = [
new THREE.Vector2(-0.12, -0.10),
new THREE.Vector2(0.12, 0.03),
new THREE.Vector2(-0.04, 0.17)
];
for (const offset of foamOffsets) {
const foam = box(
group,
0.065,
0.035,
0.065,
foamMaterial,
offset.x,
glass.baseY + initialHeight + 0.025,
offset.y,
false,
false
);
foam.renderOrder = 5;
glass.foam.push({ mesh: foam, offset });
}
glasses.push(glass);
return glass;
}
makeGlass(
new THREE.Vector3(-1.20, 0, 0.70),
0x59c7b5,
0.76,
0xf5a37a
);
makeGlass(
new THREE.Vector3(0.62, 0, 0.98),
0xee9a60,
0.88,
0x75b8cf
);
makeGlass(
new THREE.Vector3(1.55, 0, -0.34),
0x8ea9d8,
0.67,
0xf3d47a
);
// -------------------------------------------------------------------------
// Voxel water jug
// -------------------------------------------------------------------------
function makeJug() {
const group = new THREE.Group();
group.position.set(3.02, 0, -1.72);
group.rotation.y = -0.12;
scene.add(group);
const bodyWidth = 1.38;
const bodyDepth = 1.18;
const wall = 0.09;
const bodyHeight = 1.78;
const wallCenter = 0.09 + bodyHeight / 2;
const base = box(
group,
bodyWidth,
0.10,
bodyDepth,
glassMaterial,
0,
0.05,
0,
false,
false
);
base.renderOrder = 5;
addEdges(base, 0x77b4c6, 0.52);
const front = box(
group,
bodyWidth,
bodyHeight,
wall,
glassMaterial,
0,
wallCenter,
bodyDepth / 2 - wall / 2,
false,
false
);
const back = front.clone();
back.position.z *= -1;
group.add(back);
const left = box(
group,
wall,
bodyHeight,
bodyDepth - wall * 2,
glassMaterial,
-bodyWidth / 2 + wall / 2,
wallCenter,
0,
false,
false
);
const right = left.clone();
right.position.x *= -1;
group.add(right);
for (const wallMesh of [front, back, left, right]) {
wallMesh.renderOrder = 5;
addEdges(wallMesh, 0x76b0c4, 0.52);
}
const jugLiquidMaterial = new THREE.MeshPhysicalMaterial({
color: 0x65bddd,
transparent: true,
opacity: 0.68,
roughness: 0.23,
depthWrite: false
});
const liquid = box(
group,
bodyWidth - wall * 2,
1.13,
bodyDepth - wall * 2,
jugLiquidMaterial,
0,
0.10 + 1.13 / 2,
0,
false,
false
);
liquid.renderOrder = 2;
const topY = 0.09 + bodyHeight;
box(group, bodyWidth + 0.05, 0.06, 0.12, glassMaterial, 0, topY, 0.54, false, false);
box(group, bodyWidth + 0.05, 0.06, 0.12, glassMaterial, 0, topY, -0.54, false, false);
box(group, 0.12, 0.06, bodyDepth - 0.10, glassMaterial, 0.64, topY, 0, false, false);
box(group, 0.12, 0.06, bodyDepth - 0.10, glassMaterial, -0.64, topY, 0, false, false);
// Stepped pouring spout.
box(group, 0.42, 0.18, 0.86, glassMaterial, -0.80, topY - 0.04, 0, false, false);
box(group, 0.24, 0.23, 0.65, glassMaterial, -0.96, topY + 0.08, 0, false, false);
box(group, 0.08, 0.12, 0.62, materials.ink, -1.06, topY + 0.08, 0, false, false);
// Pixel handle.
const handleMaterial = standard(0x71a9bb, { roughness: 0.68 });
box(group, 0.58, 0.13, 0.15, handleMaterial, 0.91, 0.56, 0);
box(group, 0.58, 0.13, 0.15, handleMaterial, 0.91, 1.51, 0);
box(group, 0.14, 1.05, 0.15, handleMaterial, 1.16, 1.035, 0);
addStraw(group, 0xf5e6b8, -0.24, 0.18, 2.35);
}
makeJug();
// -------------------------------------------------------------------------
// Ice tray and eight-bit-style voxel ice cubes
// -------------------------------------------------------------------------
const tray = new THREE.Group();
tray.position.set(-3.18, 0, -0.42);
tray.rotation.y = 0.08;
scene.add(tray);
box(tray, 2.30, 0.13, 1.96, materials.tray, 0, 0.065, 0);
box(tray, 2.10, 0.035, 1.76, materials.trayDark, 0, 0.145, 0, false, true);
// Outer rim.
box(tray, 2.34, 0.22, 0.10, materials.tray, 0, 0.20, 0.93);
box(tray, 2.34, 0.22, 0.10, materials.tray, 0, 0.20, -0.93);
box(tray, 0.10, 0.22, 1.76, materials.tray, -1.12, 0.20, 0);
box(tray, 0.10, 0.22, 1.76, materials.tray, 1.12, 0.20, 0);
// Grid dividers.
for (const x of [-0.37, 0.37]) {
box(tray, 0.07, 0.20, 1.78, materials.tray, x, 0.20, 0);
}
for (const z of [-0.31, 0.31]) {
box(tray, 2.18, 0.20, 0.07, materials.tray, 0, 0.20, z);
}
function makeIceCube(size) {
const group = new THREE.Group();
const clearMaterial = new THREE.MeshPhysicalMaterial({
color: 0xc7f4ff,
transparent: true,
opacity: 0.76,
roughness: 0.10,
metalness: 0.02,
depthWrite: false
});
const frostMaterial = new THREE.MeshStandardMaterial({
color: 0xf2fdff,
transparent: true,
opacity: 0.88,
roughness: 0.45,
depthWrite: false
});
const subSize = size / 2 - 0.012;
for (let x = 0; x < 2; x++) {
for (let y = 0; y < 2; y++) {
for (let z = 0; z < 2; z++) {
const useFrost = (x === 1 && y === 1 && z === 1) ||
(x === 0 && y === 0 && z === 1);
const mesh = box(
group,
subSize,
subSize,
subSize,
useFrost ? frostMaterial : clearMaterial,
(x - 0.5) * size / 2,
(y - 0.5) * size / 2,
(z - 0.5) * size / 2,
false,
false
);
mesh.renderOrder = 4;
}
}
}
group.userData.iceMaterials = [
{ material: clearMaterial, baseOpacity: 0.76 },
{ material: frostMaterial, baseOpacity: 0.88 }
];
return group;
}
const iceSources = [];
for (let zIndex = 0; zIndex < 3; zIndex++) {
for (let xIndex = 0; xIndex < 3; xIndex++) {
const size = 0.32;
const group = makeIceCube(size);
group.position.set(
(xIndex - 1) * 0.70,
0.34,
(zIndex - 1) * 0.60
);
tray.add(group);
iceSources.push({
group,
size,
scale: 1,
active: false,
state: "tray",
glass: null,
start: new THREE.Vector3(),
control1: new THREE.Vector3(),
control2: new THREE.Vector3(),
end: new THREE.Vector3(),
finalY: 0,
flightStart: 0,
flightDuration: 1.2,
fallStart: 0,
fallDuration: 1,
fallFrom: 0,
settleStart: 0,
startRotation: 0,
nextDrip: 0
});
}
}
// -------------------------------------------------------------------------
// Splash particles and square surface ripples
// -------------------------------------------------------------------------
const particles = [];
const ripples = [];
const particleGeometry = new THREE.BoxGeometry(1, 1, 1);
function spawnSplash(glass) {
const surfaceY = glass.baseY + glass.level;
for (let i = 0; i < 11; i++) {
const material = new THREE.MeshBasicMaterial({
color: glass.color,
transparent: true,
opacity: 0.88,
depthWrite: false
});
const size = 0.035 + Math.random() * 0.035;
const mesh = new THREE.Mesh(particleGeometry, material);
mesh.scale.set(size, size, size);
mesh.position.set(
glass.group.position.x + (Math.random() - 0.5) * 0.28,
surfaceY + 0.03,
glass.group.position.z + (Math.random() - 0.5) * 0.28
);
mesh.renderOrder = 6;
scene.add(mesh);
const angle = Math.random() * Math.PI * 2;
const speed = 0.35 + Math.random() * 0.52;
particles.push({
mesh,
velocity: new THREE.Vector3(
Math.cos(angle) * speed,
1.1 + Math.random() * 1.25,
Math.sin(angle) * speed
),
gravity: -3.8,
age: 0,
life: 0.65 + Math.random() * 0.40
});
}
const rippleMaterial = new THREE.MeshBasicMaterial({
color: new THREE.Color(glass.color).lerp(
new THREE.Color(0xffffff),
0.48
),
transparent: true,
opacity: 0.78,
depthWrite: false
});
const ripple = new THREE.Group();
box(ripple, 0.72, 0.018, 0.035, rippleMaterial, 0, 0, 0.34, false, false);
box(ripple, 0.72, 0.018, 0.035, rippleMaterial, 0, 0, -0.34, false, false);
box(ripple, 0.035, 0.018, 0.65, rippleMaterial, 0.34, 0, 0, false, false);
box(ripple, 0.035, 0.018, 0.65, rippleMaterial, -0.34, 0, 0, false, false);
ripple.position.set(
glass.group.position.x,
surfaceY + 0.025,
glass.group.position.z
);
scene.add(ripple);
ripples.push({
group: ripple,
material: rippleMaterial,
glass,
age: 0,
life: 1.05
});
}
function spawnMeltDrip(source) {
const glass = source.glass;
const visualSize = source.size * source.scale;
const material = new THREE.MeshBasicMaterial({
color: 0xe5fbff,
transparent: true,
opacity: 0.78,
depthWrite: false
});
const mesh = new THREE.Mesh(particleGeometry, material);
mesh.scale.set(0.045, 0.06, 0.045);
mesh.position.set(
source.group.position.x + (Math.random() - 0.5) * 0.10,
source.group.position.y + visualSize / 2,
source.group.position.z + (Math.random() - 0.5) * 0.10
);
mesh.renderOrder = 6;
scene.add(mesh);
particles.push({
mesh,
velocity: new THREE.Vector3(0, -0.22, 0),
gravity: -0.38,
age: 0,
life: 0.85
});
// Keep the referenced glass alive in this scope.
void glass;
}
// -------------------------------------------------------------------------
// Ice launch choreography
// -------------------------------------------------------------------------
function cubicBezier(p0, p1, p2, p3, t) {
const u = 1 - t;
const u2 = u * u;
const t2 = t * t;
return new THREE.Vector3(
u2 * u * p0.x + 3 * u2 * t * p1.x + 3 * u * t2 * p2.x + t2 * t * p3.x,
u2 * u * p0.y + 3 * u2 * t * p1.y + 3 * u * t2 * p2.y + t2 * t * p3.y,
u2 * u * p0.z + 3 * u2 * t * p1.z + 3 * u * t2 * p2.z + t2 * t * p3.z
);
}
function launchCube(glass) {
const source = iceSources.find((candidate) => !candidate.active);
if (!source) return null;
const offset = cubeOffsets[glass.cubeCount % cubeOffsets.length];
glass.cubeCount++;
source.active = true;
source.state = "flight";
source.glass = glass;
source.scale = 1;
source.nextDrip = elapsed + 1.5 + Math.random();
source.group.scale.setScalar(1);
scene.updateMatrixWorld(true);
scene.attach(source.group);
source.start.copy(source.group.position);
source.startRotation = source.group.rotation.y;
source.end.set(
glass.group.position.x + offset.x,
2.76,
glass.group.position.z + offset.y
);
source.control1.copy(source.start).lerp(source.end, 0.28);
source.control1.y += 1.45;
source.control2.copy(source.end);
source.control2.x -= 0.62;
source.control2.y += 1.02;
source.control2.z += 0.22;
source.flightStart = elapsed;
source.flightDuration = 1.13 + Math.random() * 0.16;
source.finalY =
glass.group.position.y +
glass.baseY +
source.size / 2 +
0.012;
source.fallFrom = source.end.y;
source.fallDuration = Math.sqrt(
(2 * (source.fallFrom - source.finalY)) / 5.2
);
glass.cubes.push(source);
return source;
}
const launchPlan = [
{ at: 0.75, glass: 0 },
{ at: 2.05, glass: 1 },
{ at: 3.35, glass: 2 },
{ at: 4.65, glass: 0 },
{ at: 5.95, glass: 1 },
{ at: 7.25, glass: 2 },
{ at: 8.55, glass: 0 },
{ at: 9.85, glass: 1 },
{ at: 11.15, glass: 2 }
];
let nextLaunch = 0;
function updateIceSources(deltaTime) {
for (const source of iceSources) {
if (!source.active) continue;
if (source.state === "flight") {
const t = THREE.MathUtils.clamp(
(elapsed - source.flightStart) / source.flightDuration,
0,
1
);
source.group.position.copy(
cubicBezier(
source.start,
source.control1,
source.control2,
source.end,
t
)
);
source.group.rotation.y =
source.startRotation + t * Math.PI * 2;
if (t >= 1) {
source.state = "falling";
source.fallStart = elapsed;
}
} else if (source.state === "falling") {
const t = THREE.MathUtils.clamp(
(elapsed - source.fallStart) / source.fallDuration,
0,
1
);
const y = source.fallFrom - 0.5 * 5.2 * t * t;
source.group.position.set(
source.end.x,
Math.max(source.finalY, y),
source.end.z
);
source.group.rotation.y += deltaTime * 3.5;
if (t >= 1) {
source.state = "settled";
source.settleStart = elapsed;
source.group.position.y = source.finalY;
spawnSplash(source.glass);
}
} else if (source.state === "settled") {
const age = elapsed - source.settleStart;
const meltProgress = THREE.MathUtils.clamp(age / 17, 0, 1);
const eased = meltProgress * meltProgress * (3 - 2 * meltProgress);
// Cubes retain their footprint on the glass bottom while shrinking.
source.scale = 1 - 0.36 * eased;
source.group.scale.setScalar(source.scale);
const bottom = source.glass.group.position.y + source.glass.baseY;
source.group.position.y = bottom + source.size * source.scale / 2;
for (const entry of source.group.userData.iceMaterials) {
entry.material.opacity =
entry.baseOpacity * (0.72 + source.scale * 0.28);
}
if (elapsed >= source.nextDrip && source.scale < 0.995) {
spawnMeltDrip(source);
source.nextDrip = elapsed + 1.35 + Math.random() * 0.9;
}
}
}
}
// -------------------------------------------------------------------------
// Liquid displacement and melt-volume model
//
// Each submerged cube contributes its submerged rectangular volume.
// Melting converts the lost cube volume into liquid with a slightly
// generous 1.22 factor so the colored drink visibly rises as it melts.
// -------------------------------------------------------------------------
function updateLiquids(deltaTime) {
for (const glass of glasses) {
const previousLevel = glass.level;
let displacedVolume = 0;
let meltWater = 0;
for (const source of glass.cubes) {
const visualSize = source.size * source.scale;
const cubeBottom = source.group.position.y - visualSize / 2;
if (cubeBottom < previousLevel) {
const penetration = THREE.MathUtils.clamp(
previousLevel - cubeBottom,
0,
visualSize
);
displacedVolume += visualSize * visualSize * penetration;
}
const originalVolume = source.size ** 3;
const currentVolume = visualSize ** 3;
meltWater += (originalVolume - currentVolume) * 1.22;
}
const targetLevel = glass.baseY +
(glass.initialVolume + displacedVolume + meltWater) / glass.area;
const clampedTarget = THREE.MathUtils.clamp(targetLevel, 0.02, 1.40);
const smoothing = 1 - Math.exp(-11 * deltaTime);
glass.level += (clampedTarget - glass.level) * smoothing;
glass.liquid.scale.y = Math.max(0.005, glass.level);
glass.liquid.position.y = glass.baseY + glass.level / 2;
const surfaceY = glass.baseY + glass.level;
glass.surface.position.y = surfaceY;
for (const foam of glass.foam) {
foam.mesh.position.y =
surfaceY + 0.025 + Math.sin(elapsed * 2.3 + foam.offset.x * 9) * 0.006;
}
}
}
// -------------------------------------------------------------------------
// Particle and ripple updates
// -------------------------------------------------------------------------
function updateEffects(deltaTime) {
for (let i = particles.length - 1; i >= 0; i--) {
const particle = particles[i];
particle.age += deltaTime;
particle.velocity.y += particle.gravity * deltaTime;
particle.mesh.position.addScaledVector(particle.velocity, deltaTime);
particle.mesh.rotation.x += deltaTime * 2;
particle.mesh.rotation.z += deltaTime * 1.6;
particle.mesh.material.opacity =
0.88 * Math.max(0, 1 - particle.age / particle.life);
if (particle.age >= particle.life) {
scene.remove(particle.mesh);
particle.mesh.material.dispose();
particles.splice(i, 1);
}
}
for (let i = ripples.length - 1; i >= 0; i--) {
const ripple = ripples[i];
ripple.age += deltaTime;
const progress = ripple.age / ripple.life;
const scale = 1 + progress * 1.7;
ripple.group.scale.set(scale, 1, scale);
ripple.group.position.y =
ripple.glass.baseY + ripple.glass.level + 0.025;
ripple.material.opacity = 0.78 * Math.max(0, 1 - progress);
if (ripple.age >= ripple.life) {
scene.remove(ripple.group);
ripple.material.dispose();
ripples.splice(i, 1);
}
}
}
// -------------------------------------------------------------------------
// Direct camera controls: orbit, zoom, and glass picking
// -------------------------------------------------------------------------
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
let dragging = false;
let pointerMoved = false;
let lastPointerX = 0;
let lastPointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerMoved = false;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
if (Math.abs(dx) + Math.abs(dy) > 2) pointerMoved = true;
azimuth = THREE.MathUtils.clamp(
azimuth - dx * 0.006,
-1.22,
1.22
);
polar = THREE.MathUtils.clamp(
polar - dy * 0.005,
0.58,
1.34
);
lastPointerX = event.clientX;
lastPointerY = event.clientY;
});
renderer.domElement.addEventListener("pointerup", (event) => {
dragging = false;
if (!pointerMoved) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x =
((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y =
-((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(pickMeshes, false);
if (hits.length > 0 && hits[0].object.userData.glass) {
launchCube(hits[0].object.userData.glass);
}
}
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
});
renderer.domElement.addEventListener("pointercancel", () => {
dragging = false;
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraRadius = THREE.MathUtils.clamp(
cameraRadius + event.deltaY * 0.008,
6.4,
15.5
);
},
{ passive: false }
);
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
// -------------------------------------------------------------------------
// Resize and animation loop
// -------------------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
const clock = new THREE.Clock();
let elapsed = 0;
let uiTimer = 0;
function animate() {
requestAnimationFrame(animate);
const deltaTime = Math.min(clock.getDelta(), 0.05);
elapsed += deltaTime;
while (
nextLaunch < launchPlan.length &&
elapsed >= launchPlan[nextLaunch].at
) {
const plan = launchPlan[nextLaunch];
launchCube(glasses[plan.glass]);
nextLaunch++;
}
updateIceSources(deltaTime);
updateLiquids(deltaTime);
updateEffects(deltaTime);
updateCamera();
uiTimer += deltaTime;
if (uiTimer > 0.15) {
uiTimer = 0;
const settled = iceSources.filter(
(source) => source.state === "settled"
);
const inMotion = iceSources.filter(
(source) => source.active && source.state !== "settled"
).length;
const averageMelt = settled.length
? settled.reduce(
(sum, source) => sum + (1 - source.scale ** 3),
0
) / settled.length
: 0;
meltFill.style.transform = `scaleX(${averageMelt.toFixed(3)})`;
meltLabel.textContent = `${settled.length} / 9 cubes submerged`;
statusText.textContent = inMotion
? `${inMotion} ice cube${inMotion === 1 ? "" : "s"} in motion`
: "Slow melt · levels rising";
}
renderer.render(scene, camera);
}
animate();
requestAnimationFrame(() => {
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 500);
});
</script>
</body>
</html>
```