Prompt specification
Build or customize the Three.js 3D scene "Sink-side drying comparison" 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: Sink-side drying comparison
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/sink-side-drying-comparison-x0074
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring a toothbrush cup. Set a perforated holder and closed cup beside a sink; animate a few droplets escaping only through visible openings, with collection trays underneath. Voxel style.
Working Three.js Starter (sink-side-drying-comparison-x0074):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Voxel Bathroom — Toothbrush Cups</title>
<style>
:root {
color-scheme: light;
--ink: #17353d;
--muted: #587078;
--glass: rgba(250, 253, 252, 0.84);
--line: rgba(23, 53, 61, 0.14);
--cyan: #16b8d4;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dbe9ec;
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene.dragging {
cursor: grabbing;
}
.panel {
position: fixed;
z-index: 10;
border: 1px solid var(--line);
background: var(--glass);
box-shadow: 0 18px 50px rgba(35, 65, 72, 0.12);
backdrop-filter: blur(16px);
-webkit-backdrop-filter: blur(16px);
}
.title-panel {
top: 22px;
left: 22px;
width: min(390px, calc(100vw - 44px));
padding: 19px 21px 18px;
border-radius: 18px;
pointer-events: none;
}
.eyebrow {
margin: 0 0 7px;
color: #0a94aa;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
h1 {
margin: 0;
color: var(--ink);
font-size: clamp(25px, 4vw, 38px);
line-height: 1.02;
letter-spacing: -0.045em;
}
.description {
margin: 10px 0 14px;
color: var(--muted);
font-size: 13px;
line-height: 1.5;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 8px;
}
.badge {
display: inline-flex;
align-items: center;
gap: 7px;
min-height: 28px;
padding: 6px 9px;
border: 1px solid rgba(23, 53, 61, 0.1);
border-radius: 8px;
color: #36545c;
background: rgba(255, 255, 255, 0.66);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.025em;
}
.dot {
width: 8px;
height: 8px;
border-radius: 2px;
background: var(--cyan);
box-shadow: 0 0 0 3px rgba(22, 184, 212, 0.12);
}
.dot.coral {
background: #f47d67;
box-shadow: 0 0 0 3px rgba(244, 125, 103, 0.12);
}
.controls {
right: 22px;
bottom: 22px;
display: flex;
align-items: center;
gap: 8px;
padding: 8px;
border-radius: 14px;
}
button {
min-height: 38px;
padding: 0 13px;
border: 1px solid rgba(23, 53, 61, 0.12);
border-radius: 9px;
color: var(--ink);
background: rgba(255, 255, 255, 0.82);
font: inherit;
font-size: 12px;
font-weight: 750;
cursor: pointer;
transition:
transform 140ms ease,
background 140ms ease;
}
button:hover {
transform: translateY(-1px);
background: white;
}
button:active {
transform: translateY(0);
}
.hint {
position: fixed;
z-index: 9;
right: 24px;
top: 24px;
color: rgba(23, 53, 61, 0.68);
font-size: 11px;
font-weight: 700;
letter-spacing: 0.025em;
pointer-events: none;
}
#loading {
position: fixed;
z-index: 20;
inset: 0;
display: grid;
place-items: center;
color: var(--ink);
background: #dbe9ec;
font-size: 13px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
transition: opacity 300ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 650px) {
.title-panel {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 15px 16px;
}
.description {
margin-bottom: 10px;
}
.hint {
display: none;
}
.controls {
right: 12px;
bottom: 12px;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive voxel bathroom scene"></canvas>
<section class="panel title-panel">
<p class="eyebrow">Voxel Bathroom</p>
<h1>Rinse & Repeat</h1>
<p class="description">
A perforated toothbrush holder and a closed cup sit beside the sink.
Bright droplets escape only through the holder’s visible apertures.
</p>
<div class="legend">
<span class="badge"><i class="dot coral"></i>Perforated holder</span>
<span class="badge"><i class="dot"></i>Visible openings only</span>
</div>
</section>
<div class="hint">Drag to orbit · Scroll to zoom</div>
<div class="panel controls">
<button id="pause" type="button">Pause drops</button>
<button id="reset" type="button">Reset view</button>
</div>
<div id="loading">Building voxel scene…</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 loading = document.querySelector("#loading");
const pauseButton = document.querySelector("#pause");
const resetButton = document.querySelector("#reset");
// -------------------------------------------------------------------------
// Renderer, scene and lighting
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdbe9ec);
scene.fog = new THREE.Fog(0xdbe9ec, 21, 38);
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const camera = new THREE.OrthographicCamera(-8, 8, 5, -5, 0.1, 100);
const target = new THREE.Vector3(-0.1, 0.72, 0);
const cameraDistance = 18;
let azimuth = 0.56;
let polar = 1.02;
let zoom = 1;
function updateCamera() {
camera.position.set(
target.x +
cameraDistance * Math.sin(polar) * Math.sin(azimuth),
target.y + cameraDistance * Math.cos(polar),
target.z +
cameraDistance * Math.sin(polar) * Math.cos(azimuth)
);
camera.lookAt(target);
const aspect = window.innerWidth / window.innerHeight;
const viewHeight = Math.max(9.4, 13.2 / aspect) / zoom;
camera.left = (-viewHeight * aspect) / 2;
camera.right = (viewHeight * aspect) / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.updateProjectionMatrix();
}
updateCamera();
const hemisphere = new THREE.HemisphereLight(0xf8fdff, 0x526970, 2.15);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff5e9, 3.1);
keyLight.position.set(-5, 11, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -10;
keyLight.shadow.camera.right = 10;
keyLight.shadow.camera.top = 9;
keyLight.shadow.camera.bottom = -9;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 30;
keyLight.shadow.bias = -0.0006;
keyLight.shadow.normalBias = 0.025;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xbcecff, 1.35);
fillLight.position.set(8, 5, -5);
scene.add(fillLight);
// -------------------------------------------------------------------------
// Materials and voxel helpers
// -------------------------------------------------------------------------
const material = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.72,
metalness: 0,
...options
});
const materials = {
floor: material(0xc8dade),
pedestal: material(0x49636c),
counter: material(0xeee9dc),
tray: material(0xd9b87a),
trayRim: material(0xb99053),
sink: material(0xf7f3e9),
sinkInner: material(0x5d858b),
drain: material(0x9aaeb2, { metalness: 0.5, roughness: 0.35 }),
metal: material(0xb6c8cb, { metalness: 0.72, roughness: 0.26 }),
metalDark: material(0x71898e, { metalness: 0.58, roughness: 0.35 }),
toothbrushA: material(0x25aeba),
toothbrushB: material(0xf26d78),
bristles: material(0xf8fbef),
droplet: material(0x22c7e5, {
emissive: 0x087e9b,
emissiveIntensity: 0.5,
roughness: 0.22,
metalness: 0.08,
transparent: true,
opacity: 0.94
})
};
function addBox(size, position, mat, options = {}) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
mat
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = options.castShadow !== false;
mesh.receiveShadow = options.receiveShadow !== false;
if (options.parent) {
options.parent.add(mesh);
} else {
scene.add(mesh);
}
return mesh;
}
function addInstancedBoxes(
entries,
size,
palette,
options = {}
) {
const geometry = new THREE.BoxGeometry(size[0], size[1], size[2]);
const mat = material(0xffffff, options.materialOptions || {});
const mesh = new THREE.InstancedMesh(geometry, mat, entries.length);
const dummy = new THREE.Object3D();
entries.forEach((entry, index) => {
dummy.position.set(entry.x, entry.y, entry.z);
dummy.rotation.set(0, 0, 0);
dummy.updateMatrix();
mesh.setMatrixAt(index, dummy.matrix);
const color =
entry.color instanceof THREE.Color
? entry.color
: new THREE.Color(palette[index % palette.length]);
mesh.setColorAt(index, color);
});
mesh.instanceMatrix.needsUpdate = true;
if (mesh.instanceColor) {
mesh.instanceColor.needsUpdate = true;
}
mesh.castShadow = options.castShadow !== false;
mesh.receiveShadow = options.receiveShadow !== false;
if (options.parent) {
options.parent.add(mesh);
} else {
scene.add(mesh);
}
return mesh;
}
// -------------------------------------------------------------------------
// Diorama platform, counter and tiled backsplash
// -------------------------------------------------------------------------
addBox(
[70, 0.2, 70],
[0, -0.58, 0],
materials.floor,
{ castShadow: false }
);
addBox(
[12.45, 0.28, 7.45],
[0, -0.34, 0],
materials.pedestal
);
addBox(
[12, 0.42, 7],
[0, 0.03, 0],
materials.counter
);
const tileEntries = [];
const tilePalette = [
0xf5f0e4, 0xeee8da, 0xfaf6ec, 0xe9e5d8, 0xf1ede2
];
for (let x = 0; x < 12; x++) {
for (let z = 0; z < 7; z++) {
tileEntries.push({
x: -5.5 + x,
y: 0.27,
z: -3 + z
});
}
}
addInstancedBoxes(
tileEntries,
[0.965, 0.06, 0.965],
tilePalette,
{ castShadow: false }
);
const wallEntries = [];
const wallPalette = [
0xc7dfe1, 0xd3e7e7, 0xbcd5d9, 0xd9e9e8, 0xc2dcdf
];
for (let x = 0; x < 12; x++) {
for (let row = 0; row < 4; row++) {
wallEntries.push({
x: -5.5 + x,
y: 0.3 + (row + 0.5) * 0.7,
z: -3.43
});
}
}
addInstancedBoxes(
wallEntries,
[0.965, 0.665, 0.14],
wallPalette,
{ castShadow: false }
);
// -------------------------------------------------------------------------
// Collection trays
// -------------------------------------------------------------------------
function createTray(cx, cz, width, depth, baseColor, rimColor) {
const base = new THREE.MeshStandardMaterial({
color: baseColor,
roughness: 0.78
});
const rim = new THREE.MeshStandardMaterial({
color: rimColor,
roughness: 0.72
});
addBox(
[width, 0.08, depth],
[cx, 0.35, cz],
base
);
addBox(
[width, 0.16, 0.1],
[cx, 0.43, cz + depth / 2 - 0.05],
rim
);
addBox(
[width, 0.16, 0.1],
[cx, 0.43, cz - depth / 2 + 0.05],
rim
);
addBox(
[0.1, 0.16, depth - 0.2],
[cx + width / 2 - 0.05, 0.43, cz],
rim
);
addBox(
[0.1, 0.16, depth - 0.2],
[cx - width / 2 + 0.05, 0.43, cz],
rim
);
return 0.39;
}
const HOLDER_X = -3.05;
const HOLDER_Z = 0.55;
const HOLDER_BASE = 0.4;
const HOLDER_TRAY_TOP = createTray(
HOLDER_X,
HOLDER_Z,
2.8,
2.9,
0xe3c78f,
0xbf9658
);
const CUP_X = -0.78;
const CUP_Z = 0.36;
createTray(
CUP_X,
CUP_Z,
1.85,
1.85,
0xb8d5d5,
0x86b4b7
);
// -------------------------------------------------------------------------
// Voxel sink
// -------------------------------------------------------------------------
const SINK_X = 3.05;
const SINK_Z = 0.1;
const SINK_CELL = 0.36;
const SINK_N = 12;
addBox(
[2.95, 0.1, 2.95],
[SINK_X, 0.39, SINK_Z],
materials.sinkInner
);
addBox(
[0.12, 0.39, 2.95],
[SINK_X - 1.48, 0.615, SINK_Z],
materials.sinkInner
);
addBox(
[0.12, 0.39, 2.95],
[SINK_X + 1.48, 0.615, SINK_Z],
materials.sinkInner
);
addBox(
[2.95, 0.39, 0.12],
[SINK_X, 0.615, SINK_Z - 1.48],
materials.sinkInner
);
addBox(
[2.95, 0.39, 0.12],
[SINK_X, 0.615, SINK_Z + 1.48],
materials.sinkInner
);
const sinkEntries = [];
for (let i = 0; i < SINK_N; i++) {
for (let j = 0; j < SINK_N; j++) {
const perimeter =
i === 0 ||
i === SINK_N - 1 ||
j === 0 ||
j === SINK_N - 1;
if (!perimeter) continue;
const x =
SINK_X + (i - (SINK_N - 1) / 2) * SINK_CELL;
const z =
SINK_Z + (j - (SINK_N - 1) / 2) * SINK_CELL;
sinkEntries.push({
x,
y: 0.64,
z,
color: new THREE.Color(i % 3 === 0 ? 0xe8e3d7 : 0xf8f4e9)
});
}
}
addInstancedBoxes(
sinkEntries,
[SINK_CELL, 0.27, SINK_CELL],
[0xffffff]
);
const sinkTopEntries = sinkEntries.map((entry) => ({
...entry,
y: 0.89
}));
addInstancedBoxes(
sinkTopEntries,
[SINK_CELL, 0.22, SINK_CELL],
[0xffffff]
);
// Drain.
addBox(
[0.48, 0.035, 0.14],
[SINK_X, 0.455, SINK_Z],
materials.drain
);
addBox(
[0.14, 0.035, 0.48],
[SINK_X, 0.455, SINK_Z],
materials.drain
);
// Voxel faucet.
addBox(
[0.58, 0.12, 0.58],
[SINK_X, 0.36, -2.6],
materials.metalDark
);
addBox(
[0.22, 1.36, 0.22],
[SINK_X, 1.03, -2.6],
materials.metal
);
addBox(
[0.22, 0.22, 1.12],
[SINK_X, 1.63, -2.08],
materials.metal
);
addBox(
[0.22, 0.42, 0.22],
[SINK_X, 1.47, -1.57],
materials.metal
);
addBox(
[0.3, 0.1, 0.3],
[SINK_X, 1.28, -1.57],
materials.metalDark
);
addBox(
[0.52, 0.13, 0.16],
[SINK_X + 0.35, 1.48, -2.6],
materials.metal
);
// -------------------------------------------------------------------------
// Perforated toothbrush holder
//
// Each hole is represented twice: once as a missing voxel in the shell and
// once as a valid droplet source. There are no hidden or invalid emitters.
// -------------------------------------------------------------------------
const HOLDER_N = 9;
const HOLDER_CELL = 0.23;
const HOLDER_ROWS = 7;
const holeDefinitions = [
{ side: "front", i: 3, j: 2 },
{ side: "front", i: 5, j: 4 },
{ side: "right", k: 3, j: 3 },
{ side: "right", k: 5, j: 5 },
{ side: "right", k: 6, j: 2 }
];
const frontHoles = new Set(
holeDefinitions
.filter((hole) => hole.side === "front")
.map((hole) => `${hole.i},${hole.j}`)
);
const rightHoles = new Set(
holeDefinitions
.filter((hole) => hole.side === "right")
.map((hole) => `${hole.k},${hole.j}`)
);
const holderGroup = new THREE.Group();
holderGroup.position.set(HOLDER_X, HOLDER_BASE, HOLDER_Z);
scene.add(holderGroup);
const holderEntries = [];
const holderPalette = [
0xf27f68, 0xf48b73, 0xeb755f, 0xf59a82, 0xe97663
];
for (let row = 0; row < HOLDER_ROWS; row++) {
for (let i = 0; i < HOLDER_N; i++) {
const x =
(i - (HOLDER_N - 1) / 2) * HOLDER_CELL;
const frontZ =
((HOLDER_N - 1) / 2) * HOLDER_CELL;
const backZ =
-((HOLDER_N - 1) / 2) * HOLDER_CELL;
if (!frontHoles.has(`${i},${row}`)) {
holderEntries.push({
x,
y: (row + 0.5) * HOLDER_CELL,
z: frontZ
});
}
holderEntries.push({
x,
y: (row + 0.5) * HOLDER_CELL,
z: backZ
});
}
for (let k = 1; k < HOLDER_N - 1; k++) {
const z =
(k - (HOLDER_N - 1) / 2) * HOLDER_CELL;
const leftX =
-((HOLDER_N - 1) / 2) * HOLDER_CELL;
const rightX =
((HOLDER_N - 1) / 2) * HOLDER_CELL;
holderEntries.push({
x: leftX,
y: (row + 0.5) * HOLDER_CELL,
z
});
if (!rightHoles.has(`${k},${row}`)) {
holderEntries.push({
x: rightX,
y: (row + 0.5) * HOLDER_CELL,
z
});
}
}
}
addInstancedBoxes(
holderEntries,
[HOLDER_CELL, HOLDER_CELL, HOLDER_CELL],
holderPalette,
{ parent: holderGroup }
);
// Dark inner floor improves the visibility of the actual side apertures.
addBox(
[1.88, 0.08, 1.88],
[0, 0.04, 0],
material(0x654a4a),
{ parent: holderGroup }
);
function addToothbrush(x, z, handleMaterial, headMaterial) {
addBox(
[0.13, 2.15, 0.13],
[x, 1.43, z],
handleMaterial,
{ parent: holderGroup }
);
addBox(
[0.38, 0.54, 0.17],
[x, 2.67, z],
headMaterial,
{ parent: holderGroup }
);
for (let row = 0; row < 4; row++) {
for (let col = 0; col < 3; col++) {
addBox(
[0.075, 0.075, 0.12],
[
x + (col - 1) * 0.095,
2.49 + row * 0.12,
z + 0.13
],
materials.bristles,
{ parent: holderGroup }
);
}
}
}
addToothbrush(
-0.27,
-0.18,
materials.toothbrushA,
material(0xf8f4e9)
);
addToothbrush(
0.25,
0.13,
materials.toothbrushB,
material(0xfff3d7)
);
// -------------------------------------------------------------------------
// Closed voxel cup
// -------------------------------------------------------------------------
const cupGroup = new THREE.Group();
cupGroup.position.set(CUP_X, 0.4, CUP_Z);
scene.add(cupGroup);
const cupEntries = [];
const cupPalette = [
0x45aaa7, 0x50b5b0, 0x3b9d9b, 0x5abbb5, 0x45aaa7
];
const cupCell = 0.24;
for (let layer = 0; layer < 5; layer++) {
for (let i = 0; i < 5; i++) {
for (let k = 0; k < 5; k++) {
const isCorner =
(i === 0 || i === 4) && (k === 0 || k === 4);
if (isCorner) continue;
cupEntries.push({
x: (i - 2) * cupCell,
y: (layer + 0.5) * cupCell,
z: (k - 2) * cupCell
});
}
}
}
addInstancedBoxes(
cupEntries,
[cupCell, cupCell, cupCell],
cupPalette,
{ parent: cupGroup }
);
// The lid closes the cup completely.
addBox(
[1.42, 0.18, 1.42],
[0, 1.26, 0],
material(0x69c2ba),
{ parent: cupGroup }
);
addBox(
[1.08, 0.14, 1.08],
[0, 1.42, 0],
material(0x55b1aa),
{ parent: cupGroup }
);
addBox(
[0.28, 0.18, 0.28],
[0, 1.58, 0],
material(0x8bd1c8),
{ parent: cupGroup }
);
// Small front plaque.
addBox(
[0.52, 0.22, 0.045],
[0, 0.73, 0.59],
material(0xd7efea),
{ parent: cupGroup }
);
// -------------------------------------------------------------------------
// Droplet animation
//
// Sources are derived exclusively from the missing wall voxels above.
// A droplet starts on the outside face of one of those visible holes,
// travels outward, then falls under gravity into the collection tray.
// -------------------------------------------------------------------------
const dropletSources = holeDefinitions.map((hole) => {
let x;
let y;
let z;
let velocity;
if (hole.side === "front") {
x =
HOLDER_X +
(hole.i - (HOLDER_N - 1) / 2) * HOLDER_CELL;
y =
HOLDER_BASE +
(hole.j + 0.5) * HOLDER_CELL;
z =
HOLDER_Z +
(HOLDER_N * HOLDER_CELL) / 2;
velocity = new THREE.Vector3(0, 0.045, 0.34);
} else {
x =
HOLDER_X +
(HOLDER_N * HOLDER_CELL) / 2;
y =
HOLDER_BASE +
(hole.j + 0.5) * HOLDER_CELL;
z =
HOLDER_Z +
(hole.k - (HOLDER_N - 1) / 2) * HOLDER_CELL;
velocity = new THREE.Vector3(0.34, 0.045, 0);
}
const gravity = 4.2;
const landingY = HOLDER_TRAY_TOP + 0.035;
const duration =
(velocity.y +
Math.sqrt(
velocity.y * velocity.y +
2 * gravity * (y - landingY)
)) /
gravity;
return {
position: new THREE.Vector3(x, y, z),
velocity,
gravity,
duration
};
});
const droplets = dropletSources.map((source, index) => {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(0.105, 0.145, 0.105),
materials.droplet
);
mesh.castShadow = true;
mesh.receiveShadow = false;
mesh.visible = false;
scene.add(mesh);
return {
mesh,
source,
period: 3.65 + index * 0.19,
offset: index * 0.73
};
});
function updateDroplets(elapsed) {
droplets.forEach((droplet) => {
const phase =
(elapsed + droplet.offset) % droplet.period;
if (phase > droplet.source.duration) {
droplet.mesh.visible = false;
return;
}
const t = phase;
const { position, velocity, gravity } = droplet.source;
droplet.mesh.visible = true;
droplet.mesh.position.set(
position.x + velocity.x * t,
position.y +
velocity.y * t -
0.5 * gravity * t * t,
position.z + velocity.z * t
);
// Voxel droplets tumble slightly while falling.
droplet.mesh.rotation.set(
t * 3.1,
t * 4.4,
t * 2.2
);
const appear = Math.min(1, t / 0.06);
const landFade = Math.min(
1,
(droplet.source.duration - t) / 0.09
);
droplet.mesh.scale.setScalar(
Math.max(0.05, Math.min(appear, landFade))
);
});
}
// -------------------------------------------------------------------------
// Custom camera controls — no OrbitControls or addons
// -------------------------------------------------------------------------
let dragging = false;
let pointerX = 0;
let pointerY = 0;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
canvas.classList.add("dragging");
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - pointerX;
const deltaY = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
azimuth -= deltaX * 0.006;
polar = THREE.MathUtils.clamp(
polar + deltaY * 0.005,
0.48,
1.38
);
updateCamera();
});
function endDrag(event) {
dragging = false;
canvas.classList.remove("dragging");
if (
event.pointerId !== undefined &&
canvas.hasPointerCapture(event.pointerId)
) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
zoom = THREE.MathUtils.clamp(
zoom * Math.exp(-event.deltaY * 0.001),
0.72,
1.62
);
updateCamera();
},
{ passive: false }
);
function resetView() {
azimuth = 0.56;
polar = 1.02;
zoom = 1;
updateCamera();
}
resetButton.addEventListener("click", resetView);
// -------------------------------------------------------------------------
// Pause, resize and render loop
// -------------------------------------------------------------------------
let paused = false;
pauseButton.addEventListener("click", () => {
paused = !paused;
pauseButton.textContent = paused ? "Resume drops" : "Pause drops";
pauseButton.setAttribute("aria-pressed", String(paused));
});
window.addEventListener("keydown", (event) => {
if (event.code === "Space") {
event.preventDefault();
pauseButton.click();
}
if (event.key.toLowerCase() === "r") {
resetView();
}
});
window.addEventListener("resize", () => {
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
updateCamera();
});
let elapsed = 0;
let previousTime = performance.now();
function render(now) {
const delta = Math.min((now - previousTime) / 1000, 0.05);
previousTime = now;
if (!paused) {
elapsed += delta;
}
updateDroplets(elapsed);
renderer.render(scene, camera);
requestAnimationFrame(render);
}
renderer.render(scene, camera);
loading.classList.add("hidden");
requestAnimationFrame(render);
</script>
</body>
</html>
```