Prompt specification
Build or customize the Three.js 3D scene "Sand tray bending a 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: Sand tray bending a stream
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/sand-tray-bending-a-stream-x1174
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts river meanders. Arrange an overhead supply channel and a shallow sand tray; animate tracer beads along a curved flow path without claiming to simulate actual sediment transport. Stylized solid forms.
Working Three.js Starter (sand-tray-bending-a-stream-x1174):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>River Meanders — Illustrative Tracer Scene</title>
<style>
:root {
color-scheme: light;
--ink: #203533;
--muted: #637470;
--panel: rgba(250, 252, 248, 0.88);
--border: rgba(44, 72, 67, 0.16);
--accent: #de6b57;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e9eee9;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.panel {
position: fixed;
z-index: 10;
top: 20px;
left: 20px;
width: min(350px, calc(100vw - 40px));
padding: 18px 19px;
border: 1px solid var(--border);
border-radius: 18px;
background: var(--panel);
box-shadow: 0 16px 45px rgba(30, 52, 47, 0.12);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
pointer-events: none;
}
.eyebrow {
margin-bottom: 7px;
color: #b65748;
font-size: 0.72rem;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(1.65rem, 4vw, 2.2rem);
line-height: 1.02;
letter-spacing: -0.04em;
}
.intro {
margin: 10px 0 13px;
color: var(--muted);
font-size: 0.9rem;
line-height: 1.45;
}
.note {
padding: 10px 12px;
border: 1px solid rgba(182, 87, 72, 0.2);
border-radius: 11px;
background: rgba(222, 107, 87, 0.09);
color: #704238;
font-size: 0.78rem;
font-weight: 650;
line-height: 1.4;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 8px 15px;
margin-top: 14px;
color: #536762;
font-size: 0.78rem;
}
.legend-item {
display: flex;
align-items: center;
gap: 6px;
}
.dot {
width: 9px;
height: 9px;
border-radius: 50%;
box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
}
.dot.coral { background: #ef6b58; }
.dot.gold { background: #f1b94e; }
.dot.mint { background: #65c4ae; }
.controls {
position: fixed;
z-index: 20;
right: 20px;
bottom: 20px;
display: flex;
align-items: center;
flex-wrap: wrap;
justify-content: flex-end;
gap: 8px;
max-width: calc(100vw - 40px);
padding: 10px;
border: 1px solid var(--border);
border-radius: 15px;
background: var(--panel);
box-shadow: 0 12px 35px rgba(30, 52, 47, 0.12);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
button {
appearance: none;
border: 1px solid rgba(43, 71, 65, 0.18);
border-radius: 10px;
padding: 9px 12px;
background: rgba(255, 255, 255, 0.72);
color: var(--ink);
font: inherit;
font-size: 0.78rem;
font-weight: 750;
cursor: pointer;
transition: transform 120ms ease, background 120ms ease;
}
button:hover {
transform: translateY(-1px);
background: white;
}
button:focus-visible,
input:focus-visible {
outline: 3px solid rgba(67, 143, 178, 0.35);
outline-offset: 2px;
}
.speed {
display: flex;
align-items: center;
gap: 8px;
padding: 0 7px;
color: #526661;
font-size: 0.76rem;
font-weight: 700;
}
input[type="range"] {
width: 88px;
accent-color: #438faf;
cursor: pointer;
}
.hint {
position: fixed;
z-index: 10;
left: 22px;
bottom: 24px;
padding: 8px 10px;
border-radius: 9px;
background: rgba(250, 252, 248, 0.72);
color: #60736e;
font-size: 0.72rem;
pointer-events: none;
}
@media (max-width: 700px) {
.panel {
top: 12px;
left: 12px;
width: min(310px, calc(100vw - 24px));
padding: 14px;
}
.intro {
margin: 8px 0 10px;
}
.legend {
margin-top: 10px;
}
.controls {
right: 12px;
bottom: 12px;
}
.hint {
display: none;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive three-dimensional river meander scene"></canvas>
<section class="panel">
<div class="eyebrow">Illustrative flow scene</div>
<h1>River Meanders</h1>
<p class="intro">
Tracer beads travel from an elevated supply channel into a shallow,
stylized sand tray, following a visibly curved route.
</p>
<div class="note">
Illustrative motion only — this does not simulate actual sediment transport.
</div>
<div class="legend" aria-label="Tracer bead colors">
<span class="legend-item"><i class="dot coral"></i>Coral bead</span>
<span class="legend-item"><i class="dot gold"></i>Gold bead</span>
<span class="legend-item"><i class="dot mint"></i>Mint bead</span>
</div>
</section>
<div class="controls">
<button id="pause" type="button">Pause tracers</button>
<button id="restart" type="button">Restart</button>
<button id="reset-view" type="button">Reset view</button>
<label class="speed">
Speed
<input id="speed" type="range" min="0.35" max="1.8" step="0.05" value="1">
</label>
</div>
<div class="hint">Drag to orbit · Scroll to zoom · Space to pause</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 pauseButton = document.querySelector("#pause");
const restartButton = document.querySelector("#restart");
const resetViewButton = document.querySelector("#reset-view");
const speedInput = document.querySelector("#speed");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe9eee9);
scene.fog = new THREE.Fog(0xe9eee9, 19, 34);
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
// Direct orthographic camera controls; no external control addons.
const camera = new THREE.OrthographicCamera(-8, 8, 6, -6, 0.1, 80);
const cameraState = {
theta: 0.64,
phi: 0.76,
zoom: 1,
target: new THREE.Vector3(0, 0.75, -0.15)
};
function updateCamera() {
const radius = 14;
const { theta, phi, zoom, target } = cameraState;
camera.position.set(
target.x + radius * Math.sin(phi) * Math.sin(theta),
target.y + radius * Math.cos(phi),
target.z + radius * Math.sin(phi) * Math.cos(theta)
);
camera.lookAt(target);
camera.zoom = zoom;
camera.updateProjectionMatrix();
}
function resetView() {
cameraState.theta = 0.64;
cameraState.phi = 0.76;
cameraState.zoom = 1;
updateCamera();
}
let dragging = false;
let pointerX = 0;
let pointerY = 0;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - dy * 0.005,
0.32,
1.28
);
updateCamera();
});
function endDrag(event) {
dragging = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener("wheel", (event) => {
event.preventDefault();
cameraState.zoom = THREE.MathUtils.clamp(
cameraState.zoom * Math.exp(-event.deltaY * 0.001),
0.65,
2.1
);
updateCamera();
}, { passive: false });
canvas.addEventListener("dblclick", resetView);
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const viewHeight = Math.max(9.6, 12.2 / aspect);
camera.left = -viewHeight * aspect / 2;
camera.right = viewHeight * aspect / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.updateProjectionMatrix();
renderer.setSize(width, height, false);
}
window.addEventListener("resize", resize);
resize();
updateCamera();
// Lighting
const hemisphere = new THREE.HemisphereLight(0xf8fff8, 0x8a8577, 2.25);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff8e9, 3.1);
sun.position.set(-7, 11, 6);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -11;
sun.shadow.camera.right = 11;
sun.shadow.camera.top = 11;
sun.shadow.camera.bottom = -11;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 32;
sun.shadow.bias = -0.0003;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xc8e9f2, 1.1);
fill.position.set(8, 5, -7);
scene.add(fill);
// Materials
const material = (color, roughness = 0.82, metalness = 0) =>
new THREE.MeshStandardMaterial({ color, roughness, metalness });
const trayMaterial = material(0x315a55);
const trayEdgeMaterial = material(0x244743);
const sandMaterial = material(0xe5c88f);
const sandShadeMaterial = material(0xd5b778);
const waterMaterial = material(0x4c9fbd, 0.28, 0.06);
const waterDarkMaterial = material(0x8e7652, 0.95);
const bankMaterial = material(0xf0d7a1);
const channelMaterial = material(0x315854);
const channelInsideMaterial = material(0x6e8d83);
const supportMaterial = material(0x3e625c);
const groundMaterial = material(0xe3e9e3);
const grateMaterial = material(0x304b49, 0.6, 0.2);
function addBox(width, height, depth, mat, x, y, z, cast = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
mat
);
mesh.position.set(x, y, z);
mesh.castShadow = cast;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
function cylinderBetween(start, end, radius, mat, openEnded = false) {
const direction = end.clone().sub(start);
const length = direction.length();
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(
radius,
radius,
length,
20,
1,
openEnded
),
mat
);
mesh.position.copy(start).add(end).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
// Ground and tray
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(40, 40),
groundMaterial
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.205;
ground.receiveShadow = true;
scene.add(ground);
addBox(10.6, 0.32, 7.0, trayMaterial, 0, -0.02, 0);
addBox(9.95, 0.26, 6.35, sandMaterial, 0, 0.20, 0);
addBox(0.24, 0.58, 7.0, trayEdgeMaterial, -5.13, 0.36, 0);
addBox(0.24, 0.58, 7.0, trayEdgeMaterial, 5.13, 0.36, 0);
addBox(10.5, 0.58, 0.24, trayEdgeMaterial, 0, 0.36, -3.38);
addBox(10.5, 0.58, 0.24, trayEdgeMaterial, 0, 0.36, 3.38);
// Low solid sand mounds, placed away from the illustrated route.
const moundGeometry = new THREE.SphereGeometry(1, 16, 10);
const moundData = [
[-4.15, -2.55, 0.38, 0.13, 0.27],
[-2.65, -2.55, 0.54, 0.11, 0.30],
[-0.85, -2.56, 0.42, 0.10, 0.26],
[ 1.25, -2.48, 0.50, 0.12, 0.28],
[ 3.38, -2.48, 0.43, 0.10, 0.25],
[ 4.42, -1.12, 0.29, 0.09, 0.23],
[ 4.40, 1.92, 0.39, 0.11, 0.27],
[ 2.80, 2.55, 0.49, 0.12, 0.32],
[ 0.95, 2.56, 0.41, 0.10, 0.26],
[-1.05, 2.56, 0.53, 0.12, 0.31],
[-2.82, 2.55, 0.45, 0.11, 0.28],
[-4.40, 2.20, 0.35, 0.11, 0.25]
];
for (const [x, z, sx, sy, sz] of moundData) {
const mound = new THREE.Mesh(moundGeometry, sandShadeMaterial);
mound.position.set(x, 0.285, z);
mound.scale.set(sx, sy, sz);
mound.castShadow = true;
mound.receiveShadow = true;
scene.add(mound);
}
// Elevated supply trough
addBox(3.35, 0.16, 0.92, channelMaterial, -3.0, 2.22, -2.55);
addBox(3.35, 0.52, 0.13, channelMaterial, -3.0, 2.45, -2.96);
addBox(3.35, 0.52, 0.13, channelMaterial, -3.0, 2.45, -2.14);
addBox(3.12, 0.055, 0.59, waterMaterial, -3.0, 2.335, -2.55);
// Solid reservoir at the upstream end.
addBox(0.58, 0.76, 0.92, channelMaterial, -1.45, 2.47, -2.55);
addBox(0.43, 0.08, 0.72, waterMaterial, -1.45, 2.88, -2.55);
addBox(0.14, 2.05, 0.18, supportMaterial, -1.92, 1.02, -2.55);
addBox(0.14, 2.05, 0.18, supportMaterial, -4.28, 1.02, -2.55);
// Direction arrows inside the overhead trough.
const arrowGeometry = new THREE.ConeGeometry(0.13, 0.28, 3);
for (const x of [-2.35, -3.78]) {
const arrow = new THREE.Mesh(arrowGeometry, bankMaterial);
arrow.position.set(x, 2.43, -2.55);
arrow.rotation.z = Math.PI / 2;
arrow.castShadow = true;
scene.add(arrow);
}
// The complete illustrative route: trough, open outlet, drop, and meanders.
const channelStart = new THREE.Vector3(-1.70, 2.42, -2.55);
const channelEnd = new THREE.Vector3(-4.52, 2.42, -2.55);
const spoutEnd = new THREE.Vector3(-4.34, 1.48, -1.88);
const trayStart = new THREE.Vector3(-4.18, 0.47, -1.22);
cylinderBetween(
channelEnd,
spoutEnd,
0.21,
channelMaterial,
true
);
const outletDirection = spoutEnd.clone().sub(channelEnd).normalize();
const outletRing = new THREE.Mesh(
new THREE.TorusGeometry(0.205, 0.035, 8, 28),
supportMaterial
);
outletRing.position.copy(spoutEnd);
outletRing.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 0, 1),
outletDirection
);
outletRing.castShadow = true;
scene.add(outletRing);
const dropCurve = new THREE.CatmullRomCurve3([
spoutEnd,
new THREE.Vector3(-4.29, 0.92, -1.57),
trayStart
], false, "centripetal");
const trayCurve = new THREE.CatmullRomCurve3([
trayStart,
new THREE.Vector3(-3.45, 0.47, -0.43),
new THREE.Vector3(-1.80, 0.47, 0.03),
new THREE.Vector3(-0.35, 0.47, -0.50),
new THREE.Vector3( 0.50, 0.47, -1.64),
new THREE.Vector3( 2.20, 0.47, -2.04),
new THREE.Vector3( 3.72, 0.47, -1.23),
new THREE.Vector3( 3.86, 0.47, 0.15),
new THREE.Vector3( 2.74, 0.47, 1.18),
new THREE.Vector3( 0.95, 0.47, 1.74),
new THREE.Vector3(-0.85, 0.47, 1.34),
new THREE.Vector3(-2.48, 0.47, 1.65),
new THREE.Vector3(-3.74, 0.47, 0.94),
new THREE.Vector3(-4.18, 0.47, 0.05)
], false, "centripetal");
const flowPath = new THREE.CurvePath();
flowPath.add(new THREE.LineCurve3(channelStart, channelEnd));
flowPath.add(new THREE.LineCurve3(channelEnd, spoutEnd));
flowPath.add(dropCurve);
flowPath.add(trayCurve);
// Flat ribbon geometry laid over the sand.
function makeRibbon(curve, width, y, mat, segments = 130) {
const positions = [];
const uvs = [];
const indices = [];
for (let i = 0; i <= segments; i++) {
const u = i / segments;
const point = curve.getPointAt(u);
const tangent = curve.getTangentAt(u);
const side = new THREE.Vector3(-tangent.z, 0, tangent.x).normalize();
const left = point.clone().addScaledVector(side, width / 2);
const right = point.clone().addScaledVector(side, -width / 2);
positions.push(
left.x, y, left.z,
right.x, y, right.z
);
uvs.push(0, u, 1, u);
if (i < segments) {
const a = i * 2;
indices.push(a, a + 1, a + 2);
indices.push(a + 1, a + 3, a + 2);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setAttribute(
"uv",
new THREE.Float32BufferAttribute(uvs, 2)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
const mesh = new THREE.Mesh(geometry, mat);
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
makeRibbon(trayCurve, 0.80, 0.344, waterDarkMaterial);
makeRibbon(trayCurve, 0.56, 0.382, waterMaterial);
// Rounded banks along both sides of the route.
function makeBank(sideSign) {
const points = [];
for (let i = 0; i <= 90; i++) {
const u = i / 90;
const point = trayCurve.getPointAt(u);
const tangent = trayCurve.getTangentAt(u);
const side = new THREE.Vector3(-tangent.z, 0, tangent.x).normalize();
point.addScaledVector(side, sideSign * 0.37);
point.y = 0.405;
points.push(point);
}
const bankCurve = new THREE.CatmullRomCurve3(
points,
false,
"centripetal"
);
const bank = new THREE.Mesh(
new THREE.TubeGeometry(bankCurve, 150, 0.065, 7, false),
bankMaterial
);
bank.castShadow = true;
bank.receiveShadow = true;
scene.add(bank);
}
makeBank(1);
makeBank(-1);
// A small stylized drain at the end of the illustrated path.
const drain = new THREE.Mesh(
new THREE.CylinderGeometry(0.29, 0.29, 0.08, 28),
grateMaterial
);
drain.position.set(-4.18, 0.405, 0.05);
drain.castShadow = true;
drain.receiveShadow = true;
scene.add(drain);
for (const angle of [0, Math.PI / 2]) {
const bar = addBox(
0.46, 0.025, 0.035,
supportMaterial,
-4.18, 0.455, 0.05,
false
);
bar.rotation.y = angle;
}
// Canvas-generated labels, using only Three.js core texture support.
function makeLabel(text, accent, position, scale = 2.7) {
const labelCanvas = document.createElement("canvas");
labelCanvas.width = 512;
labelCanvas.height = 128;
const context = labelCanvas.getContext("2d");
context.clearRect(0, 0, 512, 128);
context.fillStyle = "rgba(248, 251, 246, 0.93)";
context.beginPath();
context.roundRect(6, 6, 500, 116, 26);
context.fill();
context.strokeStyle = "rgba(40, 68, 62, 0.16)";
context.lineWidth = 3;
context.stroke();
context.fillStyle = accent;
context.beginPath();
context.arc(45, 64, 12, 0, Math.PI * 2);
context.fill();
context.fillStyle = "#29423d";
context.font = "700 34px system-ui, sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, 278, 66);
const texture = new THREE.CanvasTexture(labelCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.position.copy(position);
sprite.scale.set(scale, scale * 0.25, 1);
sprite.renderOrder = 10;
scene.add(sprite);
}
makeLabel(
"OVERHEAD SUPPLY",
"#e06b57",
new THREE.Vector3(-3.05, 3.20, -2.55),
2.75
);
makeLabel(
"SHALLOW SAND TRAY",
"#4e9cba",
new THREE.Vector3(2.65, 0.95, 3.12),
2.85
);
// Tracer beads
const beadGeometry = new THREE.SphereGeometry(0.105, 16, 12);
const beadMaterials = [
material(0xef6b58, 0.36, 0.05),
material(0xf1b94e, 0.38, 0.05),
material(0x65c4ae, 0.36, 0.05)
];
const beads = [];
const beadCount = 18;
for (let i = 0; i < beadCount; i++) {
const bead = new THREE.Mesh(
beadGeometry,
beadMaterials[i % beadMaterials.length]
);
bead.castShadow = true;
bead.receiveShadow = true;
bead.userData.phase = i / beadCount;
beads.push(bead);
scene.add(bead);
}
let flowTime = 0;
let playing = true;
let speed = Number(speedInput.value);
speedInput.addEventListener("input", () => {
speed = Number(speedInput.value);
});
function setPlaying(value) {
playing = value;
pauseButton.textContent = playing ? "Pause tracers" : "Play tracers";
pauseButton.setAttribute("aria-pressed", String(!playing));
}
pauseButton.addEventListener("click", () => setPlaying(!playing));
restartButton.addEventListener("click", () => {
flowTime = 0;
});
resetViewButton.addEventListener("click", resetView);
window.addEventListener("keydown", (event) => {
if (event.code === "Space" && event.target.tagName !== "INPUT") {
event.preventDefault();
setPlaying(!playing);
}
if (event.key.toLowerCase() === "r" && event.target.tagName !== "INPUT") {
resetView();
}
});
const clock = new THREE.Clock();
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
if (playing) {
flowTime += delta * speed;
}
for (const bead of beads) {
const progress = (
flowTime * 0.055 + bead.userData.phase
) % 1;
bead.position.copy(flowPath.getPointAt(progress));
const shimmer = 1 + Math.sin(flowTime * 3.4 + bead.userData.phase * 19) * 0.035;
bead.scale.setScalar(shimmer);
}
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
animate();
</script>
</body>
</html>
```