Prompt specification
Build or customize the Three.js 3D scene "Backyard water-play table" 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: Backyard water-play table
Category: Games & Play · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/backyard-water-play-table-x0395
Scene Description Prompt:
A stylized water-play table with gates redirecting flow through channels, a wheel, and a collection basin. Three.js from cdnjs, one HTML file.
Working Three.js Starter (backyard-water-play-table-x0395):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Tideworks — Interactive Water Table</title>
<style>
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dcefee;
color: #183f45;
font-family: Inter, ui-rounded, "SF Pro Rounded", system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene:active {
cursor: grabbing;
}
.overlay {
position: fixed;
inset: 0;
pointer-events: none;
padding: 24px;
display: flex;
flex-direction: column;
justify-content: space-between;
}
.top-row {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 20px;
}
.brand {
max-width: 420px;
padding: 18px 20px;
border: 1px solid rgba(255, 255, 255, 0.7);
border-radius: 22px;
background: rgba(255, 255, 255, 0.68);
box-shadow: 0 12px 40px rgba(32, 91, 93, 0.12);
backdrop-filter: blur(16px);
}
.eyebrow {
margin: 0 0 5px;
color: #e46d57;
font-size: 11px;
font-weight: 850;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(28px, 4vw, 44px);
line-height: 0.95;
letter-spacing: -0.05em;
}
.subtitle {
margin: 10px 0 0;
color: #557276;
font-size: 13px;
line-height: 1.45;
}
.panel {
width: min(310px, 100%);
padding: 16px;
border: 1px solid rgba(255, 255, 255, 0.8);
border-radius: 22px;
background: rgba(255, 255, 255, 0.72);
box-shadow: 0 14px 45px rgba(32, 91, 93, 0.14);
backdrop-filter: blur(18px);
pointer-events: auto;
}
.status {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 14px;
padding: 10px 12px;
border-radius: 13px;
background: #e4f6f2;
color: #24686b;
font-size: 12px;
font-weight: 750;
}
.status-dot {
width: 9px;
height: 9px;
flex: 0 0 auto;
border-radius: 50%;
background: #36bfae;
box-shadow: 0 0 0 4px rgba(54, 191, 174, 0.15);
animation: pulse 1.8s ease-in-out infinite;
}
@keyframes pulse {
50% {
box-shadow: 0 0 0 7px rgba(54, 191, 174, 0.04);
}
}
.control {
width: 100%;
min-height: 54px;
margin-top: 8px;
padding: 10px 12px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
border: 1px solid rgba(45, 112, 115, 0.13);
border-radius: 14px;
background: rgba(255, 255, 255, 0.8);
color: #244e52;
font: inherit;
text-align: left;
cursor: pointer;
transition: transform 160ms ease, background 160ms ease,
box-shadow 160ms ease;
}
.control:hover {
transform: translateY(-1px);
background: #fff;
box-shadow: 0 7px 20px rgba(38, 103, 106, 0.1);
}
.control:active {
transform: translateY(1px) scale(0.99);
}
.control-main {
display: flex;
flex-direction: column;
gap: 2px;
}
.control-title {
font-size: 13px;
font-weight: 800;
}
.control-help {
color: #779093;
font-size: 10px;
}
.control-value {
min-width: 66px;
padding: 6px 9px;
border-radius: 10px;
background: #fce7df;
color: #c95643;
font-size: 10px;
font-weight: 850;
text-align: center;
text-transform: uppercase;
letter-spacing: 0.05em;
}
.bottom-row {
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 20px;
}
.instructions {
padding: 11px 14px;
border-radius: 15px;
background: rgba(22, 65, 69, 0.78);
color: #ecffff;
box-shadow: 0 8px 25px rgba(20, 64, 67, 0.16);
font-size: 11px;
font-weight: 650;
letter-spacing: 0.01em;
backdrop-filter: blur(12px);
}
.instructions b {
color: #ffcf78;
}
#tooltip {
position: fixed;
z-index: 5;
display: none;
padding: 7px 10px;
border-radius: 9px;
background: rgba(20, 57, 61, 0.9);
color: white;
font-size: 11px;
font-weight: 700;
pointer-events: none;
transform: translate(12px, 12px);
box-shadow: 0 5px 15px rgba(15, 50, 53, 0.18);
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #dcefee;
color: #326d70;
font-size: 13px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
transition: opacity 400ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 760px) {
.overlay {
padding: 12px;
}
.top-row {
gap: 8px;
}
.brand {
padding: 13px 14px;
border-radius: 17px;
}
.brand .subtitle {
display: none;
}
.panel {
width: 180px;
padding: 10px;
border-radius: 17px;
}
.status {
margin-bottom: 7px;
padding: 8px;
font-size: 10px;
}
.control {
min-height: 44px;
padding: 7px 8px;
}
.control-help {
display: none;
}
.control-value {
min-width: 54px;
padding: 5px 6px;
font-size: 8px;
}
.instructions {
max-width: 270px;
font-size: 9px;
}
}
</style>
</head>
<body>
<canvas id="scene"></canvas>
<div class="overlay">
<div class="top-row">
<section class="brand">
<p class="eyebrow">Interactive water table</p>
<h1>Tideworks</h1>
<p class="subtitle">
Turn the gates, send water through the wheel, and watch it collect
in the lower basin.
</p>
</section>
<section class="panel" aria-label="Water table controls">
<div class="status">
<span class="status-dot"></span>
<span id="flowStatus">Flowing: wheel → basin</span>
</div>
<button class="control" id="forkButton" type="button">
<span class="control-main">
<span class="control-title">Fork gate</span>
<span class="control-help">Choose the main route</span>
</span>
<span class="control-value" id="forkValue">Wheel</span>
</button>
<button class="control" id="outletButton" type="button">
<span class="control-main">
<span class="control-title">Wheel outlet</span>
<span class="control-help">Open or hold the lower gate</span>
</span>
<span class="control-value" id="outletValue">Open</span>
</button>
<button class="control" id="wheelButton" type="button">
<span class="control-main">
<span class="control-title">Water wheel</span>
<span class="control-help">Give it a manual nudge</span>
</span>
<span class="control-value">Spin</span>
</button>
<button class="control" id="viewButton" type="button">
<span class="control-main">
<span class="control-title">Camera</span>
<span class="control-help">Return to the overview</span>
</span>
<span class="control-value">Reset</span>
</button>
</section>
</div>
<div class="bottom-row">
<div class="instructions">
<b>Drag</b> to orbit · <b>Scroll</b> to zoom · <b>Tap gates</b> to
redirect · <b>Tap wheel</b> to spin
</div>
</div>
</div>
<div id="tooltip"></div>
<div id="loading">Building the water table…</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 tooltip = document.querySelector("#tooltip");
const loading = document.querySelector("#loading");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdcefee);
scene.fog = new THREE.Fog(0xdcefee, 18, 34);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
const cameraTarget = new THREE.Vector3(-0.35, 0.15, 0);
const initialCamera = new THREE.Vector3(10.2, 9.2, 12.4);
camera.position.copy(initialCamera);
const orbit = new THREE.Spherical().setFromVector3(
camera.position.clone().sub(cameraTarget)
);
const hemisphere = new THREE.HemisphereLight(0xf5ffff, 0x7ca19a, 2.25);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff4df, 3.2);
keyLight.position.set(-5, 11, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -11;
keyLight.shadow.camera.right = 11;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -10;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 30;
keyLight.shadow.bias = -0.0005;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x9fe8e7, 1.25);
rimLight.position.set(7, 5, -8);
scene.add(rimLight);
const table = new THREE.Group();
scene.add(table);
const materials = {
frame: new THREE.MeshStandardMaterial({
color: 0x2d7478,
roughness: 0.62,
metalness: 0.08
}),
frameDark: new THREE.MeshStandardMaterial({
color: 0x174f57,
roughness: 0.7
}),
wood: new THREE.MeshStandardMaterial({
color: 0xe9c995,
roughness: 0.8
}),
cream: new THREE.MeshStandardMaterial({
color: 0xf8e8c6,
roughness: 0.72
}),
bed: new THREE.MeshStandardMaterial({
color: 0x17646b,
roughness: 0.48
}),
water: new THREE.MeshPhysicalMaterial({
color: 0x43d5cf,
roughness: 0.2,
metalness: 0.02,
clearcoat: 0.85,
clearcoatRoughness: 0.18,
transparent: true,
opacity: 0.83,
depthWrite: false,
side: THREE.DoubleSide
}),
coral: new THREE.MeshStandardMaterial({
color: 0xee715b,
roughness: 0.48
}),
coralLight: new THREE.MeshStandardMaterial({
color: 0xffa084,
roughness: 0.48
}),
yellow: new THREE.MeshStandardMaterial({
color: 0xffce69,
roughness: 0.44
}),
white: new THREE.MeshStandardMaterial({
color: 0xfff8df,
roughness: 0.65
}),
dark: new THREE.MeshStandardMaterial({
color: 0x173f45,
roughness: 0.72
}),
metal: new THREE.MeshStandardMaterial({
color: 0xd4b16b,
roughness: 0.34,
metalness: 0.6
})
};
function roundedShape(width, depth, radius) {
const x = -width / 2;
const y = -depth / 2;
const r = Math.min(radius, width / 2, depth / 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 + depth - r);
shape.quadraticCurveTo(
x + width,
y + depth,
x + width - r,
y + depth
);
shape.lineTo(x + r, y + depth);
shape.quadraticCurveTo(x, y + depth, x, y + depth - r);
shape.lineTo(x, y + r);
shape.quadraticCurveTo(x, y, x + r, y);
return shape;
}
function roundedSlabGeometry(width, depth, height, radius) {
const geometry = new THREE.ExtrudeGeometry(
roundedShape(width, depth, radius),
{
depth: height,
bevelEnabled: false,
curveSegments: 10
}
);
geometry.rotateX(-Math.PI / 2);
geometry.translate(0, -height / 2, 0);
return geometry;
}
function roundedPlaneGeometry(width, depth, radius) {
const geometry = new THREE.ShapeGeometry(
roundedShape(width, depth, radius),
12
);
geometry.rotateX(-Math.PI / 2);
return geometry;
}
function addSlab(
width,
depth,
height,
radius,
material,
x,
y,
z,
parent = table
) {
const mesh = new THREE.Mesh(
roundedSlabGeometry(width, depth, height, radius),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addBox(
width,
height,
depth,
material,
x,
y,
z,
parent = table
) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addCylinder(
radiusTop,
radiusBottom,
height,
material,
x,
y,
z,
parent = table,
segments = 24
) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(
radiusTop,
radiusBottom,
height,
segments
),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinderBetween(a, b, radius, material, parent = table) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, length, 16),
material
);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addWall(width, depth, x, z, material = materials.cream) {
return addBox(width, 0.28, depth, material, x, 0.665, z);
}
const channelWaters = [];
function addChannelWater(width, depth, x, z, phase = 0) {
const segmentsX = Math.max(2, Math.round(width * 5));
const segmentsY = Math.max(2, Math.round(depth * 5));
const geometry = new THREE.PlaneGeometry(
width,
depth,
segmentsX,
segmentsY
);
geometry.rotateX(-Math.PI / 2);
const water = new THREE.Mesh(geometry, materials.water);
water.position.set(x, 0.525, z);
water.receiveShadow = true;
water.renderOrder = 2;
table.add(water);
channelWaters.push({ mesh: water, phase });
return water;
}
// Ground and table structure.
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(80, 80),
new THREE.MeshStandardMaterial({
color: 0xe9f3ed,
roughness: 0.95
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -1.48;
ground.receiveShadow = true;
scene.add(ground);
const shadowDisc = new THREE.Mesh(
new THREE.CircleGeometry(7.6, 64),
new THREE.MeshBasicMaterial({
color: 0x7ca59e,
transparent: true,
opacity: 0.1,
depthWrite: false
})
);
shadowDisc.rotation.x = -Math.PI / 2;
shadowDisc.position.set(-0.3, -1.465, 0);
scene.add(shadowDisc);
addSlab(12.25, 7.45, 0.48, 0.5, materials.frame, -0.35, 0.08, 0);
addSlab(11.95, 7.15, 0.16, 0.42, materials.wood, -0.35, 0.38, 0);
const legPositions = [
[-5.25, -2.8],
[4.55, -2.8],
[-5.25, 2.75],
[4.55, 2.75]
];
legPositions.forEach(([x, z]) => {
addBox(0.48, 1.45, 0.48, materials.frameDark, x, -0.66, z);
addBox(0.63, 0.12, 0.63, materials.frame, x, -1.36, z);
});
// Source pool.
addSlab(1.85, 1.42, 0.14, 0.25, materials.bed, -4.64, 0.45, -2.2);
const sourceWater = new THREE.Mesh(
roundedPlaneGeometry(1.65, 1.22, 0.22),
materials.water
);
sourceWater.position.set(-4.64, 0.535, -2.2);
sourceWater.renderOrder = 2;
table.add(sourceWater);
addWall(1.7, 0.13, -4.64, -2.83);
addWall(1.7, 0.13, -4.64, -1.57);
addWall(0.13, 1.3, -5.43, -2.2);
// Channel beds.
addBox(3.42, 0.12, 1.08, materials.bed, -2.08, 0.43, -2.2);
addBox(3.82, 0.12, 1.08, materials.bed, 1.49, 0.43, -2.2);
addBox(1.08, 0.12, 2.92, materials.bed, -0.4, 0.43, -0.24);
addBox(1.08, 0.12, 2.28, materials.bed, 3.4, 0.43, -0.58);
addBox(1.52, 0.12, 1.08, materials.bed, 0.34, 0.43, 1.2);
// Continuous channel water surfaces.
addChannelWater(3.4, 0.9, -2.09, -2.2, 0.2);
addChannelWater(3.8, 0.9, 1.5, -2.2, 1.3);
addChannelWater(0.9, 2.9, -0.4, -0.25, 2.1);
addChannelWater(0.9, 2.25, 3.4, -0.575, 3.6);
addChannelWater(1.5, 0.9, 0.35, 1.2, 4.8);
// Channel curbs, with openings at junctions and basin entrances.
addWall(3.15, 0.12, -2.13, -2.73);
addWall(2.78, 0.12, -1.95, -1.67);
addWall(3.1, 0.12, 1.58, -2.73);
addWall(2.86, 0.12, 1.39, -1.67);
addWall(0.12, 2.68, -0.83, -0.3);
addWall(0.12, 2.55, 0.03, -0.33);
addWall(0.12, 2.18, 2.97, -0.63);
addWall(0.12, 2.18, 3.83, -0.63);
addWall(1.42, 0.12, 0.29, 0.77);
addWall(1.42, 0.12, 0.29, 1.63);
// Collection basin.
addSlab(3.45, 2.43, 0.15, 0.34, materials.bed, 2.75, 0.44, 1.65);
const basinWater = new THREE.Mesh(
roundedPlaneGeometry(3.23, 2.2, 0.3),
materials.water
);
basinWater.position.set(2.75, 0.538, 1.65);
basinWater.renderOrder = 2;
table.add(basinWater);
addWall(2.02, 0.13, 2.05, 0.48);
addWall(0.64, 0.13, 3.78, 0.48);
addWall(0.13, 1.08, 1.07, 1.08);
addWall(0.13, 1.27, 1.07, 2.22);
addWall(0.13, 2.3, 4.43, 1.65);
addWall(3.18, 0.13, 2.78, 2.78);
// Basin drain.
const drain = addCylinder(
0.34,
0.34,
0.035,
materials.dark,
2.78,
0.565,
1.75,
table,
32
);
drain.castShadow = false;
for (let i = -2; i <= 2; i++) {
addBox(
0.53,
0.025,
0.035,
materials.metal,
2.78,
0.59,
1.75 + i * 0.105
);
}
// Faucet and source pipe.
addCylinder(0.14, 0.18, 1.38, materials.frame, -5.02, 1.11, -3.05);
addCylinder(0.24, 0.24, 0.13, materials.yellow, -5.02, 1.83, -3.05);
cylinderBetween(
new THREE.Vector3(-5.02, 1.73, -3.05),
new THREE.Vector3(-4.64, 1.73, -3.05),
0.11,
materials.frame
);
cylinderBetween(
new THREE.Vector3(-4.64, 1.73, -3.05),
new THREE.Vector3(-4.64, 1.73, -2.42),
0.11,
materials.frame
);
cylinderBetween(
new THREE.Vector3(-4.64, 1.73, -2.42),
new THREE.Vector3(-4.64, 1.54, -2.42),
0.11,
materials.frame
);
// Gate helper.
const interactiveMeshes = [];
function createGate(position, label, kind) {
const group = new THREE.Group();
group.position.copy(position);
table.add(group);
const pivot = new THREE.Group();
group.add(pivot);
const board = new THREE.Mesh(
new THREE.BoxGeometry(0.94, 0.48, 0.13),
materials.coral
);
board.position.set(0.46, 0.25, 0);
board.castShadow = true;
board.receiveShadow = true;
pivot.add(board);
const stripe = new THREE.Mesh(
new THREE.BoxGeometry(0.13, 0.42, 0.145),
materials.white
);
stripe.position.set(0.64, 0.25, 0);
stripe.castShadow = true;
pivot.add(stripe);
const axle = addCylinder(
0.07,
0.07,
0.92,
materials.yellow,
position.x,
0.69,
position.z,
table,
18
);
const lamp = new THREE.Mesh(
new THREE.SphereGeometry(0.105, 16, 10),
materials.yellow
);
lamp.position.set(position.x, 1.18, position.z);
lamp.castShadow = true;
table.add(lamp);
const hit = new THREE.Mesh(
new THREE.BoxGeometry(1.1, 0.9, 0.42),
new THREE.MeshBasicMaterial({
transparent: true,
opacity: 0,
depthWrite: false
})
);
hit.position.set(position.x + 0.43, 0.69, position.z);
hit.userData.interaction = kind;
hit.userData.label = label;
table.add(hit);
interactiveMeshes.push(hit);
return {
group,
pivot,
board,
lamp,
axle,
currentAngle: 0,
targetAngle: 0
};
}
const forkGate = createGate(
new THREE.Vector3(-0.38, 0, -1.72),
"Fork gate — redirect the main flow",
"fork"
);
const outletGate = createGate(
new THREE.Vector3(2.94, 0, -0.88),
"Outlet gate — open or hold the flow",
"outlet"
);
// Water wheel.
const wheel = new THREE.Group();
wheel.position.set(2.12, 1.37, -2.2);
table.add(wheel);
const wheelRim = new THREE.Mesh(
new THREE.TorusGeometry(0.83, 0.105, 12, 48),
materials.yellow
);
wheelRim.castShadow = true;
wheel.add(wheelRim);
const innerRim = new THREE.Mesh(
new THREE.TorusGeometry(0.58, 0.055, 10, 40),
materials.coralLight
);
wheel.add(innerRim);
for (let i = 0; i < 12; i++) {
const angle = (i / 12) * Math.PI * 2;
const inner = new THREE.Vector3(
Math.cos(angle) * 0.12,
Math.sin(angle) * 0.12,
0
);
const outer = new THREE.Vector3(
Math.cos(angle) * 0.82,
Math.sin(angle) * 0.82,
0
);
cylinderBetween(inner, outer, 0.035, materials.coralLight, wheel);
const paddle = new THREE.Mesh(
new THREE.BoxGeometry(0.31, 0.13, 0.48),
i % 3 === 0 ? materials.coral : materials.frame
);
paddle.position.set(
Math.cos(angle) * 0.72,
Math.sin(angle) * 0.72,
0
);
paddle.rotation.z = angle + Math.PI / 2;
paddle.castShadow = true;
wheel.add(paddle);
}
const hub = new THREE.Mesh(
new THREE.CylinderGeometry(0.19, 0.19, 0.78, 24),
materials.coral
);
hub.rotation.x = Math.PI / 2;
hub.castShadow = true;
wheel.add(hub);
const axle = new THREE.Mesh(
new THREE.CylinderGeometry(0.08, 0.08, 1.65, 18),
materials.metal
);
axle.rotation.x = Math.PI / 2;
axle.position.copy(wheel.position);
axle.castShadow = true;
table.add(axle);
[-0.68, 0.68].forEach((offset) => {
addBox(
0.18,
1.22,
0.18,
materials.frame,
wheel.position.x,
0.96,
wheel.position.z + offset
);
addCylinder(
0.13,
0.13,
0.24,
materials.yellow,
wheel.position.x,
1.37,
wheel.position.z + offset,
table,
18
);
});
const wheelHit = new THREE.Mesh(
new THREE.SphereGeometry(0.96, 12, 8),
new THREE.MeshBasicMaterial({
transparent: true,
opacity: 0,
depthWrite: false
})
);
wheelHit.position.copy(wheel.position);
wheelHit.userData.interaction = "wheel";
wheelHit.userData.label = "Water wheel — click to spin";
table.add(wheelHit);
interactiveMeshes.push(wheelHit);
// Labels rendered as camera-facing sprites.
function makeLabel(text, width = 1.45) {
const labelCanvas = document.createElement("canvas");
labelCanvas.width = 512;
labelCanvas.height = 128;
const ctx = labelCanvas.getContext("2d");
ctx.clearRect(0, 0, 512, 128);
ctx.fillStyle = "rgba(255,255,255,0.9)";
ctx.beginPath();
ctx.roundRect(8, 12, 496, 104, 36);
ctx.fill();
ctx.strokeStyle = "rgba(34,92,96,0.18)";
ctx.lineWidth = 4;
ctx.stroke();
ctx.fillStyle = "#285c60";
ctx.font = "800 42px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 256, 66);
const texture = new THREE.CanvasTexture(labelCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false
})
);
sprite.scale.set(width, width * 0.25, 1);
return sprite;
}
const sourceLabel = makeLabel("SOURCE", 1.35);
sourceLabel.position.set(-4.65, 2.3, -2.55);
table.add(sourceLabel);
const forkLabel = makeLabel("GATE 01", 1.15);
forkLabel.position.set(-0.45, 1.55, -2.2);
table.add(forkLabel);
const wheelLabel = makeLabel("WHEEL", 1.2);
wheelLabel.position.set(2.12, 2.62, -2.2);
table.add(wheelLabel);
const basinLabel = makeLabel("BASIN", 1.25);
basinLabel.position.set(2.72, 1.2, 2.88);
table.add(basinLabel);
// Front table plaque.
const plaqueCanvas = document.createElement("canvas");
plaqueCanvas.width = 1024;
plaqueCanvas.height = 256;
const plaqueContext = plaqueCanvas.getContext("2d");
plaqueContext.fillStyle = "#f7e8c6";
plaqueContext.fillRect(0, 0, 1024, 256);
plaqueContext.fillStyle = "#e46d57";
plaqueContext.font = "900 106px system-ui, sans-serif";
plaqueContext.textAlign = "center";
plaqueContext.textBaseline = "middle";
plaqueContext.fillText("TIDEWORKS", 512, 132);
const plaqueTexture = new THREE.CanvasTexture(plaqueCanvas);
plaqueTexture.colorSpace = THREE.SRGBColorSpace;
const plaque = new THREE.Mesh(
new THREE.PlaneGeometry(3.3, 0.72),
new THREE.MeshBasicMaterial({ map: plaqueTexture })
);
plaque.position.set(-1.5, 0.13, 3.731);
table.add(plaque);
// Small corner hardware.
[
[-5.75, -3.16],
[5.04, -3.16],
[-5.75, 3.16],
[5.04, 3.16]
].forEach(([x, z]) => {
addCylinder(
0.09,
0.09,
0.035,
materials.metal,
x,
0.48,
z,
table,
18
);
});
// Flow paths.
const wheelFullPath = [
[-5.05, -2.2],
[-3.7, -2.2],
[-0.4, -2.2],
[1.0, -2.2],
[2.15, -2.2],
[3.4, -2.2],
[3.4, -1.2],
[3.4, 0.2],
[3.4, 0.9],
[2.75, 1.2]
];
const wheelHeldPath = [
[-5.05, -2.2],
[-3.7, -2.2],
[-0.4, -2.2],
[1.0, -2.2],
[2.15, -2.2],
[3.4, -2.2],
[3.4, -1.0]
];
const basinPath = [
[-5.05, -2.2],
[-3.7, -2.2],
[-0.4, -2.2],
[-0.4, -1.2],
[-0.4, 0.2],
[-0.4, 1.2],
[0.5, 1.2],
[1.4, 1.2],
[2.3, 1.2]
];
function makePathData(points) {
const cumulative = [0];
let length = 0;
for (let i = 1; i < points.length; i++) {
const dx = points[i][0] - points[i - 1][0];
const dz = points[i][1] - points[i - 1][1];
length += Math.hypot(dx, dz);
cumulative.push(length);
}
return { points, cumulative, length };
}
const pathData = {
wheel: makePathData(wheelFullPath),
held: makePathData(wheelHeldPath),
basin: makePathData(basinPath)
};
function samplePath(data, t) {
const distance = THREE.MathUtils.clamp(t, 0, 1) * data.length;
let index = 1;
while (
index < data.cumulative.length - 1 &&
data.cumulative[index] < distance
) {
index++;
}
const startDistance = data.cumulative[index - 1];
const endDistance = data.cumulative[index];
const segmentLength = Math.max(0.0001, endDistance - startDistance);
const local = (distance - startDistance) / segmentLength;
const a = data.points[index - 1];
const b = data.points[index];
return {
x: THREE.MathUtils.lerp(a[0], b[0], local),
z: THREE.MathUtils.lerp(a[1], b[1], local),
distance: distance / data.length
};
}
const particleCount = 54;
const flowParticles = new THREE.InstancedMesh(
new THREE.SphereGeometry(0.052, 7, 5),
new THREE.MeshBasicMaterial({
color: 0xf0ffff,
transparent: true,
opacity: 0.88,
depthWrite: false
}),
particleCount
);
flowParticles.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
flowParticles.frustumCulled = false;
flowParticles.renderOrder = 4;
table.add(flowParticles);
const particleProgress = Array.from(
{ length: particleCount },
(_, i) => i / particleCount
);
// Falling faucet droplets.
const dropletCount = 16;
const droplets = new THREE.InstancedMesh(
new THREE.SphereGeometry(0.045, 7, 5),
new THREE.MeshBasicMaterial({
color: 0xbffdf5,
transparent: true,
opacity: 0.88
}),
dropletCount
);
droplets.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
droplets.frustumCulled = false;
table.add(droplets);
// Expanding basin ripples.
const ripples = [];
for (let i = 0; i < 3; i++) {
const ripple = new THREE.Mesh(
new THREE.TorusGeometry(0.28, 0.014, 6, 42),
new THREE.MeshBasicMaterial({
color: 0xeaffff,
transparent: true,
opacity: 0.5,
depthWrite: false
})
);
ripple.rotation.x = Math.PI / 2;
ripple.position.set(2.78, 0.565, 1.75);
ripple.renderOrder = 3;
table.add(ripple);
ripples.push(ripple);
}
let forkRoute = "wheel";
let outletOpen = true;
let wheelBoost = 0;
function activePath() {
if (forkRoute === "basin") return pathData.basin;
return outletOpen ? pathData.wheel : pathData.held;
}
function updateUI() {
document.querySelector("#forkValue").textContent =
forkRoute === "wheel" ? "Wheel" : "Basin";
document.querySelector("#outletValue").textContent =
outletOpen ? "Open" : "Held";
let status = "";
if (forkRoute === "basin") {
status = "Flowing: lower bypass → basin";
} else if (outletOpen) {
status = "Flowing: wheel → basin";
} else {
status = "Wheel flowing · outlet held";
}
document.querySelector("#flowStatus").textContent = status;
forkGate.targetAngle =
forkRoute === "wheel" ? 0 : Math.PI / 2;
outletGate.targetAngle =
outletOpen ? Math.PI / 2 : 0;
forkGate.lamp.material = outletOpen
? materials.yellow
: materials.coralLight;
}
function toggleFork() {
forkRoute = forkRoute === "wheel" ? "basin" : "wheel";
updateUI();
}
function toggleOutlet() {
outletOpen = !outletOpen;
updateUI();
}
document
.querySelector("#forkButton")
.addEventListener("click", toggleFork);
document
.querySelector("#outletButton")
.addEventListener("click", toggleOutlet);
document.querySelector("#wheelButton").addEventListener("click", () => {
wheelBoost = 7.5;
});
document.querySelector("#viewButton").addEventListener("click", () => {
camera.position.copy(initialCamera);
orbit.setFromVector3(camera.position.clone().sub(cameraTarget));
});
updateUI();
// Direct camera controls, implemented without camera-control addons.
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
let dragging = false;
let dragMoved = false;
let previousPointer = { x: 0, y: 0 };
function updatePointer(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;
}
function findInteraction(event) {
updatePointer(event);
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(interactiveMeshes, false);
return hits.length ? hits[0].object : null;
}
canvas.addEventListener("pointerdown", (event) => {
const interaction = findInteraction(event);
if (interaction) {
const type = interaction.userData.interaction;
if (type === "fork") toggleFork();
if (type === "outlet") toggleOutlet();
if (type === "wheel") wheelBoost = 6.5;
return;
}
dragging = true;
dragMoved = false;
previousPointer.x = event.clientX;
previousPointer.y = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (dragging) {
const dx = event.clientX - previousPointer.x;
const dy = event.clientY - previousPointer.y;
if (Math.abs(dx) + Math.abs(dy) > 2) dragMoved = true;
orbit.theta -= dx * 0.006;
orbit.phi = THREE.MathUtils.clamp(
orbit.phi - dy * 0.005,
0.45,
1.35
);
previousPointer.x = event.clientX;
previousPointer.y = event.clientY;
return;
}
const interaction = findInteraction(event);
if (interaction) {
canvas.style.cursor = "pointer";
tooltip.style.display = "block";
tooltip.style.left = `${event.clientX}px`;
tooltip.style.top = `${event.clientY}px`;
tooltip.textContent = interaction.userData.label;
} else {
canvas.style.cursor = "grab";
tooltip.style.display = "none";
}
});
function endPointer(event) {
dragging = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener("pointerleave", () => {
if (!dragging) tooltip.style.display = "none";
});
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius + event.deltaY * 0.008,
7.4,
21
);
},
{ passive: false }
);
// Animation.
const clock = new THREE.Clock();
const dummy = new THREE.Object3D();
const flowMatrix = new THREE.Matrix4();
const flowPosition = new THREE.Vector3();
const flowQuaternion = new THREE.Quaternion();
const flowScale = new THREE.Vector3();
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
const delta = Math.min(clock.getDelta(), 0.05);
// Camera orbit.
camera.position.setFromSpherical(orbit).add(cameraTarget);
camera.lookAt(cameraTarget);
// Gentle gate animation.
forkGate.currentAngle = THREE.MathUtils.damp(
forkGate.currentAngle,
forkGate.targetAngle,
8,
delta
);
outletGate.currentAngle = THREE.MathUtils.damp(
outletGate.currentAngle,
outletGate.targetAngle,
8,
delta
);
forkGate.pivot.rotation.y = forkGate.currentAngle;
outletGate.pivot.rotation.y = outletGate.currentAngle;
// Water surface ripples.
channelWaters.forEach(({ mesh, phase }, index) => {
const position = mesh.geometry.attributes.position;
for (let i = 0; i < position.count; i++) {
const x = position.getX(i);
const z = position.getZ(i);
const wave =
Math.sin(x * 5.2 + elapsed * 2.4 + phase) * 0.009 +
Math.sin(z * 6.1 - elapsed * 1.8 + phase) * 0.006;
position.setY(i, wave);
}
position.needsUpdate = true;
});
// Wheel motion.
const wheelRouteActive = forkRoute === "wheel";
const desiredSpeed = wheelRouteActive ? 1.5 : 0.08;
const speed = desiredSpeed + wheelBoost;
wheel.rotation.z -= speed * delta;
wheelBoost = Math.max(0, wheelBoost - delta * 5.5);
// Flow particles.
const path = activePath();
const flowSpeed = forkRoute === "wheel" && !outletOpen ? 0.07 : 0.095;
for (let i = 0; i < particleCount; i++) {
particleProgress[i] =
(particleProgress[i] + delta * flowSpeed) % 1;
const sample = samplePath(path, particleProgress[i]);
const edgeFade = Math.min(
1,
sample.distance / 0.035,
(1 - sample.distance) / 0.035
);
const pulse = 0.85 + Math.sin(elapsed * 5 + i) * 0.15;
flowPosition.set(sample.x, 0.59, sample.z);
flowQuaternion.identity();
flowScale.setScalar(Math.max(0, edgeFade) * pulse);
flowMatrix.compose(flowPosition, flowQuaternion, flowScale);
flowParticles.setMatrixAt(i, flowMatrix);
}
flowParticles.instanceMatrix.needsUpdate = true;
// Faucet droplets.
for (let i = 0; i < dropletCount; i++) {
const phase = (elapsed * 1.6 + i / dropletCount) % 1;
const y = THREE.MathUtils.lerp(1.54, 0.57, phase);
const sway = Math.sin(i * 4.7) * 0.018;
dummy.position.set(-4.64 + sway, y, -2.42);
dummy.scale.set(1, 1.3 + phase * 0.5, 1);
dummy.rotation.set(0, 0, 0);
dummy.updateMatrix();
droplets.setMatrixAt(i, dummy.matrix);
}
droplets.instanceMatrix.needsUpdate = true;
// Basin ripples.
ripples.forEach((ripple, i) => {
const phase = (elapsed * 0.42 + i / ripples.length) % 1;
const scale = 0.7 + phase * 3.6;
ripple.scale.setScalar(scale);
ripple.material.opacity = (1 - phase) * 0.42;
});
// Small label bobbing.
wheelLabel.position.y = 2.62 + Math.sin(elapsed * 1.4) * 0.025;
sourceLabel.position.y = 2.3 + Math.sin(elapsed * 1.2 + 1) * 0.02;
renderer.render(scene, camera);
}
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
animate();
requestAnimationFrame(() => loading.classList.add("hidden"));
</script>
</body>
</html>
```