Prompt specification
Build or customize the Three.js 3D scene "Two banks and one stepping bridge" 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 banks and one stepping bridge
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/two-banks-and-one-stepping-bridge-x1341
Scene Description Prompt:
I'd like to see this as a stylized Three.js scene: two banks and one stepping bridge. Build two riverbanks connected by a single footbridge. Place two walkers opposite each other and show why their accessible route bends toward the crossing. Use cdnjs and return one self-contained HTML file.
Working Three.js Starter (two-banks-and-one-stepping-bridge-x1341):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>One Bridge — Accessible River Crossing</title>
<style>
:root {
--ink: #253332;
--muted: #667471;
--paper: rgba(250, 248, 241, 0.92);
--accent: #d96f4c;
--accent-dark: #a84732;
--teal: #287b78;
--line: rgba(37, 51, 50, 0.15);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e9e5da;
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;
background: var(--paper);
border: 1px solid rgba(255, 255, 255, 0.72);
box-shadow: 0 14px 40px rgba(49, 57, 53, 0.13);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
}
.title-panel {
top: 22px;
left: 22px;
width: min(420px, calc(100vw - 44px));
padding: 20px 22px 18px;
border-radius: 18px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 9px;
color: var(--teal);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.eyebrow::before {
width: 23px;
height: 2px;
content: "";
background: var(--teal);
border-radius: 2px;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(31px, 4vw, 48px);
font-weight: 500;
line-height: 0.98;
letter-spacing: -0.035em;
}
.title-panel p {
max-width: 355px;
margin: 13px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.controls {
top: 22px;
right: 22px;
display: flex;
align-items: center;
gap: 8px;
padding: 8px;
border-radius: 14px;
}
button {
border: 0;
border-radius: 9px;
padding: 10px 12px;
background: #f0ede4;
color: var(--ink);
font: inherit;
font-size: 12px;
font-weight: 750;
cursor: pointer;
transition: transform 150ms ease, background 150ms ease;
}
button:hover {
transform: translateY(-1px);
background: #e4e0d5;
}
button:focus-visible {
outline: 3px solid rgba(40, 123, 120, 0.25);
outline-offset: 2px;
}
.hint {
position: fixed;
z-index: 9;
right: 24px;
bottom: 22px;
padding: 9px 12px;
border-radius: 10px;
background: rgba(250, 248, 241, 0.76);
color: var(--muted);
font-size: 11px;
font-weight: 650;
letter-spacing: 0.02em;
backdrop-filter: blur(8px);
pointer-events: none;
}
.story {
position: fixed;
z-index: 9;
left: 22px;
bottom: 22px;
display: flex;
align-items: center;
gap: 13px;
max-width: min(540px, calc(100vw - 44px));
padding: 13px 16px;
border-radius: 14px;
background: rgba(250, 248, 241, 0.9);
border: 1px solid rgba(255, 255, 255, 0.68);
box-shadow: 0 10px 30px rgba(49, 57, 53, 0.1);
backdrop-filter: blur(10px);
}
.story-icon {
display: grid;
flex: 0 0 auto;
width: 35px;
height: 35px;
place-items: center;
border-radius: 50%;
background: #dcebe7;
color: var(--teal);
font-size: 18px;
font-weight: 900;
}
.story strong {
display: block;
margin-bottom: 2px;
font-size: 12px;
}
.story span {
display: block;
color: var(--muted);
font-size: 11px;
line-height: 1.4;
}
.label {
position: fixed;
z-index: 8;
top: 0;
left: 0;
transform: translate(-50%, -50%);
padding: 7px 10px;
border: 1px solid rgba(255, 255, 255, 0.75);
border-radius: 9px;
background: rgba(250, 248, 241, 0.94);
box-shadow: 0 5px 16px rgba(38, 48, 45, 0.13);
color: var(--ink);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.055em;
text-transform: uppercase;
white-space: nowrap;
pointer-events: none;
}
.label::before {
display: inline-block;
width: 7px;
height: 7px;
margin-right: 7px;
content: "";
vertical-align: 1px;
border-radius: 50%;
background: var(--accent);
}
.label.bridge::before {
background: var(--teal);
}
.label.blocked {
border-color: rgba(188, 74, 58, 0.25);
color: #923f33;
}
.label.blocked::before {
background: #bd4a3a;
}
.label.soft {
padding: 6px 9px;
color: var(--teal);
}
.label.soft::before {
background: #77a99d;
}
.label.hidden {
display: none;
}
#loading {
position: fixed;
inset: 0;
z-index: 100;
display: grid;
place-items: center;
background: #e9e5da;
color: var(--muted);
font-size: 13px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
transition: opacity 300ms ease;
}
#loading.done {
opacity: 0;
pointer-events: none;
}
@media (max-width: 720px) {
.title-panel {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 15px 17px;
}
.title-panel p {
max-width: none;
font-size: 12px;
}
.controls {
top: auto;
right: 12px;
bottom: 78px;
}
.hint {
display: none;
}
.story {
right: 12px;
bottom: 12px;
left: 12px;
max-width: none;
}
.label {
font-size: 9px;
}
}
</style>
</head>
<body>
<div id="loading">Building the river crossing…</div>
<section class="panel title-panel">
<div class="eyebrow">River crossing study</div>
<h1>One bridge.<br />A gentler route.</h1>
<p>
Two walkers face each other across the river. Their direct alignment has no
crossing, so the accessible route follows the banks, bends toward the
footbridge, and crosses once.
</p>
</section>
<nav class="panel controls" aria-label="Scene controls">
<button id="routeToggle" type="button" aria-pressed="true">Hide route</button>
<button id="resetView" type="button">Reset view</button>
</nav>
<div class="label" id="labelA">Walker A</div>
<div class="label" id="labelB">Walker B</div>
<div class="label bridge" id="labelBridge">Single footbridge</div>
<div class="label soft" id="labelBend">Gentle bank bend</div>
<div class="label blocked" id="labelBlocked">Direct line · no crossing</div>
<aside class="story">
<div class="story-icon" aria-hidden="true">↗</div>
<div>
<strong>Why the route bends</strong>
<span>
A straight crossing is impossible. The path follows the gentler contour
toward the only bridge, then bends back toward Walker B.
</span>
</div>
</aside>
<div class="hint">Drag to orbit · Scroll to zoom</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.createElement("canvas");
document.body.insertBefore(canvas, document.body.firstChild);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe9e5da);
scene.fog = new THREE.Fog(0xe9e5da, 48, 82);
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.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
const camera = new THREE.PerspectiveCamera(
36,
window.innerWidth / window.innerHeight,
0.1,
140
);
const controls = {
target: new THREE.Vector3(0, 0.3, 0),
theta: 0.62,
phi: 0.82,
radius: 42
};
function updateCamera() {
const sinPhi = Math.sin(controls.phi);
camera.position.set(
controls.target.x + controls.radius * sinPhi * Math.sin(controls.theta),
controls.target.y + controls.radius * Math.cos(controls.phi),
controls.target.z + controls.radius * sinPhi * Math.cos(controls.theta)
);
camera.lookAt(controls.target);
}
updateCamera();
const hemi = new THREE.HemisphereLight(0xf8f2df, 0x718078, 2.25);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff2d7, 3.1);
sun.position.set(-12, 24, 13);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -24;
sun.shadow.camera.right = 24;
sun.shadow.camera.top = 22;
sun.shadow.camera.bottom = -22;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 60;
sun.shadow.bias = -0.00035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb7d8d6, 0.8);
fill.position.set(16, 10, -18);
scene.add(fill);
const material = (color, extra = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0,
flatShading: true,
...extra
});
const mats = {
plinth: material(0xd4c8ae),
floor: material(0xe9e5da),
bank: material(0x8fa977),
bankSide: material(0x728d65),
wall: material(0xc5b38f),
water: material(0x4c9fa6, {
roughness: 0.3,
metalness: 0.08,
transparent: true,
opacity: 0.94
}),
path: material(0xe5d5ad, { side: THREE.DoubleSide }),
route: new THREE.MeshBasicMaterial({ color: 0xd96f4c }),
routeTube: new THREE.MeshBasicMaterial({ color: 0xc9573d }),
wood: material(0xb77745),
woodLight: material(0xc99059),
woodDark: material(0x8e5938),
rope: material(0x5e5a43),
trunk: material(0x70513c),
leaf1: material(0x376f58),
leaf2: material(0x4c8464),
leaf3: material(0x739567),
rock: material(0xa7a99b),
reeds: material(0x66865a),
navy: material(0x283f46),
shoe: material(0x34312e),
skin: material(0xc88f67),
backpack: material(0x345b61),
shirtA: material(0x247c78),
shirtB: material(0xd0834e),
white: material(0xf8f4e9),
red: new THREE.MeshBasicMaterial({ color: 0xbd4a3a })
};
function addBox(w, h, d, mat, x, y, z, parent = scene) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(w, h, d), mat);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addCylinderBetween(a, b, radius, mat, parent = scene, radialSegments = 10) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, length, radialSegments),
mat
);
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;
}
// Studio floor and raised diorama base.
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(140, 140),
mats.floor
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -2.03;
floor.receiveShadow = true;
scene.add(floor);
addBox(34, 1.0, 26, mats.plinth, 0, -1.53, 0);
// The two distinct riverbanks.
addBox(11.5, 1.45, 24, mats.bank, -10.25, -0.28, 0);
addBox(11.5, 1.45, 24, mats.bank, 10.25, -0.28, 0);
// Stone retaining faces along the river.
addBox(0.34, 0.9, 24, mats.wall, -4.58, -0.05, 0);
addBox(0.34, 0.9, 24, mats.wall, 4.58, -0.05, 0);
// River surface.
const water = new THREE.Mesh(new THREE.PlaneGeometry(9, 24), mats.water);
water.rotation.x = -Math.PI / 2;
water.position.y = -0.075;
water.receiveShadow = true;
scene.add(water);
// Low riverbank stones.
for (const side of [-1, 1]) {
for (let i = 0; i < 10; i++) {
const z = -10.8 + i * 2.25 + (side === 1 ? 0.25 : -0.1);
if (z > 0.2 && z < 3.7) continue;
const rock = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.28 + (i % 3) * 0.06, 0),
mats.rock
);
rock.position.set(side * (4.22 + (i % 2) * 0.08), 0.05, z);
rock.scale.set(1.25, 0.65, 1);
rock.rotation.set(i * 0.3, i * 0.7, i * 0.15);
rock.castShadow = true;
scene.add(rock);
}
}
// Stylized raised landforms make the route's contour-following shape legible.
const hillSpecs = [
{ x: -12.0, z: 6.2, r: 3.7, h: 0.54, color: 0x789764 },
{ x: -12.5, z: -8.3, r: 3.1, h: 0.48, color: 0x86a16d },
{ x: -8.2, z: 8.3, r: 3.3, h: 0.42, color: 0x91aa72 },
{ x: 12.0, z: 6.2, r: 3.7, h: 0.54, color: 0x789764 },
{ x: 12.5, z: -8.3, r: 3.1, h: 0.48, color: 0x86a16d },
{ x: 8.2, z: 8.3, r: 3.3, h: 0.42, color: 0x91aa72 }
];
for (const spec of hillSpecs) {
const hill = new THREE.Mesh(
new THREE.CylinderGeometry(
spec.r,
spec.r * 1.07,
spec.h,
36
),
material(spec.color)
);
hill.position.set(spec.x, 0.445 + spec.h / 2, spec.z);
hill.scale.z = 0.67;
hill.castShadow = true;
hill.receiveShadow = true;
scene.add(hill);
for (const ratio of [0.64, 0.82]) {
const contour = new THREE.Mesh(
new THREE.TorusGeometry(spec.r * ratio, 0.026, 6, 64),
material(0xa5b982)
);
contour.rotation.x = Math.PI / 2;
contour.position.set(spec.x, 0.45 + spec.h + 0.018, spec.z);
contour.scale.y = 0.67;
scene.add(contour);
}
}
function addTree(x, z, scale = 1, baseY = 0.45, variant = 0) {
const tree = new THREE.Group();
tree.position.set(x, baseY, z);
tree.scale.setScalar(scale);
const trunk = new THREE.Mesh(
new THREE.CylinderGeometry(0.13, 0.18, 1.05, 8),
mats.trunk
);
trunk.position.y = 0.52;
trunk.castShadow = true;
tree.add(trunk);
const leafMats = [mats.leaf1, mats.leaf2, mats.leaf3];
for (let i = 0; i < 3; i++) {
const cone = new THREE.Mesh(
new THREE.ConeGeometry(0.83 - i * 0.17, 1.25, 9),
leafMats[(variant + i) % leafMats.length]
);
cone.position.y = 1.25 + i * 0.55;
cone.rotation.y = i * 0.7;
cone.castShadow = true;
tree.add(cone);
}
scene.add(tree);
}
addTree(-12.1, 6.3, 1.05, 0.99, 0);
addTree(-9.7, 6.9, 0.82, 0.99, 1);
addTree(-13.0, -8.2, 0.95, 0.93, 2);
addTree(-10.7, -8.8, 0.74, 0.93, 0);
addTree(-8.3, 8.2, 0.94, 0.87, 1);
addTree(12.1, 6.3, 1.02, 0.99, 2);
addTree(9.7, 6.9, 0.78, 0.99, 0);
addTree(13.0, -8.2, 0.93, 0.93, 1);
addTree(10.7, -8.8, 0.72, 0.93, 2);
addTree(8.3, 8.2, 0.91, 0.87, 0);
addTree(-14.5, 1.4, 0.74, 0.45, 2);
addTree(14.5, 1.4, 0.74, 0.45, 0);
// Reeds near the water.
for (const side of [-1, 1]) {
for (const z of [-10, -7.7, -3.2, 5.6, 8.1, 10.2]) {
for (let j = 0; j < 3; j++) {
const reed = new THREE.Mesh(
new THREE.CylinderGeometry(0.025, 0.035, 0.55 + j * 0.1, 5),
mats.reeds
);
reed.position.set(
side * (3.95 + j * 0.1),
0.25 + j * 0.05,
z + (j - 1) * 0.1
);
reed.rotation.z = side * (0.12 + j * 0.05);
reed.castShadow = true;
scene.add(reed);
}
}
}
// Small rocks on the grassy banks.
const rockSpots = [
[-14.4, -2.6], [-10.8, 3.6], [-6.5, -7.8], [-13.8, 9.1],
[14.2, -2.4], [10.8, 3.7], [6.5, -7.8], [13.8, 9.1]
];
for (const [x, z] of rockSpots) {
const rock = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.3 + (x % 3) * 0.06, 0),
mats.rock
);
rock.position.set(x, 0.59, z);
rock.scale.y = 0.65;
rock.rotation.set(x, z, x * 0.2);
rock.castShadow = true;
scene.add(rock);
}
// The single footbridge.
const bridge = new THREE.Group();
scene.add(bridge);
addBox(11.0, 0.16, 0.16, mats.woodDark, 0, 0.47, -0.86, bridge);
addBox(11.0, 0.16, 0.16, mats.woodDark, 0, 0.47, 0.86, bridge);
const plankCount = 29;
for (let i = 0; i < plankCount; i++) {
const x = -5.25 + (i / (plankCount - 1)) * 10.5;
const plank = addBox(
0.34,
0.18,
2.32,
i % 3 === 0 ? mats.wood : (i % 2 ? mats.woodLight : mats.wood),
x,
0.64,
2,
bridge
);
plank.rotation.y = (i % 2 ? 1 : -1) * 0.006;
}
// Abutments.
addBox(1.25, 0.75, 2.65, mats.wall, -4.82, 0.25, 2, bridge);
addBox(1.25, 0.75, 2.65, mats.wall, 4.82, 0.25, 2, bridge);
// Rail posts and gently sagging rope rails.
for (const z of [0.87, 3.13]) {
for (let i = 0; i <= 9; i++) {
const x = -5.25 + i * (10.5 / 9);
addBox(0.11, 1.08, 0.11, mats.woodDark, x, 1.18, z, bridge);
addBox(0.17, 0.07, 0.17, mats.woodLight, x, 1.75, z, bridge);
if (i < 9) {
const nextX = x + 10.5 / 9;
for (const height of [1.66, 1.18]) {
const curve = new THREE.CatmullRomCurve3([
new THREE.Vector3(x, height, z),
new THREE.Vector3((x + nextX) / 2, height - 0.13, z),
new THREE.Vector3(nextX, height, z)
]);
const rope = new THREE.Mesh(
new THREE.TubeGeometry(curve, 14, 0.025, 5, false),
mats.rope
);
rope.castShadow = true;
bridge.add(rope);
}
}
}
}
// A small bench at each bridgehead.
function addBench(x, z, rotation) {
const group = new THREE.Group();
group.position.set(x, 0.47, z);
group.rotation.y = rotation;
addBox(1.7, 0.12, 0.55, mats.wood, 0, 0.52, 0, group);
addBox(1.7, 0.55, 0.1, mats.woodLight, 0, 0.85, -0.24, group);
addBox(0.1, 0.55, 0.42, mats.woodDark, -0.65, 0.23, 0, group);
addBox(0.1, 0.55, 0.42, mats.woodDark, 0.65, 0.23, 0, group);
scene.add(group);
}
addBench(-6.2, 3.5, 0);
addBench(6.2, 3.5, 0);
// Flat ribbon generator for the wider bank paths.
function makeRibbon(points, width, mat) {
const curve = new THREE.CatmullRomCurve3(points, false, "centripetal");
const segments = Math.max(60, points.length * 18);
const vertices = [];
const indices = [];
const uvs = [];
for (let i = 0; i <= segments; i++) {
const t = i / segments;
const point = curve.getPoint(t);
const tangent = curve.getTangent(t).normalize();
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);
vertices.push(left.x, left.y, left.z, right.x, right.y, right.z);
uvs.push(0, t, 1, t);
if (i < segments) {
const a = i * 2;
indices.push(a, a + 1, a + 2, a + 1, a + 3, a + 2);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(vertices, 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;
}
const leftPathPoints = [
new THREE.Vector3(-11.0, 0.505, -5.0),
new THREE.Vector3(-9.4, 0.505, -5.8),
new THREE.Vector3(-8.2, 0.505, -3.8),
new THREE.Vector3(-7.0, 0.505, -0.5),
new THREE.Vector3(-6.2, 0.505, 1.5),
new THREE.Vector3(-5.6, 0.53, 2.0),
new THREE.Vector3(-4.8, 0.82, 2.0)
];
const rightPathPoints = [
new THREE.Vector3(4.8, 0.82, 2.0),
new THREE.Vector3(5.6, 0.53, 2.0),
new THREE.Vector3(6.2, 0.505, 1.5),
new THREE.Vector3(7.0, 0.505, -0.5),
new THREE.Vector3(8.2, 0.505, -3.8),
new THREE.Vector3(9.4, 0.505, -5.8),
new THREE.Vector3(11.0, 0.505, -5.0)
];
makeRibbon(leftPathPoints, 1.35, mats.path);
makeRibbon(rightPathPoints, 1.35, mats.path);
// Bright route overlay, arrows, and bridge crossing.
const routeGroup = new THREE.Group();
scene.add(routeGroup);
const leftRoutePoints = leftPathPoints.map((p) =>
new THREE.Vector3(p.x, p.y + 0.075, p.z)
);
const rightRoutePoints = rightPathPoints.map((p) =>
new THREE.Vector3(p.x, p.y + 0.075, p.z)
);
const routeCurves = [
new THREE.CatmullRomCurve3(leftRoutePoints, false, "centripetal"),
new THREE.LineCurve3(
new THREE.Vector3(-4.8, 0.91, 2),
new THREE.Vector3(4.8, 0.91, 2)
),
new THREE.CatmullRomCurve3(rightRoutePoints, false, "centripetal")
];
for (const curve of routeCurves) {
const tube = new THREE.Mesh(
new THREE.TubeGeometry(curve, 90, 0.065, 7, false),
mats.routeTube
);
routeGroup.add(tube);
}
const arrowMaterial = new THREE.MeshBasicMaterial({ color: 0xba4f38 });
const arrowGeometry = new THREE.ConeGeometry(0.16, 0.44, 4);
const up = new THREE.Vector3(0, 1, 0);
function addArrows(curve, values) {
for (const t of values) {
const arrow = new THREE.Mesh(arrowGeometry, arrowMaterial);
const tangent = curve.getTangent(t).normalize();
arrow.quaternion.setFromUnitVectors(up, tangent);
arrow.position.copy(curve.getPoint(t));
arrow.position.y += 0.07;
routeGroup.add(arrow);
}
}
addArrows(routeCurves[0], [0.1, 0.3, 0.52, 0.75, 0.92]);
addArrows(routeCurves[1], [0.18, 0.5, 0.82]);
addArrows(routeCurves[2], [0.1, 0.3, 0.52, 0.75, 0.92]);
// The tempting but impossible direct alignment.
const directGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-11.0, 0.69, -5.0),
new THREE.Vector3(11.0, 0.69, -5.0)
]);
const directMaterial = new THREE.LineDashedMaterial({
color: 0xa95b4d,
dashSize: 0.28,
gapSize: 0.2,
transparent: true,
opacity: 0.62
});
const directLine = new THREE.Line(directGeometry, directMaterial);
directLine.computeLineDistances();
scene.add(directLine);
// Floating blocked-crossing marker.
const blockedMarker = new THREE.Group();
blockedMarker.position.set(0, 1.55, -5);
scene.add(blockedMarker);
const markerDisk = new THREE.Mesh(
new THREE.CircleGeometry(0.62, 40),
mats.white
);
markerDisk.position.z = -0.01;
blockedMarker.add(markerDisk);
const markerRing = new THREE.Mesh(
new THREE.RingGeometry(0.52, 0.62, 40),
mats.red
);
markerRing.position.z = 0.005;
blockedMarker.add(markerRing);
const xBar1 = addBox(0.72, 0.11, 0.035, mats.red, 0, 0, 0.02, blockedMarker);
const xBar2 = addBox(0.72, 0.11, 0.035, mats.red, 0, 0, 0.025, blockedMarker);
xBar1.rotation.z = Math.PI / 4;
xBar2.rotation.z = -Math.PI / 4;
// Stylized walkers, each facing the crossing.
function createWalker(shirtMaterial, facing) {
const group = new THREE.Group();
const leftLeg = addCylinderBetween(
new THREE.Vector3(-0.16, 0.78, 0),
new THREE.Vector3(-0.18, 0.15, 0.04),
0.095,
mats.navy,
group
);
const rightLeg = addCylinderBetween(
new THREE.Vector3(0.16, 0.78, 0),
new THREE.Vector3(0.18, 0.15, -0.03),
0.095,
mats.navy,
group
);
addBox(0.27, 0.15, 0.42, mats.shoe, -0.18, 0.09, 0.09, group);
addBox(0.27, 0.15, 0.42, mats.shoe, 0.18, 0.09, 0.0, group);
const torso = new THREE.Mesh(
new THREE.CylinderGeometry(0.29, 0.37, 0.88, 10),
shirtMaterial
);
torso.position.y = 1.08;
torso.castShadow = true;
group.add(torso);
addCylinderBetween(
new THREE.Vector3(-0.31, 1.4, 0),
new THREE.Vector3(-0.48, 0.84, 0.12),
0.085,
shirtMaterial,
group
);
addCylinderBetween(
new THREE.Vector3(0.31, 1.4, 0),
new THREE.Vector3(0.47, 0.87, 0.1),
0.085,
shirtMaterial,
group
);
const head = new THREE.Mesh(
new THREE.SphereGeometry(0.3, 18, 14),
mats.skin
);
head.position.y = 1.76;
head.castShadow = true;
group.add(head);
const nose = new THREE.Mesh(
new THREE.SphereGeometry(0.075, 10, 8),
mats.skin
);
nose.position.set(0, 1.75, 0.285);
group.add(nose);
const backpack = addBox(
0.5,
0.63,
0.25,
mats.backpack,
0,
1.1,
-0.33,
group
);
backpack.rotation.x = -0.07;
const shadow = new THREE.Mesh(
new THREE.CircleGeometry(0.62, 24),
new THREE.MeshBasicMaterial({
color: 0x263a32,
transparent: true,
opacity: 0.16,
depthWrite: false
})
);
shadow.rotation.x = -Math.PI / 2;
shadow.position.y = 0.012;
group.add(shadow);
group.rotation.y = facing;
group.userData.leftLeg = leftLeg;
group.userData.rightLeg = rightLeg;
scene.add(group);
return group;
}
const walkerA = createWalker(mats.shirtA, Math.atan2(11, 7));
walkerA.position.set(-11, 0.505, -5);
const walkerB = createWalker(mats.shirtB, Math.atan2(-11, 7));
walkerB.position.set(11, 0.505, -5);
// Water ripple rings.
const ripples = [];
const rippleSpots = [
[-2.6, -8.7, 0.65],
[1.8, -3.2, 0.8],
[-1.2, 2.0, 0.55],
[2.7, 7.1, 0.75],
[0.3, 10.0, 0.55]
];
for (const [x, z, radius] of rippleSpots) {
const ring = new THREE.Mesh(
new THREE.TorusGeometry(radius, 0.022, 5, 48),
new THREE.MeshBasicMaterial({
color: 0xd1eeee,
transparent: true,
opacity: 0.38
})
);
ring.rotation.x = Math.PI / 2;
ring.position.set(x, 0.01, z);
ring.scale.z = 0.52;
scene.add(ring);
ripples.push({ ring, phase: Math.random() * Math.PI * 2 });
}
// HTML labels projected from 3D anchor points.
const labelDefinitions = [
{
element: document.getElementById("labelA"),
position: new THREE.Vector3(-11, 2.75, -5)
},
{
element: document.getElementById("labelB"),
position: new THREE.Vector3(11, 2.75, -5)
},
{
element: document.getElementById("labelBridge"),
position: new THREE.Vector3(0, 2.55, 2)
},
{
element: document.getElementById("labelBend"),
position: new THREE.Vector3(-7.2, 1.45, -0.1)
},
{
element: document.getElementById("labelBlocked"),
position: new THREE.Vector3(0, 2.65, -5)
}
];
const projected = new THREE.Vector3();
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const label of labelDefinitions) {
projected.copy(label.position).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.15 &&
projected.x < 1.15 &&
projected.y > -1.15 &&
projected.y < 1.15;
label.element.classList.toggle("hidden", !visible);
if (visible) {
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
label.element.style.left = `${x}px`;
label.element.style.top = `${y}px`;
}
}
}
// Direct camera controls implemented without addons.
let dragging = false;
let previousX = 0;
let previousY = 0;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
controls.theta -= dx * 0.006;
controls.phi = THREE.MathUtils.clamp(
controls.phi - dy * 0.005,
0.35,
1.28
);
updateCamera();
});
function endDrag(event) {
dragging = false;
if (event.pointerId !== undefined && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.radius = THREE.MathUtils.clamp(
controls.radius + event.deltaY * 0.025,
24,
58
);
updateCamera();
},
{ passive: false }
);
document.getElementById("resetView").addEventListener("click", () => {
controls.theta = 0.62;
controls.phi = 0.82;
controls.radius = window.innerWidth < 720 ? 50 : 42;
controls.target.set(0, 0.3, 0);
updateCamera();
});
const routeToggle = document.getElementById("routeToggle");
routeToggle.addEventListener("click", () => {
routeGroup.visible = !routeGroup.visible;
routeToggle.textContent = routeGroup.visible ? "Hide route" : "Show route";
routeToggle.setAttribute("aria-pressed", String(routeGroup.visible));
});
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
if (window.innerWidth < 720) controls.radius = 50;
updateCamera();
const clock = new THREE.Clock();
function animate() {
const elapsed = clock.getElapsedTime();
for (const ripple of ripples) {
const pulse = (Math.sin(elapsed * 1.25 + ripple.phase) + 1) * 0.5;
ripple.ring.scale.set(
0.92 + pulse * 0.22,
0.52 + pulse * 0.1,
1
);
ripple.ring.material.opacity = 0.18 + pulse * 0.22;
}
// Gentle breathing/idle movement keeps the walkers from feeling static.
walkerA.position.y = 0.505 + Math.sin(elapsed * 1.6) * 0.012;
walkerB.position.y = 0.505 + Math.sin(elapsed * 1.6 + 1.3) * 0.012;
walkerA.userData.leftLeg.rotation.z = Math.sin(elapsed * 1.6) * 0.012;
walkerA.userData.rightLeg.rotation.z = -Math.sin(elapsed * 1.6) * 0.012;
walkerB.userData.leftLeg.rotation.z = Math.sin(elapsed * 1.6 + 1.3) * 0.012;
walkerB.userData.rightLeg.rotation.z = -Math.sin(elapsed * 1.6 + 1.3) * 0.012;
blockedMarker.position.y = 1.55 + Math.sin(elapsed * 1.8) * 0.07;
blockedMarker.lookAt(camera.position);
updateLabels();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
animate();
requestAnimationFrame(() => {
document.getElementById("loading").classList.add("done");
setTimeout(() => document.getElementById("loading").remove(), 350);
});
</script>
</body>
</html>
```