Prompt specification
Build or customize the Three.js 3D scene "Two-level fountain reach study" 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: Two-level fountain reach study
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/two-level-fountain-reach-study-x0425
Scene Description Prompt:
A schematic voxel drinking fountain with two basin heights, front controls, and seated versus standing reach. Use Three.js from cdnjs in one HTML file.
Working Three.js Starter (two-level-fountain-reach-study-x0425):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Two-Level Voxel Drinking Fountain</title>
<style>
:root {
--ink: #19333a;
--muted: #60757b;
--panel: rgba(248, 251, 250, 0.9);
--line: rgba(25, 51, 58, 0.14);
--low: #18a9b4;
--high: #ed8b32;
--control: #e65353;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e8eeef;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene canvas:active {
cursor: grabbing;
}
.hud {
position: fixed;
z-index: 5;
pointer-events: none;
}
.title-card {
top: 24px;
left: 24px;
width: min(380px, calc(100vw - 48px));
padding: 17px 19px 16px;
background: var(--panel);
border: 1px solid var(--line);
border-radius: 14px;
box-shadow: 0 12px 34px rgba(43, 68, 73, 0.1);
backdrop-filter: blur(12px);
}
.eyebrow {
margin-bottom: 7px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(20px, 2.3vw, 30px);
line-height: 1.05;
letter-spacing: -0.035em;
}
.subtitle {
margin: 9px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
.legend {
left: 24px;
bottom: 24px;
display: grid;
gap: 9px;
min-width: 235px;
padding: 13px 15px;
background: var(--panel);
border: 1px solid var(--line);
border-radius: 12px;
box-shadow: 0 12px 34px rgba(43, 68, 73, 0.08);
backdrop-filter: blur(12px);
}
.legend-row {
display: flex;
align-items: center;
gap: 9px;
color: #496168;
font-size: 11px;
font-weight: 650;
}
.swatch {
width: 22px;
height: 4px;
border-radius: 10px;
flex: 0 0 auto;
}
.swatch.low {
background: var(--low);
}
.swatch.high {
background: var(--high);
}
.swatch.control {
width: 9px;
height: 9px;
margin-left: 6px;
margin-right: 9px;
background: var(--control);
border-radius: 2px;
}
.instructions {
right: 24px;
bottom: 24px;
padding: 10px 13px;
color: #60757b;
background: rgba(248, 251, 250, 0.82);
border: 1px solid var(--line);
border-radius: 10px;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.04em;
}
#tagLayer {
position: fixed;
inset: 0;
z-index: 4;
pointer-events: none;
overflow: hidden;
}
.tag {
position: absolute;
top: 0;
left: 0;
min-width: 112px;
padding: 8px 10px;
background: rgba(250, 252, 251, 0.94);
border: 1px solid var(--line);
border-left-width: 3px;
border-radius: 8px;
box-shadow: 0 6px 18px rgba(36, 58, 63, 0.09);
backdrop-filter: blur(8px);
white-space: nowrap;
}
.tag strong {
display: block;
color: var(--ink);
font-size: 10px;
line-height: 1.2;
letter-spacing: 0.02em;
}
.tag span {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 9px;
font-weight: 650;
}
.tag.low {
border-left-color: var(--low);
}
.tag.high {
border-left-color: var(--high);
}
.tag.control {
border-left-color: var(--control);
}
.tag.user {
background: rgba(247, 250, 249, 0.87);
}
#toast {
position: fixed;
z-index: 8;
left: 50%;
bottom: 28px;
padding: 10px 15px;
color: white;
background: #203b42;
border-radius: 9px;
box-shadow: 0 12px 30px rgba(22, 42, 47, 0.2);
font-size: 11px;
font-weight: 750;
pointer-events: none;
opacity: 0;
transform: translate(-50%, 12px);
transition:
opacity 180ms ease,
transform 180ms ease;
}
#toast.visible {
opacity: 1;
transform: translate(-50%, 0);
}
@media (max-width: 700px) {
.title-card {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 13px 15px;
}
.subtitle {
display: none;
}
.legend {
left: 12px;
bottom: 12px;
min-width: 0;
padding: 10px 12px;
}
.legend-row {
font-size: 9px;
}
.instructions,
.tag.user {
display: none;
}
.tag {
min-width: 94px;
padding: 6px 8px;
}
.tag strong {
font-size: 9px;
}
.tag span {
font-size: 8px;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<div id="tagLayer">
<div class="tag user" id="seatedTag">
<strong>SEATED USER</strong>
<span>Lower operating zone</span>
</div>
<div class="tag user" id="standingTag">
<strong>STANDING USER</strong>
<span>Higher operating zone</span>
</div>
<div class="tag low" id="lowTag">
<strong>LOW BASIN</strong>
<span>Seated access</span>
</div>
<div class="tag high" id="highTag">
<strong>HIGH BASIN</strong>
<span>Standing access</span>
</div>
<div class="tag control" id="controlTag">
<strong>FRONT PUSH CONTROL</strong>
<span>Click the red buttons</span>
</div>
</div>
<header class="hud title-card">
<div class="eyebrow">Schematic / Access Study</div>
<h1>Two-Level Voxel Fountain</h1>
<p class="subtitle">
A schematic drinking fountain with low seated access, high standing access,
and independently operated front controls.
</p>
</header>
<aside class="hud legend">
<div class="legend-row">
<span class="swatch low"></span>
Seated reach envelope
</div>
<div class="legend-row">
<span class="swatch high"></span>
Standing reach envelope
</div>
<div class="legend-row">
<span class="swatch control"></span>
Front push-button control
</div>
</aside>
<div class="hud instructions">
DRAG TO ORBIT · SCROLL TO ZOOM · DOUBLE-CLICK TO RESET
</div>
<div id="toast"></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 camera
// ---------------------------------------------------------------------
const host = document.querySelector("#scene");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe8eeef);
scene.fog = new THREE.Fog(0xe8eeef, 15, 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.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
host.appendChild(renderer.domElement);
renderer.domElement.setAttribute(
"aria-label",
"Interactive schematic of a two-level voxel drinking fountain"
);
const camera = new THREE.OrthographicCamera(-5, 5, 4, -4, 0.1, 100);
const cameraTarget = new THREE.Vector3(0, 1.0, 0);
const view = {
azimuth: 0.58,
polar: 1.04,
radius: 10.5
};
const homeView = { ...view };
function updateCamera() {
const sinPolar = Math.sin(view.polar);
const cosPolar = Math.cos(view.polar);
camera.position.set(
cameraTarget.x + view.radius * Math.sin(view.azimuth) * sinPolar,
cameraTarget.y + view.radius * cosPolar,
cameraTarget.z + view.radius * Math.cos(view.azimuth) * sinPolar
);
camera.lookAt(cameraTarget);
}
updateCamera();
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const frustumHeight = Math.max(6.5, 7.4 / aspect);
camera.left = (-frustumHeight * aspect) / 2;
camera.right = (frustumHeight * aspect) / 2;
camera.top = frustumHeight / 2;
camera.bottom = -frustumHeight / 2;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
}
window.addEventListener("resize", resize);
resize();
// ---------------------------------------------------------------------
// Lighting
// ---------------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xf8ffff, 0x819195, 2.25));
const keyLight = new THREE.DirectionalLight(0xffffff, 3.1);
keyLight.position.set(4.5, 8.5, 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 = 0.5;
keyLight.shadow.camera.far = 22;
keyLight.shadow.bias = -0.0007;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0xc9eef2, 1.2);
rimLight.position.set(-5, 4, -4);
scene.add(rimLight);
// ---------------------------------------------------------------------
// Geometry helpers
// ---------------------------------------------------------------------
const outlineMaterial = new THREE.LineBasicMaterial({
color: 0x29474d,
transparent: true,
opacity: 0.14
});
function box(
parent,
size,
position,
color,
options = {}
) {
const geometry = new THREE.BoxGeometry(...size);
const material = new THREE.MeshStandardMaterial({
color,
roughness: options.roughness ?? 0.72,
metalness: options.metalness ?? 0.02,
transparent: options.transparent ?? false,
opacity: options.opacity ?? 1,
emissive: options.emissive ?? 0x000000,
emissiveIntensity: options.emissiveIntensity ?? 0
});
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(...position);
mesh.castShadow = options.castShadow ?? true;
mesh.receiveShadow = options.receiveShadow ?? true;
if (options.outline !== false) {
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(geometry),
outlineMaterial
);
mesh.add(edges);
}
parent.add(mesh);
return mesh;
}
function beam(parent, a, b, width, depth, color, options = {}) {
const start = new THREE.Vector3(...a);
const end = new THREE.Vector3(...b);
const direction = end.clone().sub(start);
const length = direction.length();
const mesh = box(
parent,
[width, length, depth],
start.clone().add(end).multiplyScalar(0.5).toArray(),
color,
options
);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
return mesh;
}
function basicMarker(color, size = 0.075) {
const material = new THREE.MeshBasicMaterial({
color,
depthTest: false,
transparent: true,
opacity: 0.95
});
const marker = new THREE.Mesh(
new THREE.BoxGeometry(size, size, size),
material
);
marker.renderOrder = 10;
return marker;
}
// ---------------------------------------------------------------------
// Floor and schematic grid
// ---------------------------------------------------------------------
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(18, 14),
new THREE.MeshStandardMaterial({
color: 0xe3e9e9,
roughness: 1
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.035;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(14, 28, 0x9eafb2, 0xc4d0d2);
grid.position.y = -0.025;
grid.material.transparent = true;
grid.material.opacity = 0.48;
scene.add(grid);
// ---------------------------------------------------------------------
// Main fountain
// ---------------------------------------------------------------------
const fountain = new THREE.Group();
fountain.position.z = -0.1;
scene.add(fountain);
// Platform and lower body.
box(fountain, [2.55, 0.16, 1.8], [0, 0.08, 0], 0x60777d);
box(fountain, [2.08, 0.18, 1.45], [0, 0.25, -0.05], 0x93a7aa);
box(fountain, [1.48, 1.62, 0.45], [0, 1.08, -0.47], 0xb8c7c8);
// Narrow side uprights make the silhouette read as a fixture.
box(fountain, [0.16, 1.38, 0.68], [-0.68, 0.98, -0.19], 0xa7b9bb);
box(fountain, [0.16, 1.38, 0.68], [0.68, 0.98, -0.19], 0xa7b9bb);
// Central service panel.
box(
fountain,
[0.42, 0.92, 0.06],
[0, 0.78, -0.215],
0x8da4a8,
{ metalness: 0.14 }
);
// Pixel water-drop emblem.
box(fountain, [0.07, 0.18, 0.035], [0, 1.03, -0.17], 0x28b8c2);
box(fountain, [0.19, 0.07, 0.035], [0, 0.95, -0.17], 0x28b8c2);
box(fountain, [0.11, 0.06, 0.035], [0, 0.87, -0.17], 0x28b8c2);
const controls = [];
const waterSystems = [];
function makeBasin(y, z, name, initiallyActive) {
const basin = new THREE.Group();
basin.name = name;
fountain.add(basin);
const width = 1.2;
const depth = 0.72;
const rim = 0.105;
// Recess and basin floor.
box(
basin,
[width - 0.16, 0.055, depth - 0.16],
[0, y - 0.02, z],
0x31494f,
{ metalness: 0.2, roughness: 0.4 }
);
// Water surface.
const water = box(
basin,
[width - 0.24, 0.012, depth - 0.24],
[0, y + 0.012, z],
0x39b8ca,
{
metalness: 0.05,
roughness: 0.18,
transparent: true,
opacity: 0.78,
outline: false
}
);
// Four voxel rim pieces.
box(basin, [width, rim, 0.11], [0, y, z - depth / 2], 0xcbd7d8, {
metalness: 0.32,
roughness: 0.34
});
box(basin, [width, rim, 0.11], [0, y, z + depth / 2], 0xcbd7d8, {
metalness: 0.32,
roughness: 0.34
});
box(basin, [0.11, rim, depth], [-width / 2, y, z], 0xcbd7d8, {
metalness: 0.32,
roughness: 0.34
});
box(basin, [0.11, rim, depth], [width / 2, y, z], 0xcbd7d8, {
metalness: 0.32,
roughness: 0.34
});
// Rear splash guard.
box(basin, [width + 0.04, 0.19, 0.07], [0, y + 0.08, z - 0.31], 0x9eb2b5);
// Spout assembly.
box(basin, [0.08, 0.28, 0.08], [0, y + 0.12, z - 0.19], 0x748a8f, {
metalness: 0.72,
roughness: 0.22
});
box(basin, [0.08, 0.065, 0.28], [0, y + 0.235, z - 0.07], 0x748a8f, {
metalness: 0.72,
roughness: 0.22
});
box(basin, [0.07, 0.06, 0.07], [0, y + 0.19, z + 0.045], 0x43585d, {
metalness: 0.75,
roughness: 0.2
});
// Front push control.
const button = box(
basin,
[0.135, 0.135, 0.065],
[0.47, y + 0.015, z + depth / 2 + 0.035],
0xe65353,
{
roughness: 0.38,
emissive: 0xe65353,
emissiveIntensity: initiallyActive ? 0.55 : 0.08
}
);
button.userData.control = true;
button.userData.basinName = name;
button.userData.active = initiallyActive;
controls.push(button);
// Small status LED.
const led = box(
basin,
[0.045, 0.045, 0.035],
[0.47, y + 0.115, z + depth / 2 + 0.025],
initiallyActive ? 0x42d5ce : 0x75878b,
{
emissive: initiallyActive ? 0x42d5ce : 0x000000,
emissiveIntensity: initiallyActive ? 1.2 : 0,
outline: false
}
);
// Animated schematic water stream.
const stream = new THREE.Group();
stream.position.set(0, y - 0.03, z + 0.045);
stream.visible = initiallyActive;
basin.add(stream);
const streamMaterial = new THREE.MeshBasicMaterial({
color: 0x43c7d2,
transparent: true,
opacity: 0.55,
depthWrite: false
});
const streamLine = new THREE.Mesh(
new THREE.BoxGeometry(0.012, 0.19, 0.012),
streamMaterial
);
streamLine.position.y = 0.085;
stream.add(streamLine);
const drop = new THREE.Mesh(
new THREE.BoxGeometry(0.026, 0.026, 0.026),
new THREE.MeshBasicMaterial({
color: 0xb6f3f4,
transparent: true,
opacity: 0.9
})
);
stream.add(drop);
waterSystems.push({
basin,
button,
led,
stream,
drop,
water,
active: initiallyActive
});
return basin;
}
const lowerBasin = makeBasin(0.92, 0.17, "LOW BASIN", true);
const upperBasin = makeBasin(1.52, 0.035, "HIGH BASIN", true);
// ---------------------------------------------------------------------
// Seated voxel user
// ---------------------------------------------------------------------
const seated = new THREE.Group();
seated.position.z = 0.03;
scene.add(seated);
const chairColor = 0x72868a;
const seatedShirt = 0x32aeb8;
const skin = 0xd3a27f;
// Chair.
box(seated, [0.56, 0.09, 0.58], [-1.96, 0.49, 0.19], chairColor);
box(seated, [0.09, 0.58, 0.58], [-2.22, 0.76, 0.19], chairColor);
box(seated, [0.075, 0.42, 0.075], [-2.13, 0.22, 0.48], chairColor);
box(seated, [0.075, 0.42, 0.075], [-1.79, 0.22, 0.48], chairColor);
box(seated, [0.075, 0.42, 0.075], [-2.13, 0.22, -0.1], chairColor);
box(seated, [0.075, 0.42, 0.075], [-1.79, 0.22, -0.1], chairColor);
// Person.
box(seated, [0.38, 0.26, 0.4], [-1.9, 0.67, 0.19], 0x415a63);
box(seated, [0.43, 0.51, 0.4], [-1.88, 0.94, 0.19], seatedShirt);
box(seated, [0.34, 0.34, 0.34], [-1.72, 1.32, 0.19], skin);
box(seated, [0.11, 0.08, 0.34], [-1.54, 1.38, 0.19], skin);
// Thigh and lower leg.
box(seated, [0.67, 0.18, 0.23], [-1.58, 0.68, 0.19], 0x344c55);
box(seated, [0.18, 0.48, 0.2], [-1.26, 0.4, 0.19], 0x344c55);
box(seated, [0.33, 0.13, 0.22], [-1.12, 0.11, 0.19], 0x263b43);
// Reaching arm.
beam(seated, [-1.62, 1.1, 0.37], [-1.13, 1.0, 0.43], 0.12, 0.14, seatedShirt);
beam(seated, [-1.13, 1.0, 0.43], [-0.47, 0.94, 0.44], 0.105, 0.12, skin);
box(seated, [0.13, 0.12, 0.13], [-0.44, 0.94, 0.44], skin);
// ---------------------------------------------------------------------
// Standing voxel user
// ---------------------------------------------------------------------
const standing = new THREE.Group();
standing.position.z = 0.02;
scene.add(standing);
const standingShirt = 0xe68c35;
// Legs.
box(standing, [0.19, 0.75, 0.21], [1.72, 0.43, 0.31], 0x40555d);
box(standing, [0.19, 0.75, 0.21], [1.72, 0.43, -0.08], 0x40555d);
box(standing, [0.36, 0.14, 0.23], [1.58, 0.1, 0.31], 0x263b43);
box(standing, [0.36, 0.14, 0.23], [1.58, 0.1, -0.08], 0x263b43);
// Torso and head.
box(standing, [0.43, 0.66, 0.43], [1.72, 1.13, 0.12], standingShirt);
box(standing, [0.35, 0.35, 0.35], [1.59, 1.69, 0.12], skin);
box(standing, [0.1, 0.08, 0.35], [1.4, 1.73, 0.12], skin);
// Reaching arm.
beam(standing, [1.46, 1.4, 0.36], [1.02, 1.43, 0.44], 0.12, 0.14, standingShirt);
beam(standing, [1.02, 1.43, 0.44], [0.47, 1.51, 0.44], 0.105, 0.12, skin);
box(standing, [0.13, 0.12, 0.13], [0.44, 1.51, 0.44], skin);
// ---------------------------------------------------------------------
// Reach envelopes
// ---------------------------------------------------------------------
function addReachEnvelope(start, control, end, color) {
const curve = new THREE.QuadraticBezierCurve3(
new THREE.Vector3(...start),
new THREE.Vector3(...control),
new THREE.Vector3(...end)
);
const geometry = new THREE.BufferGeometry().setFromPoints(
curve.getPoints(56)
);
const material = new THREE.LineDashedMaterial({
color,
dashSize: 0.105,
gapSize: 0.075,
transparent: true,
opacity: 0.9,
depthTest: false
});
const line = new THREE.Line(geometry, material);
line.computeLineDistances();
line.renderOrder = 8;
scene.add(line);
const startMarker = basicMarker(color, 0.07);
startMarker.position.set(...start);
scene.add(startMarker);
const endMarker = basicMarker(color, 0.085);
endMarker.position.set(...end);
scene.add(endMarker);
return line;
}
addReachEnvelope(
[-1.58, 1.1, 0.56],
[-1.03, 1.34, 0.56],
[-0.47, 0.94, 0.56],
0x18a9b4
);
addReachEnvelope(
[1.45, 1.42, 0.57],
[0.98, 1.83, 0.57],
[0.47, 1.51, 0.57],
0xed8b32
);
// ---------------------------------------------------------------------
// HTML annotation projection
// ---------------------------------------------------------------------
const tags = [
{
element: document.querySelector("#seatedTag"),
point: new THREE.Vector3(-1.9, 1.63, 0.19),
offset: [-75, -20]
},
{
element: document.querySelector("#standingTag"),
point: new THREE.Vector3(1.68, 2.04, 0.12),
offset: [50, -18]
},
{
element: document.querySelector("#lowTag"),
point: new THREE.Vector3(-0.18, 0.92, 0.58),
offset: [-112, 43]
},
{
element: document.querySelector("#highTag"),
point: new THREE.Vector3(0.08, 1.52, 0.43),
offset: [103, -45]
},
{
element: document.querySelector("#controlTag"),
point: new THREE.Vector3(0.47, 0.95, 0.61),
offset: [124, 63]
}
];
function updateTags() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const tag of tags) {
const projected = tag.point.clone().project(camera);
const x = (projected.x * 0.5 + 0.5) * width + tag.offset[0];
const y = (-projected.y * 0.5 + 0.5) * height + tag.offset[1];
tag.element.style.transform =
`translate(-50%, -50%) translate(${x}px, ${y}px)`;
}
}
// ---------------------------------------------------------------------
// Direct camera controls, implemented without addons
// ---------------------------------------------------------------------
const canvas = renderer.domElement;
const pointerState = {
active: false,
moved: false,
x: 0,
y: 0
};
canvas.addEventListener("pointerdown", (event) => {
pointerState.active = true;
pointerState.moved = false;
pointerState.x = event.clientX;
pointerState.y = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!pointerState.active) return;
const dx = event.clientX - pointerState.x;
const dy = event.clientY - pointerState.y;
if (Math.abs(dx) + Math.abs(dy) > 2) {
pointerState.moved = true;
}
view.azimuth -= dx * 0.007;
view.polar = THREE.MathUtils.clamp(
view.polar - dy * 0.006,
0.52,
1.38
);
pointerState.x = event.clientX;
pointerState.y = event.clientY;
updateCamera();
});
canvas.addEventListener("pointerup", (event) => {
pointerState.active = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
if (!pointerState.moved) {
checkControlClick(event);
}
});
canvas.addEventListener("pointercancel", () => {
pointerState.active = false;
});
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
view.radius = THREE.MathUtils.clamp(
view.radius + event.deltaY * 0.007,
7.4,
14.5
);
updateCamera();
},
{ passive: false }
);
canvas.addEventListener("dblclick", () => {
view.azimuth = homeView.azimuth;
view.polar = homeView.polar;
view.radius = homeView.radius;
updateCamera();
});
// ---------------------------------------------------------------------
// Interactive front controls
// ---------------------------------------------------------------------
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const toast = document.querySelector("#toast");
let toastTimer;
function showToast(message) {
toast.textContent = message;
toast.classList.add("visible");
clearTimeout(toastTimer);
toastTimer = setTimeout(() => {
toast.classList.remove("visible");
}, 1500);
}
function checkControlClick(event) {
const rect = canvas.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(controls, false);
if (!hits.length) return;
const button = hits[0].object;
const system = waterSystems.find(
(item) => item.button === button
);
if (!system) return;
system.active = !system.active;
system.button.userData.active = system.active;
system.stream.visible = system.active;
system.button.material.emissiveIntensity = system.active ? 0.55 : 0.08;
system.led.material.color.setHex(
system.active ? 0x42d5ce : 0x75878b
);
system.led.material.emissive.setHex(
system.active ? 0x42d5ce : 0x000000
);
system.led.material.emissiveIntensity = system.active ? 1.2 : 0;
showToast(
`${system.button.userData.basinName}: ${
system.active ? "water on" : "water off"
}`
);
}
// ---------------------------------------------------------------------
// Animation
// ---------------------------------------------------------------------
const clock = new THREE.Clock();
renderer.setAnimationLoop(() => {
const elapsed = clock.getElapsedTime();
for (const system of waterSystems) {
if (!system.active) continue;
const cycle = (elapsed * 2.4) % 1;
system.drop.position.y = THREE.MathUtils.lerp(0.19, 0.015, cycle);
system.water.material.opacity = 0.74 + Math.sin(elapsed * 2.3) * 0.05;
}
updateTags();
renderer.render(scene, camera);
});
</script>
</body>
</html>
```