Prompt specification
Build or customize the Three.js 3D scene "Ice tray cavity and cube" 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: Ice tray cavity and cube
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/ice-tray-cavity-and-cube-x0121
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts ice cubes and melting. Model a flexible tray with one raised cube above its matching cavity, rounded corners, and a thin melt puddle; preserve the recognizable inverse shapes. Stylized solid forms.
Working Three.js Starter (ice-tray-cavity-and-cube-x0121):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Soft Thaw — Melting Ice Tray</title>
<style>
:root {
color-scheme: light;
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: #e8f3ef;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.hud {
position: fixed;
top: clamp(18px, 4vw, 42px);
left: clamp(18px, 4vw, 46px);
z-index: 2;
max-width: min(360px, calc(100vw - 36px));
pointer-events: none;
color: #174b50;
text-shadow: 0 1px 12px rgba(255, 255, 255, 0.65);
}
.eyebrow {
display: inline-flex;
align-items: center;
gap: 8px;
margin-bottom: 10px;
padding: 7px 11px;
border: 1px solid rgba(35, 117, 120, 0.18);
border-radius: 999px;
background: rgba(255, 255, 255, 0.46);
backdrop-filter: blur(12px);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.eyebrow::before {
width: 7px;
height: 7px;
border-radius: 50%;
background: #58c9cf;
box-shadow: 0 0 0 4px rgba(88, 201, 207, 0.14);
content: "";
}
h1 {
margin: 0;
font-size: clamp(34px, 5vw, 62px);
font-weight: 720;
line-height: 0.95;
letter-spacing: -0.055em;
}
.subtitle {
margin: 12px 0 0;
max-width: 290px;
color: rgba(23, 75, 80, 0.7);
font-size: 13px;
line-height: 1.5;
}
.controls {
position: fixed;
right: clamp(16px, 3vw, 34px);
bottom: clamp(16px, 3vw, 30px);
z-index: 2;
padding: 9px 13px;
border: 1px solid rgba(31, 104, 108, 0.13);
border-radius: 999px;
background: rgba(255, 255, 255, 0.54);
box-shadow: 0 8px 30px rgba(36, 92, 91, 0.08);
backdrop-filter: blur(12px);
color: rgba(20, 73, 78, 0.7);
font-size: 11px;
font-weight: 650;
letter-spacing: 0.02em;
pointer-events: none;
}
@media (max-width: 640px) {
.subtitle {
max-width: 230px;
font-size: 12px;
}
.controls {
left: 50%;
right: auto;
transform: translateX(-50%);
white-space: nowrap;
}
}
</style>
</head>
<body>
<header class="hud">
<div class="eyebrow">Melting study</div>
<h1>Soft<br />Thaw</h1>
<p class="subtitle">
A raised ice cube, its matching silicone cavity, and a slowly spreading melt puddle.
</p>
</header>
<div class="controls">Drag to orbit · Scroll to zoom</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 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.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Interactive three-dimensional scene of ice cubes melting in a flexible tray"
);
document.body.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe8f3ef);
scene.fog = new THREE.Fog(0xe8f3ef, 14, 28);
const camera = new THREE.PerspectiveCamera(
35,
window.innerWidth / window.innerHeight,
0.1,
60
);
const cameraTarget = new THREE.Vector3(0, 0.8, 0);
const spherical = new THREE.Spherical(11.4, 1.02, 0.68);
function updateCamera() {
camera.position.setFromSpherical(spherical).add(cameraTarget);
camera.lookAt(cameraTarget);
}
updateCamera();
// ------------------------------------------------------------
// Lighting
// ------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xf4ffff, 0x789b8d, 2.25));
const keyLight = new THREE.DirectionalLight(0xfffaf0, 3.1);
keyLight.position.set(-4.5, 9, 5.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -7;
keyLight.shadow.camera.right = 7;
keyLight.shadow.camera.top = 7;
keyLight.shadow.camera.bottom = -7;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 22;
keyLight.shadow.bias = -0.00035;
keyLight.shadow.normalBias = 0.025;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xb8e9ff, 1.25);
fillLight.position.set(7, 4, -5);
scene.add(fillLight);
const rimLight = new THREE.PointLight(0x7de4e1, 12, 18, 2);
rimLight.position.set(-5, 3.2, -4);
scene.add(rimLight);
// ------------------------------------------------------------
// Geometry helpers
// ------------------------------------------------------------
function roundedRectShape(width, height, radius) {
const x = -width / 2;
const y = -height / 2;
const r = Math.min(radius, width / 2, height / 2);
const shape = new THREE.Shape();
shape.moveTo(x + r, y);
shape.lineTo(x + width - r, y);
shape.quadraticCurveTo(x + width, y, x + width, y + r);
shape.lineTo(x + width, y + height - r);
shape.quadraticCurveTo(
x + width,
y + height,
x + width - r,
y + height
);
shape.lineTo(x + r, y + height);
shape.quadraticCurveTo(x, y + height, x, y + height - r);
shape.lineTo(x, y + r);
shape.quadraticCurveTo(x, y, x + r, y);
return shape;
}
// Opposite winding is required when a path is used as a hole.
function roundedRectHole(width, height, radius, centerX = 0, centerY = 0) {
const x = centerX - width / 2;
const y = centerY - height / 2;
const r = Math.min(radius, width / 2, height / 2);
const path = new THREE.Path();
path.moveTo(x + r, y);
path.quadraticCurveTo(x, y, x, y + r);
path.lineTo(x, y + height - r);
path.quadraticCurveTo(x, y + height, x + r, y + height);
path.lineTo(x + width - r, y + height);
path.quadraticCurveTo(
x + width,
y + height,
x + width,
y + height - r
);
path.lineTo(x + width, y + r);
path.quadraticCurveTo(x + width, y, x + width - r, y);
path.lineTo(x + r, y);
return path;
}
function verticalExtrusion(shape, height, bevel = 0.04) {
const bevelThickness = Math.min(bevel, height / 3);
const bevelSize = bevel * 0.8;
const depth = Math.max(0.001, height - bevelThickness * 2);
const geometry = new THREE.ExtrudeGeometry(shape, {
depth,
bevelEnabled: bevel > 0,
bevelSegments: 3,
steps: 1,
bevelSize,
bevelThickness,
curveSegments: 12
});
geometry.rotateX(-Math.PI / 2);
geometry.translate(0, -height / 2, 0);
geometry.computeVertexNormals();
return geometry;
}
function roundedBoxGeometry(width, height, depth, radius, bevel = 0.08) {
const bevelSize = bevel * 0.8;
const shape = roundedRectShape(
width - bevelSize * 2,
depth - bevelSize * 2,
Math.max(0.02, radius - bevelSize)
);
return verticalExtrusion(shape, height, bevel);
}
function roundedRectPoints(width, height, radius, segments = 7) {
const points = [];
const r = Math.min(radius, width / 2, height / 2);
const corners = [
[width / 2 - r, -height / 2 + r, -Math.PI / 2, 0],
[width / 2 - r, height / 2 - r, 0, Math.PI / 2],
[-width / 2 + r, height / 2 - r, Math.PI / 2, Math.PI],
[-width / 2 + r, -height / 2 + r, Math.PI, Math.PI * 1.5]
];
for (const [cx, cy, start, end] of corners) {
for (let i = 0; i <= segments; i++) {
const angle = THREE.MathUtils.lerp(start, end, i / segments);
points.push(
new THREE.Vector2(
cx + Math.cos(angle) * r,
cy + Math.sin(angle) * r
)
);
}
}
return points;
}
function makeCavityGeometry(topWidth, topDepth, bottomWidth, bottomDepth, depth) {
const top = roundedRectPoints(topWidth, topDepth, 0.24);
const bottom = roundedRectPoints(bottomWidth, bottomDepth, 0.18);
const count = top.length;
const positions = [];
const indices = [];
for (const point of top) {
positions.push(point.x, 0, point.y);
}
for (const point of bottom) {
positions.push(point.x, -depth, point.y);
}
for (let i = 0; i < count; i++) {
const next = (i + 1) % count;
const a = i;
const b = next;
const c = count + next;
const d = count + i;
indices.push(a, b, c, a, c, d);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
return geometry;
}
function makeIrregularPuddle(radiusX, radiusZ, phase = 0) {
const shape = new THREE.Shape();
const points = [];
for (let i = 0; i < 64; i++) {
const angle = (i / 64) * Math.PI * 2;
const wobble =
1 +
Math.sin(angle * 3 + phase) * 0.045 +
Math.cos(angle * 7 - phase * 0.7) * 0.025;
points.push(
new THREE.Vector2(
Math.cos(angle) * radiusX * wobble,
Math.sin(angle) * radiusZ * wobble
)
);
}
shape.setFromPoints(points);
shape.closePath();
const geometry = new THREE.ExtrudeGeometry(shape, {
depth: 0.018,
bevelEnabled: true,
bevelSegments: 2,
steps: 1,
bevelSize: 0.012,
bevelThickness: 0.008,
curveSegments: 8
});
geometry.rotateX(-Math.PI / 2);
geometry.computeVertexNormals();
return geometry;
}
// ------------------------------------------------------------
// Table
// ------------------------------------------------------------
const table = new THREE.Mesh(
new THREE.PlaneGeometry(36, 36),
new THREE.MeshStandardMaterial({
color: 0xdcebe4,
roughness: 0.94,
metalness: 0
})
);
table.rotation.x = -Math.PI / 2;
table.position.y = -0.005;
table.receiveShadow = true;
scene.add(table);
// ------------------------------------------------------------
// Materials
// ------------------------------------------------------------
const trayMaterial = new THREE.MeshPhysicalMaterial({
color: 0x56b9b1,
roughness: 0.48,
metalness: 0,
clearcoat: 0.45,
clearcoatRoughness: 0.42
});
const trayTopMaterial = new THREE.MeshPhysicalMaterial({
color: 0x67c7bd,
roughness: 0.38,
metalness: 0,
clearcoat: 0.62,
clearcoatRoughness: 0.3
});
const cavityMaterial = new THREE.MeshStandardMaterial({
color: 0x287f83,
roughness: 0.38,
metalness: 0,
side: THREE.DoubleSide
});
const cavityFloorMaterial = new THREE.MeshStandardMaterial({
color: 0x58aeb0,
roughness: 0.3,
metalness: 0,
side: THREE.DoubleSide
});
const iceMaterials = [
new THREE.MeshPhysicalMaterial({
color: 0xc8f2fa,
roughness: 0.24,
metalness: 0,
transmission: 0.08,
thickness: 0.8,
transparent: true,
opacity: 0.94,
clearcoat: 0.72,
clearcoatRoughness: 0.2
}),
new THREE.MeshPhysicalMaterial({
color: 0xaee8f4,
roughness: 0.27,
metalness: 0,
transmission: 0.1,
thickness: 0.8,
transparent: true,
opacity: 0.94,
clearcoat: 0.68,
clearcoatRoughness: 0.23
}),
new THREE.MeshPhysicalMaterial({
color: 0xd8f7fb,
roughness: 0.22,
metalness: 0,
transmission: 0.06,
thickness: 0.8,
transparent: true,
opacity: 0.95,
clearcoat: 0.76,
clearcoatRoughness: 0.18
})
];
const beadMaterial = new THREE.MeshPhysicalMaterial({
color: 0xf2ffff,
roughness: 0.08,
transmission: 0.25,
transparent: true,
opacity: 0.72,
clearcoat: 1
});
const puddleMaterial = new THREE.MeshPhysicalMaterial({
color: 0x67cddd,
roughness: 0.13,
metalness: 0,
transmission: 0.14,
transparent: true,
opacity: 0.5,
clearcoat: 1,
clearcoatRoughness: 0.08,
depthWrite: false,
side: THREE.DoubleSide
});
const cavityWaterMaterial = new THREE.MeshPhysicalMaterial({
color: 0x4cc7d8,
roughness: 0.1,
transmission: 0.1,
transparent: true,
opacity: 0.64,
clearcoat: 1,
depthWrite: false,
side: THREE.DoubleSide
});
// ------------------------------------------------------------
// Flexible tray: base, thin outer wall, and perforated top
// ------------------------------------------------------------
const TRAY_WIDTH = 6.6;
const TRAY_DEPTH = 4.8;
const OPENING_Y = 1.14;
const CAVITY_FLOOR_Y = 0.43;
const trayRoot = new THREE.Group();
scene.add(trayRoot);
const trayBase = new THREE.Mesh(
roundedBoxGeometry(TRAY_WIDTH, 0.36, TRAY_DEPTH, 0.43, 0.08),
trayMaterial
);
trayBase.position.y = 0.22;
trayBase.castShadow = true;
trayBase.receiveShadow = true;
trayRoot.add(trayBase);
const wallShape = roundedRectShape(TRAY_WIDTH - 0.08, TRAY_DEPTH - 0.08, 0.39);
wallShape.holes.push(
roundedRectHole(TRAY_WIDTH - 0.55, TRAY_DEPTH - 0.55, 0.29)
);
const trayWall = new THREE.Mesh(
verticalExtrusion(wallShape, 0.78, 0.045),
trayMaterial
);
trayWall.position.y = 0.67;
trayWall.castShadow = true;
trayWall.receiveShadow = true;
trayRoot.add(trayWall);
const cavityPositions = [];
for (const z of [-1.05, 1.05]) {
for (const x of [-1.85, 0, 1.85]) {
cavityPositions.push(new THREE.Vector2(x, z));
}
}
const topShape = roundedRectShape(
TRAY_WIDTH - 0.08,
TRAY_DEPTH - 0.08,
0.39
);
for (const position of cavityPositions) {
topShape.holes.push(
roundedRectHole(1.56, 1.56, 0.24, position.x, position.y)
);
}
const trayTop = new THREE.Mesh(
verticalExtrusion(topShape, 0.24, 0.04),
trayTopMaterial
);
trayTop.position.y = 1.02;
trayTop.castShadow = true;
trayTop.receiveShadow = true;
trayRoot.add(trayTop);
// Matching inverse cavity walls and floors.
for (const position of cavityPositions) {
const cavity = new THREE.Group();
cavity.position.set(position.x, OPENING_Y, position.y);
const wall = new THREE.Mesh(
makeCavityGeometry(1.56, 1.56, 1.22, 1.22, OPENING_Y - CAVITY_FLOOR_Y),
cavityMaterial
);
wall.receiveShadow = true;
cavity.add(wall);
const floorShape = roundedRectShape(1.22, 1.22, 0.18);
const floorGeometry = new THREE.ShapeGeometry(floorShape, 12);
floorGeometry.rotateX(-Math.PI / 2);
const floor = new THREE.Mesh(floorGeometry, cavityFloorMaterial);
floor.position.y = CAVITY_FLOOR_Y - OPENING_Y + 0.008;
floor.receiveShadow = true;
cavity.add(floor);
trayRoot.add(cavity);
}
// ------------------------------------------------------------
// Ice cubes
// ------------------------------------------------------------
const CUBE_WIDTH = 1.34;
const CUBE_HEIGHT = 1.02;
const CUBE_DEPTH = 1.34;
const cubeGeometry = roundedBoxGeometry(
CUBE_WIDTH,
CUBE_HEIGHT,
CUBE_DEPTH,
0.19,
0.1
);
const beadGeometry = new THREE.SphereGeometry(0.047, 12, 8);
function addCondensation(group) {
const beadPositions = [
[-0.29, 0.2, 0.672],
[0.16, -0.1, 0.674],
[0.39, 0.25, 0.648],
[-0.08, 0.512, -0.23]
];
for (const [x, y, z] of beadPositions) {
const bead = new THREE.Mesh(beadGeometry, beadMaterial);
bead.position.set(x, y, z);
bead.scale.y = 1.2;
group.add(bead);
}
}
function makeIceCube(position, material, raised = false) {
const group = new THREE.Group();
group.position.copy(position);
const cube = new THREE.Mesh(cubeGeometry, material);
cube.castShadow = true;
cube.receiveShadow = true;
group.add(cube);
addCondensation(group);
if (raised) {
group.rotation.y = 0.08;
} else {
group.rotation.y = (Math.random() - 0.5) * 0.11;
group.rotation.z = (Math.random() - 0.5) * 0.018;
}
scene.add(group);
return group;
}
const raisedIndex = 5;
let raisedCube;
cavityPositions.forEach((position, index) => {
const material = iceMaterials[index % iceMaterials.length];
if (index === raisedIndex) {
raisedCube = makeIceCube(
new THREE.Vector3(position.x, 2.28, position.y),
material,
true
);
} else {
makeIceCube(
new THREE.Vector3(
position.x,
CAVITY_FLOOR_Y + CUBE_HEIGHT / 2 + 0.015,
position.y
),
material
);
}
});
// A thin layer of meltwater in the now-empty matching cavity.
const cavityPuddle = new THREE.Mesh(
makeIrregularPuddle(0.48, 0.43, 1.2),
cavityWaterMaterial
);
cavityPuddle.position.set(
cavityPositions[raisedIndex].x,
CAVITY_FLOOR_Y + 0.025,
cavityPositions[raisedIndex].y
);
scene.add(cavityPuddle);
// ------------------------------------------------------------
// Thin melting puddle around the tray
// ------------------------------------------------------------
const mainPuddle = new THREE.Mesh(
makeIrregularPuddle(3.25, 0.72, 0.35),
puddleMaterial
);
mainPuddle.position.set(0.4, 0.014, 2.47);
mainPuddle.receiveShadow = true;
scene.add(mainPuddle);
const sidePuddle = new THREE.Mesh(
makeIrregularPuddle(1.05, 0.43, 2.1),
puddleMaterial
);
sidePuddle.position.set(-2.9, 0.012, 1.8);
scene.add(sidePuddle);
const tinyPuddle = new THREE.Mesh(
makeIrregularPuddle(0.54, 0.31, 4.3),
puddleMaterial
);
tinyPuddle.position.set(3.15, 0.011, 1.55);
scene.add(tinyPuddle);
// Small table droplets.
const tableDropGeometry = new THREE.SphereGeometry(0.1, 16, 10);
const tableDropMaterial = new THREE.MeshPhysicalMaterial({
color: 0x78d8e4,
roughness: 0.08,
transmission: 0.15,
transparent: true,
opacity: 0.55,
clearcoat: 1,
depthWrite: false
});
const tableDrops = [
[-2.1, 2.68, 0.11],
[-1.7, 2.83, 0.075],
[2.9, 2.72, 0.13],
[3.18, 2.58, 0.07],
[0.1, 3.03, 0.085]
];
for (const [x, z, scale] of tableDrops) {
const drop = new THREE.Mesh(tableDropGeometry, tableDropMaterial);
drop.position.set(x, 0.045, z);
drop.scale.set(scale * 1.25, scale * 0.42, scale);
scene.add(drop);
}
// ------------------------------------------------------------
// Falling melt droplet and splash ring
// ------------------------------------------------------------
const fallingDrop = new THREE.Mesh(
new THREE.SphereGeometry(0.075, 18, 12),
new THREE.MeshPhysicalMaterial({
color: 0x65d5e3,
roughness: 0.05,
transmission: 0.2,
transparent: true,
opacity: 0.86,
clearcoat: 1
})
);
fallingDrop.castShadow = true;
scene.add(fallingDrop);
const splash = new THREE.Mesh(
new THREE.TorusGeometry(0.12, 0.014, 8, 36),
new THREE.MeshBasicMaterial({
color: 0x69d6e5,
transparent: true,
opacity: 0,
depthWrite: false
})
);
splash.rotation.x = Math.PI / 2;
splash.position.set(
cavityPositions[raisedIndex].x,
CAVITY_FLOOR_Y + 0.04,
cavityPositions[raisedIndex].y
);
scene.add(splash);
// ------------------------------------------------------------
// Direct camera controls: orbit, zoom, and reset
// ------------------------------------------------------------
let dragging = false;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
spherical.theta -= deltaX * 0.006;
spherical.phi = THREE.MathUtils.clamp(
spherical.phi - deltaY * 0.005,
0.43,
1.36
);
previousX = event.clientX;
previousY = event.clientY;
updateCamera();
});
function stopDragging(event) {
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
spherical.radius = THREE.MathUtils.clamp(
spherical.radius * Math.exp(event.deltaY * 0.001),
7.8,
17
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", () => {
spherical.set(11.4, 1.02, 0.68);
updateCamera();
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.fov = window.innerWidth < 640 ? 43 : 35;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
// ------------------------------------------------------------
// Animation
// ------------------------------------------------------------
const clock = new THREE.Clock();
const raisedBaseY = 2.28;
renderer.setAnimationLoop(() => {
const elapsed = clock.getElapsedTime();
// Gentle lift and rotation make the raised cube clearly separate.
raisedCube.position.y = raisedBaseY + Math.sin(elapsed * 1.05) * 0.045;
raisedCube.position.x =
cavityPositions[raisedIndex].x + Math.sin(elapsed * 0.62) * 0.025;
raisedCube.position.z =
cavityPositions[raisedIndex].y + Math.cos(elapsed * 0.51) * 0.02;
raisedCube.rotation.y = 0.08 + Math.sin(elapsed * 0.55) * 0.075;
raisedCube.rotation.z = Math.sin(elapsed * 0.43) * 0.014;
// Accelerating droplet falling into the matching cavity.
const phase = (elapsed * 0.62) % 1;
const fall = THREE.MathUtils.clamp((phase - 0.06) / 0.8, 0, 1);
const dropStart = raisedBaseY - CUBE_HEIGHT / 2 - 0.045;
const dropEnd = CAVITY_FLOOR_Y + 0.09;
fallingDrop.position.set(
raisedCube.position.x,
THREE.MathUtils.lerp(dropStart, dropEnd, fall * fall),
raisedCube.position.z
);
fallingDrop.scale.set(
0.8 - fall * 0.2,
1.55 + fall * 0.3,
0.8 - fall * 0.2
);
fallingDrop.visible = phase > 0.045 && phase < 0.9;
// Small expanding ring at the point of impact.
const splashPhase = THREE.MathUtils.clamp((phase - 0.88) / 0.12, 0, 1);
splash.visible = splashPhase > 0;
splash.scale.setScalar(0.5 + splashPhase * 2.7);
splash.material.opacity = (1 - splashPhase) * 0.68;
// The puddle subtly expands and settles.
const puddlePulse = 1 + Math.sin(elapsed * 0.72) * 0.018;
mainPuddle.scale.set(puddlePulse, 1, 0.96 + puddlePulse * 0.04);
mainPuddle.material.opacity = 0.47 + Math.sin(elapsed * 0.72) * 0.035;
cavityPuddle.rotation.y = Math.sin(elapsed * 0.18) * 0.035;
cavityPuddle.scale.set(
1 + Math.sin(elapsed * 0.85) * 0.025,
1,
1 + Math.cos(elapsed * 0.73) * 0.02
);
renderer.render(scene, camera);
});
</script>
</body>
</html>
```