Prompt specification
Build or customize the Three.js 3D scene "Bottle refill versus drinking stream" 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: Bottle refill versus drinking stream
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/bottle-refill-versus-drinking-stream-x0426
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows accessible drinking fountains. Show separate fountain outlets for a bottle and a drinking basin; selecting either creates a distinct water path that stops when its control is released. Low-poly.
Working Three.js Starter (bottle-refill-versus-drinking-stream-x0426):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Twin Source — Accessible Drinking Fountain</title>
<style>
:root {
--ink: #15383d;
--muted: #587477;
--panel: rgba(248, 251, 246, 0.9);
--line: rgba(21, 56, 61, 0.15);
--basin: #087e80;
--basin-light: #bcebe2;
--bottle: #c36b25;
--bottle-light: #ffe0aa;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
color: var(--ink);
background: #dbe7e2;
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#app,
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
outline: none;
}
.topbar {
position: fixed;
z-index: 5;
top: 22px;
left: 22px;
right: 22px;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 18px;
pointer-events: none;
}
.intro,
.utilities {
pointer-events: auto;
}
.intro {
width: min(390px, calc(100vw - 44px));
padding: 18px 20px;
border: 1px solid rgba(255, 255, 255, 0.68);
border-radius: 20px;
background: var(--panel);
box-shadow: 0 16px 50px rgba(24, 62, 62, 0.13);
backdrop-filter: blur(14px);
}
.eyebrow {
margin: 0 0 7px;
color: var(--basin);
font-size: 0.73rem;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(1.55rem, 4vw, 2.25rem);
line-height: 1;
letter-spacing: -0.045em;
}
.intro p:last-child {
margin: 11px 0 0;
color: var(--muted);
font-size: 0.91rem;
line-height: 1.5;
}
.utilities {
display: flex;
align-items: center;
gap: 9px;
}
.status {
display: flex;
align-items: center;
gap: 8px;
min-height: 42px;
padding: 0 14px;
border: 1px solid rgba(255, 255, 255, 0.7);
border-radius: 999px;
background: var(--panel);
box-shadow: 0 10px 30px rgba(24, 62, 62, 0.1);
font-size: 0.78rem;
font-weight: 800;
letter-spacing: 0.06em;
text-transform: uppercase;
backdrop-filter: blur(14px);
}
.status-dot {
width: 9px;
height: 9px;
border-radius: 50%;
background: #86a19b;
box-shadow: 0 0 0 4px rgba(134, 161, 155, 0.16);
}
.status[data-active="true"] .status-dot {
background: #16aaa2;
box-shadow: 0 0 0 4px rgba(22, 170, 162, 0.18);
}
.icon-button {
display: grid;
place-items: center;
width: 42px;
height: 42px;
padding: 0;
border: 1px solid rgba(255, 255, 255, 0.7);
border-radius: 50%;
color: var(--ink);
background: var(--panel);
box-shadow: 0 10px 30px rgba(24, 62, 62, 0.1);
cursor: pointer;
backdrop-filter: blur(14px);
}
.icon-button:hover {
background: #fff;
}
.icon-button:focus-visible,
.control:focus-visible {
outline: 3px solid #15383d;
outline-offset: 4px;
}
.icon-button svg {
width: 19px;
height: 19px;
fill: none;
stroke: currentColor;
stroke-linecap: round;
stroke-linejoin: round;
stroke-width: 1.9;
}
.outlet-tag {
position: fixed;
z-index: 3;
padding: 7px 10px;
border: 1px solid rgba(255, 255, 255, 0.75);
border-radius: 9px;
color: var(--ink);
background: rgba(250, 252, 248, 0.84);
box-shadow: 0 8px 24px rgba(24, 62, 62, 0.12);
font-size: 0.67rem;
font-weight: 850;
letter-spacing: 0.11em;
text-transform: uppercase;
pointer-events: none;
transform: translate(-50%, -50%);
white-space: nowrap;
backdrop-filter: blur(8px);
}
.outlet-tag::after {
content: "";
position: absolute;
left: 50%;
bottom: -7px;
width: 12px;
height: 12px;
border-right: 1px solid rgba(255, 255, 255, 0.75);
border-bottom: 1px solid rgba(255, 255, 255, 0.75);
background: rgba(250, 252, 248, 0.84);
transform: translateX(-50%) rotate(45deg);
}
.dock-wrap {
position: fixed;
z-index: 6;
left: 50%;
bottom: 22px;
width: min(620px, calc(100vw - 28px));
transform: translateX(-50%);
}
.dock {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 10px;
padding: 10px;
border: 1px solid rgba(255, 255, 255, 0.75);
border-radius: 23px;
background: rgba(248, 251, 246, 0.91);
box-shadow: 0 20px 60px rgba(24, 62, 62, 0.2);
backdrop-filter: blur(18px);
}
.control {
--accent: var(--basin);
--accent-light: var(--basin-light);
position: relative;
display: grid;
grid-template-columns: 46px 1fr;
align-items: center;
gap: 12px;
min-height: 76px;
padding: 12px 15px;
overflow: hidden;
border: 1px solid transparent;
border-radius: 16px;
color: var(--ink);
background: transparent;
cursor: pointer;
text-align: left;
touch-action: none;
user-select: none;
-webkit-user-select: none;
}
.control[data-mode="bottle"] {
--accent: var(--bottle);
--accent-light: var(--bottle-light);
}
.control:hover {
background: rgba(255, 255, 255, 0.72);
}
.control[aria-pressed="true"] {
border-color: var(--accent);
background: var(--accent-light);
box-shadow: inset 0 0 0 1px var(--accent);
}
.control-icon {
display: grid;
place-items: center;
width: 46px;
height: 46px;
border-radius: 13px;
color: white;
background: var(--accent);
box-shadow: 0 7px 16px color-mix(in srgb, var(--accent) 25%, transparent);
}
.control-icon svg {
width: 27px;
height: 27px;
fill: none;
stroke: currentColor;
stroke-linecap: round;
stroke-linejoin: round;
stroke-width: 1.8;
}
.control-copy {
min-width: 0;
}
.control-copy strong {
display: block;
font-size: 0.98rem;
}
.control-copy small {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 0.72rem;
font-weight: 650;
}
.fill-track {
position: absolute;
right: 14px;
bottom: 9px;
left: 73px;
height: 3px;
overflow: hidden;
border-radius: 10px;
background: rgba(21, 56, 61, 0.1);
}
.fill-track::after {
content: "";
display: block;
width: var(--level, 0%);
height: 100%;
border-radius: inherit;
background: var(--accent);
transition: width 80ms linear;
}
.help {
margin: 9px 0 0;
color: rgba(21, 56, 61, 0.72);
font-size: 0.72rem;
font-weight: 650;
text-align: center;
text-shadow: 0 1px 8px rgba(255, 255, 255, 0.9);
}
.sr-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border: 0;
}
@media (max-width: 720px) {
.topbar {
top: 12px;
left: 12px;
right: 12px;
}
.intro {
width: min(290px, calc(100vw - 72px));
padding: 14px 16px;
border-radius: 16px;
}
.intro p:last-child {
display: none;
}
.status {
position: fixed;
top: 78px;
right: 12px;
min-height: 34px;
padding: 0 11px;
font-size: 0.65rem;
}
.outlet-tag {
display: none;
}
.dock-wrap {
bottom: 12px;
}
.dock {
gap: 5px;
padding: 7px;
border-radius: 18px;
}
.control {
grid-template-columns: 38px 1fr;
gap: 8px;
min-height: 70px;
padding: 9px;
border-radius: 13px;
}
.control-icon {
width: 38px;
height: 38px;
border-radius: 10px;
}
.control-icon svg {
width: 23px;
height: 23px;
}
.control-copy strong {
font-size: 0.86rem;
}
.control-copy small {
font-size: 0.64rem;
}
.fill-track {
left: 55px;
}
.help {
font-size: 0.65rem;
}
}
</style>
</head>
<body>
<main id="app">
<div id="scene"></div>
<div class="topbar">
<header class="intro">
<p class="eyebrow">Public water point</p>
<h1>Twin Source</h1>
<p>
An accessible drinking basin and bottle refill station.
Press and hold either control to run its separate water path.
</p>
</header>
<div class="utilities">
<div
id="status"
class="status"
role="status"
aria-live="polite"
aria-atomic="true"
data-active="false"
>
<span class="status-dot" aria-hidden="true"></span>
<span id="statusText">Ready</span>
</div>
<button
id="resetWater"
class="icon-button"
type="button"
aria-label="Empty both the basin and bottle"
title="Empty water containers"
>
<svg viewBox="0 0 24 24" aria-hidden="true">
<path d="M4 7h16M9 7V4h6v3M7 7l1 13h8l1-13M10 11v5M14 11v5"/>
</svg>
</button>
<button
id="resetCamera"
class="icon-button"
type="button"
aria-label="Reset camera view"
title="Reset camera view"
>
<svg viewBox="0 0 24 24" aria-hidden="true">
<path d="M4 8V4h4M20 8V4h-4M4 16v4h4M20 16v4h-4"/>
<circle cx="12" cy="12" r="3"/>
</svg>
</button>
</div>
</div>
<div id="basinTag" class="outlet-tag" aria-hidden="true">
Drinking basin
</div>
<div id="bottleTag" class="outlet-tag" aria-hidden="true">
Bottle outlet
</div>
<section class="dock-wrap" aria-label="Fountain controls">
<div class="dock">
<button
id="basinControl"
class="control"
type="button"
data-mode="basin"
aria-pressed="false"
aria-describedby="controlHelp"
>
<span class="control-icon" aria-hidden="true">
<svg viewBox="0 0 32 32">
<path d="M5 10h22v4c0 6-5 10-11 10S5 20 5 14v-4Z"/>
<path d="M16 3v7M12 7h8M11 24v4M21 24v4"/>
</svg>
</span>
<span class="control-copy">
<strong>Basin</strong>
<small>Hold to drink</small>
</span>
<span class="fill-track" aria-hidden="true"></span>
</button>
<button
id="bottleControl"
class="control"
type="button"
data-mode="bottle"
aria-pressed="false"
aria-describedby="controlHelp"
>
<span class="control-icon" aria-hidden="true">
<svg viewBox="0 0 32 32">
<path d="M12 3h8v4l-1 2v4l4 3v12H9V16l4-3V9l-1-2V3Z"/>
<path d="M9 21h14M13 25h6"/>
</svg>
</span>
<span class="control-copy">
<strong>Bottle</strong>
<small>Hold to refill</small>
</span>
<span class="fill-track" aria-hidden="true"></span>
</button>
</div>
<p id="controlHelp" class="help">
Press and hold with a pointer, or hold Space or Enter while a control is focused.
Release to stop the water.
</p>
</section>
</main>
<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 status = document.getElementById("status");
const statusText = document.getElementById("statusText");
const basinControl = document.getElementById("basinControl");
const bottleControl = document.getElementById("bottleControl");
const basinTag = document.getElementById("basinTag");
const bottleTag = document.getElementById("bottleTag");
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.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.15;
renderer.domElement.setAttribute("aria-hidden", "true");
sceneHost.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdbe7e2);
scene.fog = new THREE.Fog(0xdbe7e2, 13, 23);
const camera = new THREE.PerspectiveCamera(
39,
window.innerWidth / window.innerHeight,
0.1,
50
);
const cameraTarget = new THREE.Vector3(0, 1.25, -0.05);
let cameraYaw = 0.38;
let cameraPitch = 0.36;
let cameraRadius = 9.2;
let cameraTouched = false;
function updateCamera() {
const horizontal = cameraRadius * Math.cos(cameraPitch);
camera.position.set(
cameraTarget.x + Math.sin(cameraYaw) * horizontal,
cameraTarget.y + Math.sin(cameraPitch) * cameraRadius,
cameraTarget.z + Math.cos(cameraYaw) * horizontal
);
camera.lookAt(cameraTarget);
}
updateCamera();
function resetCamera() {
cameraYaw = 0.38;
cameraPitch = 0.36;
cameraRadius =
window.innerWidth / window.innerHeight < 0.85 ? 13.4 : 9.2;
cameraTouched = false;
updateCamera();
}
document.getElementById("resetCamera").addEventListener("click", resetCamera);
const hemisphere = new THREE.HemisphereLight(0xf3fbff, 0x5a726d, 2.25);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff4dc, 3.1);
sun.position.set(-5, 9, 6);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -8;
sun.shadow.camera.right = 8;
sun.shadow.camera.top = 8;
sun.shadow.camera.bottom = -8;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 24;
sun.shadow.bias = -0.0004;
scene.add(sun);
const rimLight = new THREE.DirectionalLight(0x9de5df, 1.15);
rimLight.position.set(6, 5, -5);
scene.add(rimLight);
const materials = {
ground: new THREE.MeshStandardMaterial({
color: 0xd4dfda,
roughness: 0.95,
flatShading: true
}),
paving: new THREE.MeshStandardMaterial({
color: 0xc5d4cf,
roughness: 0.92,
flatShading: true
}),
wall: new THREE.MeshStandardMaterial({
color: 0xe8eee7,
roughness: 0.88,
flatShading: true
}),
wallInset: new THREE.MeshStandardMaterial({
color: 0xbfcfc9,
roughness: 0.82,
flatShading: true
}),
metal: new THREE.MeshStandardMaterial({
color: 0x2d7473,
roughness: 0.42,
metalness: 0.32,
flatShading: true
}),
metalLight: new THREE.MeshStandardMaterial({
color: 0x91b8b1,
roughness: 0.46,
metalness: 0.26,
flatShading: true
}),
dark: new THREE.MeshStandardMaterial({
color: 0x183b40,
roughness: 0.48,
metalness: 0.18,
flatShading: true
}),
basinWater: new THREE.MeshStandardMaterial({
color: 0x36cfc4,
roughness: 0.18,
metalness: 0.05,
transparent: true,
opacity: 0.68,
depthWrite: false
}),
bottleWater: new THREE.MeshStandardMaterial({
color: 0x55baf1,
roughness: 0.16,
metalness: 0.02,
transparent: true,
opacity: 0.72,
depthWrite: false
}),
bottleGlass: new THREE.MeshStandardMaterial({
color: 0xb9e4e6,
roughness: 0.16,
metalness: 0,
transparent: true,
opacity: 0.28,
depthWrite: false,
flatShading: true
}),
orange: new THREE.MeshStandardMaterial({
color: 0xd9773a,
roughness: 0.5,
flatShading: true
}),
yellow: new THREE.MeshStandardMaterial({
color: 0xf1b84b,
roughness: 0.45,
flatShading: true
}),
soil: new THREE.MeshStandardMaterial({
color: 0x536a5c,
roughness: 1,
flatShading: true
}),
leaf: new THREE.MeshStandardMaterial({
color: 0x628f78,
roughness: 0.95,
flatShading: true
}),
leafLight: new THREE.MeshStandardMaterial({
color: 0x82aa87,
roughness: 0.95,
flatShading: true
}),
wood: new THREE.MeshStandardMaterial({
color: 0x9d7450,
roughness: 0.88,
flatShading: true
})
};
function addMesh(
parent,
geometry,
material,
x = 0,
y = 0,
z = 0,
rx = 0,
ry = 0,
rz = 0
) {
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(x, y, z);
mesh.rotation.set(rx, ry, rz);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addBox(parent, w, h, d, material, x = 0, y = 0, z = 0) {
return addMesh(parent, new THREE.BoxGeometry(w, h, d), material, x, y, z);
}
function addCylinder(
parent,
topRadius,
bottomRadius,
height,
sides,
material,
x = 0,
y = 0,
z = 0
) {
return addMesh(
parent,
new THREE.CylinderGeometry(topRadius, bottomRadius, height, sides),
material,
x,
y,
z
);
}
function makeSign(title, subtitle, background, foreground) {
const canvas = document.createElement("canvas");
canvas.width = 640;
canvas.height = 240;
const context = canvas.getContext("2d");
context.fillStyle = background;
context.fillRect(0, 0, canvas.width, canvas.height);
context.strokeStyle = foreground;
context.globalAlpha = 0.25;
context.lineWidth = 5;
context.strokeRect(14, 14, canvas.width - 28, canvas.height - 28);
context.globalAlpha = 1;
context.textAlign = "center";
context.fillStyle = foreground;
context.font = "800 62px system-ui, sans-serif";
context.fillText(title, canvas.width / 2, 112);
context.globalAlpha = 0.78;
context.font = "700 25px system-ui, sans-serif";
context.letterSpacing = "4px";
context.fillText(subtitle, canvas.width / 2, 165);
context.globalAlpha = 1;
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return new THREE.MeshBasicMaterial({
map: texture,
toneMapped: false
});
}
// Plaza and architectural background.
const ground = addMesh(
scene,
new THREE.PlaneGeometry(22, 18),
materials.ground,
0,
-0.035,
0,
-Math.PI / 2
);
ground.castShadow = false;
const pavingDisc = addMesh(
scene,
new THREE.CircleGeometry(5.65, 32),
materials.paving,
0,
-0.025,
0.05,
-Math.PI / 2
);
pavingDisc.castShadow = false;
for (const x of [-3.6, -1.8, 0, 1.8, 3.6]) {
addBox(scene, 0.025, 0.012, 9.2, materials.wallInset, x, -0.012, 0.8);
}
for (const z of [-3.2, -0.8, 1.6, 4]) {
addBox(scene, 10.5, 0.012, 0.025, materials.wallInset, 0, -0.011, z);
}
const wall = addBox(
scene,
8.65,
3.5,
0.28,
materials.wall,
0,
1.72,
-1.46
);
for (let x = -4; x <= 4; x += 0.8) {
addBox(
scene,
0.035,
3.25,
0.035,
materials.wallInset,
x,
1.72,
-1.305
);
}
const mainSign = new THREE.Mesh(
new THREE.PlaneGeometry(2.7, 0.58),
makeSign("TWIN SOURCE", "ACCESSIBLE WATER POINT", "#163f43", "#f3f6e9")
);
mainSign.position.set(0, 3.02, -1.302);
scene.add(mainSign);
function addPlanter(x) {
const planter = addCylinder(
scene,
0.48,
0.38,
0.52,
8,
materials.metalLight,
x,
0.26,
-0.72
);
addCylinder(
scene,
0.41,
0.41,
0.035,
8,
materials.soil,
x,
0.525,
-0.72
);
addCylinder(
scene,
0.075,
0.095,
1.15,
7,
materials.wood,
x,
1.08,
-0.72
);
const crown = addMesh(
scene,
new THREE.DodecahedronGeometry(0.62, 0),
materials.leaf,
x,
1.72,
-0.72
);
crown.scale.set(1, 1.18, 0.9);
const crown2 = addMesh(
scene,
new THREE.DodecahedronGeometry(0.38, 0),
materials.leafLight,
x + 0.28,
1.45,
-0.62
);
crown2.scale.set(1, 0.85, 1);
}
addPlanter(-3.35);
addPlanter(3.35);
// Low-poly bench.
const bench = new THREE.Group();
bench.position.set(3.45, 0, 1.2);
scene.add(bench);
for (let i = 0; i < 3; i++) {
addBox(bench, 1.8, 0.09, 0.15, materials.wood, 0, 0.5, i * 0.2);
}
for (const x of [-0.65, 0.65]) {
addBox(bench, 0.12, 0.48, 0.48, materials.dark, x, 0.24, 0.2);
}
// Drinking basin station.
const basinStation = new THREE.Group();
basinStation.position.set(-1.48, 0, 0.12);
scene.add(basinStation);
addCylinder(
basinStation,
0.38,
0.48,
0.78,
8,
materials.metal,
0,
0.39,
0
);
addCylinder(
basinStation,
0.66,
0.47,
0.25,
10,
materials.metalLight,
0,
0.9,
0
);
addMesh(
basinStation,
new THREE.TorusGeometry(0.56, 0.055, 6, 12),
materials.metal,
0,
1.035,
0,
Math.PI / 2
);
addCylinder(
basinStation,
0.515,
0.515,
0.025,
12,
materials.dark,
0,
1.035,
0
);
const basinWater = addCylinder(
basinStation,
0.49,
0.49,
1,
12,
materials.basinWater,
0,
1.055,
0
);
basinWater.scale.y = 0.001;
basinWater.castShadow = false;
// Basin spout.
addCylinder(
basinStation,
0.047,
0.047,
0.5,
8,
materials.metal,
0,
1.22,
-0.18
);
addMesh(
basinStation,
new THREE.CylinderGeometry(0.047, 0.047, 0.39, 8),
materials.metal,
0,
1.46,
-0.025,
Math.PI / 2
);
addCylinder(
basinStation,
0.048,
0.048,
0.11,
8,
materials.metal,
0,
1.405,
0.16
);
const basinSign = new THREE.Mesh(
new THREE.PlaneGeometry(0.72, 0.27),
makeSign("BASIN", "DRINK", "#eaf2ea", "#185b5c")
);
basinSign.position.set(0, 0.69, 0.442);
basinStation.add(basinSign);
const basinButtonBaseZ = 0.465;
addMesh(
basinStation,
new THREE.CylinderGeometry(0.13, 0.13, 0.045, 12),
materials.dark,
0,
0.43,
0.435,
Math.PI / 2
);
const basinButton = addMesh(
basinStation,
new THREE.CylinderGeometry(0.095, 0.095, 0.065, 12),
materials.yellow,
0,
0.43,
basinButtonBaseZ,
Math.PI / 2
);
basinButton.userData.mode = "basin";
// Bottle refill station.
const bottleStation = new THREE.Group();
bottleStation.position.set(1.47, 0, 0.12);
scene.add(bottleStation);
addBox(bottleStation, 1.28, 0.18, 0.86, materials.dark, 0, 0.09, 0);
addBox(bottleStation, 1.15, 2.22, 0.64, materials.metal, 0, 1.29, 0);
addBox(bottleStation, 1.33, 0.18, 0.79, materials.orange, 0, 2.49, 0);
// Faceted corner strips.
for (const x of [-0.53, 0.53]) {
addBox(bottleStation, 0.08, 2.12, 0.08, materials.metalLight, x, 1.3, 0.325);
}
addBox(bottleStation, 0.78, 1.35, 0.045, materials.dark, 0, 1.54, 0.335);
addBox(bottleStation, 0.93, 0.075, 0.48, materials.metalLight, 0, 1.02, 0.46);
const bottleSign = new THREE.Mesh(
new THREE.PlaneGeometry(0.82, 0.31),
makeSign("BOTTLE", "REFILL", "#fff0d4", "#77451f")
);
bottleSign.position.set(0, 2.31, 0.327);
bottleStation.add(bottleSign);
// Bottle filler spout.
addMesh(
bottleStation,
new THREE.CylinderGeometry(0.052, 0.052, 0.29, 8),
materials.metalLight,
0,
2.075,
0.465,
Math.PI / 2
);
addCylinder(
bottleStation,
0.052,
0.052,
0.11,
8,
materials.metalLight,
0,
2.035,
0.59
);
// Faceted bottle.
const bottle = new THREE.Group();
bottle.position.set(0, 0, 0.55);
bottleStation.add(bottle);
const bottleBody = addCylinder(
bottle,
0.19,
0.225,
0.62,
8,
materials.bottleGlass,
0,
1.43,
0
);
bottleBody.castShadow = false;
bottleBody.renderOrder = 3;
const shoulder = addCylinder(
bottle,
0.105,
0.19,
0.12,
8,
materials.bottleGlass,
0,
1.8,
0
);
shoulder.castShadow = false;
shoulder.renderOrder = 3;
const neck = addCylinder(
bottle,
0.098,
0.098,
0.13,
8,
materials.bottleGlass,
0,
1.895,
0
);
neck.castShadow = false;
neck.renderOrder = 3;
const bottleWater = addCylinder(
bottle,
0.165,
0.19,
0.56,
8,
materials.bottleWater,
0,
1.14,
0
);
bottleWater.scale.y = 0.001;
bottleWater.castShadow = false;
bottleWater.renderOrder = 2;
addCylinder(
bottleStation,
0.13,
0.13,
0.09,
8,
materials.orange,
0.34,
1.115,
0.54
);
const bottleButtonBaseZ = 0.375;
addMesh(
bottleStation,
new THREE.CylinderGeometry(0.13, 0.13, 0.045, 12),
materials.dark,
0,
0.5,
0.345,
Math.PI / 2
);
const bottleButton = addMesh(
bottleStation,
new THREE.CylinderGeometry(0.095, 0.095, 0.065, 12),
materials.yellow,
0,
0.5,
bottleButtonBaseZ,
Math.PI / 2
);
bottleButton.userData.mode = "bottle";
// Separate animated water paths.
function createFlow(parent, points, color, dropletCount, speed) {
const curve = new THREE.CatmullRomCurve3(
points.map((point) => new THREE.Vector3(...point))
);
const material = new THREE.MeshStandardMaterial({
color,
roughness: 0.12,
metalness: 0,
transparent: true,
opacity: 0.76,
depthWrite: false
});
const tube = new THREE.Mesh(
new THREE.TubeGeometry(curve, 8, 0.034, 6, false),
material
);
tube.visible = false;
tube.castShadow = false;
tube.renderOrder = 4;
parent.add(tube);
const dropletMaterial = new THREE.MeshBasicMaterial({
color: 0xe7ffff,
transparent: true,
opacity: 0.9,
depthWrite: false
});
const droplets = [];
for (let i = 0; i < dropletCount; i++) {
const droplet = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.03, 0),
dropletMaterial
);
droplet.visible = false;
droplet.renderOrder = 5;
parent.add(droplet);
droplets.push(droplet);
}
return { curve, tube, droplets, speed };
}
const basinFlow = createFlow(
basinStation,
[
[0, 1.35, 0.16],
[0.012, 1.26, 0.17],
[-0.01, 1.15, 0.18],
[0, 1.055, 0.18]
],
0x38d6c9,
8,
1.15
);
const bottleFlow = createFlow(
bottleStation,
[
[0, 2.0, 0.59],
[0.01, 1.96, 0.59],
[0, 1.9, 0.59]
],
0x58bdf3,
5,
0.85
);
const ripples = [];
for (let i = 0; i < 3; i++) {
const ripple = new THREE.Mesh(
new THREE.RingGeometry(0.12, 0.15, 12),
new THREE.MeshBasicMaterial({
color: 0xc9fff8,
transparent: true,
opacity: 0,
depthWrite: false,
side: THREE.DoubleSide
})
);
ripple.rotation.x = -Math.PI / 2;
ripple.position.set(0, 1.062 + i * 0.001, 0.18);
ripple.visible = false;
basinStation.add(ripple);
ripples.push(ripple);
}
const buttonTargets = [basinButton, bottleButton];
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
let activeMode = null;
let basinFill = 0;
let bottleFill = 0;
function setStatus(message, active) {
statusText.textContent = message;
status.dataset.active = String(active);
}
function startMode(mode) {
if (activeMode === mode) return;
if (activeMode) stopMode(activeMode);
activeMode = mode;
basinControl.setAttribute("aria-pressed", "false");
bottleControl.setAttribute("aria-pressed", "false");
if (mode === "basin") {
basinControl.setAttribute("aria-pressed", "true");
basinFlow.tube.visible = true;
basinFlow.droplets.forEach((droplet) => (droplet.visible = true));
ripples.forEach((ripple) => (ripple.visible = true));
setStatus("Basin flowing", true);
} else {
bottleControl.setAttribute("aria-pressed", "true");
bottleFlow.tube.visible = true;
bottleFlow.droplets.forEach((droplet) => (droplet.visible = true));
setStatus("Bottle flowing", true);
}
}
function stopMode(mode) {
if (activeMode !== mode) return;
activeMode = null;
basinControl.setAttribute("aria-pressed", "false");
bottleControl.setAttribute("aria-pressed", "false");
basinFlow.tube.visible = false;
basinFlow.droplets.forEach((droplet) => (droplet.visible = false));
bottleFlow.tube.visible = false;
bottleFlow.droplets.forEach((droplet) => (droplet.visible = false));
ripples.forEach((ripple) => (ripple.visible = false));
setStatus("Ready", false);
}
function bindHoldControl(element, mode) {
element.addEventListener("pointerdown", (event) => {
event.preventDefault();
element.setPointerCapture(event.pointerId);
startMode(mode);
});
element.addEventListener("pointerup", () => stopMode(mode));
element.addEventListener("pointercancel", () => stopMode(mode));
element.addEventListener("lostpointercapture", () => stopMode(mode));
element.addEventListener("keydown", (event) => {
if (event.key === " " || event.key === "Enter") {
event.preventDefault();
if (!event.repeat) startMode(mode);
}
});
element.addEventListener("keyup", (event) => {
if (event.key === " " || event.key === "Enter") {
event.preventDefault();
stopMode(mode);
}
});
element.addEventListener("blur", () => stopMode(mode));
element.addEventListener("contextmenu", (event) => event.preventDefault());
}
bindHoldControl(basinControl, "basin");
bindHoldControl(bottleControl, "bottle");
// The physical 3D push buttons also use press-and-release behavior.
function pickButton(event) {
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 hit = raycaster.intersectObjects(buttonTargets, false);
return hit.length ? hit[0].object : null;
}
let pointerAction = null;
let pointerId = null;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
const button = pickButton(event);
pointerAction = button ? "water" : "orbit";
pointerId = event.pointerId;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
if (button) {
event.preventDefault();
startMode(button.userData.mode);
renderer.domElement.style.cursor = "pointer";
} else {
cameraTouched = true;
renderer.domElement.style.cursor = "grabbing";
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (pointerAction === "orbit" && event.pointerId === pointerId) {
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
cameraYaw -= dx * 0.006;
cameraPitch = THREE.MathUtils.clamp(
cameraPitch + dy * 0.004,
0.16,
1.05
);
previousX = event.clientX;
previousY = event.clientY;
updateCamera();
} else if (!pointerAction) {
renderer.domElement.style.cursor = pickButton(event) ? "pointer" : "grab";
}
});
function endPointer(event) {
if (pointerAction === "water") {
const button = pickButton(event);
if (button) stopMode(button.userData.mode);
else stopMode(activeMode);
}
pointerAction = null;
pointerId = null;
renderer.domElement.style.cursor = "grab";
}
renderer.domElement.addEventListener("pointerup", endPointer);
renderer.domElement.addEventListener("pointercancel", endPointer);
renderer.domElement.addEventListener("lostpointercapture", endPointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraTouched = true;
cameraRadius = THREE.MathUtils.clamp(
cameraRadius + event.deltaY * 0.008,
6.2,
15
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
document.addEventListener("visibilitychange", () => {
if (document.hidden && activeMode) stopMode(activeMode);
});
document.getElementById("resetWater").addEventListener("click", () => {
if (activeMode) stopMode(activeMode);
basinFill = 0;
bottleFill = 0;
});
function updateTag(element, position) {
const projected = position.clone().project(camera);
const visible = projected.z > -1 && projected.z < 1;
element.style.opacity = visible ? "1" : "0";
if (visible) {
element.style.left = `${(projected.x * 0.5 + 0.5) * window.innerWidth}px`;
element.style.top = `${(-projected.y * 0.5 + 0.5) * window.innerHeight}px`;
}
}
const basinTagPosition = new THREE.Vector3(-1.48, 1.61, 0.05);
const bottleTagPosition = new THREE.Vector3(1.47, 2.66, 0.12);
const clock = new THREE.Clock();
let elapsed = 0;
function animateFlow(flow, active, flowTime) {
if (!active) return;
flow.tube.material.opacity =
0.67 + Math.sin(flowTime * 8) * 0.08;
flow.droplets.forEach((droplet, index) => {
const t = (flowTime * flow.speed + index / flow.droplets.length) % 1;
droplet.position.copy(flow.curve.getPointAt(t));
const pulse = 0.75 + Math.sin(flowTime * 10 + index) * 0.25;
droplet.scale.setScalar(pulse);
});
}
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
elapsed += delta;
if (activeMode === "basin") {
basinFill = Math.min(1, basinFill + delta * 0.17);
} else if (activeMode === "bottle") {
bottleFill = Math.min(1, bottleFill + delta * 0.22);
}
const basinWaterHeight = Math.max(0.001, basinFill * 0.07);
basinWater.scale.y = basinWaterHeight;
basinWater.position.y = 1.045 + basinWaterHeight / 2;
basinWater.visible = basinFill > 0.001;
bottleWater.scale.y = Math.max(0.001, bottleFill);
bottleWater.position.y = 1.14 + (0.56 * bottleFill) / 2;
bottleWater.visible = bottleFill > 0.001;
basinControl.style.setProperty("--level", `${basinFill * 100}%`);
bottleControl.style.setProperty("--level", `${bottleFill * 100}%`);
animateFlow(basinFlow, activeMode === "basin", elapsed);
animateFlow(bottleFlow, activeMode === "bottle", elapsed);
ripples.forEach((ripple, index) => {
const phase = (elapsed * 0.9 + index / ripples.length) % 1;
ripple.scale.setScalar(0.7 + phase * 3.2);
ripple.material.opacity = (1 - phase) * 0.7;
});
basinButton.position.z =
basinButtonBaseZ - (activeMode === "basin" ? 0.025 : 0);
bottleButton.position.z =
bottleButtonBaseZ - (activeMode === "bottle" ? 0.025 : 0);
basinButton.material.emissive.setHex(
activeMode === "basin" ? 0x6a3b00 : 0x000000
);
bottleButton.material.emissive.setHex(
activeMode === "bottle" ? 0x6a3b00 : 0x000000
);
updateTag(basinTag, basinTagPosition);
updateTag(bottleTag, bottleTagPosition);
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
if (!cameraTouched) {
cameraRadius =
window.innerWidth / window.innerHeight < 0.85 ? 13.4 : 9.2;
}
updateCamera();
});
animate();
</script>
</body>
</html>
```