Prompt specification
Build or customize the Three.js 3D scene "Wave tank shoreline profiles" 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: Wave tank shoreline profiles
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/wave-tank-shoreline-profiles-x1122
Scene Description Prompt:
Compare stylized sandy and steep rocky shorelines in transparent tanks under identical schematic waves. Make one HTML file with Three.js from cdnjs.
Working Three.js Starter (wave-tank-shoreline-profiles-x1122):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Same Waves, Different Coasts</title>
<style>
:root {
--ink: #17343d;
--muted: #617980;
--line: rgba(44, 91, 101, 0.16);
--glass: rgba(255, 255, 255, 0.68);
--sand: #d89b4e;
--rock: #60747c;
--cyan: #36b9c7;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
}
body {
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
background:
radial-gradient(circle at 50% 43%, rgba(255, 255, 255, 0.96) 0 16%, transparent 52%),
linear-gradient(145deg, #edf3f1 0%, #e3ecec 48%, #dbe7e8 100%);
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
}
#scene.dragging {
cursor: grabbing;
}
.hero {
position: fixed;
z-index: 4;
top: 28px;
left: 34px;
width: min(530px, calc(100vw - 68px));
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 12px;
color: #4c747d;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
width: 24px;
height: 2px;
content: "";
background: var(--cyan);
border-radius: 99px;
}
h1 {
max-width: 620px;
margin: 0;
font-size: clamp(38px, 5vw, 68px);
font-weight: 760;
letter-spacing: -0.055em;
line-height: 0.96;
}
.hero p {
max-width: 500px;
margin: 18px 0 0;
color: var(--muted);
font-size: 14px;
line-height: 1.65;
}
.toolbar {
position: fixed;
z-index: 8;
top: 28px;
right: 30px;
display: flex;
gap: 8px;
}
button {
display: inline-flex;
min-height: 40px;
align-items: center;
justify-content: center;
gap: 8px;
padding: 0 14px;
color: var(--ink);
font: inherit;
font-size: 12px;
font-weight: 750;
letter-spacing: 0.01em;
background: rgba(255, 255, 255, 0.68);
border: 1px solid rgba(61, 102, 112, 0.16);
border-radius: 12px;
box-shadow: 0 8px 24px rgba(34, 73, 81, 0.07);
backdrop-filter: blur(14px);
cursor: pointer;
transition:
background 160ms ease,
transform 160ms ease,
border-color 160ms ease;
}
button:hover {
background: rgba(255, 255, 255, 0.94);
border-color: rgba(42, 135, 149, 0.32);
transform: translateY(-1px);
}
button:active {
transform: translateY(0);
}
.button-icon {
display: grid;
width: 18px;
height: 18px;
place-items: center;
color: #168b99;
font-size: 14px;
}
.scene-label {
position: fixed;
z-index: 5;
top: 24%;
width: 242px;
padding: 15px 16px 14px;
pointer-events: none;
background: var(--glass);
border: 1px solid rgba(255, 255, 255, 0.86);
border-radius: 17px;
box-shadow:
0 18px 45px rgba(38, 70, 78, 0.09),
inset 0 0 0 1px rgba(46, 91, 102, 0.07);
backdrop-filter: blur(18px);
transform: translate(-50%, -50%);
}
.scene-label.sand {
left: 30%;
}
.scene-label.rock {
left: 70%;
}
.label-top {
display: flex;
align-items: center;
gap: 10px;
}
.label-number {
display: grid;
width: 30px;
height: 30px;
flex: 0 0 auto;
place-items: center;
color: white;
font-size: 10px;
font-weight: 850;
letter-spacing: 0.08em;
border-radius: 9px;
}
.sand .label-number {
background: var(--sand);
}
.rock .label-number {
background: var(--rock);
}
.label-title {
margin: 0;
font-size: 14px;
font-weight: 800;
letter-spacing: -0.015em;
}
.label-subtitle {
margin: 3px 0 0;
color: var(--muted);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.response {
margin-top: 13px;
}
.response-row {
display: grid;
grid-template-columns: 72px 1fr 31px;
align-items: center;
gap: 7px;
margin-top: 7px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.response-track {
height: 4px;
overflow: hidden;
background: rgba(44, 84, 93, 0.1);
border-radius: 99px;
}
.response-fill {
height: 100%;
border-radius: inherit;
}
.sand .response-fill {
background: linear-gradient(90deg, #e2b36d, #c98a40);
}
.rock .response-fill {
background: linear-gradient(90deg, #7d9299, #50656e);
}
.console {
position: fixed;
z-index: 7;
bottom: 27px;
left: 50%;
width: min(880px, calc(100vw - 40px));
padding: 13px 17px;
pointer-events: none;
background: rgba(255, 255, 255, 0.7);
border: 1px solid rgba(255, 255, 255, 0.9);
border-radius: 18px;
box-shadow: 0 16px 45px rgba(36, 72, 80, 0.09);
backdrop-filter: blur(18px);
transform: translateX(-50%);
}
.console-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 18px;
padding-bottom: 10px;
border-bottom: 1px solid var(--line);
}
.sync-status {
display: flex;
align-items: center;
gap: 8px;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.status-light {
width: 7px;
height: 7px;
background: #35bca8;
border-radius: 50%;
box-shadow: 0 0 0 5px rgba(53, 188, 168, 0.1);
}
.paused .status-light {
background: #e3a44d;
box-shadow: 0 0 0 5px rgba(227, 164, 77, 0.1);
}
.direction {
color: var(--muted);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.direction strong {
color: #1594a1;
font-size: 16px;
}
.metrics {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 12px;
padding-top: 11px;
}
.metric span {
display: block;
color: var(--muted);
font-size: 8px;
font-weight: 850;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.metric strong {
display: block;
margin-top: 4px;
font-size: 13px;
font-weight: 790;
}
.help {
position: fixed;
z-index: 4;
right: 31px;
bottom: 28px;
color: rgba(41, 72, 80, 0.62);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.03em;
pointer-events: none;
}
#loading {
position: fixed;
z-index: 20;
inset: 0;
display: grid;
place-items: center;
color: #52727a;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
background: #e7efee;
transition: opacity 500ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
.paused .wave-dot {
animation-play-state: paused;
}
.wave-dot {
position: relative;
width: 7px;
height: 7px;
margin-left: 6px;
background: #1da8b6;
border-radius: 50%;
animation: waveTravel 4.65s linear infinite;
}
.wave-dot::after {
position: absolute;
top: 50%;
left: 7px;
width: 80px;
height: 1px;
content: "";
background: linear-gradient(90deg, #1da8b6, transparent);
transform: translateY(-50%);
}
@keyframes waveTravel {
0% {
transform: translateX(0);
opacity: 0;
}
12% {
opacity: 1;
}
88% {
opacity: 1;
}
100% {
transform: translateX(110px);
opacity: 0;
}
}
@media (max-width: 1050px) {
.help {
display: none;
}
.console {
bottom: 18px;
}
}
@media (max-width: 760px) {
.hero {
top: 18px;
left: 20px;
width: calc(100vw - 40px);
}
.hero p {
display: none;
}
h1 {
max-width: 360px;
font-size: 37px;
}
.toolbar {
top: auto;
right: 16px;
bottom: 119px;
}
button {
min-height: 37px;
padding: 0 11px;
}
.button-label {
display: none;
}
.scene-label {
top: 126px;
width: 44%;
max-width: 220px;
padding: 11px;
transform: none;
}
.scene-label.sand {
left: 3%;
}
.scene-label.rock {
left: 53%;
}
.label-subtitle {
font-size: 8px;
}
.response {
display: none;
}
.console {
bottom: 12px;
width: calc(100vw - 24px);
padding: 11px 12px;
}
.metrics {
grid-template-columns: repeat(2, 1fr);
gap: 8px;
}
.direction {
display: none;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive comparison of sandy and rocky shoreline wave tanks"></canvas>
<header class="hero">
<div class="eyebrow">Coastal dynamics · synchronized experiment</div>
<h1>Same waves.<br />Different coasts.</h1>
<p>
Two transparent shoreline tanks receive identical schematic wave forcing.
A gentle sand bed disperses energy across a broad surf zone, while a steep
rocky face reflects and redirects it.
</p>
</header>
<nav class="toolbar" aria-label="Visualization controls">
<button id="pauseButton" type="button" aria-label="Pause wave animation">
<span class="button-icon" id="pauseIcon">Ⅱ</span>
<span class="button-label" id="pauseLabel">Pause waves</span>
</button>
<button id="resetButton" type="button" aria-label="Reset camera view">
<span class="button-icon">↺</span>
<span class="button-label">Reset view</span>
</button>
</nav>
<section class="scene-label sand" aria-label="Sandy shoreline information">
<div class="label-top">
<div class="label-number">01</div>
<div>
<h2 class="label-title">Sandy shoreline</h2>
<p class="label-subtitle">24° slope · dissipative</p>
</div>
</div>
<div class="response">
<div class="response-row">
<span>Dissipation</span>
<div class="response-track"><div class="response-fill" style="width: 72%"></div></div>
<span>72</span>
</div>
<div class="response-row">
<span>Reflection</span>
<div class="response-track"><div class="response-fill" style="width: 28%"></div></div>
<span>28</span>
</div>
</div>
</section>
<section class="scene-label rock" aria-label="Rocky shoreline information">
<div class="label-top">
<div class="label-number">02</div>
<div>
<h2 class="label-title">Rocky shoreline</h2>
<p class="label-subtitle">78° face · reflective</p>
</div>
</div>
<div class="response">
<div class="response-row">
<span>Dissipation</span>
<div class="response-track"><div class="response-fill" style="width: 24%"></div></div>
<span>24</span>
</div>
<div class="response-row">
<span>Reflection</span>
<div class="response-track"><div class="response-fill" style="width: 76%"></div></div>
<span>76</span>
</div>
</div>
</section>
<section class="console" aria-label="Shared wave conditions">
<div class="console-top">
<div class="sync-status">
<span class="status-light"></span>
<span id="statusText">Synchronized wave drive</span>
<span class="wave-dot"></span>
</div>
<div class="direction">Incident wave direction <strong>→</strong></div>
</div>
<div class="metrics">
<div class="metric">
<span>Wavelength</span>
<strong>4.8 m</strong>
</div>
<div class="metric">
<span>Wave period</span>
<strong>4.65 s</strong>
</div>
<div class="metric">
<span>Water level</span>
<strong>0.68 m</strong>
</div>
<div class="metric">
<span>Tank spacing</span>
<strong>8.3 m</strong>
</div>
</div>
</section>
<div class="help">Drag to orbit · scroll to zoom · double-click to reset</div>
<div id="loading">Preparing wave tanks</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("#pauseButton");
const pauseIcon = document.querySelector("#pauseIcon");
const pauseLabel = document.querySelector("#pauseLabel");
const statusText = document.querySelector("#statusText");
const resetButton = document.querySelector("#resetButton");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setClearColor(0x000000, 0);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.fog = new THREE.Fog(0xe6eeee, 25, 48);
const camera = new THREE.PerspectiveCamera(
40,
window.innerWidth / window.innerHeight,
0.1,
100
);
const controls = {
yaw: 0.18,
pitch: 0.43,
radius: 18.5,
target: new THREE.Vector3(0, -0.12, 0)
};
const TANK = {
width: 7,
depth: 3.7,
height: 4.7,
bottom: -2.35,
top: 2.35,
water: 0.68,
sandLow: -1.35,
sandHigh: 1.72,
rockLow: -1.16,
rockHigh: 1.68,
rockCliff: 1.25
};
const sharedTime = { value: 0 };
const sandTank = new THREE.Group();
const rockTank = new THREE.Group();
sandTank.position.x = -4.15;
rockTank.position.x = 4.15;
scene.add(sandTank, rockTank);
const hemi = new THREE.HemisphereLight(0xf5fcff, 0x607075, 2.25);
scene.add(hemi);
const keyLight = new THREE.DirectionalLight(0xfff6e8, 3.2);
keyLight.position.set(-6, 10, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -12;
keyLight.shadow.camera.right = 12;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -8;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 35;
keyLight.shadow.bias = -0.00025;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x91dce7, 1.45);
rimLight.position.set(8, 5, -7);
scene.add(rimLight);
const platformMaterial = new THREE.MeshStandardMaterial({
color: 0xdbe5e4,
roughness: 0.9,
metalness: 0
});
const platform = new THREE.Mesh(
new THREE.BoxGeometry(16.7, 0.18, 5.1),
platformMaterial
);
platform.position.y = -2.55;
platform.receiveShadow = true;
scene.add(platform);
function seededRandom(seed) {
let value = seed >>> 0;
return () => {
value += 0x6d2b79f5;
let t = value;
t = Math.imul(t ^ (t >>> 15), t | 1);
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
function makePrism(points, depth, materials) {
const shape = new THREE.Shape();
shape.moveTo(points[0][0], points[0][1]);
for (let i = 1; i < points.length; i++) {
shape.lineTo(points[i][0], points[i][1]);
}
shape.closePath();
const geometry = new THREE.ExtrudeGeometry(shape, {
depth,
bevelEnabled: false,
steps: 1,
curveSegments: 1
});
geometry.translate(0, 0, -depth / 2);
geometry.computeVertexNormals();
const mesh = new THREE.Mesh(geometry, materials);
mesh.castShadow = true;
mesh.receiveShadow = true;
return mesh;
}
function createTankShell(group) {
const baseMaterial = new THREE.MeshStandardMaterial({
color: 0xcdd9da,
roughness: 0.72,
metalness: 0.08
});
const base = new THREE.Mesh(
new THREE.BoxGeometry(TANK.width + 0.18, 0.15, TANK.depth + 0.18),
baseMaterial
);
base.position.y = TANK.bottom - 0.03;
base.castShadow = true;
base.receiveShadow = true;
group.add(base);
const glassMaterial = new THREE.MeshPhongMaterial({
color: 0xbcecf1,
transparent: true,
opacity: 0.095,
shininess: 100,
specular: 0xffffff,
side: THREE.DoubleSide,
depthWrite: false
});
const glass = new THREE.Mesh(
new THREE.BoxGeometry(TANK.width, TANK.height, TANK.depth),
glassMaterial
);
glass.position.y = 0;
glass.renderOrder = 5;
group.add(glass);
const edgeGeometry = new THREE.EdgesGeometry(
new THREE.BoxGeometry(TANK.width, TANK.height, TANK.depth)
);
const edges = new THREE.LineSegments(
edgeGeometry,
new THREE.LineBasicMaterial({
color: 0x669ba6,
transparent: true,
opacity: 0.48,
depthWrite: false
})
);
edges.position.y = 0;
edges.renderOrder = 6;
group.add(edges);
const waterVolume = new THREE.Mesh(
new THREE.BoxGeometry(
TANK.width - 0.12,
TANK.water - TANK.bottom - 0.06,
TANK.depth - 0.12
),
new THREE.MeshBasicMaterial({
color: 0x38b9c7,
transparent: true,
opacity: 0.045,
depthWrite: false,
side: THREE.DoubleSide
})
);
waterVolume.position.y =
(TANK.water + TANK.bottom) / 2;
waterVolume.renderOrder = 1;
group.add(waterVolume);
const levelMaterial = new THREE.MeshBasicMaterial({
color: 0x65d5df,
transparent: true,
opacity: 0.68,
depthWrite: false
});
for (const z of [-TANK.depth / 2 - 0.012, TANK.depth / 2 + 0.012]) {
const line = new THREE.Mesh(
new THREE.BoxGeometry(TANK.width - 0.12, 0.018, 0.022),
levelMaterial
);
line.position.set(0, TANK.water, z);
line.renderOrder = 4;
group.add(line);
}
}
const waterVertexShader = `
uniform float uTime;
varying vec3 vLocalPosition;
varying float vWave;
void main() {
vec3 p = position;
float primary =
sin(p.x * 1.309 - uTime * 1.350 + p.z * 0.28) * 0.105;
float secondary =
sin(p.x * 0.630 - uTime * 0.875 + p.z * 0.85) * 0.055;
p.y += primary + secondary;
vLocalPosition = p;
vWave = primary + secondary;
gl_Position = projectionMatrix * modelViewMatrix * vec4(p, 1.0);
}
`;
const waterFragmentShader = `
uniform float uTime;
varying vec3 vLocalPosition;
varying float vWave;
void main() {
vec3 deep = vec3(0.10, 0.48, 0.58);
vec3 light = vec3(0.30, 0.78, 0.82);
float mixAmount = smoothstep(-0.13, 0.13, vWave);
vec3 color = mix(deep, light, mixAmount);
float shimmer = pow(
max(
0.0,
sin(vLocalPosition.z * 9.0 +
vLocalPosition.x * 2.3 -
uTime * 1.15)
),
18.0
);
float edgeGlow = smoothstep(
1.9,
0.0,
abs(vLocalPosition.z)
);
color += shimmer * vec3(0.16, 0.22, 0.21);
color += edgeGlow * 0.025;
float alpha = 0.39 + mixAmount * 0.08 + shimmer * 0.13;
gl_FragColor = vec4(color, alpha);
}
`;
function createWaterSurface(group) {
const geometry = new THREE.PlaneGeometry(
TANK.width - 0.14,
TANK.depth - 0.14,
76,
38
);
geometry.rotateX(-Math.PI / 2);
const material = new THREE.ShaderMaterial({
uniforms: {
uTime: sharedTime
},
vertexShader: waterVertexShader,
fragmentShader: waterFragmentShader,
transparent: true,
depthWrite: false,
side: THREE.DoubleSide
});
const surface = new THREE.Mesh(geometry, material);
surface.position.y = TANK.water;
surface.renderOrder = 2;
group.add(surface);
}
function sandHeight(x, z) {
const t =
(x + TANK.width / 2) /
TANK.width;
const base = THREE.MathUtils.lerp(
TANK.sandLow,
TANK.sandHigh,
t
);
const ripple =
Math.sin(x * 2.1 + z * 1.4) *
Math.sin(Math.PI * t) *
0.045;
return base + ripple;
}
function createSandBed(group) {
const capMaterial = new THREE.MeshStandardMaterial({
color: 0xd3a05c,
roughness: 0.95,
metalness: 0
});
const sideMaterial = new THREE.MeshStandardMaterial({
color: 0xb87b3f,
roughness: 0.98,
metalness: 0
});
const bed = makePrism(
[
[-TANK.width / 2, TANK.bottom],
[TANK.width / 2, TANK.bottom],
[TANK.width / 2, TANK.sandHigh],
[-TANK.width / 2, TANK.sandLow]
],
TANK.depth,
[capMaterial, sideMaterial]
);
group.add(bed);
const nx = 42;
const nz = 20;
const positions = [];
const colors = [];
const indices = [];
const random = seededRandom(117);
const lowColor = new THREE.Color(0xd39b51);
const highColor = new THREE.Color(0xf0c985);
for (let iz = 0; iz <= nz; iz++) {
const z =
-TANK.depth / 2 +
(iz / nz) * TANK.depth;
for (let ix = 0; ix <= nx; ix++) {
const x =
-TANK.width / 2 +
(ix / nx) * TANK.width;
const t = ix / nx;
const y = sandHeight(x, z);
positions.push(x, y, z);
const color = lowColor.clone().lerp(highColor, t * 0.8);
color.multiplyScalar(0.94 + random() * 0.1);
colors.push(color.r, color.g, color.b);
}
}
for (let iz = 0; iz < nz; iz++) {
for (let ix = 0; ix < nx; ix++) {
const a = iz * (nx + 1) + ix;
const b = a + 1;
const c = a + nx + 1;
const d = c + 1;
indices.push(a, c, b, b, c, d);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(colors, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
const surface = new THREE.Mesh(
geometry,
new THREE.MeshStandardMaterial({
color: 0xffffff,
vertexColors: true,
roughness: 0.94,
metalness: 0,
flatShading: true
})
);
surface.castShadow = true;
surface.receiveShadow = true;
group.add(surface);
const pebbleGeometry = new THREE.DodecahedronGeometry(1, 0);
const pebbleMaterials = [
new THREE.MeshStandardMaterial({
color: 0xf2d9a8,
roughness: 0.9,
flatShading: true
}),
new THREE.MeshStandardMaterial({
color: 0xa97543,
roughness: 1,
flatShading: true
}),
new THREE.MeshStandardMaterial({
color: 0xd9b475,
roughness: 0.95,
flatShading: true
})
];
const randomPebble = seededRandom(441);
for (let i = 0; i < 26; i++) {
const x =
-TANK.width * 0.42 +
randomPebble() * TANK.width * 0.78;
const z =
(randomPebble() - 0.5) * TANK.depth * 0.82;
const size =
0.035 +
randomPebble() * 0.075;
const pebble = new THREE.Mesh(
pebbleGeometry,
pebbleMaterials[
Math.floor(randomPebble() * pebbleMaterials.length)
]
);
pebble.position.set(
x,
sandHeight(x, z) + size * 0.3,
z
);
pebble.scale.set(
size * (1 + randomPebble()),
size * 0.45,
size
);
pebble.rotation.set(
randomPebble(),
randomPebble() * Math.PI,
randomPebble()
);
pebble.castShadow = true;
pebble.receiveShadow = true;
group.add(pebble);
}
}
function createRockBed(group) {
const capMaterial = new THREE.MeshStandardMaterial({
color: 0x66777d,
roughness: 0.88,
metalness: 0.03,
flatShading: true
});
const sideMaterial = new THREE.MeshStandardMaterial({
color: 0x3f5158,
roughness: 0.92,
metalness: 0.04,
flatShading: true
});
const bed = makePrism(
[
[-TANK.width / 2, TANK.bottom],
[TANK.width / 2, TANK.bottom],
[TANK.width / 2, TANK.rockHigh],
[TANK.rockCliff, TANK.rockHigh],
[TANK.rockCliff, TANK.rockLow],
[-TANK.width / 2, TANK.rockLow]
],
TANK.depth,
[capMaterial, sideMaterial]
);
group.add(bed);
const plateauWidth = TANK.width / 2 - TANK.rockCliff;
const floorWidth = TANK.rockCliff + TANK.width / 2;
const plateau = new THREE.Mesh(
new THREE.BoxGeometry(plateauWidth, 0.07, TANK.depth),
new THREE.MeshStandardMaterial({
color: 0x718188,
roughness: 0.95,
flatShading: true
})
);
plateau.position.set(
TANK.rockCliff + plateauWidth / 2,
TANK.rockHigh + 0.035,
0
);
plateau.castShadow = true;
plateau.receiveShadow = true;
group.add(plateau);
const floor = new THREE.Mesh(
new THREE.BoxGeometry(floorWidth, 0.07, TANK.depth),
new THREE.MeshStandardMaterial({
color: 0x586a70,
roughness: 0.96,
flatShading: true
})
);
floor.position.set(
-TANK.width / 2 + floorWidth / 2,
TANK.rockLow + 0.035,
0
);
floor.castShadow = true;
floor.receiveShadow = true;
group.add(floor);
const facetColors = [
0x52666e,
0x788a90,
0x435860,
0x87969a,
0x63777e
];
const facetDefinitions = [
[
[TANK.rockCliff - 0.48, -1.10],
[TANK.rockCliff + 0.07, -0.86],
[TANK.rockCliff - 0.12, -0.33]
],
[
[TANK.rockCliff - 0.15, -0.37],
[TANK.rockCliff + 0.07, -0.86],
[TANK.rockCliff + 0.03, -0.04]
],
[
[TANK.rockCliff - 0.12, -0.35],
[TANK.rockCliff + 0.03, -0.04],
[TANK.rockCliff - 0.23, 0.45]
],
[
[TANK.rockCliff - 0.28, 0.42],
[TANK.rockCliff + 0.03, -0.04],
[TANK.rockCliff + 0.04, 0.83]
],
[
[TANK.rockCliff - 0.20, 0.82],
[TANK.rockCliff + 0.04, 0.83],
[TANK.rockCliff + 0.02, 1.46]
]
];
facetDefinitions.forEach((points, index) => {
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(
[
points[0][0],
points[0][1],
TANK.depth / 2 + 0.018,
points[1][0],
points[1][1],
TANK.depth / 2 + 0.018,
points[2][0],
points[2][1],
TANK.depth / 2 + 0.018
],
3
)
);
geometry.computeVertexNormals();
const facet = new THREE.Mesh(
geometry,
new THREE.MeshStandardMaterial({
color: facetColors[index],
roughness: 0.9,
flatShading: true,
side: THREE.DoubleSide
})
);
facet.receiveShadow = true;
group.add(facet);
});
const rockGeometry = new THREE.IcosahedronGeometry(1, 0);
const rockMaterials = [
0x566970,
0x6d8087,
0x455961,
0x829197
].map(
(color) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.86,
metalness: 0.04,
flatShading: true
})
);
const random = seededRandom(928);
for (let i = 0; i < 25; i++) {
const onPlateau = random() > 0.48;
let x;
let y;
if (onPlateau) {
x =
TANK.rockCliff +
0.16 +
random() *
(TANK.width / 2 - TANK.rockCliff - 0.32);
const sy = 0.14 + random() * 0.42;
y = TANK.rockHigh + sy * 0.62;
} else {
x =
TANK.rockCliff -
0.34 +
random() * 0.58;
y =
-0.72 +
random() * 2.13;
}
const z =
(random() - 0.5) * TANK.depth * 0.82;
const sx = 0.14 + random() * 0.36;
const sy = 0.16 + random() * 0.48;
const sz = 0.14 + random() * 0.34;
const rock = new THREE.Mesh(
rockGeometry,
rockMaterials[
Math.floor(random() * rockMaterials.length)
]
);
rock.position.set(x, y, z);
rock.scale.set(sx, sy, sz);
rock.rotation.set(
random() * Math.PI,
random() * Math.PI,
random() * Math.PI
);
rock.castShadow = true;
rock.receiveShadow = true;
group.add(rock);
}
}
function waveHeight(x, z, time) {
return (
Math.sin(x * 1.309 - time * 1.35 + z * 0.28) *
0.105 +
Math.sin(x * 0.63 - time * 0.875 + z * 0.85) *
0.055
);
}
function createFoam(group, shorelineX, spread, seed) {
const count = 58;
const random = seededRandom(seed);
const items = [];
const geometry = new THREE.SphereGeometry(1, 7, 5);
const material = new THREE.MeshBasicMaterial({
color: 0xf5ffff,
transparent: true,
opacity: 0.86,
depthWrite: false
});
const mesh = new THREE.InstancedMesh(
geometry,
material,
count
);
mesh.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
mesh.frustumCulled = false;
mesh.renderOrder = 4;
group.add(mesh);
for (let i = 0; i < count; i++) {
items.push({
x:
shorelineX +
(random() - 0.5) * spread,
z:
(random() - 0.5) * TANK.depth * 0.84,
size:
0.035 +
random() * 0.07,
phase:
random() * Math.PI * 2,
drift:
0.025 +
random() * 0.055
});
}
const dummy = new THREE.Object3D();
return {
update(time) {
items.forEach((item, index) => {
const x =
item.x +
Math.sin(time * 0.72 + item.phase) *
item.drift;
const z = item.z;
const y =
TANK.water +
waveHeight(x, z, time) +
0.028;
dummy.position.set(x, y, z);
dummy.rotation.set(0, item.phase, 0);
dummy.scale.set(
item.size * 1.6,
item.size * 0.28,
item.size * 0.85
);
dummy.updateMatrix();
mesh.setMatrixAt(index, dummy.matrix);
});
mesh.instanceMatrix.needsUpdate = true;
}
};
}
function createSpray(group, shorelineX, count, height, seed) {
const random = seededRandom(seed);
const items = [];
const geometry = new THREE.SphereGeometry(1, 6, 4);
const material = new THREE.MeshBasicMaterial({
color: 0xeaffff,
transparent: true,
opacity: 0.62,
depthWrite: false
});
const mesh = new THREE.InstancedMesh(
geometry,
material,
count
);
mesh.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
mesh.frustumCulled = false;
mesh.renderOrder = 4;
group.add(mesh);
for (let i = 0; i < count; i++) {
items.push({
offset: random(),
z: (random() - 0.5) * TANK.depth * 0.7,
size: 0.025 + random() * 0.045,
height: height * (0.65 + random() * 0.55)
});
}
const dummy = new THREE.Object3D();
return {
update(time) {
items.forEach((item, index) => {
const phase = (time * 0.47 + item.offset) % 1;
const x =
shorelineX +
phase * 0.28;
const y =
TANK.water +
waveHeight(x, item.z, time) +
Math.sin(Math.PI * phase) * item.height +
0.05;
dummy.position.set(x, y, item.z);
dummy.scale.setScalar(
item.size * (1 - phase * 0.55)
);
dummy.updateMatrix();
mesh.setMatrixAt(index, dummy.matrix);
});
mesh.instanceMatrix.needsUpdate = true;
}
};
}
function createReflection(group) {
const lines = [];
const material = new THREE.LineBasicMaterial({
color: 0xbaf9ff,
transparent: true,
opacity: 0.36,
depthWrite: false
});
for (let band = 0; band < 4; band++) {
const segments = 30;
const positions = new Float32Array((segments + 1) * 3);
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.BufferAttribute(positions, 3)
);
const line = new THREE.Line(geometry, material);
line.frustumCulled = false;
line.renderOrder = 3;
group.add(line);
lines.push(line);
}
return {
update(time) {
lines.forEach((line, band) => {
const travel =
(time * 0.76 + band * 1.14) % 4.35;
const centerX =
TANK.rockCliff - travel;
line.visible =
centerX > -TANK.width / 2 + 0.08;
const attribute =
line.geometry.attributes.position;
for (let i = 0; i <= 30; i++) {
const z =
-TANK.depth * 0.41 +
(i / 30) * TANK.depth * 0.82;
const x =
centerX +
Math.sin(z * 2.25 + band) * 0.07;
const y =
TANK.water +
waveHeight(x, z, time) +
0.035;
attribute.setXYZ(i, x, y, z);
}
attribute.needsUpdate = true;
});
}
};
}
function createArrow(group, origin, direction, length, color) {
const arrow = new THREE.ArrowHelper(
direction,
origin,
length,
color,
0.22,
0.13
);
arrow.line.material.transparent = true;
arrow.line.material.opacity = 0.72;
arrow.cone.material.transparent = true;
arrow.cone.material.opacity = 0.82;
arrow.line.material.depthWrite = false;
arrow.cone.material.depthWrite = false;
arrow.renderOrder = 4;
group.add(arrow);
return arrow;
}
createTankShell(sandTank);
createTankShell(rockTank);
createSandBed(sandTank);
createRockBed(rockTank);
createWaterSurface(sandTank);
createWaterSurface(rockTank);
const sandFoam = createFoam(
sandTank,
1.02,
0.54,
640
);
const rockFoam = createFoam(
rockTank,
TANK.rockCliff,
0.23,
641
);
const sandSpray = createSpray(
sandTank,
1.02,
10,
0.22,
810
);
const rockSpray = createSpray(
rockTank,
TANK.rockCliff,
26,
0.52,
811
);
const reflection = createReflection(rockTank);
createArrow(
sandTank,
new THREE.Vector3(-2.65, TANK.water + 0.34, 0.15),
new THREE.Vector3(1, 0, 0),
1.35,
0xf0ffff
);
createArrow(
rockTank,
new THREE.Vector3(-2.65, TANK.water + 0.34, 0.15),
new THREE.Vector3(1, 0, 0),
1.35,
0xf0ffff
);
createArrow(
rockTank,
new THREE.Vector3(0.18, TANK.water + 0.34, -0.72),
new THREE.Vector3(-1, 0, 0),
0.9,
0x76eef1
);
function updateCamera() {
const horizontalRadius =
controls.radius * Math.cos(controls.pitch);
camera.position.set(
controls.target.x +
horizontalRadius * Math.sin(controls.yaw),
controls.target.y +
controls.radius * Math.sin(controls.pitch),
controls.target.z +
horizontalRadius * Math.cos(controls.yaw)
);
camera.lookAt(controls.target);
}
function defaultRadius() {
return window.innerWidth < 760 ? 29 : 18.5;
}
function resetView() {
controls.yaw = 0.18;
controls.pitch = 0.43;
controls.radius = defaultRadius();
controls.target.set(0, -0.12, 0);
updateCamera();
}
updateCamera();
const pointers = new Map();
let lastPinchDistance = 0;
canvas.addEventListener("pointerdown", (event) => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
canvas.classList.add("dragging");
if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
lastPinchDistance = Math.hypot(
b.x - a.x,
b.y - a.y
);
}
});
canvas.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
const previous = pointers.get(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 1) {
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
controls.yaw -= dx * 0.006;
controls.pitch = THREE.MathUtils.clamp(
controls.pitch + dy * 0.005,
0.12,
1.22
);
updateCamera();
} else if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
const distance = Math.hypot(
b.x - a.x,
b.y - a.y
);
if (lastPinchDistance > 0) {
controls.radius = THREE.MathUtils.clamp(
controls.radius *
(lastPinchDistance / distance),
10,
44
);
updateCamera();
}
lastPinchDistance = distance;
}
});
function endPointer(event) {
pointers.delete(event.pointerId);
lastPinchDistance = 0;
if (pointers.size === 0) {
canvas.classList.remove("dragging");
}
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.radius = THREE.MathUtils.clamp(
controls.radius + event.deltaY * 0.012,
10,
44
);
updateCamera();
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetView);
let playing = true;
function togglePause() {
playing = !playing;
document.body.classList.toggle("paused", !playing);
pauseIcon.textContent = playing ? "Ⅱ" : "▶";
pauseLabel.textContent = playing
? "Pause waves"
: "Resume waves";
statusText.textContent = playing
? "Synchronized wave drive"
: "Wave animation paused";
}
pauseButton.addEventListener("click", togglePause);
resetButton.addEventListener("click", resetView);
window.addEventListener("keydown", (event) => {
if (event.code === "Space") {
event.preventDefault();
togglePause();
}
if (event.key.toLowerCase() === "r") {
resetView();
}
});
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
renderer.setSize(width, height);
renderer.setPixelRatio(
Math.min(window.devicePixelRatio, 2)
);
camera.aspect = width / height;
camera.fov = width < 760 ? 46 : 40;
camera.updateProjectionMatrix();
}
window.addEventListener("resize", resize);
let elapsed = 0;
let previousTime = performance.now();
function animate(now) {
requestAnimationFrame(animate);
const delta = Math.min(
(now - previousTime) / 1000,
0.05
);
previousTime = now;
if (playing) {
elapsed += delta;
}
sharedTime.value = elapsed;
sandFoam.update(elapsed);
rockFoam.update(elapsed);
sandSpray.update(elapsed);
rockSpray.update(elapsed);
reflection.update(elapsed);
renderer.render(scene, camera);
}
requestAnimationFrame(animate);
requestAnimationFrame(() => {
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 550);
});
</script>
</body>
</html>
```